gas cost modification

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
pull/7004/head
Karim Taam 7 months ago committed by garyschulte
parent 80b8cd7669
commit 229b867c95
  1. 19
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/AccessWitness.java
  2. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java
  3. 7
      evm/src/main/java/org/hyperledger/besu/evm/EVM.java
  4. 2
      evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java
  5. 43
      evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ShanghaiGasCalculator.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;
}

@ -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(

@ -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);

@ -26,7 +26,7 @@ import static org.hyperledger.besu.datatypes.Address.KZG_POINT_EVAL;
* <LI>TBD
* </UL>
*/
public class PragueGasCalculator extends CancunGasCalculator {
public class PragueGasCalculator extends ShanghaiGasCalculator {
/** Instantiates a new Prague Gas Calculator. */
public PragueGasCalculator() {

@ -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

Loading…
Cancel
Save