diff --git a/evm/src/cpu/kernel/asm/core/precompiles/expmod.asm b/evm/src/cpu/kernel/asm/core/precompiles/expmod.asm index 916afd94..ad85cc0e 100644 --- a/evm/src/cpu/kernel/asm/core/precompiles/expmod.asm +++ b/evm/src/cpu/kernel/asm/core/precompiles/expmod.asm @@ -113,10 +113,18 @@ calculate_l_E_prime: JUMP case_le_32: // stack: l_E, l_B, retdest + SWAP1 + // stack: l_B, l_E, retdest + %add_const(96) + // stack: 96 + l_B, l_E, retdest + PUSH @SEGMENT_CALLDATA + GET_CONTEXT + %mload_packing + // stack: E, retdest %log2_floor - // stack: log2(l_E), l_B, retdest - %stack (log, l_B, retdest) -> (retdest, log) - // stack: retdest, log2(l_E) + // stack: log2(E), retdest + SWAP1 + // stack: retdest, log2(E) JUMP global precompile_expmod: @@ -177,8 +185,7 @@ l_E_prime_return: // stack: f(max(l_M, l_B)), l_E_prime, len, l_M, l_E, l_B, kexit_info SWAP1 // stack: l_E_prime, f(max(l_M, l_B)), len, l_M, l_E, l_B, kexit_info - PUSH 1 - %max + %max_const(1) // stack: max(1, l_E_prime), f(max(l_M, l_B)), len, l_M, l_E, l_B, kexit_info MUL // stack: max(1, l_E_prime) * f(max(l_M, l_B)), len, l_M, l_E, l_B, kexit_info diff --git a/evm/src/cpu/kernel/asm/util/math.asm b/evm/src/cpu/kernel/asm/util/math.asm index 38d29410..98f7b008 100644 --- a/evm/src/cpu/kernel/asm/util/math.asm +++ b/evm/src/cpu/kernel/asm/util/math.asm @@ -5,14 +5,12 @@ log2_floor_helper: ISZERO %jumpi(end) // stack: val, counter, retdest - %shr_const(1) - // stack: val >> 1, counter, retdest + %div_const(2) + // stack: val/2, counter, retdest SWAP1 - // stack: counter, val >> 1, retdest %increment - // stack: counter + 1, val >> 1, retdest SWAP1 - // stack: val >> 1, counter + 1, retdest + // stack: val/2, counter + 1, retdest %jump(log2_floor_helper) end: // stack: val, counter, retdest @@ -24,12 +22,12 @@ end: global log2_floor: // stack: val, retdest - %shr_const(1) - // stack: val >> 1, retdest + %div_const(2) + // stack: val/2, retdest PUSH 0 - // stack: 0, val >> 1, retdest + // stack: 0, val/2, retdest SWAP1 - // stack: val >> 1, 0, retdest + // stack: val/2, 0, retdest %jump(log2_floor_helper) %macro log2_floor