From ca546641654d510c414bac40f77f94f3ac16df8f Mon Sep 17 00:00:00 2001 From: Nazaret Garcia Date: Fri, 22 Nov 2024 19:07:09 -0300 Subject: [PATCH] Add gas cost --- rskj-core/src/main/java/org/ethereum/vm/VM.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rskj-core/src/main/java/org/ethereum/vm/VM.java b/rskj-core/src/main/java/org/ethereum/vm/VM.java index 7ae5fdd73d..6d34421ac5 100644 --- a/rskj-core/src/main/java/org/ethereum/vm/VM.java +++ b/rskj-core/src/main/java/org/ethereum/vm/VM.java @@ -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();