Skip to content

Commit

Permalink
Interface update #81 nil-foundation/zkllvm-transpiler#45 (#82)
Browse files Browse the repository at this point in the history
* Interface update #81 nil-foundation/zkllvm-transpiler#45

* updated example circuits to new interface #81

* cleanup #81 NilFoundation/zkllvm-transpiler#45

* modular_verifier interface update, added eta value checks #81 NilFoundation/zkllvm-transpiler#46
  • Loading branch information
vo-nil committed Nov 10, 2023
1 parent 0ccfe55 commit b3e6349
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 24 deletions.
4 changes: 2 additions & 2 deletions contracts/interfaces/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ interface IModularVerifier {
address commitment_contract_address
) external;

function verify(
function verify(
bytes calldata blob,
uint256[] calldata public_input
) external view;
) external view returns (bool result);
}
38 changes: 36 additions & 2 deletions contracts/zkllvm/circuit1/commitment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ library modular_commitment_scheme_circuit1 {
uint256 constant unique_points = 4;
uint256 constant permutation_point = 2;
uint256 constant quotient_point = 0;
uint256 constant lookup_point = 140731511355664;
uint256 constant lookup_point = 0;
bytes constant points_ids = hex"01010101010101010303010100000000";
uint256 constant omega = 14450201850503471296781915119640920297985789873634237091629829669980153907901;
uint256 constant _etha = 14062721881273474090606415031361994540585550571695842571456013353340629726555;
Expand Down Expand Up @@ -421,6 +421,40 @@ library modular_commitment_scheme_circuit1 {
types.transcript_data memory tr_state;
tr_state.current_challenge = transcript_state;
commitment_state memory state;

{
uint256 poly_at_eta;
/* 1 - 2*permutation_size */
poly_at_eta = basic_marshalling.get_uint256_be(blob, 40);// 0
if(poly_at_eta != 0x1f1737f0f9693494b37fd517f70fe4d844c0e4dd11e9df8639a0be9abfccb55b) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x68);// 0x1
if(poly_at_eta != 0x1b7417b4df0e06e7817f2977d34f78391337465946f76b67edc9572bbeff8ac5) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0xa8);// 0x2
if(poly_at_eta != 0x94476885b462285877bcf57208d591d1b872dc6503b26d072945200bafdb5d7) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0xe8);// 0x3
if(poly_at_eta != 0x2e5650a9c85eac9ba56b0cb3a2c2bd9189a3e4df9127c2123ce59a03a6f48d33) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x128);// 0x4
if(poly_at_eta != 0x1f1737f0f9693494b37fd517f70fe4d844c0e4dd11e9df8639a0be9abfccb55b) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x168);// 0x5
if(poly_at_eta != 0x1b7417b4df0e06e7817f2977d34f78391337465946f76b67edc9572bbeff8ac5) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x1a8);// 0x6
if(poly_at_eta != 0x94476885b462285877bcf57208d591d1b872dc6503b26d072945200bafdb5d7) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x1e8);// 0x7
if(poly_at_eta != 0x2e5650a9c85eac9ba56b0cb3a2c2bd9189a3e4df9127c2123ce59a03a6f48d33) return false;
/* 2 - special selectors */
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x248);// 0x8
if(poly_at_eta != 0xf3114c664f481e6028c47f122b53b12f6aa455ea26f54aad80ad778950b2177) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x2a8);// 0x9
if(poly_at_eta != 0x2acd90c58b8637d005a76e69a474de1cc5f432a41724e855b2a0b19b71a52150) return false;
/* 3 - constant columns */
/* 4 - selector columns */
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x2e8);// 0xa
if(poly_at_eta != 0x277b3d077e65208b010bc2f62957e87b900bd1f007ef61acf14649463be06cbb) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x328);// 0xb
if(poly_at_eta != 0x308efe88baf9b3bc3787b68d279234d783ef3e4064de84b20dc2a1d72eb2e0e3) return false;
}


{
uint256 offset;

Expand Down Expand Up @@ -591,4 +625,4 @@ library modular_commitment_scheme_circuit1 {
return true;
}
}


4 changes: 3 additions & 1 deletion contracts/zkllvm/circuit1/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ contract modular_verifier_circuit1 is IModularVerifier{
function verify(
bytes calldata blob,
uint256[] calldata public_input
) public view{
) public view returns (bool result) {
verifier_state memory state;
state.b = true;
state.gas = gasleft();
Expand Down Expand Up @@ -164,6 +164,7 @@ contract modular_verifier_circuit1 is IModularVerifier{
state.F[2] = permutation_argument[2];
}

//4. Lookup library call
//No lookups

//5. Push permutation batch to transcript
Expand Down Expand Up @@ -239,6 +240,7 @@ contract modular_verifier_circuit1 is IModularVerifier{
}

console.log("Gas for verification:", state.gas-gasleft());
result = state.b;
}
}

38 changes: 36 additions & 2 deletions contracts/zkllvm/circuit2/commitment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ library modular_commitment_scheme_circuit2 {
uint256 constant unique_points = 5;
uint256 constant permutation_point = 3;
uint256 constant quotient_point = 1;
uint256 constant lookup_point = 140731511355584;
uint256 constant lookup_point = 0;
bytes constant points_ids = hex"02020202020202020404020200010101";
uint256 constant omega = 14788168760825820622209131888203028446852016562542525606630160374691593895118;
uint256 constant _etha = 12217208067492249031102872072655908974751031861422067257283053495957748658893;
Expand Down Expand Up @@ -424,6 +424,40 @@ library modular_commitment_scheme_circuit2 {
types.transcript_data memory tr_state;
tr_state.current_challenge = transcript_state;
commitment_state memory state;

{
uint256 poly_at_eta;
/* 1 - 2*permutation_size */
poly_at_eta = basic_marshalling.get_uint256_be(blob, 40);// 0
if(poly_at_eta != 0x1b02b1d914ea72056989679d7826ca1f9adbc9880002cf6daffb7f1fa3b332cd) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x68);// 0x1
if(poly_at_eta != 0x4925359c68cba0ddaf87fd463f6daed7e844deb500155000cfe079de79e6639a) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0xa8);// 0x2
if(poly_at_eta != 0x304dd9fa371b70eeffd08ccb957867d20aeb86e7009bc009af235519554cb932) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0xe8);// 0x3
if(poly_at_eta != 0x6a45a7312e851bf898402981030726b3a4f5684b04458845c9f753b35519105c) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x128);// 0x4
if(poly_at_eta != 0x1b02b1d914ea72056989679d7826ca1f9adbc9880002cf6daffb7f1fa3b332cd) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x168);// 0x5
if(poly_at_eta != 0x3d9bd931d08eee60195862ede438d303f80e10fc9093f2a0920d1f3d2bed12c9) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x1a8);// 0x6
if(poly_at_eta != 0x5d118568c35ccff0c8e14aeb77fcd0a05ba585f78d646348b66c554b10625e60) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x1e8);// 0x7
if(poly_at_eta != 0x3a68771f10abc9d88dbdf7ce531cd3044141f573048011fdb1b76e4ec34435a6) return false;
/* 2 - special selectors */
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x248);// 0x8
if(poly_at_eta != 0x3f1b4adcabfaa14cf2ee7ec3990f58d91ae75bfaaefe1327313d89eb23baf96f) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x2a8);// 0x9
if(poly_at_eta != 0x662761bdeda7376d374c58b68475ecfa30064120c27daa97edfbda94eecaeaff) return false;
/* 3 - constant columns */
/* 4 - selector columns */
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x2e8);// 0xa
if(poly_at_eta != 0x369369e984155e5f975bd41103c801ea569e500244152d768985604be0800b06) return false;
poly_at_eta = basic_marshalling.get_uint256_be(blob, 0x328);// 0xb
if(poly_at_eta != 0x3cd3d24de7686966f8fa3577ea539d516c0a16d46d0e2c283db58b157952ca53) return false;
}


{
uint256 offset;

Expand Down Expand Up @@ -589,4 +623,4 @@ library modular_commitment_scheme_circuit2 {
return true;
}
}


4 changes: 3 additions & 1 deletion contracts/zkllvm/circuit2/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ contract modular_verifier_circuit2 is IModularVerifier{
function verify(
bytes calldata blob,
uint256[] calldata public_input
) public view{
) public view returns (bool result) {
verifier_state memory state;
state.b = true;
state.gas = gasleft();
Expand Down Expand Up @@ -164,6 +164,7 @@ contract modular_verifier_circuit2 is IModularVerifier{
state.F[2] = permutation_argument[2];
}

//4. Lookup library call
//No lookups

//5. Push permutation batch to transcript
Expand Down Expand Up @@ -239,6 +240,7 @@ contract modular_verifier_circuit2 is IModularVerifier{
}

console.log("Gas for verification:", state.gas-gasleft());
result = state.b;
}
}

Loading

0 comments on commit b3e6349

Please sign in to comment.