From 852ace4c3fb38f450f1b0059beb6fb0f6e69099c Mon Sep 17 00:00:00 2001 From: garyschulte Date: Tue, 23 Apr 2024 17:35:59 -0700 Subject: [PATCH] call value transfer cost fix, added non-accumulating method for touchCodeChunks Signed-off-by: garyschulte --- .../besu/datatypes/AccessWitness.java | 5 +++++ .../besu/ethereum/core/AccessWitness.java | 22 ++++++++++--------- .../gascalculator/ShanghaiGasCalculator.java | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccessWitness.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccessWitness.java index 8ea3db513b..f6a02698f7 100644 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccessWitness.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccessWitness.java @@ -35,4 +35,9 @@ public interface AccessWitness { long touchCodeChunksUponContractCreation(Address address, long codeLength); long touchCodeChunks(Address address, long offset, long readSize, long codeLength); + + default long touchCodeChunksWithoutAccessCost( + final Address address, final long offset, final long readSize, final long codeLength) { + return touchCodeChunks(address, offset, readSize, codeLength); + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/AccessWitness.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/AccessWitness.java index e0affe66e8..4e01152a03 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/AccessWitness.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/AccessWitness.java @@ -190,19 +190,21 @@ public class AccessWitness implements org.hyperledger.besu.datatypes.AccessWitne if ((readSize == 0 && codeLength == 0) || startPc > codeLength) { return 0; } - long endPc = startPc+readSize; - if(endPc>codeLength){ + long endPc = startPc + readSize; + if (endPc > codeLength) { endPc = codeLength; } - if(endPc>0){ - endPc-=1; + if (endPc > 0) { + endPc -= 1; } - for (long i = startPc / 31; i <= endPc/31; i++) { - gas = clampedAdd(gas, - touchAddressOnReadAndComputeGas( - address, - CODE_OFFSET.add(i).divide(VERKLE_NODE_WIDTH), - CODE_OFFSET.add(i).mod(VERKLE_NODE_WIDTH))); + for (long i = startPc / 31; i <= endPc / 31; i++) { + gas = + clampedAdd( + gas, + touchAddressOnReadAndComputeGas( + address, + CODE_OFFSET.add(i).divide(VERKLE_NODE_WIDTH), + CODE_OFFSET.add(i).mod(VERKLE_NODE_WIDTH))); } return gas; } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ShanghaiGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ShanghaiGasCalculator.java index 4eeb3fb8fb..86e461675f 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ShanghaiGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ShanghaiGasCalculator.java @@ -174,7 +174,7 @@ public class ShanghaiGasCalculator extends LondonGasCalculator { if (!transferValue.isZero()) { cost = clampedAdd( - baseCost, + cost, frame.getAccessWitness().touchAndChargeValueTransfer(recipient.getAddress(), to)); } return cost;