Skip to content

Commit

Permalink
feat(fw): add call_return_code
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jul 30, 2024
1 parent 650b3eb commit f12d155
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ethereum_test_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
OpcodeCallArg,
Opcodes,
UndefinedOpcodes,
call_return_code,
)

from .code import (
Expand Down Expand Up @@ -135,6 +136,7 @@
"Yul",
"YulCompiler",
"add_kzg_version",
"call_return_code",
"ceiling_division",
"compute_create_address",
"compute_create2_address",
Expand Down
2 changes: 2 additions & 0 deletions src/ethereum_test_vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .bytecode import Bytecode
from .evm_types import EVMCodeType
from .helpers import call_return_code
from .opcode import Macro, Macros, Opcode, OpcodeCallArg, Opcodes, UndefinedOpcodes

__all__ = (
Expand All @@ -15,4 +16,5 @@
"OpcodeCallArg",
"Opcodes",
"UndefinedOpcodes",
"call_return_code",
)
20 changes: 20 additions & 0 deletions src/ethereum_test_vm/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Helper functions for the EVM.
"""

from .opcode import Opcodes as Op


def call_return_code(opcode: Op, success: bool, *, revert: bool = False) -> int:
"""
Returns the return code for a CALL operation.
"""
if opcode in [Op.CALL, Op.CALLCODE, Op.DELEGATECALL, Op.STATICCALL]:
return int(success)
elif opcode in [Op.EXTCALL, Op.EXTDELEGATECALL, Op.EXTSTATICCALL]:
if success:
return 0
if revert:
return 2
return 1
raise ValueError(f"Not a call opcode: {opcode}")

0 comments on commit f12d155

Please sign in to comment.