Skip to content

Commit

Permalink
Merge pull request Fantom-foundation#27 from Fantom-foundation/HonzaD…
Browse files Browse the repository at this point in the history
…ajc/interpreter_refactor

Interpreter refactoring
  • Loading branch information
jenikd authored Feb 16, 2023
2 parents 4d1ecae + 62897b0 commit c94baa2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/vm/lfvm/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func gasSStoreEIP2200(c *context) (uint64, error) {
func gasSStoreEIP2929(c *context) (uint64, error) {

clearingRefund := params.SstoreClearsScheduleRefundEIP2200
if c.evm.ChainConfig().IsLondon(c.evm.Context.BlockNumber) {
if c.isLondon {
clearingRefund = params.SstoreClearsScheduleRefundEIP3529
}

Expand Down
16 changes: 13 additions & 3 deletions core/vm/lfvm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
SUICIDED
INVALID_INSTRUCTION
OUT_OF_GAS
SEGMENTATION_FAULT
ERROR
)

Expand Down Expand Up @@ -177,14 +178,21 @@ func Run(evm *vm.EVM, cfg vm.Config, contract *vm.Contract, code Code, data []by
return nil, vm.ErrOutOfGas
case INVALID_INSTRUCTION:
return nil, vm.ErrInvalidCode
case SEGMENTATION_FAULT:
return nil, vm.ErrInvalidCode
case ERROR:
if ctxt.err != nil {
return nil, ctxt.err
}
return nil, fmt.Errorf("unspecified error in interpreter")
}

panic(fmt.Sprintf("unknown interpreter status: %d", ctxt.status))
if ctxt.err != nil {
ctxt.status = ERROR
return nil, fmt.Errorf("unknown interpreter status %d with error %v", ctxt.status, ctxt.err)
} else {
return nil, fmt.Errorf("unknown interpreter status %d", ctxt.status)
}
}

func run(c *context) {
Expand Down Expand Up @@ -671,7 +679,8 @@ func steps(c *context, one_step_only bool) {
case NOOP:
opNoop(c)
case DATA:
panic("can not interpret data as instruction")
c.status = SEGMENTATION_FAULT
return
case INVALID:
opInvalid(c)
case SLOAD:
Expand Down Expand Up @@ -788,7 +797,8 @@ func steps(c *context, one_step_only bool) {
case PUSH1_PUSH1_PUSH1_SHL_SUB:
opPush1_Push1_Push1_Shl_Sub(c)
default:
panic(fmt.Sprintf("Unsupported operation: %v", op))
c.status = INVALID_INSTRUCTION
return
}
c.pc++

Expand Down
1 change: 1 addition & 0 deletions core/vm/lfvm/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ var op_to_string = map[OpCode]string{
MSTORE: "MSTORE",
MSTORE8: "MSTORE8",
MLOAD: "MLOAD",
MSIZE: "MSIZE",

SLOAD: "SLOAD",
SSTORE: "SSTORE",
Expand Down
8 changes: 4 additions & 4 deletions core/vm/lfvm/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ func getStaticStackInternal(op OpCode) InstructionStack {
case EXTCODECOPY:
return newInstructionStack(4, 0, 0)
case CREATE:
return newInstructionStack(3, 1, 1)
return newInstructionStack(3, 0, 1)
case CREATE2:
return newInstructionStack(4, 1, 1)
return newInstructionStack(4, 0, 1)
case CALL, CALLCODE:
return newInstructionStack(7, 1, 1)
return newInstructionStack(7, 0, 1)
case STATICCALL, DELEGATECALL:
return newInstructionStack(6, 1, 1)
return newInstructionStack(6, 0, 1)
case PUSH1_DUP1, PUSH1_PUSH1:
return newInstructionStack(0, 2, 2)
case SWAP2_SWAP1:
Expand Down

0 comments on commit c94baa2

Please sign in to comment.