<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: onurinanc</title>
    <description>The latest articles on DEV Community by onurinanc (@onurinanc).</description>
    <link>https://dev.to/onurinanc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1220636%2Fb878c25c-3231-4a53-af26-c9d8e2f594ed.jpeg</url>
      <title>DEV Community: onurinanc</title>
      <link>https://dev.to/onurinanc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/onurinanc"/>
    <language>en</language>
    <item>
      <title>Groth16 Verifier in Fe-lang</title>
      <dc:creator>onurinanc</dc:creator>
      <pubDate>Tue, 28 Nov 2023 09:44:23 +0000</pubDate>
      <link>https://dev.to/onurinanc/groth16-verifier-in-fe-lang-1dl6</link>
      <guid>https://dev.to/onurinanc/groth16-verifier-in-fe-lang-1dl6</guid>
      <description>&lt;p&gt;&lt;a href="https://fe-lang.org/"&gt;Fe-lang&lt;/a&gt; is a next generation smart contract language for Ethereum. &lt;/p&gt;

&lt;p&gt;Writing smart contracts in Fe is easy to learn, which is inspired by Python and Rust (but, there won't be a learning curve as Rust). In other words, writing in Fe looks like writing in Rust, but it is easy to write as Python. &lt;/p&gt;

&lt;p&gt;It uses the same intermediate language as Solidity (YUL), which makes a very good choice not only for Ethereum mainnet, but also for the Layer2 solutions.&lt;/p&gt;

&lt;p&gt;By leveraging the EVM compatibility, I have implemented Groth16 Verifier contract in Fe (&lt;a href="https://github.com/fe-lang/fe-crypto"&gt;https://github.com/fe-lang/fe-crypto&lt;/a&gt;). It uses BN254 EVM precompiles in Fe as similar in Solidity.&lt;/p&gt;

&lt;p&gt;Groth16 verifier in fe-lang allows you to verify circom circuits using &lt;a href="https://github.com/iden3/snarkjs"&gt;snarkjs&lt;/a&gt;. Using groth16.fe, you will be able to leverage zero-knowledge proofs with Fe.&lt;/p&gt;

&lt;p&gt;As an example, I write a Circom circuit that you can prove that you know 2 factors of an integer without revealing what the factors are. Here is the simple circuit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pragma circom 2.0.0;

/*This circuit template checks that c is the multiplication of a and b.*/  

template Multiplier2 () {  

   // Declaration of signals.  
   signal input a;  
   signal input b;  
   signal output c;  

   // Constraints.  
   c &amp;lt;== a * b;  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To be able to use the verifier to this circuit, you can follow the steps that is documented &lt;a href="https://github.com/fe-lang/fe-crypto/tree/main/verifiers"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using the specified steps in the above link, you will be able to generate a Verifier.fe file.&lt;/p&gt;

&lt;p&gt;Then, the only thing you need to do is use the &lt;code&gt;verifyProof()&lt;/code&gt; functions in your Fe contract.&lt;/p&gt;

&lt;p&gt;Here is the simple contract that verifies that I know 2 factors of an integer without revealing the factors in &lt;a href="https://github.com/fe-lang/fe-crypto/blob/main/verifiers/src/main.fe"&gt;main.fe&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#test
fn test_verify_proof() {
    let verification: bool = verifyProof(
        a: [0x28930e0aeb50e7e3b5f9a54a6abdce99978e00701914dfd4d87f8dc5ea9e1d02, 0x02c1e99774e679c144aceac4e9fdbc67dc858533d9f49c5933939c89010131b7],
        b: [[0x0684d8357689fb95e886a8251db0e142ffdda8032e314750455b9f5ff13159ca, 0x26189ebc171412019704e808c432062721db66c4a22635f20ed422a2147ad5bf], [0x005d309291fd34bef6248c17779114907b6d912a5a02ddae46d902dbd05e2e1c, 0x01673b4a2e94569e28e23a9ae808b9f92b4d21beca07522f79d16ec419a6e85c]],
        c: [0x25170145c09315e2df3c93d155b39df35434469607b0121a16125224190a596a, 0x05467081343913d54408694735a8d149578e7cbb3168f2b4283a7fe2861a7a42],
        input: [0x0000000000000000000000000000000000000000000000000000000000000021]
    )

    assert verification == true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all! The verification is correct in Fe.&lt;/p&gt;

&lt;p&gt;I also created &lt;a href="https://github.com/fe-lang/fe-crypto/blob/main/crypto/src/curve/bn254.fe"&gt;bn254.fe library&lt;/a&gt; that you can use the precompiles more easily.&lt;/p&gt;

&lt;p&gt;Fe is currently a developing language to write smart contracts. It is designed to be safe, and helps you to write clean code without getting rid of compile-time guarantees. Further, you can see the links below to discover Fe yourself.&lt;/p&gt;

&lt;p&gt;Explore some advanced contracts written in Fe: &lt;a href="https://github.com/ethereum/fe/tree/master/crates/test-files/fixtures/demos"&gt;https://github.com/ethereum/fe/tree/master/crates/test-files/fixtures/demos&lt;/a&gt;&lt;br&gt;
Fe-lang: &lt;a href="https://fe-lang.org/"&gt;https://fe-lang.org/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ethereum</category>
      <category>circom</category>
      <category>smartcontract</category>
      <category>felang</category>
    </item>
  </channel>
</rss>
