CALLF and JUMPF rules validation updates (#7787)

* Check JUMPF stack

Rule 2 in EIP-6206 requires us to check stack prior to JUMPF

Signed-off-by: Danno Ferrin <danno@numisight.com>

* CALLF rule 4 rollback

Rule 4 is about return stack, not operand stack

Signed-off-by: Danno Ferrin <danno@numisight.com>

---------

Signed-off-by: Danno Ferrin <danno@numisight.com>
This commit is contained in:
Danno Ferrin
2024-10-23 11:04:11 -06:00
committed by GitHub
parent 653ebcbd70
commit d583863225
2 changed files with 9 additions and 2 deletions

View File

@@ -54,8 +54,7 @@ public class CallFOperation extends AbstractOperation {
int section = code.readBigEndianU16(pc + 1);
CodeSection info = code.getCodeSection(section);
int operandStackSize = frame.stackSize();
if (operandStackSize >= 1024
|| operandStackSize > 1024 - info.getMaxStackHeight() + info.getInputs()) {
if (operandStackSize > 1024 - info.getMaxStackHeight() + info.getInputs()) {
return callfStackOverflow;
}
frame.getReturnStack().push(new ReturnStack.ReturnStackItem(frame.getSection(), pc + 2));

View File

@@ -16,6 +16,7 @@ package org.hyperledger.besu.evm.operation;
import org.hyperledger.besu.evm.Code;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
@@ -28,6 +29,9 @@ public class JumpFOperation extends AbstractOperation {
/** The Jump F success operation result. */
static final OperationResult jumpfSuccess = new OperationResult(5, null);
static final OperationResult jumpfStackOverflow =
new OperationResult(5, ExceptionalHaltReason.TOO_MANY_STACK_ITEMS);
/**
* Instantiates a new Jump F operation.
*
@@ -46,6 +50,10 @@ public class JumpFOperation extends AbstractOperation {
int pc = frame.getPC();
int section = code.readBigEndianU16(pc + 1);
var info = code.getCodeSection(section);
int operandStackSize = frame.stackSize();
if (operandStackSize > 1024 - info.getMaxStackHeight() + info.getInputs()) {
return jumpfStackOverflow;
}
frame.setPC(info.getEntryPoint() - 1); // will be +1ed at end of operations loop
frame.setSection(section);
return jumpfSuccess;