From 218f689422f0d90041d5a023ce32bc13e7e92af3 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Wed, 21 Sep 2022 12:53:47 -0700 Subject: [PATCH 1/2] Fix prohibited macro names --- evm/src/cpu/kernel/assembler.rs | 6 ++++++ evm/src/cpu/kernel/evm_asm.pest | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/evm/src/cpu/kernel/assembler.rs b/evm/src/cpu/kernel/assembler.rs index 4319612d..5364e8a5 100644 --- a/evm/src/cpu/kernel/assembler.rs +++ b/evm/src/cpu/kernel/assembler.rs @@ -512,6 +512,12 @@ mod tests { assert_eq!(kernel.code, vec![push1, 42, push1, 42]); } + #[test] + fn macro_with_reserved_prefix() { + // The name `repeat` should be allowed, even though `rep` is reserved. + parse_and_assemble(&["%macro repeat %endmacro", "%repeat"]); + } + #[test] #[should_panic] fn macro_with_wrong_vars() { diff --git a/evm/src/cpu/kernel/evm_asm.pest b/evm/src/cpu/kernel/evm_asm.pest index 89d06e74..5d670c6c 100644 --- a/evm/src/cpu/kernel/evm_asm.pest +++ b/evm/src/cpu/kernel/evm_asm.pest @@ -17,7 +17,7 @@ constant = ${ "@" ~ identifier } item = { macro_def | macro_call | repeat | stack | global_label_decl | local_label_decl | macro_label_decl | bytes_item | push_instruction | prover_input_instruction | nullary_instruction } macro_def = { ^"%macro" ~ identifier ~ paramlist? ~ item* ~ ^"%endmacro" } -macro_call = ${ "%" ~ !(^"macro" | ^"endmacro" | ^"rep" | ^"endrep" | ^"stack") ~ identifier ~ macro_arglist? } +macro_call = ${ "%" ~ !((^"macro" | ^"endmacro" | ^"rep" | ^"endrep" | ^"stack") ~ !identifier_char) ~ identifier ~ macro_arglist? } repeat = { ^"%rep" ~ literal ~ item* ~ ^"%endrep" } paramlist = { "(" ~ identifier ~ ("," ~ identifier)* ~ ")" } macro_arglist = !{ "(" ~ push_target ~ ("," ~ push_target)* ~ ")" } From 8fb1e4e760089401a5f992f3450cb4da5ea4fc54 Mon Sep 17 00:00:00 2001 From: BGluth Date: Wed, 21 Sep 2022 15:40:11 -0600 Subject: [PATCH 2/2] Added a mapping between code hashes and contract byte code Added a mapping between an account's `codehash` field and the actual contract byte code in `GenerationInputs`. --- evm/src/generation/mod.rs | 8 +++++++- evm/tests/transfer_to_new_addr.rs | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/evm/src/generation/mod.rs b/evm/src/generation/mod.rs index baf2ec32..1d2fbf30 100644 --- a/evm/src/generation/mod.rs +++ b/evm/src/generation/mod.rs @@ -1,5 +1,7 @@ +use std::collections::HashMap; + use eth_trie_utils::partial_trie::PartialTrie; -use ethereum_types::Address; +use ethereum_types::{Address, H256}; use plonky2::field::extension::Extendable; use plonky2::field::polynomial::PolynomialValues; use plonky2::field::types::Field; @@ -41,6 +43,10 @@ pub struct GenerationInputs { /// storage tries, and nodes therein, that will be accessed by these transactions. pub storage_tries: Vec<(Address, PartialTrie)>, + /// Mapping between smart contract code hashes and the contract byte code. + /// All account smart contracts that are invoked will have an entry present. + pub contract_code: HashMap>, + pub block_metadata: BlockMetadata, } diff --git a/evm/tests/transfer_to_new_addr.rs b/evm/tests/transfer_to_new_addr.rs index 1cd79194..82f4938b 100644 --- a/evm/tests/transfer_to_new_addr.rs +++ b/evm/tests/transfer_to_new_addr.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use eth_trie_utils::partial_trie::PartialTrie; use hex_literal::hex; use plonky2::field::goldilocks_field::GoldilocksField; @@ -31,6 +33,7 @@ fn test_simple_transfer() -> anyhow::Result<()> { transactions_trie: PartialTrie::Empty, receipts_trie: PartialTrie::Empty, storage_tries: vec![], + contract_code: HashMap::new(), block_metadata, };