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 ef223a317f..e0affe66e8 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 @@ -9,6 +9,7 @@ import static org.hyperledger.besu.ethereum.trie.verkle.util.Parameters.MAIN_STO import static org.hyperledger.besu.ethereum.trie.verkle.util.Parameters.NONCE_LEAF_KEY; import static org.hyperledger.besu.ethereum.trie.verkle.util.Parameters.VERKLE_NODE_WIDTH; import static org.hyperledger.besu.ethereum.trie.verkle.util.Parameters.VERSION_LEAF_KEY; +import static org.hyperledger.besu.evm.internal.Words.clampedAdd; import org.hyperledger.besu.datatypes.Address; @@ -114,7 +115,6 @@ public class AccessWitness implements org.hyperledger.besu.datatypes.AccessWitne if (createSendsValue) { gas += touchAddressOnWriteAndComputeGas(address, zeroTreeIndex, BALANCE_LEAF_KEY); } - return gas; } @@ -185,17 +185,24 @@ public class AccessWitness implements org.hyperledger.besu.datatypes.AccessWitne @Override public long touchCodeChunks( - final Address address, final long offset, final long readSize, final long codeLength) { + final Address address, final long startPc, final long readSize, final long codeLength) { long gas = 0; - if (readSize == 0 || codeLength == 0 || offset > codeLength) { + if ((readSize == 0 && codeLength == 0) || startPc > codeLength) { return 0; } - for (long i = offset / 31; i <= (Math.min(offset + readSize, codeLength) - 1) / 31; i++) { - gas += + long endPc = startPc+readSize; + if(endPc>codeLength){ + endPc = codeLength; + } + 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)); + CODE_OFFSET.add(i).mod(VERKLE_NODE_WIDTH))); } return gas; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index 8c503221e3..996c39982e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -462,11 +462,11 @@ public class MainnetTransactionProcessor { final Wei balancePriorToRefund = sender.getBalance(); sender.incrementBalance(refundedWei); LOG.atTrace() - .setMessage("refunded sender {} {} wei ({} -> {})") + .setMessage("refunded sender {} {} wei (balance before:{} -> after:{})") .addArgument(senderAddress) - .addArgument(refundedWei) - .addArgument(balancePriorToRefund) - .addArgument(sender.getBalance()) + .addArgument(refundedWei.toShortHexString()) + .addArgument(balancePriorToRefund.toShortHexString()) + .addArgument(sender.getBalance().toShortHexString()) .log(); final long gasUsedByTransaction = transaction.getGasLimit() - initialFrame.getRemainingGas(); LOG.info( diff --git a/evm/src/main/java/org/hyperledger/besu/evm/EVM.java b/evm/src/main/java/org/hyperledger/besu/evm/EVM.java index e440c6c9f9..1b061e89c8 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/EVM.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/EVM.java @@ -183,11 +183,17 @@ public class EVM { var operationTracer = tracing == OperationTracer.NO_TRACING ? null : tracing; byte[] code = frame.getCode().getBytes().toArrayUnsafe(); + + Operation[] operationArray = operations.getOperations(); while (frame.getState() == MessageFrame.State.CODE_EXECUTING) { Operation currentOperation; int opcode; int pc = frame.getPC(); + + if (!frame.wasCreatedInTransaction(frame.getContractAddress())) { + frame.getAccessWitness().touchCodeChunks(frame.getContractAddress(), pc, 1, code.length); + } try { opcode = code[pc] & 0xff; currentOperation = operationArray[opcode]; @@ -278,7 +284,6 @@ public class EVM { } catch (final UnderflowException ue) { result = UNDERFLOW_RESPONSE; } - System.out.println("operation "+currentOperation.getName()+" "+result.getGasCost()+" "+frame.getRemainingGas()); final ExceptionalHaltReason haltReason = result.getHaltReason(); if (haltReason != null) { LOG.trace("MessageFrame evaluation halted because of {}", haltReason); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java index a48085f426..6f2839f265 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java @@ -26,7 +26,7 @@ import static org.hyperledger.besu.datatypes.Address.KZG_POINT_EVAL; *
  • TBD * */ -public class PragueGasCalculator extends CancunGasCalculator { +public class PragueGasCalculator extends ShanghaiGasCalculator { /** Instantiates a new Prague Gas Calculator. */ public PragueGasCalculator() { 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 cdaa29a33a..4eeb3fb8fb 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 @@ -295,32 +295,27 @@ public class ShanghaiGasCalculator extends LondonGasCalculator { final MessageFrame frame, final long codeOffset, final long readSize, final long codeSize) { long gasCost = super.pushOperationGasCost(frame, codeOffset, readSize, codeSize); if (!frame.wasCreatedInTransaction(frame.getContractAddress())) { - gasCost = - clampedAdd( - gasCost, - frame - .getAccessWitness() - .touchCodeChunks(frame.getContractAddress(), codeOffset, readSize, codeSize)); - System.out.println("push "+isPrecompile(frame.getContractAddress())+" "+frame.getContractAddress()+" "+codeOffset+" "+readSize+" "+codeSize+" "+gasCost); - } - return gasCost; - } + if(readSize==1){ + if( (codeOffset%31==0)){ + gasCost = + clampedAdd( + gasCost, + frame + .getAccessWitness() + .touchCodeChunks(frame.getContractAddress(), codeOffset+1, readSize, codeSize)); + + } + } else { + gasCost = + clampedAdd( + gasCost, + frame + .getAccessWitness() + .touchCodeChunks(frame.getContractAddress(), codeOffset, readSize, codeSize)); - @Override - public long extCodeSizeOperationGasCost(final MessageFrame frame) { - if(!isPrecompile(frame.getContractAddress())) { - long gasCost = - frame - .getAccessWitness() - .touchAddressOnReadAndComputeGas(frame.getContractAddress(), UInt256.ZERO, VERSION_LEAF_KEY); - return - clampedAdd( - gasCost, - frame - .getAccessWitness() - .touchAddressOnReadAndComputeGas(frame.getContractAddress(), UInt256.ZERO, CODE_SIZE_LEAF_KEY)); + } } - return 0; + return gasCost; } @Override