Skip to content

Commit 35abb34

Browse files
committed
fixup! Speed up ID precompile
context ending frame instructions can read from mutable memory Signed-off-by: Luis Pinto <[email protected]>
1 parent 8844d4c commit 35abb34

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

evm/src/main/java/org/hyperledger/besu/evm/operation/ReturnOperation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
4646
return new OperationResult(cost, ExceptionalHaltReason.INSUFFICIENT_GAS);
4747
}
4848

49-
frame.setOutputData(frame.readMemory(from, length));
49+
// can read from mutable memory as this frame's memory is going out of scope
50+
frame.setOutputData(frame.readMutableMemory(from, length));
5051
frame.setState(MessageFrame.State.CODE_SUCCESS);
5152
return new OperationResult(cost, null);
5253
}

evm/src/main/java/org/hyperledger/besu/evm/operation/RevertOperation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
4848
return new OperationResult(cost, ExceptionalHaltReason.INSUFFICIENT_GAS);
4949
}
5050

51-
final Bytes reason = frame.readMemory(from, length);
51+
// can read from mutable memory as this frame's memory is going out of scope
52+
final Bytes reason = frame.readMutableMemory(from, length);
5253
frame.setOutputData(reason);
5354
frame.setRevertReason(reason);
5455
frame.setState(MessageFrame.State.REVERT);

evm/src/test/java/org/hyperledger/besu/evm/operation/RevertOperationTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator;
2323

2424
import org.apache.tuweni.bytes.Bytes;
25+
import org.apache.tuweni.bytes.MutableBytes;
2526
import org.apache.tuweni.units.bigints.UInt256;
2627
import org.junit.jupiter.api.BeforeEach;
2728
import org.junit.jupiter.api.Test;
@@ -37,14 +38,15 @@ class RevertOperationTest {
3738
@Mock private MessageFrame messageFrame;
3839
private final RevertOperation operation = new RevertOperation(new ConstantinopleGasCalculator());
3940

40-
private final Bytes revertReasonBytes = Bytes.fromHexString("726576657274206d657373616765");
41+
private final MutableBytes revertReasonBytes =
42+
Bytes.fromHexString("726576657274206d657373616765").mutableCopy();
4143

4244
@BeforeEach
4345
void setUp() {
4446
when(messageFrame.popStackItem())
4547
.thenReturn(UInt256.fromHexString("0x00"))
4648
.thenReturn(UInt256.fromHexString("0x0e"));
47-
when(messageFrame.readMemory(0, 14)).thenReturn(revertReasonBytes);
49+
when(messageFrame.readMutableMemory(0, 14)).thenReturn(revertReasonBytes);
4850
when(messageFrame.memoryWordSize()).thenReturn(0);
4951
when(messageFrame.calculateMemoryExpansion(anyLong(), anyLong())).thenReturn(14L);
5052
when(messageFrame.getRemainingGas()).thenReturn(10_000L);

0 commit comments

Comments
 (0)