Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public RelativeJumpVectorOperation(final GasCalculator gasCalculator) {
@Override
protected OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
final Bytes code = frame.getCode().getBytes();
final int offsetCase = frame.popStackItem().toInt();
int offsetCase;
try {
offsetCase = frame.popStackItem().toInt() & 0xff;
} catch (ArithmeticException | IllegalArgumentException ae) {
offsetCase = Integer.MAX_VALUE;
}
final int vectorSize = getVectorSize(code, frame.getPC() + 1);
return new OperationResult(
gasCost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.hyperledger.besu.evm.operation.RelativeJumpVectorOperation;
import org.hyperledger.besu.evm.testutils.TestMessageFrameBuilder;

import java.util.List;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -129,6 +131,51 @@ void rjumpvOperation() {
assertThat(rjumpResult.getPcIncrement()).isEqualTo(1 + 2 * jumpVectorSize + 1);
}

@Test
void rjumpvOverflowOperation() {
final GasCalculator gasCalculator = mock(GasCalculator.class);
final Code mockCode = mock(Code.class);
final int rjumpOperationIndex = 3;
final int jumpVectorSize = 1;
final int jumpLength = 4;
final Bytes code =
Bytes.fromHexString(
"00".repeat(rjumpOperationIndex)
+ String.format("5e%02x%04x", jumpVectorSize, jumpLength));

when(mockCode.getBytes()).thenReturn(code);
RelativeJumpVectorOperation rjumpv = new RelativeJumpVectorOperation(gasCalculator);

for (Bytes jump :
List.of(
Bytes.fromHexString("0x7f"),
Bytes.fromHexString("0xff"),
Bytes.fromHexString("0x7fff"),
Bytes.fromHexString("0xffff"),
Bytes.fromHexString("0x7fffffff"),
Bytes.fromHexString("0xffffffff"),
Bytes.fromHexString("0x7fffffffffffffff"),
Bytes.fromHexString("0xffffffffffffffff"),
Bytes.fromHexString("0x7fffffffffffffffffffffffffffffff"),
Bytes.fromHexString("0xffffffffffffffffffffffffffffffff"),
Bytes.fromHexString(
"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
Bytes.fromHexString(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))) {
MessageFrame messageFrame =
new TestMessageFrameBuilder()
.code(mockCode)
.pc(rjumpOperationIndex)
.initialGas(5L)
.pushStackItem(jump)
.build();

Operation.OperationResult rjumpResult = rjumpv.execute(messageFrame, null);

assertThat(rjumpResult.getPcIncrement()).isEqualTo(1 + 2 * jumpVectorSize + 1);
}
}

@Test
void rjumpvHitOperation() {
final GasCalculator gasCalculator = mock(GasCalculator.class);
Expand Down