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 5 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
39 changes: 37 additions & 2 deletions contracts/interfaces/modular_verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,51 @@
//---------------------------------------------------------------------------//
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 table does not satisfy constraint system
*/
event ConstraintSystemNotSatisfied();

/**
* @dev Emitted when proof is verified
*/
event ProofVerified();

/**
* @dev Emitted when proof verification failed
*/
event ProofVerificationFailed();


/**
* @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);
}
18 changes: 9 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,16 @@ 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!");
if(state.b) {
emit ProofVerified();
} else {
emit ProofVerificationFailed();
}
}

console.log("Gas for verification:", state.gas-gasleft());
result = state.b;
}
}
Expand Down
18 changes: 9 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,16 @@ 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!");
if(state.b) {
emit ProofVerified();
} else {
emit ProofVerificationFailed();
}
}

console.log("Gas for verification:", state.gas-gasleft());
result = state.b;
}
}
Expand Down
18 changes: 9 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,16 @@ 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!");
if(state.b) {
emit ProofVerified();
} else {
emit ProofVerificationFailed();
}
}

console.log("Gas for verification:", state.gas-gasleft());
result = state.b;
}
}
Expand Down
18 changes: 9 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,16 @@ 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!");
if(state.b) {
emit ProofVerified();
} else {
emit ProofVerificationFailed();
}
}

console.log("Gas for verification:", state.gas-gasleft());
result = state.b;
}
}
Expand Down
18 changes: 9 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,16 @@ 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!");
if(state.b) {
emit ProofVerified();
} else {
emit ProofVerificationFailed();
}
}

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