Skip to content

Commit

Permalink
Cleanup types (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored Sep 23, 2024
1 parent f6ce57b commit 00a998c
Show file tree
Hide file tree
Showing 30 changed files with 165 additions and 186 deletions.
5 changes: 2 additions & 3 deletions evm_arithmetization/benches/fibonacci_25m_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ use evm_arithmetization::testing_utils::{
beacon_roots_account_nibbles, beacon_roots_contract_from_storage,
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use evm_arithmetization::Node;
use evm_arithmetization::{Node, EMPTY_CONSOLIDATED_BLOCKHASH};
use hex_literal::hex;
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;

type F = GoldilocksField;

Expand Down Expand Up @@ -183,7 +182,7 @@ fn prepare_setup() -> anyhow::Result<GenerationInputs<F>> {
checkpoint_state_trie_root: H256(hex!(
"fe07ff6d1ab215df17884b89112ccf2373597285a56c5902150313ad1a53ee57"
)),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
ger_data: None,
block_metadata,
txn_number_before: 0.into(),
Expand Down
9 changes: 4 additions & 5 deletions evm_arithmetization/src/cpu/kernel/tests/add11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField as F;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;

use crate::cpu::kernel::aggregator::KERNEL;
use crate::cpu::kernel::interpreter::Interpreter;
Expand All @@ -21,7 +20,7 @@ use crate::testing_utils::{
beacon_roots_account_nibbles, beacon_roots_contract_from_storage,
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use crate::GenerationInputs;
use crate::{GenerationInputs, EMPTY_CONSOLIDATED_BLOCKHASH};

#[test]
fn test_add11_yml() {
Expand Down Expand Up @@ -176,7 +175,7 @@ fn test_add11_yml() {
receipts_root: receipts_trie.hash(),
};

let inputs = GenerationInputs::<F> {
let inputs = GenerationInputs {
signed_txns: vec![txn.to_vec()],
burn_addr: None,
withdrawals: vec![],
Expand All @@ -186,7 +185,7 @@ fn test_add11_yml() {
contract_code: contract_code.clone(),
block_metadata,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
txn_number_before: 0.into(),
gas_used_before: 0.into(),
gas_used_after: gas_used,
Expand Down Expand Up @@ -363,7 +362,7 @@ fn test_add11_yml_with_exception() {
contract_code: contract_code.clone(),
block_metadata,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
txn_number_before: 0.into(),
gas_used_before: 0.into(),
gas_used_after: txn_gas_limit.into(),
Expand Down
6 changes: 3 additions & 3 deletions evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use keccak_hash::{keccak, H256};
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField as F;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;

use crate::cpu::kernel::{aggregator::KERNEL, interpreter::Interpreter};
use crate::generation::{
Expand All @@ -17,6 +16,7 @@ use crate::testing_utils::{
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use crate::witness::{memory::MemoryAddress, state::RegistersState};
use crate::EMPTY_CONSOLIDATED_BLOCKHASH;
use crate::{
proof::{BlockHashes, BlockMetadata, TrieRoots},
GenerationInputs, Node,
Expand Down Expand Up @@ -78,7 +78,7 @@ fn test_init_exc_stop() {
receipts_root: receipts_trie.hash(),
};

let inputs = GenerationInputs::<F> {
let inputs = GenerationInputs {
signed_txns: vec![],
burn_addr: None,
withdrawals: vec![],
Expand All @@ -91,7 +91,7 @@ fn test_init_exc_stop() {
trie_roots_after,
contract_code,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
block_metadata,
txn_number_before: 0.into(),
gas_used_before: 0.into(),
Expand Down
6 changes: 5 additions & 1 deletion evm_arithmetization/src/generation/segments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use anyhow::Result;
use plonky2::hash::hash_types::RichField;
use serde::{Deserialize, Serialize};

use super::TrimmedGenerationInputs;
use crate::cpu::kernel::aggregator::KERNEL;
use crate::cpu::kernel::interpreter::{set_registers_and_run, ExtraSegmentData, Interpreter};
use crate::generation::state::State;
use crate::generation::{debug_inputs, GenerationInputs};
use crate::witness::memory::MemoryState;
use crate::witness::state::RegistersState;
use crate::AllData;

/// Structure holding the data needed to initialize a segment.
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -169,6 +169,10 @@ impl<F: RichField> SegmentDataIterator<F> {
}
}

/// Returned type from a `SegmentDataIterator`, needed to prove all segments in
/// a transaction batch.
pub type AllData<F> = Result<(TrimmedGenerationInputs<F>, GenerationSegmentData), SegmentError>;

impl<F: RichField> Iterator for SegmentDataIterator<F> {
type Item = AllData<F>;

Expand Down
20 changes: 4 additions & 16 deletions evm_arithmetization/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,10 @@ pub mod extension_tower;
pub mod testing_utils;
pub mod util;

use generation::segments::SegmentError;
use generation::TrimmedGenerationInputs;
use mpt_trie::partial_trie::HashedPartialTrie;

// Public definitions and re-exports

pub type Node = mpt_trie::partial_trie::Node<HashedPartialTrie>;
/// A type alias for `u64` of a block height.
pub type BlockHeight = u64;

pub use all_stark::{AllStark, NUM_TABLES};
pub use fixed_recursive_verifier::AllRecursiveCircuits;
pub use generation::segments::{GenerationSegmentData, SegmentDataIterator};
pub use generation::GenerationInputs;
mod public_types;
pub use public_types::*;
pub use starky::config::StarkConfig;

/// Returned type from a `SegmentDataIterator`, needed to prove all segments in
/// a transaction batch.
pub type AllData<F> = Result<(TrimmedGenerationInputs<F>, GenerationSegmentData), SegmentError>;
pub use crate::all_stark::{AllStark, NUM_TABLES};
pub use crate::generation::segments::{GenerationSegmentData, SegmentDataIterator};
67 changes: 67 additions & 0 deletions evm_arithmetization/src/public_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use mpt_trie::partial_trie::HashedPartialTrie;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;

use crate::{generation::segments::SegmentError, GenerationSegmentData};

pub type Node = mpt_trie::partial_trie::Node<HashedPartialTrie>;
pub type BlockHeight = u64;

use plonky2::{
field::goldilocks_field::GoldilocksField, hash::poseidon::PoseidonHash,
plonk::config::PoseidonGoldilocksConfig,
};

/// The base field on which statements are being proven.
pub type Field = GoldilocksField;
/// The recursive circuit configuration to be used to shrink and aggregate
/// proofs.
pub type RecursionConfig = PoseidonGoldilocksConfig;
/// The extension degree of the field used in the proof system.
pub const EXTENSION_DEGREE: usize = 2;

/// A type alias for EVM witness payloads.
pub type GenerationInputs = crate::generation::GenerationInputs<Field>;
/// A type alias for the trimmed version of EVM witness payloads.
pub type TrimmedGenerationInputs = crate::generation::TrimmedGenerationInputs<Field>;

pub type Hasher = PoseidonHash;
/// A type alias for plonky2 hash outputs.
pub type Hash = <Hasher as plonky2::plonk::config::Hasher<Field>>::Hash;

pub type ConsolidatedHash = [Field; NUM_HASH_OUT_ELTS];
pub use crate::proof::EMPTY_CONSOLIDATED_BLOCKHASH;

/// A type alias for recursive proofs generated by the zkEVM.
pub type ProofWithPublicInputs =
plonky2::plonk::proof::ProofWithPublicInputs<Field, RecursionConfig, EXTENSION_DEGREE>;

/// A type alias for EVM public values used to generate and verify intermediate
/// proofs.
pub type PublicValues = crate::proof::PublicValues<Field>;

pub type AllData = Result<(TrimmedGenerationInputs, GenerationSegmentData), SegmentError>;

/// Returned type from the zkEVM STARK prover, before recursive verification.
pub type AllProof = crate::proof::AllProof<Field, RecursionConfig, EXTENSION_DEGREE>;

/// A type alias for the set of preprocessed circuits necessary to generate
/// succinct block proofs.
pub type AllRecursiveCircuits =
crate::fixed_recursive_verifier::AllRecursiveCircuits<Field, RecursionConfig, EXTENSION_DEGREE>;

/// A type alias for the recursive chains of circuits needed to shrink EVM STARK
/// proofs.
pub type RecursiveCircuitsForTableSize =
crate::fixed_recursive_verifier::RecursiveCircuitsForTableSize<
Field,
RecursionConfig,
{ EXTENSION_DEGREE },
>;

/// A type alias for the verifier data necessary to verify succinct block
/// proofs.
/// While the prover state [`AllRecursiveCircuits`] can also verify proofs, this
/// [`VerifierData`] is much lighter, allowing anyone to verify block proofs,
/// regardless of the underlying hardware.
pub type VerifierData =
plonky2::plonk::circuit_data::VerifierCircuitData<Field, RecursionConfig, EXTENSION_DEGREE>;
12 changes: 6 additions & 6 deletions evm_arithmetization/tests/add11_yml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ use evm_arithmetization::testing_utils::{
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
use evm_arithmetization::StarkConfig;
use evm_arithmetization::{AllStark, GenerationInputs, Node};
use evm_arithmetization::{
AllStark, GenerationInputs, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH,
};
use hex_literal::hex;
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;
use plonky2::plonk::config::KeccakGoldilocksConfig;
use plonky2::util::timing::TimingTree;

type F = GoldilocksField;
const D: usize = 2;
type C = KeccakGoldilocksConfig;

fn get_generation_inputs() -> GenerationInputs<F> {
fn get_generation_inputs() -> GenerationInputs {
let beneficiary = hex!("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba");
let sender = hex!("a94f5374fce5edbc8e2a8697c15331677e6ebf0b");
let to = hex!("095e7baea6a6c7c4c2dfeb977efac326af552d87");
Expand Down Expand Up @@ -182,7 +182,7 @@ fn get_generation_inputs() -> GenerationInputs<F> {
receipts_root: receipts_trie.hash(),
};

GenerationInputs::<F> {
GenerationInputs {
signed_txns: vec![txn.to_vec()],
burn_addr: None,
withdrawals: vec![],
Expand All @@ -192,7 +192,7 @@ fn get_generation_inputs() -> GenerationInputs<F> {
contract_code,
block_metadata,
checkpoint_state_trie_root: state_trie_before.hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
txn_number_before: 0.into(),
gas_used_before: 0.into(),
gas_used_after: 0xa868u64.into(),
Expand Down
5 changes: 2 additions & 3 deletions evm_arithmetization/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ use evm_arithmetization::testing_utils::{
init_logger, preinitialized_state_and_storage_tries, sd2u, update_beacon_roots_account_storage,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH};
use hex_literal::hex;
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;
use plonky2::plonk::config::KeccakGoldilocksConfig;
use plonky2::util::timing::TimingTree;

Expand Down Expand Up @@ -187,7 +186,7 @@ fn test_erc20() -> anyhow::Result<()> {
trie_roots_after,
contract_code,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
block_metadata,
txn_number_before: 0.into(),
gas_used_before: 0.into(),
Expand Down
5 changes: 2 additions & 3 deletions evm_arithmetization/tests/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ use evm_arithmetization::testing_utils::{
update_beacon_roots_account_storage,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH};
use hex_literal::hex;
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;
use plonky2::plonk::config::KeccakGoldilocksConfig;
use plonky2::util::timing::TimingTree;

Expand Down Expand Up @@ -191,7 +190,7 @@ fn test_erc721() -> anyhow::Result<()> {
trie_roots_after,
contract_code,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
block_metadata,
txn_number_before: 0.into(),
gas_used_before: 0.into(),
Expand Down
3 changes: 1 addition & 2 deletions evm_arithmetization/tests/global_exit_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use keccak_hash::keccak;
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;
use plonky2::plonk::config::PoseidonGoldilocksConfig;
use plonky2::util::timing::TimingTree;

Expand Down Expand Up @@ -105,7 +104,7 @@ fn test_global_exit_root() -> anyhow::Result<()> {
trie_roots_after,
contract_code,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
block_metadata,
txn_number_before: 0.into(),
gas_used_before: 0.into(),
Expand Down
5 changes: 2 additions & 3 deletions evm_arithmetization/tests/log_opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ use evm_arithmetization::testing_utils::{
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH};
use hex_literal::hex;
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;
use plonky2::plonk::config::PoseidonGoldilocksConfig;
use plonky2::util::timing::TimingTree;

Expand Down Expand Up @@ -257,7 +256,7 @@ fn test_log_opcodes() -> anyhow::Result<()> {
trie_roots_after,
contract_code,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
block_metadata,
txn_number_before: 0.into(),
gas_used_before: 0.into(),
Expand Down
5 changes: 2 additions & 3 deletions evm_arithmetization/tests/selfdestruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ use evm_arithmetization::testing_utils::{
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
use evm_arithmetization::{AllStark, Node, StarkConfig};
use evm_arithmetization::{AllStark, Node, StarkConfig, EMPTY_CONSOLIDATED_BLOCKHASH};
use hex_literal::hex;
use keccak_hash::keccak;
use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
use plonky2::hash::hash_types::NUM_HASH_OUT_ELTS;
use plonky2::plonk::config::KeccakGoldilocksConfig;
use plonky2::util::timing::TimingTree;
use zk_evm_common::eth_to_wei;
Expand Down Expand Up @@ -162,7 +161,7 @@ fn test_selfdestruct() -> anyhow::Result<()> {
trie_roots_after,
contract_code,
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(),
checkpoint_consolidated_hash: [F::ZERO; NUM_HASH_OUT_ELTS],
checkpoint_consolidated_hash: EMPTY_CONSOLIDATED_BLOCKHASH.map(F::from_canonical_u64),
block_metadata,
txn_number_before: 0.into(),
gas_used_before: 0.into(),
Expand Down
Loading

0 comments on commit 00a998c

Please sign in to comment.