call value transfer cost fix, added non-accumulating method for touchCodeChunks

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/7004/head
garyschulte 7 months ago
parent dd893219ef
commit 852ace4c3f
  1. 5
      datatypes/src/main/java/org/hyperledger/besu/datatypes/AccessWitness.java
  2. 22
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/AccessWitness.java
  3. 2
      evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ShanghaiGasCalculator.java

@ -35,4 +35,9 @@ public interface AccessWitness {
long touchCodeChunksUponContractCreation(Address address, long codeLength); long touchCodeChunksUponContractCreation(Address address, long codeLength);
long touchCodeChunks(Address address, long offset, long readSize, 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);
}
} }

@ -190,19 +190,21 @@ public class AccessWitness implements org.hyperledger.besu.datatypes.AccessWitne
if ((readSize == 0 && codeLength == 0) || startPc > codeLength) { if ((readSize == 0 && codeLength == 0) || startPc > codeLength) {
return 0; return 0;
} }
long endPc = startPc+readSize; long endPc = startPc + readSize;
if(endPc>codeLength){ if (endPc > codeLength) {
endPc = codeLength; endPc = codeLength;
} }
if(endPc>0){ if (endPc > 0) {
endPc-=1; endPc -= 1;
} }
for (long i = startPc / 31; i <= endPc/31; i++) { for (long i = startPc / 31; i <= endPc / 31; i++) {
gas = clampedAdd(gas, gas =
touchAddressOnReadAndComputeGas( clampedAdd(
address, gas,
CODE_OFFSET.add(i).divide(VERKLE_NODE_WIDTH), touchAddressOnReadAndComputeGas(
CODE_OFFSET.add(i).mod(VERKLE_NODE_WIDTH))); address,
CODE_OFFSET.add(i).divide(VERKLE_NODE_WIDTH),
CODE_OFFSET.add(i).mod(VERKLE_NODE_WIDTH)));
} }
return gas; return gas;
} }

@ -174,7 +174,7 @@ public class ShanghaiGasCalculator extends LondonGasCalculator {
if (!transferValue.isZero()) { if (!transferValue.isZero()) {
cost = cost =
clampedAdd( clampedAdd(
baseCost, cost,
frame.getAccessWitness().touchAndChargeValueTransfer(recipient.getAddress(), to)); frame.getAccessWitness().touchAndChargeValueTransfer(recipient.getAddress(), to));
} }
return cost; return cost;

Loading…
Cancel
Save