From 1ae2dffecf9fccf2735f281ac33c10a13c3feff1 Mon Sep 17 00:00:00 2001 From: Nazaret Garcia Date: Thu, 12 Dec 2024 20:38:17 -0300 Subject: [PATCH] Updating gas calculation --- rskj-core/src/main/java/org/ethereum/vm/VM.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 93ce25885a..649981f229 100644 --- a/rskj-core/src/main/java/org/ethereum/vm/VM.java +++ b/rskj-core/src/main/java/org/ethereum/vm/VM.java @@ -769,10 +769,19 @@ private long computeDataCopyGas() { private long computeMemoryCopyGas() { DataWord length = stack.get(stack.size() - 3); - DataWord offset = stack.peek(); + DataWord src = stack.get(stack.size() - 2); + DataWord dst = stack.peek(); + long copySize = Program.limitToMaxLong(length); checkSizeArgument(copySize); + + DataWord offset = dst; + if (src.value().compareTo(dst.value()) > 0) { + offset = src; + } + long newMemSize = memNeeded(offset, copySize); + // Note: 3 additional units are added outside because of the "Very Low Tier" configuration return calcMemGas(oldMemSize, newMemSize, copySize); }