diff --git a/evm/src/cpu/kernel/asm/assertions.asm b/evm/src/cpu/kernel/asm/assertions.asm index a8e65036..69193e5f 100644 --- a/evm/src/cpu/kernel/asm/assertions.asm +++ b/evm/src/cpu/kernel/asm/assertions.asm @@ -6,13 +6,13 @@ global panic: // Consumes the top element and asserts that it is zero. %macro assert_zero - %jumpi panic + %jumpi(panic) %endmacro // Consumes the top element and asserts that it is nonzero. %macro assert_nonzero ISZERO - %jumpi panic + %jumpi(panic) %endmacro %macro assert_eq @@ -49,34 +49,34 @@ global panic: %endmacro %macro assert_eq_const(c) - %eq_const(c) + %eq_const($c) %assert_nonzero %endmacro %macro assert_lt_const(c) // %assert_zero is cheaper than %assert_nonzero, so we will leverage the // fact that (x < c) == !(x >= c). - %ge_const(c) + %ge_const($c) %assert_zero %endmacro %macro assert_le_const(c) // %assert_zero is cheaper than %assert_nonzero, so we will leverage the // fact that (x <= c) == !(x > c). - %gt_const(c) + %gt_const($c) %assert_zero %endmacro %macro assert_gt_const(c) // %assert_zero is cheaper than %assert_nonzero, so we will leverage the // fact that (x > c) == !(x <= c). - %le_const(c) + %le_const($c) %assert_zero %endmacro %macro assert_ge_const(c) // %assert_zero is cheaper than %assert_nonzero, so we will leverage the // fact that (x >= c) == !(x < c). - %lt_const(c) + %lt_const($c) %assert_zero %endmacro diff --git a/evm/src/cpu/kernel/asm/memory.asm b/evm/src/cpu/kernel/asm/memory.asm index 26d0b855..81474d12 100644 --- a/evm/src/cpu/kernel/asm/memory.asm +++ b/evm/src/cpu/kernel/asm/memory.asm @@ -6,7 +6,7 @@ // stack: offset PUSH $segment // stack: segment, offset - CURRENT_CONTEXT + GET_CONTEXT // stack: context, segment, offset MLOAD_GENERAL // stack: value @@ -20,7 +20,7 @@ // stack: offset, value PUSH $segment // stack: segment, offset, value - CURRENT_CONTEXT + GET_CONTEXT // stack: context, segment, offset, value MSTORE_GENERAL // stack: (empty) diff --git a/evm/src/cpu/kernel/assembler.rs b/evm/src/cpu/kernel/assembler.rs index 070ec291..4dbc46ca 100644 --- a/evm/src/cpu/kernel/assembler.rs +++ b/evm/src/cpu/kernel/assembler.rs @@ -132,13 +132,29 @@ fn expand_macro_call( args.len() ); + let get_arg = |var| { + let param_index = _macro.get_param_index(var); + args[param_index].clone() + }; + let expanded_item = _macro .items .iter() .map(|item| { if let Item::Push(PushTarget::MacroVar(var)) = item { - let param_index = _macro.get_param_index(var); - Item::Push(args[param_index].clone()) + Item::Push(get_arg(var)) + } else if let Item::MacroCall(name, args) = item { + let expanded_args = args + .iter() + .map(|arg| { + if let PushTarget::MacroVar(var) = arg { + get_arg(var) + } else { + arg.clone() + } + }) + .collect(); + Item::MacroCall(name.clone(), expanded_args) } else { item.clone() } @@ -419,6 +435,17 @@ mod tests { assert_eq!(kernel.code, vec![push1, 2, push1, 3, add]); } + #[test] + fn macro_in_macro_with_vars() { + let kernel = parse_and_assemble(&[ + "%macro foo(x) %bar($x) %bar($x) %endmacro", + "%macro bar(y) PUSH $y %endmacro", + "%foo(42)", + ]); + let push = get_push_opcode(1); + assert_eq!(kernel.code, vec![push, 42, push, 42]); + } + #[test] #[should_panic] fn macro_with_wrong_vars() { diff --git a/evm/src/cpu/kernel/opcodes.rs b/evm/src/cpu/kernel/opcodes.rs index b9ef7d5e..69ee13fe 100644 --- a/evm/src/cpu/kernel/opcodes.rs +++ b/evm/src/cpu/kernel/opcodes.rs @@ -59,6 +59,7 @@ pub(crate) fn get_opcode(mnemonic: &str) -> u8 { "GASLIMIT" => 0x45, "CHAINID" => 0x46, "BASEFEE" => 0x48, + "PROVER_INPUT" => 0x49, "POP" => 0x50, "MLOAD" => 0x51, "MSTORE" => 0x52, diff --git a/evm/src/memory/segments.rs b/evm/src/memory/segments.rs index f1b92dfc..f6a67dc8 100644 --- a/evm/src/memory/segments.rs +++ b/evm/src/memory/segments.rs @@ -21,12 +21,10 @@ pub(crate) enum Segment { TxnData = 7, /// Raw RLP data. RlpRaw = 8, - /// RLP data that has been parsed and converted to a more "friendly" format. - RlpParsed = 9, } impl Segment { - pub(crate) const COUNT: usize = 10; + pub(crate) const COUNT: usize = 9; pub(crate) fn all() -> [Self; Self::COUNT] { [ @@ -39,7 +37,6 @@ impl Segment { Self::KernelGeneral, Self::TxnData, Self::RlpRaw, - Self::RlpParsed, ] } @@ -55,7 +52,6 @@ impl Segment { Segment::KernelGeneral => "SEGMENT_KERNEL_GENERAL", Segment::TxnData => "SEGMENT_TXN_DATA", Segment::RlpRaw => "SEGMENT_RLP_RAW", - Segment::RlpParsed => "SEGMENT_RLP_PARSED", } } }