Skip to content

Commit

Permalink
Use unchecked push in safe cases
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Aug 19, 2024
1 parent d272a7e commit 3d766a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions system-contracts/contracts/EvmInterpreterLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ for { } true { } {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

sp := pushStackItem(sp, balance(addr), evmGasLeft)
sp := pushStackItemWithoutCheck(sp, balance(addr))
ip := add(ip, 1)
}
case 0x32 { // OP_ORIGIN
Expand Down Expand Up @@ -495,8 +495,8 @@ for { } true { } {
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)

switch _isEVM(addr)
case 0 { sp := pushStackItem(sp, extcodesize(addr), evmGasLeft) }
default { sp := pushStackItem(sp, _fetchDeployedCodeLen(addr), evmGasLeft) }
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
ip := add(ip, 1)
}
case 0x3C { // OP_EXTCODECOPY
Expand Down Expand Up @@ -549,10 +549,10 @@ for { } true { } {

ip := add(ip, 1)
if iszero(addr) {
sp := pushStackItem(sp, 0, evmGasLeft)
sp := pushStackItemWithoutCheck(sp, 0)
continue
}
sp := pushStackItem(sp, extcodehash(addr), evmGasLeft)
sp := pushStackItemWithoutCheck(sp, extcodehash(addr))
}
case 0x40 { // OP_BLOCKHASH
evmGasLeft := chargeGas(evmGasLeft, 20)
Expand Down Expand Up @@ -625,7 +625,7 @@ for { } true { } {
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

let memValue := mload(add(MEM_OFFSET_INNER(), offset))
sp := pushStackItem(sp, memValue, evmGasLeft)
sp := pushStackItemWithoutCheck(sp, memValue)
ip := add(ip, 1)
}
case 0x52 { // OP_MSTORE
Expand Down Expand Up @@ -682,7 +682,7 @@ for { } true { } {
let _wasW, _orgV := warmSlot(key, value)
}

sp := pushStackItem(sp,value, evmGasLeft)
sp := pushStackItemWithoutCheck(sp,value)
ip := add(ip, 1)
}
case 0x55 { // OP_SSTORE
Expand Down
28 changes: 14 additions & 14 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

sp := pushStackItem(sp, balance(addr), evmGasLeft)
sp := pushStackItemWithoutCheck(sp, balance(addr))
ip := add(ip, 1)
}
case 0x32 { // OP_ORIGIN
Expand Down Expand Up @@ -2034,8 +2034,8 @@ object "EVMInterpreter" {
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)

switch _isEVM(addr)
case 0 { sp := pushStackItem(sp, extcodesize(addr), evmGasLeft) }
default { sp := pushStackItem(sp, _fetchDeployedCodeLen(addr), evmGasLeft) }
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
ip := add(ip, 1)
}
case 0x3C { // OP_EXTCODECOPY
Expand Down Expand Up @@ -2088,10 +2088,10 @@ object "EVMInterpreter" {

ip := add(ip, 1)
if iszero(addr) {
sp := pushStackItem(sp, 0, evmGasLeft)
sp := pushStackItemWithoutCheck(sp, 0)
continue
}
sp := pushStackItem(sp, extcodehash(addr), evmGasLeft)
sp := pushStackItemWithoutCheck(sp, extcodehash(addr))
}
case 0x40 { // OP_BLOCKHASH
evmGasLeft := chargeGas(evmGasLeft, 20)
Expand Down Expand Up @@ -2164,7 +2164,7 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

let memValue := mload(add(MEM_OFFSET_INNER(), offset))
sp := pushStackItem(sp, memValue, evmGasLeft)
sp := pushStackItemWithoutCheck(sp, memValue)
ip := add(ip, 1)
}
case 0x52 { // OP_MSTORE
Expand Down Expand Up @@ -2221,7 +2221,7 @@ object "EVMInterpreter" {
let _wasW, _orgV := warmSlot(key, value)
}

sp := pushStackItem(sp,value, evmGasLeft)
sp := pushStackItemWithoutCheck(sp,value)
ip := add(ip, 1)
}
case 0x55 { // OP_SSTORE
Expand Down Expand Up @@ -4888,7 +4888,7 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

sp := pushStackItem(sp, balance(addr), evmGasLeft)
sp := pushStackItemWithoutCheck(sp, balance(addr))
ip := add(ip, 1)
}
case 0x32 { // OP_ORIGIN
Expand Down Expand Up @@ -5021,8 +5021,8 @@ object "EVMInterpreter" {
// sp := pushStackItem(sp, extcodesize(addr), evmGasLeft)

switch _isEVM(addr)
case 0 { sp := pushStackItem(sp, extcodesize(addr), evmGasLeft) }
default { sp := pushStackItem(sp, _fetchDeployedCodeLen(addr), evmGasLeft) }
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
ip := add(ip, 1)
}
case 0x3C { // OP_EXTCODECOPY
Expand Down Expand Up @@ -5075,10 +5075,10 @@ object "EVMInterpreter" {

ip := add(ip, 1)
if iszero(addr) {
sp := pushStackItem(sp, 0, evmGasLeft)
sp := pushStackItemWithoutCheck(sp, 0)
continue
}
sp := pushStackItem(sp, extcodehash(addr), evmGasLeft)
sp := pushStackItemWithoutCheck(sp, extcodehash(addr))
}
case 0x40 { // OP_BLOCKHASH
evmGasLeft := chargeGas(evmGasLeft, 20)
Expand Down Expand Up @@ -5151,7 +5151,7 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, expansionGas)

let memValue := mload(add(MEM_OFFSET_INNER(), offset))
sp := pushStackItem(sp, memValue, evmGasLeft)
sp := pushStackItemWithoutCheck(sp, memValue)
ip := add(ip, 1)
}
case 0x52 { // OP_MSTORE
Expand Down Expand Up @@ -5208,7 +5208,7 @@ object "EVMInterpreter" {
let _wasW, _orgV := warmSlot(key, value)
}

sp := pushStackItem(sp,value, evmGasLeft)
sp := pushStackItemWithoutCheck(sp,value)
ip := add(ip, 1)
}
case 0x55 { // OP_SSTORE
Expand Down

0 comments on commit 3d766a2

Please sign in to comment.