Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

86 add error events #88

Merged
merged 8 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contracts/interfaces/modular_commitment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pragma solidity >=0.8.4;
import "../types.sol";

interface ICommitmentScheme {

function initialize(
bytes32 tr_state_before
) external returns(bytes32 tr_state_after);
Expand All @@ -31,4 +32,4 @@ interface ICommitmentScheme {
uint256 challenge,
bytes32 transcript_state_before
) external view returns (bool);
}
}
38 changes: 36 additions & 2 deletions contracts/interfaces/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,50 @@
//---------------------------------------------------------------------------//
pragma solidity ^0.8.0;

/**
* @dev Interface class to verify Placeholder proof
*/
interface IModularVerifier {

/**
* @dev Emitted when public input is wrong
*/
event WrongPublicInput();

/**
* @dev Emitted when commitment is wrong
*/
event WrongCommitment();

/**
* @dev Emitted when proof does not contain valid eta point values
*/
event WrongEtaPointValues();

/**
* @dev Emitted when table does not satisfy constraint system
*/
event ConstraintSystemNotSatisfied();

/**
* @dev Emitted when proof verification completed
*/
event VerificationResult(bool result);

/**
* @dev Initializes verifier
*/
function initialize(
// address permutation_argument_contract_address,
address lookup_argument_contract_address,
address gate_argument_contract_address,
address commitment_contract_address
) external;

/**
* @dev Verifies proof
*/
function verify(
bytes calldata blob,
uint256[] calldata public_input
) external view returns (bool result);
) external returns (bool result);
}
15 changes: 6 additions & 9 deletions contracts/zkllvm/circuit1/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ contract modular_verifier_circuit1 is IModularVerifier{
uint256 Z_at_xi;
uint256 l0;
uint256[f_parts] F;
uint256 gas;
bool b;
}

Expand Down Expand Up @@ -124,10 +123,9 @@ contract modular_verifier_circuit1 is IModularVerifier{
function verify(
bytes calldata blob,
uint256[] calldata public_input
) public view returns (bool result) {
) public returns (bool result) {
verifier_state memory state;
state.b = true;
state.gas = gasleft();
state.xi = basic_marshalling.get_uint256_be(blob, 0x79);
state.Z_at_xi = addmod(field.pow_small(state.xi, rows_amount, modulus), modulus-1, modulus);
state.l0 = mulmod(
Expand All @@ -139,7 +137,7 @@ contract modular_verifier_circuit1 is IModularVerifier{
//0. Direct public input check
if(public_input.length > 0) {
if (!public_input_direct(blob[865:865+320], public_input, state)) {
console.log("Wrong public input!");
emit WrongPublicInput();
state.b = false;
}
}
Expand Down Expand Up @@ -198,7 +196,6 @@ contract modular_verifier_circuit1 is IModularVerifier{
F_consolidated = addmod(F_consolidated, mulmod(state.F[i],transcript.get_field_challenge(tr_state, modulus), modulus), modulus);
unchecked{i++;}
}
uint256 points_num = basic_marshalling.get_length(blob, 0x79 + 0x20);
transcript.update_transcript_b32_by_offset_calldata(tr_state, blob, 0x59);
}

Expand All @@ -214,7 +211,7 @@ contract modular_verifier_circuit1 is IModularVerifier{
if(!modular_commitment_scheme_circuit1.verify_eval(
blob[z_offset - 0x8:], commitments, state.xi, tr_state.current_challenge
)) {
console.log("Error from commitment scheme!");
emit WrongCommitment();
state.b = false;
}
}
Expand All @@ -233,13 +230,13 @@ contract modular_verifier_circuit1 is IModularVerifier{
unchecked{i++;}
}
if( F_consolidated != mulmod(T_consolidated, state.Z_at_xi, modulus) ) {
console.log("Error. Table does't satisfy constraint system");
emit ConstraintSystemNotSatisfied();
state.b = false;
}
if(state.b) console.log("SUCCESS!"); else console.log("FAILURE!");
}

console.log("Gas for verification:", state.gas-gasleft());
emit VerificationResult(state.b);

result = state.b;
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/zkllvm/circuit1/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"17166126583027276163107155648953851600645935739886150467584901586847365754678"
],
"grinding_params": {
"mask": "4294934528"
"mask": "4294901760"
}
}
}
15 changes: 6 additions & 9 deletions contracts/zkllvm/circuit2/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ contract modular_verifier_circuit2 is IModularVerifier{
uint256 Z_at_xi;
uint256 l0;
uint256[f_parts] F;
uint256 gas;
bool b;
}

Expand Down Expand Up @@ -124,10 +123,9 @@ contract modular_verifier_circuit2 is IModularVerifier{
function verify(
bytes calldata blob,
uint256[] calldata public_input
) public view returns (bool result) {
) public returns (bool result) {
verifier_state memory state;
state.b = true;
state.gas = gasleft();
state.xi = basic_marshalling.get_uint256_be(blob, 0x79);
state.Z_at_xi = addmod(field.pow_small(state.xi, rows_amount, modulus), modulus-1, modulus);
state.l0 = mulmod(
Expand All @@ -139,7 +137,7 @@ contract modular_verifier_circuit2 is IModularVerifier{
//0. Direct public input check
if(public_input.length > 0) {
if (!public_input_direct(blob[865:865+352], public_input, state)) {
console.log("Wrong public input!");
emit WrongPublicInput();
state.b = false;
}
}
Expand Down Expand Up @@ -198,7 +196,6 @@ contract modular_verifier_circuit2 is IModularVerifier{
F_consolidated = addmod(F_consolidated, mulmod(state.F[i],transcript.get_field_challenge(tr_state, modulus), modulus), modulus);
unchecked{i++;}
}
uint256 points_num = basic_marshalling.get_length(blob, 0x79 + 0x20);
transcript.update_transcript_b32_by_offset_calldata(tr_state, blob, 0x59);
}

Expand All @@ -214,7 +211,7 @@ contract modular_verifier_circuit2 is IModularVerifier{
if(!modular_commitment_scheme_circuit2.verify_eval(
blob[z_offset - 0x8:], commitments, state.xi, tr_state.current_challenge
)) {
console.log("Error from commitment scheme!");
emit WrongCommitment();
state.b = false;
}
}
Expand All @@ -233,13 +230,13 @@ contract modular_verifier_circuit2 is IModularVerifier{
unchecked{i++;}
}
if( F_consolidated != mulmod(T_consolidated, state.Z_at_xi, modulus) ) {
console.log("Error. Table does't satisfy constraint system");
emit ConstraintSystemNotSatisfied();
state.b = false;
}
if(state.b) console.log("SUCCESS!"); else console.log("FAILURE!");
}

console.log("Gas for verification:", state.gas-gasleft());
emit VerificationResult(state.b);

result = state.b;
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/zkllvm/circuit2/proof.bin

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions contracts/zkllvm/circuit3/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ contract modular_verifier_circuit3 is IModularVerifier{
uint256 Z_at_xi;
uint256 l0;
uint256[f_parts] F;
uint256 gas;
bool b;
}

Expand Down Expand Up @@ -124,10 +123,9 @@ contract modular_verifier_circuit3 is IModularVerifier{
function verify(
bytes calldata blob,
uint256[] calldata public_input
) public view returns (bool result) {
) public returns (bool result) {
verifier_state memory state;
state.b = true;
state.gas = gasleft();
state.xi = basic_marshalling.get_uint256_be(blob, 0xa1);
state.Z_at_xi = addmod(field.pow_small(state.xi, rows_amount, modulus), modulus-1, modulus);
state.l0 = mulmod(
Expand All @@ -139,7 +137,7 @@ contract modular_verifier_circuit3 is IModularVerifier{
//0. Direct public input check
if(public_input.length > 0) {
if (!public_input_direct(blob[905:905+672], public_input, state)) {
console.log("Wrong public input!");
emit WrongPublicInput();
state.b = false;
}
}
Expand Down Expand Up @@ -216,7 +214,6 @@ contract modular_verifier_circuit3 is IModularVerifier{
F_consolidated = addmod(F_consolidated, mulmod(state.F[i],transcript.get_field_challenge(tr_state, modulus), modulus), modulus);
unchecked{i++;}
}
uint256 points_num = basic_marshalling.get_length(blob, 0xa1 + 0x20);
transcript.update_transcript_b32_by_offset_calldata(tr_state, blob, 0x59);
}

Expand All @@ -232,7 +229,7 @@ contract modular_verifier_circuit3 is IModularVerifier{
if(!modular_commitment_scheme_circuit3.verify_eval(
blob[z_offset - 0x8:], commitments, state.xi, tr_state.current_challenge
)) {
console.log("Error from commitment scheme!");
emit WrongCommitment();
state.b = false;
}
}
Expand All @@ -251,13 +248,13 @@ contract modular_verifier_circuit3 is IModularVerifier{
unchecked{i++;}
}
if( F_consolidated != mulmod(T_consolidated, state.Z_at_xi, modulus) ) {
console.log("Error. Table does't satisfy constraint system");
emit ConstraintSystemNotSatisfied();
state.b = false;
}
if(state.b) console.log("SUCCESS!"); else console.log("FAILURE!");
}

console.log("Gas for verification:", state.gas-gasleft());
emit VerificationResult(state.b);

result = state.b;
}
}
Expand Down
15 changes: 6 additions & 9 deletions contracts/zkllvm/circuit4/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ contract modular_verifier_circuit4 is IModularVerifier{
uint256 Z_at_xi;
uint256 l0;
uint256[f_parts] F;
uint256 gas;
bool b;
}

Expand Down Expand Up @@ -124,10 +123,9 @@ contract modular_verifier_circuit4 is IModularVerifier{
function verify(
bytes calldata blob,
uint256[] calldata public_input
) public view returns (bool result) {
) public returns (bool result) {
verifier_state memory state;
state.b = true;
state.gas = gasleft();
state.xi = basic_marshalling.get_uint256_be(blob, 0xa1);
state.Z_at_xi = addmod(field.pow_small(state.xi, rows_amount, modulus), modulus-1, modulus);
state.l0 = mulmod(
Expand All @@ -139,7 +137,7 @@ contract modular_verifier_circuit4 is IModularVerifier{
//0. Direct public input check
if(public_input.length > 0) {
if (!public_input_direct(blob[905:905+736], public_input, state)) {
console.log("Wrong public input!");
emit WrongPublicInput();
state.b = false;
}
}
Expand Down Expand Up @@ -216,7 +214,6 @@ contract modular_verifier_circuit4 is IModularVerifier{
F_consolidated = addmod(F_consolidated, mulmod(state.F[i],transcript.get_field_challenge(tr_state, modulus), modulus), modulus);
unchecked{i++;}
}
uint256 points_num = basic_marshalling.get_length(blob, 0xa1 + 0x20);
transcript.update_transcript_b32_by_offset_calldata(tr_state, blob, 0x59);
}

Expand All @@ -232,7 +229,7 @@ contract modular_verifier_circuit4 is IModularVerifier{
if(!modular_commitment_scheme_circuit4.verify_eval(
blob[z_offset - 0x8:], commitments, state.xi, tr_state.current_challenge
)) {
console.log("Error from commitment scheme!");
emit WrongCommitment();
state.b = false;
}
}
Expand All @@ -251,13 +248,13 @@ contract modular_verifier_circuit4 is IModularVerifier{
unchecked{i++;}
}
if( F_consolidated != mulmod(T_consolidated, state.Z_at_xi, modulus) ) {
console.log("Error. Table does't satisfy constraint system");
emit ConstraintSystemNotSatisfied();
state.b = false;
}
if(state.b) console.log("SUCCESS!"); else console.log("FAILURE!");
}

console.log("Gas for verification:", state.gas-gasleft());
emit VerificationResult(state.b);

result = state.b;
}
}
Expand Down
15 changes: 6 additions & 9 deletions contracts/zkllvm/circuit6/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ contract modular_verifier_circuit6 is IModularVerifier{
uint256 Z_at_xi;
uint256 l0;
uint256[f_parts] F;
uint256 gas;
bool b;
}

Expand Down Expand Up @@ -124,10 +123,9 @@ contract modular_verifier_circuit6 is IModularVerifier{
function verify(
bytes calldata blob,
uint256[] calldata public_input
) public view returns (bool result) {
) public returns (bool result) {
verifier_state memory state;
state.b = true;
state.gas = gasleft();
state.xi = basic_marshalling.get_uint256_be(blob, 0xa1);
state.Z_at_xi = addmod(field.pow_small(state.xi, rows_amount, modulus), modulus-1, modulus);
state.l0 = mulmod(
Expand All @@ -139,7 +137,7 @@ contract modular_verifier_circuit6 is IModularVerifier{
//0. Direct public input check
if(public_input.length > 0) {
if (!public_input_direct(blob[905:905+736], public_input, state)) {
console.log("Wrong public input!");
emit WrongPublicInput();
state.b = false;
}
}
Expand Down Expand Up @@ -216,7 +214,6 @@ contract modular_verifier_circuit6 is IModularVerifier{
F_consolidated = addmod(F_consolidated, mulmod(state.F[i],transcript.get_field_challenge(tr_state, modulus), modulus), modulus);
unchecked{i++;}
}
uint256 points_num = basic_marshalling.get_length(blob, 0xa1 + 0x20);
transcript.update_transcript_b32_by_offset_calldata(tr_state, blob, 0x59);
}

Expand All @@ -232,7 +229,7 @@ contract modular_verifier_circuit6 is IModularVerifier{
if(!modular_commitment_scheme_circuit6.verify_eval(
blob[z_offset - 0x8:], commitments, state.xi, tr_state.current_challenge
)) {
console.log("Error from commitment scheme!");
emit WrongCommitment();
state.b = false;
}
}
Expand All @@ -251,13 +248,13 @@ contract modular_verifier_circuit6 is IModularVerifier{
unchecked{i++;}
}
if( F_consolidated != mulmod(T_consolidated, state.Z_at_xi, modulus) ) {
console.log("Error. Table does't satisfy constraint system");
emit ConstraintSystemNotSatisfied();
state.b = false;
}
if(state.b) console.log("SUCCESS!"); else console.log("FAILURE!");
}

console.log("Gas for verification:", state.gas-gasleft());
emit VerificationResult(state.b);

result = state.b;
}
}
Expand Down
Loading