Skip to content

Commit

Permalink
Add gas cost
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarev committed Nov 22, 2024
1 parent 1ba7a01 commit ca54664
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions rskj-core/src/main/java/org/ethereum/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -1438,11 +1438,14 @@ protected void doJUMPDEST()

protected void doMCOPY() {
if (computeGas) {
// See "Gas Cost" section on EIP 5656
// gas cost = 3 * (length + 31) + memory expansion cost + very low
long length = stack.get(stack.size() - 3).longValue();
long newMemSize = memNeeded(stack.peek(), length);
long cost = 3 * (length + 31) + calcMemGas(oldMemSize, newMemSize, 0) + 3; // TODO -> Check copy size

// See "Gas Cost" section on EIP 5656 for reference
long copiedWords = (length + 31) / 32;
long memoryExpansionCost = calcMemGas(oldMemSize, newMemSize, copiedWords);
long copyGasCost = 3 * copiedWords + memoryExpansionCost;
long cost = 3 + copyGasCost; // 3 is the fixed gas cost for very low mem usage

gasCost = GasCost.add(gasCost, cost);
spendOpCodeGas();
Expand Down

0 comments on commit ca54664

Please sign in to comment.