diff --git a/evm/src/cpu/kernel/asm/util/basic_macros.asm b/evm/src/cpu/kernel/asm/util/basic_macros.asm index a91feb05..4dd93d14 100644 --- a/evm/src/cpu/kernel/asm/util/basic_macros.asm +++ b/evm/src/cpu/kernel/asm/util/basic_macros.asm @@ -120,9 +120,7 @@ // stack: input, ... PUSH $c // stack: c, input, ... - %add_const(1) // This will be optimized out. - // stack: c + 1, input, ... - GT // Check it backwards: (input <= c) == (c + 1 > input) + LT ISZERO // Check it backwards: (input <= c) == !(c < input) // stack: input <= c, ... %endmacro @@ -138,9 +136,7 @@ // stack: input, ... PUSH $c // stack: c, input, ... - %sub_const(1) // This will be optimized out. - // stack: c - 1, input, ... - LT // Check it backwards: (input >= c) == (c - 1 < input) + GT ISZERO // Check it backwards: (input >= c) == !(c > input) // stack: input >= c, ... %endmacro diff --git a/evm/src/cpu/kernel/optimizer.rs b/evm/src/cpu/kernel/optimizer.rs index ac46011a..a334f2d8 100644 --- a/evm/src/cpu/kernel/optimizer.rs +++ b/evm/src/cpu/kernel/optimizer.rs @@ -50,6 +50,8 @@ fn constant_propagation(code: &mut Vec) { "SUB" => Some(x.overflowing_sub(y).0), "MUL" => Some(x.overflowing_mul(y).0), "DIV" => Some(x.checked_div(y).unwrap_or(U256::zero())), + "MOD" => Some(x.checked_rem(y).unwrap_or(U256::zero())), + "EXP" => Some(x.overflowing_pow(y).0), "SHL" => Some(x << y), "SHR" => Some(x >> y), "AND" => Some(x & y), @@ -58,6 +60,11 @@ fn constant_propagation(code: &mut Vec) { "LT" => Some(u256_from_bool(x < y)), "GT" => Some(u256_from_bool(x > y)), "EQ" => Some(u256_from_bool(x == y)), + "BYTE" => Some(if x < 32.into() { + y.byte(x.as_usize()).into() + } else { + U256::zero() + }), _ => None, } .map(|res| vec![Push(Literal(res))])