Skip to content

Commit

Permalink
Fix exp gas
Browse files Browse the repository at this point in the history
  • Loading branch information
gianbelinche authored and jrchatruc committed May 22, 2024
1 parent 9124b42 commit 7047533
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
10 changes: 6 additions & 4 deletions system-contracts/contracts/EvmInterpreterLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ for { } true { } {

sp := pushStackItem(sp, exp(a, exponent))

if exponent {
let expSizeByte := div(add(exponent, 256), 256) // TODO: Replace with shr(8, add(exponent, 256))
evmGasLeft := chargeGas(evmGasLeft, mul(50, expSizeByte))
}
let to_charge := 0
for {} gt(exponent,0) {} { // while exponent > 0
to_charge := add(to_charge, 50)
exponent := shr(8, exponent)
}
evmGasLeft := chargeGas(evmGasLeft, to_charge)
}
case 0x0B { // OP_SIGNEXTEND
evmGasLeft := chargeGas(evmGasLeft, 5)
Expand Down
28 changes: 18 additions & 10 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -1406,12 +1406,16 @@ object "EVMInterpreter" {
a, sp := popStackItem(sp)
exponent, sp := popStackItem(sp)

sp := pushStackItem(sp, exp(a, exponent))
let result := exp(a, exponent)

if exponent {
let expSizeByte := div(add(exponent, 256), 256) // TODO: Replace with shr(8, add(exponent, 256))
evmGasLeft := chargeGas(evmGasLeft, mul(50, expSizeByte))
}
sp := pushStackItem(sp, result)

let to_charge := 0
for {} gt(exponent,0) {} { // while exponent > 0
to_charge := add(to_charge, 50)
exponent := shr(8, exponent)
}
evmGasLeft := chargeGas(evmGasLeft, to_charge)
}
case 0x0B { // OP_SIGNEXTEND
evmGasLeft := chargeGas(evmGasLeft, 5)
Expand Down Expand Up @@ -3993,12 +3997,16 @@ object "EVMInterpreter" {
a, sp := popStackItem(sp)
exponent, sp := popStackItem(sp)

sp := pushStackItem(sp, exp(a, exponent))
let result := exp(a, exponent)

if exponent {
let expSizeByte := div(add(exponent, 256), 256) // TODO: Replace with shr(8, add(exponent, 256))
evmGasLeft := chargeGas(evmGasLeft, mul(50, expSizeByte))
}
sp := pushStackItem(sp, result)

let to_charge := 0
for {} gt(exponent,0) {} { // while exponent > 0
to_charge := add(to_charge, 50)
exponent := shr(8, exponent)
}
evmGasLeft := chargeGas(evmGasLeft, to_charge)
}
case 0x0B { // OP_SIGNEXTEND
evmGasLeft := chargeGas(evmGasLeft, 5)
Expand Down

0 comments on commit 7047533

Please sign in to comment.