Skip to content

Instantly share code, notes, and snippets.

@obscuren
Last active November 28, 2016 16:14
Show Gist options
  • Save obscuren/8ae66b033f1bf5b5fd74f87a86b44790 to your computer and use it in GitHub Desktop.
Save obscuren/8ae66b033f1bf5b5fd74f87a86b44790 to your computer and use it in GitHub Desktop.
for {
// Get the memory location of pc
op = contract.GetOp(pc)
// get the operation from the jump table matching the opcode
operation := evm.jumpTable[op]
// if the op is invalid abort the process and return an error
if operation.valid {
return nil, fmt.Errorf("Invalid opcode %x", op)
}
// consume the gas and return an error if not enough gas is available
if !contract.UseGas(operation.gasCost(evm.gasTable, evm.env, mem, stack)) {
return nil, OutOfGasError
}
// validate the stack and make sure there enough stack items available
// to perform the operation
if err := operation.validateStack(stack); err != nil {
return nil, err
}
// calucalte the new memory size and expand the memory to fit
// the operation
operation.resizeMemory(mem, stack)
// execute the operation
res, err := operation.execute(instruction{}, &pg, evm.env, contract, mem, stack)
if err != nil {
return nil, err
}
if operation.halts {
return res, nil
}
pc++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment