Skip to content

Commit

Permalink
Merge pull request #609 from lambdaclass/increment-nonce-only-for-eoa…
Browse files Browse the repository at this point in the history
…s-on-failure

[EVM Equivalence Yul] Increment nonce on failed deployments only for eoas
  • Loading branch information
jrchatruc authored Jul 11, 2024
2 parents 0b58290 + a252e10 commit dc2e056
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
25 changes: 24 additions & 1 deletion system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,19 @@ function warmSlot(key,currentValue) -> isWarm, originalValue {
originalValue := mload(32)
}

function MAX_SYSTEM_CONTRACT_ADDR() -> ret {
ret := 0x000000000000000000000000000000000000ffff
}

/// @dev Checks whether an address is an EOA (i.e. has not code deployed on it)
/// @param addr The address to check
function isEOA(addr) -> ret {
ret := 0
if gt(addr, MAX_SYSTEM_CONTRACT_ADDR()) {
ret := iszero(_getRawCodeHash(addr))
}
}

function getNewAddress(addr) -> newAddr {
let digest, nonce, addressEncoded, nonceEncoded, nonceEncodedLength, listLength, listLengthEconded

Expand Down Expand Up @@ -1280,7 +1293,17 @@ function genericCreate(addr, offset, size, sp, value, evmGasLeftOld) -> result,

_popEVMFrame()

incrementNonce(address())
switch result
case 1 {
incrementNonce(address())
}
default {
switch isEOA(address())
case 1 {
incrementNonce(address())
}
default {}
}

let back

Expand Down
50 changes: 48 additions & 2 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,19 @@ object "EVMInterpreter" {
originalValue := mload(32)
}

function MAX_SYSTEM_CONTRACT_ADDR() -> ret {
ret := 0x000000000000000000000000000000000000ffff
}

/// @dev Checks whether an address is an EOA (i.e. has not code deployed on it)
/// @param addr The address to check
function isEOA(addr) -> ret {
ret := 0
if gt(addr, MAX_SYSTEM_CONTRACT_ADDR()) {
ret := iszero(_getRawCodeHash(addr))
}
}

function getNewAddress(addr) -> newAddr {
let digest, nonce, addressEncoded, nonceEncoded, nonceEncodedLength, listLength, listLengthEconded

Expand Down Expand Up @@ -1354,7 +1367,17 @@ object "EVMInterpreter" {

_popEVMFrame()

incrementNonce(address())
switch result
case 1 {
incrementNonce(address())
}
default {
switch isEOA(address())
case 1 {
incrementNonce(address())
}
default {}
}

let back

Expand Down Expand Up @@ -3502,6 +3525,19 @@ object "EVMInterpreter" {
originalValue := mload(32)
}

function MAX_SYSTEM_CONTRACT_ADDR() -> ret {
ret := 0x000000000000000000000000000000000000ffff
}

/// @dev Checks whether an address is an EOA (i.e. has not code deployed on it)
/// @param addr The address to check
function isEOA(addr) -> ret {
ret := 0
if gt(addr, MAX_SYSTEM_CONTRACT_ADDR()) {
ret := iszero(_getRawCodeHash(addr))
}
}

function getNewAddress(addr) -> newAddr {
let digest, nonce, addressEncoded, nonceEncoded, nonceEncodedLength, listLength, listLengthEconded

Expand Down Expand Up @@ -4186,7 +4222,17 @@ object "EVMInterpreter" {

_popEVMFrame()

incrementNonce(address())
switch result
case 1 {
incrementNonce(address())
}
default {
switch isEOA(address())
case 1 {
incrementNonce(address())
}
default {}
}

let back

Expand Down

0 comments on commit dc2e056

Please sign in to comment.