Skip to content

Instantly share code, notes, and snippets.

@voith
Created October 19, 2020 12:58
Show Gist options
  • Save voith/f43d0e5eb0a2880c6c59beabcc4bd1af to your computer and use it in GitHub Desktop.
Save voith/f43d0e5eb0a2880c6c59beabcc4bd1af to your computer and use it in GitHub Desktop.
Example to add two numbers using the Ethereum virtual Machine.
from eth.vm.forks import (
IstanbulVM,
)
from eth.vm import (
opcode_values
)
from tests.core.opcodes.test_opcodes import (
assemble,
CANONICAL_ADDRESS_B,
setup_computation,
)
code = assemble(
opcode_values.PUSH1,
0x1,
opcode_values.PUSH1,
0x1,
opcode_values.ADD
)
computation = setup_computation(IstanbulVM, CANONICAL_ADDRESS_B, code)
comp = computation.apply_message(
computation.state,
computation.msg,
computation.transaction_context,
)
result = comp.stack_pop1_any()
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment