Skip to content

Commit

Permalink
Fix keccak gas charge flow
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Oct 25, 2024
1 parent a3305ee commit ead5188
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 4 additions & 4 deletions system-contracts/SystemContractsHashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"contractName": "ContractDeployer",
"bytecodePath": "artifacts-zk/contracts-preprocessed/ContractDeployer.sol/ContractDeployer.json",
"sourceCodePath": "contracts-preprocessed/ContractDeployer.sol",
"bytecodeHash": "0x010006899163a15f72c2af3cc5501a19f422506d2c08967f184c084d7a8a4b61",
"sourceCodeHash": "0xa89aa977537c1883e5f99eb22b22b1326a1cca179c7201a26a6678846d6145b6"
"bytecodeHash": "0x010006893b07703146f0b1c9b4cd9d481e206eef99147d13fea699be2fdc8ad9",
"sourceCodeHash": "0xa4c2c1f55f5ef1281e18fd016865d9b83b71ad7facb2fd5130940b3b0b7de621"
},
{
"contractName": "Create2Factory",
Expand Down Expand Up @@ -122,8 +122,8 @@
"contractName": "EvmEmulator",
"bytecodePath": "contracts-preprocessed/artifacts/EvmEmulator.yul/EvmEmulator.yul.zbin",
"sourceCodePath": "contracts-preprocessed/EvmEmulator.yul",
"bytecodeHash": "0x01000cd957604ca7e653a0fa0e80e96bd575b52e6d07182fad2fecb3fa6cd7d1",
"sourceCodeHash": "0x1ad51b4b8b559793df21ff15e03aea492563040763ace8f231b8be12ff7c6767"
"bytecodeHash": "0x01000cd17989fbfbda00c1058d3cbe559dcd05ff07a71e9182f198e22d622cc0",
"sourceCodeHash": "0x43c82a32662ed95d5ecb809535f8487a04c14cbeedcd67eeb29bb33bf5bc74fd"
},
{
"contractName": "EvmGasManager",
Expand Down
10 changes: 4 additions & 6 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -1559,16 +1559,15 @@ object "EvmEmulator" {

checkMemIsAccessible(offset, size)

let keccak := keccak256(add(MEM_OFFSET_INNER(), offset), size)

// When an offset is first accessed (either read or write), memory may trigger
// an expansion, which costs gas.
// dynamicGas = 6 * minimum_word_size + memory_expansion_cost
// minimum_word_size = (size + 31) / 32
let dynamicGas := add(mul(6, shr(5, add(size, 31))), expandMemory(add(offset, size)))
evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

stackHead := keccak
stackHead := keccak256(add(MEM_OFFSET_INNER(), offset), size)

ip := add(ip, 1)
}
case 0x30 { // OP_ADDRESS
Expand Down Expand Up @@ -4569,16 +4568,15 @@ object "EvmEmulator" {

checkMemIsAccessible(offset, size)

let keccak := keccak256(add(MEM_OFFSET_INNER(), offset), size)

// When an offset is first accessed (either read or write), memory may trigger
// an expansion, which costs gas.
// dynamicGas = 6 * minimum_word_size + memory_expansion_cost
// minimum_word_size = (size + 31) / 32
let dynamicGas := add(mul(6, shr(5, add(size, 31))), expandMemory(add(offset, size)))
evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

stackHead := keccak
stackHead := keccak256(add(MEM_OFFSET_INNER(), offset), size)

ip := add(ip, 1)
}
case 0x30 { // OP_ADDRESS
Expand Down
5 changes: 2 additions & 3 deletions system-contracts/evm-emulator/EvmEmulatorLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,15 @@ for { } true { } {

checkMemIsAccessible(offset, size)

let keccak := keccak256(add(MEM_OFFSET_INNER(), offset), size)

// When an offset is first accessed (either read or write), memory may trigger
// an expansion, which costs gas.
// dynamicGas = 6 * minimum_word_size + memory_expansion_cost
// minimum_word_size = (size + 31) / 32
let dynamicGas := add(mul(6, shr(5, add(size, 31))), expandMemory(add(offset, size)))
evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

stackHead := keccak
stackHead := keccak256(add(MEM_OFFSET_INNER(), offset), size)

ip := add(ip, 1)
}
case 0x30 { // OP_ADDRESS
Expand Down

0 comments on commit ead5188

Please sign in to comment.