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

Introduce verify_all_proofs and update integration tests #192

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 26 additions & 5 deletions evm_arithmetization/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,32 @@ fn verify_initial_memory<
Ok(())
}

pub fn verify_proof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>(
pub fn verify_all_proofs<
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather put this in a testing module, similarly to prove_all_segments as it isn't aimed to be used outside of testing.

F: RichField + Extendable<D>,
C: GenericConfig<D, F = F>,
const D: usize,
>(
all_stark: &AllStark<F, D>,
all_proofs: &[AllProof<F, C, D>],
config: &StarkConfig,
) -> Result<()> {
assert!(!all_proofs.is_empty());

verify_proof(all_stark, all_proofs[0].clone(), config, true)?;

for all_proof in &all_proofs[1..] {
verify_proof(all_stark, all_proof.clone(), config, false)?;
}

Ok(())
}

fn verify_proof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>(
all_stark: &AllStark<F, D>,
all_proof: AllProof<F, C, D>,
config: &StarkConfig,
) -> Result<()>
where
{
is_initial: bool,
) -> Result<()> {
let AllProofChallenges {
stark_challenges,
ctl_challenges,
Expand Down Expand Up @@ -232,7 +251,9 @@ where
let public_values = all_proof.public_values;

// Verify shift table and kernel code.
verify_initial_memory::<F, C, D>(&public_values, config)?;
if is_initial {
verify_initial_memory::<F, C, D>(&public_values, config)?;
}

// Extra sums to add to the looked last value.
// Only necessary for the Memory values.
Expand Down
17 changes: 12 additions & 5 deletions evm_arithmetization/tests/add11_yml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use ethereum_types::{Address, BigEndianHash, H256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp};
use evm_arithmetization::generation::TrieInputs;
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, GenerationInputs, Node};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -183,14 +183,21 @@ fn add11_yml() -> anyhow::Result<()> {
let inputs = get_generation_inputs();

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);

let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;
let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn init_logger() {
Expand Down
18 changes: 13 additions & 5 deletions evm_arithmetization/tests/basic_smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use evm_arithmetization::cpu::kernel::opcodes::{get_opcode, get_push_opcode};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -199,13 +199,21 @@ fn test_basic_smart_contract() -> anyhow::Result<()> {
};

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;

let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn eth_to_wei(eth: U256) -> U256 {
Expand Down
19 changes: 13 additions & 6 deletions evm_arithmetization/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use ethereum_types::{Address, BigEndianHash, H160, H256, U256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp, LogRlp};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -175,13 +175,20 @@ fn test_erc20() -> anyhow::Result<()> {
};

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;

let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn init_logger() {
Expand Down
18 changes: 12 additions & 6 deletions evm_arithmetization/tests/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use ethereum_types::{Address, BigEndianHash, H160, H256, U256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp, LogRlp};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -176,15 +176,21 @@ fn test_erc721() -> anyhow::Result<()> {
},
};

let max_cpu_len_log = 20;
let mut timing = TimingTree::new("prove", log::Level::Debug);

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;
let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;
timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn init_logger() {
Expand Down
28 changes: 12 additions & 16 deletions evm_arithmetization/tests/log_opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use evm_arithmetization::generation::mpt::transaction_testing::{
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp, LogRlp};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllRecursiveCircuits, AllStark, Node, StarkConfig};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -237,24 +237,20 @@ fn test_log_opcodes() -> anyhow::Result<()> {
};

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;
timing.filter(Duration::from_millis(100)).print();

// Assert that the proof leads to the correct state and receipt roots.
assert_eq!(
proof.public_values.trie_roots_after.state_root,
expected_state_trie_after.hash()
);
let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

assert_eq!(
proof.public_values.trie_roots_after.receipts_root,
receipts_trie.hash()
);
timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

// Tests proving two transactions, one of which with logs, and aggregating them.
Expand Down
19 changes: 13 additions & 6 deletions evm_arithmetization/tests/self_balance_gas_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use ethereum_types::{Address, H256, U256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -186,13 +186,20 @@ fn self_balance_gas_cost() -> anyhow::Result<()> {
};

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;

let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn init_logger() {
Expand Down
19 changes: 13 additions & 6 deletions evm_arithmetization/tests/selfdestruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use ethereum_types::{Address, BigEndianHash, H256, U256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -138,13 +138,20 @@ fn test_selfdestruct() -> anyhow::Result<()> {
};

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;

let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn eth_to_wei(eth: U256) -> U256 {
Expand Down
19 changes: 13 additions & 6 deletions evm_arithmetization/tests/simple_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use ethereum_types::{Address, BigEndianHash, H256, U256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp};
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use hex_literal::hex;
use keccak_hash::keccak;
Expand Down Expand Up @@ -154,13 +154,20 @@ fn test_simple_transfer() -> anyhow::Result<()> {
};

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;

let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn eth_to_wei(eth: U256) -> U256 {
Expand Down
19 changes: 13 additions & 6 deletions evm_arithmetization/tests/withdrawals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use ethereum_types::{H160, H256, U256};
use evm_arithmetization::generation::mpt::AccountRlp;
use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::{generate_all_data_segments, prove};
use evm_arithmetization::verifier::verify_proof;
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::verifier::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
Expand Down Expand Up @@ -83,13 +83,20 @@ fn test_withdrawals() -> anyhow::Result<()> {
};

let max_cpu_len_log = 20;
let mut data = generate_all_data_segments::<F>(Some(max_cpu_len_log), &inputs)?;

let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut data[0], &mut timing, None)?;

let proofs = prove_all_segments::<F, C, D>(
&all_stark,
&config,
inputs,
max_cpu_len_log,
&mut timing,
None,
)?;

timing.filter(Duration::from_millis(100)).print();

verify_proof(&all_stark, proof, &config)
verify_all_proofs(&all_stark, &proofs, &config)
}

fn init_logger() {
Expand Down