-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dummy segment to the left (#185)
* Add kernel code to MemBefore * Remove kernel code hashing from * Fix comments * Add initial memory check to verifier * Remove dead code * Address comment * Add dummy segments to the left. * Remove comment and make add11_segments_aggreg use a dummy segment * Change dummy insertion. * Apply comments * Fix Clippy
- Loading branch information
1 parent
d391d36
commit dc23696
Showing
8 changed files
with
204 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
evm_arithmetization/src/cpu/kernel/tests/init_exc_stop.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
use std::collections::HashMap; | ||
|
||
use ethereum_types::U256; | ||
use keccak_hash::keccak; | ||
use keccak_hash::H256; | ||
use mpt_trie::partial_trie::HashedPartialTrie; | ||
use mpt_trie::partial_trie::PartialTrie; | ||
use plonky2::field::goldilocks_field::GoldilocksField as F; | ||
|
||
use crate::cpu::kernel::aggregator::KERNEL; | ||
use crate::cpu::kernel::interpreter::Interpreter; | ||
use crate::generation::state::State; | ||
use crate::generation::TrieInputs; | ||
use crate::generation::NUM_EXTRA_CYCLES_AFTER; | ||
use crate::generation::NUM_EXTRA_CYCLES_BEFORE; | ||
use crate::proof::BlockMetadata; | ||
use crate::proof::TrieRoots; | ||
use crate::witness::state::RegistersState; | ||
use crate::{proof::BlockHashes, GenerationInputs, Node}; | ||
|
||
// Test to check NUM_EXTRA_CYCLES_BEFORE and NUM_EXTRA_CYCLES_AFTER | ||
#[test] | ||
fn test_init_exc_stop() { | ||
let block_metadata = BlockMetadata { | ||
block_number: 1.into(), | ||
..Default::default() | ||
}; | ||
|
||
let state_trie = HashedPartialTrie::from(Node::Empty); | ||
let transactions_trie = HashedPartialTrie::from(Node::Empty); | ||
let receipts_trie = HashedPartialTrie::from(Node::Empty); | ||
let storage_tries = vec![]; | ||
|
||
let mut contract_code = HashMap::new(); | ||
contract_code.insert(keccak(vec![]), vec![]); | ||
|
||
// No transactions, so no trie roots change. | ||
let trie_roots_after = TrieRoots { | ||
state_root: state_trie.hash(), | ||
transactions_root: transactions_trie.hash(), | ||
receipts_root: receipts_trie.hash(), | ||
}; | ||
|
||
let inputs = GenerationInputs { | ||
signed_txn: None, | ||
withdrawals: vec![], | ||
tries: TrieInputs { | ||
state_trie, | ||
transactions_trie, | ||
receipts_trie, | ||
storage_tries, | ||
}, | ||
trie_roots_after, | ||
contract_code, | ||
checkpoint_state_trie_root: HashedPartialTrie::from(Node::Empty).hash(), | ||
block_metadata, | ||
txn_number_before: 0.into(), | ||
gas_used_before: 0.into(), | ||
gas_used_after: 0.into(), | ||
block_hashes: BlockHashes { | ||
prev_hashes: vec![H256::default(); 256], | ||
cur_hash: H256::default(), | ||
}, | ||
}; | ||
let initial_stack = vec![]; | ||
let initial_offset = KERNEL.global_labels["init"]; | ||
let mut interpreter: Interpreter<F> = | ||
Interpreter::new_with_generation_inputs(initial_offset, initial_stack, &inputs, None); | ||
interpreter.halt_offsets = vec![KERNEL.global_labels["main"]]; | ||
interpreter.set_is_kernel(true); | ||
interpreter.run().expect("Running dummy init failed."); | ||
|
||
assert_eq!( | ||
interpreter.get_clock(), | ||
NUM_EXTRA_CYCLES_BEFORE, | ||
"NUM_EXTRA_CYCLES_BEFORE is set incorrectly." | ||
); | ||
|
||
// The registers should not have changed, besides the stack top. | ||
let expected_registers = RegistersState { | ||
stack_top: interpreter.get_registers().stack_top, | ||
check_overflow: interpreter.get_registers().check_overflow, | ||
..RegistersState::new() | ||
}; | ||
|
||
assert_eq!( | ||
interpreter.get_registers(), | ||
expected_registers, | ||
"Incorrect registers for dummy run." | ||
); | ||
|
||
let main_offset = KERNEL.global_labels["main"]; | ||
let mut interpreter: Interpreter<F> = | ||
Interpreter::new_dummy_with_generation_inputs(initial_offset, vec![], &inputs); | ||
interpreter.halt_offsets = vec![KERNEL.global_labels["halt_final"]]; | ||
interpreter.set_is_kernel(true); | ||
interpreter.clock = 0; | ||
interpreter.run().expect("Running dummy exc_stop failed."); | ||
|
||
// The "-1" comes from the fact that we stop 1 cycle before the max, to allow | ||
// for one padding row, which is needed for CPU STARK. | ||
assert_eq!( | ||
interpreter.get_clock(), | ||
NUM_EXTRA_CYCLES_BEFORE + NUM_EXTRA_CYCLES_AFTER - 1, | ||
"NUM_EXTRA_CYCLES_AFTER is set incorrectly." | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ mod core; | |
mod ecc; | ||
mod exp; | ||
mod hash; | ||
mod init_exc_stop; | ||
mod kernel_consistency; | ||
mod log; | ||
mod mpt; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters