Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EVM): Warm origin and sender accounts #1036

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions system-contracts/SystemContractsHashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@
"contractName": "EvmEmulator",
"bytecodePath": "contracts-preprocessed/artifacts/EvmEmulator.yul/EvmEmulator.yul.zbin",
"sourceCodePath": "contracts-preprocessed/EvmEmulator.yul",
"bytecodeHash": "0x01000c17a11dbdb15973a96a4ddd5b95f19843ea7e7affa8f63fe0e5e4ef5b7c",
"sourceCodeHash": "0x5b6098d09a93c5a55cc119d6a30a6e8e446db778af4a4350deb1b5d8ba5c764a"
"bytecodeHash": "0x01000c17f157cd87a1e8d9d8c0e9fb8a1b3ecd0409e68769365f5014e4b053ff",
"sourceCodeHash": "0xd17982c310a48c4edc2c5351b2a4372a0c161719f09c73de8aa8a960a2eae1a5"
},
{
"contractName": "EvmGasManager",
"bytecodePath": "contracts-preprocessed/artifacts/EvmGasManager.yul/EvmGasManager.yul.zbin",
"sourceCodePath": "contracts-preprocessed/EvmGasManager.yul",
"bytecodeHash": "0x01000059d5a1736d5865f592c5dcf2e301697b83d4abfdc4a8fa2b5cfe88de8d",
"sourceCodeHash": "0xad51904bf2b8cd81cb66962c3211c9514e6ccd0c5bd30288d1f5697b29639fcb"
"bytecodeHash": "0x010000610462e7b494ad4db402ee0ca6369f20d9267aa2b5aa51886d869d16a2",
"sourceCodeHash": "0x5d683d77785f928d62a6b876cec35e4fb057db809e2328ad3df329a5d88a32c3"
},
{
"contractName": "CodeOracle",
Expand Down
6 changes: 4 additions & 2 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,9 @@ object "EvmEmulator" {
// function consumeEvmFrame() external returns (uint256 passGas, uint256 auxDataRes)
// non-standard selector 0x04
mstore(0, 0x0400000000000000000000000000000000000000000000000000000000000000)
mstore(1, caller())

performSystemCall(EVM_GAS_MANAGER_CONTRACT(), 1)
performSystemCall(EVM_GAS_MANAGER_CONTRACT(), 33)

let _returndatasize := returndatasize()
if _returndatasize {
Expand Down Expand Up @@ -3590,8 +3591,9 @@ object "EvmEmulator" {
// function consumeEvmFrame() external returns (uint256 passGas, uint256 auxDataRes)
// non-standard selector 0x04
mstore(0, 0x0400000000000000000000000000000000000000000000000000000000000000)
mstore(1, caller())

performSystemCall(EVM_GAS_MANAGER_CONTRACT(), 1)
performSystemCall(EVM_GAS_MANAGER_CONTRACT(), 33)

let _returndatasize := returndatasize()
if _returndatasize {
Expand Down
17 changes: 14 additions & 3 deletions system-contracts/contracts/EvmGasManager.yul
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ object "EvmGasManager" {
}
}

function warmAccount(account) {
let transientSlot := or(IS_ACCOUNT_WARM_PREFIX(), account)
tstore(transientSlot, 1)
}

////////////////////////////////////////////////////////////////
// FALLBACK
////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -209,9 +214,15 @@ object "EvmGasManager" {
}

// We do not have active frame. This means that the EVM contract was called from the EraVM contract.
// We should mark the EVM contract as warm.
let isSenderWarmSlot := or(IS_ACCOUNT_WARM_PREFIX(), caller())
tstore(isSenderWarmSlot, 1)
// mark caller and txorigin as warm
let _msgsender := calldataload(1)
let _origin := origin()
warmAccount(_msgsender)
if iszero(eq(_msgsender, _origin)) {
warmAccount(_origin)
}
// We should mark the EVM contract as warm too.
warmAccount(caller())
return(0x0, 0x0)
}
default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,9 @@ function consumeEvmFrame() -> passGas, isStatic, callerEVM {
// function consumeEvmFrame() external returns (uint256 passGas, uint256 auxDataRes)
// non-standard selector 0x04
mstore(0, 0x0400000000000000000000000000000000000000000000000000000000000000)
mstore(1, caller())

performSystemCall(EVM_GAS_MANAGER_CONTRACT(), 1)
performSystemCall(EVM_GAS_MANAGER_CONTRACT(), 33)

let _returndatasize := returndatasize()
if _returndatasize {
Expand Down
Loading