From ead5188abe2c3f3268e6e870864e2c4ce8cdb588 Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Fri, 25 Oct 2024 17:24:15 +0200 Subject: [PATCH] Fix keccak gas charge flow --- system-contracts/SystemContractsHashes.json | 8 ++++---- system-contracts/contracts/EvmEmulator.yul | 10 ++++------ .../evm-emulator/EvmEmulatorLoop.template.yul | 5 ++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/system-contracts/SystemContractsHashes.json b/system-contracts/SystemContractsHashes.json index 5996afe39..35a0c1b1c 100644 --- a/system-contracts/SystemContractsHashes.json +++ b/system-contracts/SystemContractsHashes.json @@ -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", @@ -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", diff --git a/system-contracts/contracts/EvmEmulator.yul b/system-contracts/contracts/EvmEmulator.yul index c76c01b9e..ad8595955 100644 --- a/system-contracts/contracts/EvmEmulator.yul +++ b/system-contracts/contracts/EvmEmulator.yul @@ -1559,8 +1559,6 @@ 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 @@ -1568,7 +1566,8 @@ object "EvmEmulator" { 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 @@ -4569,8 +4568,6 @@ 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 @@ -4578,7 +4575,8 @@ object "EvmEmulator" { 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 diff --git a/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul b/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul index 907fce9ea..cd8af797b 100644 --- a/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul @@ -284,8 +284,6 @@ 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 @@ -293,7 +291,8 @@ for { } true { } { 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