Skip to content

Commit

Permalink
Fix CALLCODE gas costs regression with previous forks (#7959)
Browse files Browse the repository at this point in the history
Signed-off-by: Luis Pinto <[email protected]>
  • Loading branch information
lu-pinto authored Nov 29, 2024
1 parent 588a058 commit f7535f3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ public long proofOfAbsenceCost(final MessageFrame frame, final Address address)
return frame.getAccessWitness().touchAndChargeProofOfAbsence(address);
}

@Override
public long callCodeOperationGasCost(
final MessageFrame frame,
final long stipend,
final long inputDataOffset,
final long inputDataLength,
final long outputDataOffset,
final long outputDataLength,
final Wei transferValue,
final Account recipient,
final Address contract,
final boolean accountIsWarm) {
return callOperationGasCost(
frame,
stipend,
inputDataOffset,
inputDataLength,
outputDataOffset,
outputDataLength,
// CALLCODE transfers value to itself so hardcode it to zero
Wei.ZERO,
recipient,
contract,
accountIsWarm);
}

@Override
public long callOperationGasCost(
final MessageFrame frame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ public long callOperationGasCost(
true);
}

@Override
public long callCodeOperationGasCost(
final MessageFrame frame,
final long stipend,
final long inputDataOffset,
final long inputDataLength,
final long outputDataOffset,
final long outputDataLength,
final Wei transferValue,
final Account recipient,
final Address contract,
final boolean accountIsWarm) {
return callOperationGasCost(
frame,
stipend,
inputDataOffset,
inputDataLength,
outputDataOffset,
outputDataLength,
transferValue,
recipient,
contract,
accountIsWarm);
}

@Override
public long callOperationGasCost(
final MessageFrame frame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,33 @@ default long callOperationGasCost(
true);
}

/**
* Returns the gas cost that the CALLCODE operation will consume.
*
* @param frame The current frame
* @param stipend The gas stipend being provided by the CALL caller
* @param inputDataOffset The offset in memory to retrieve the CALL input data
* @param inputDataLength The CALL input data length
* @param outputDataOffset The offset in memory to place the CALL output data
* @param outputDataLength The CALL output data length
* @param transferValue The wei being transferred
* @param recipient The CALL recipient (may be null if self destructed or new)
* @param contract The address of the recipient (never null)
* @param accountIsWarm The address of the contract is "warm" as per EIP-2929
* @return The gas cost for the CALL operation
*/
long callCodeOperationGasCost(
final MessageFrame frame,
final long stipend,
final long inputDataOffset,
final long inputDataLength,
final long outputDataOffset,
final long outputDataLength,
final Wei transferValue,
final Account recipient,
final Address contract,
final boolean accountIsWarm);

/**
* Returns the gas cost for one of the various CALL operations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@ public long cost(final MessageFrame frame, final boolean accountIsWarm) {
final Address to = to(frame);
GasCalculator gasCalculator = gasCalculator();

return gasCalculator.callOperationGasCost(
return gasCalculator.callCodeOperationGasCost(
frame,
stipend,
inputDataOffset,
inputDataLength,
outputDataOffset,
outputDataLength,
// As far as CALLCODE is concerned, there isn't a value transfer
Wei.ZERO,
value(frame),
recipient,
to,
accountIsWarm);
Expand Down

0 comments on commit f7535f3

Please sign in to comment.