Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 19 21:23
    developerfred commented #1958
  • Oct 19 20:58
    Peppece synchronize #1937
  • Oct 19 20:40
    Peppece synchronize #1937
  • Oct 19 20:36
    Peppece synchronize #1937
  • Oct 19 14:37
    voith commented #1958
  • Oct 19 14:37
    voith commented #1958
  • Oct 19 14:10
    pipermerriam commented #1958
  • Oct 19 14:05
    gitcoinbot commented #1958
  • Oct 19 14:04
    pipermerriam commented #1958
  • Oct 19 12:28
    Peppece synchronize #1937
  • Oct 19 12:23
    MatthiasLohr opened #1959
  • Oct 19 12:15
    Peppece synchronize #1937
  • Oct 19 12:10
    voith commented #1958
  • Oct 19 12:10
    Peppece synchronize #1937
  • Oct 19 12:06
    Peppece synchronize #1937
  • Oct 19 11:56
    Peppece synchronize #1937
  • Oct 19 11:44
    Peppece synchronize #1937
  • Oct 16 16:53
    pipermerriam commented #1958
  • Oct 16 16:50
    gitcoinbot commented #1958
  • Oct 16 15:22
    voith commented #1958
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<Christoph Burgdorf (cburgdorf)> Cool, happy to hear it's working
thor-ragnarok
@thor-ragnarok
Hey all - is it possible to use mainnet storage with py-evm? - I need to simulate multiple transactions that may depend on each other at a specific block height hence why a simple eth_call will not suffice
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<carver, Jason Carver> You mean you want to run a series of transactions on mainnet state, right? AIUI this feature supports it: https://eth-brownie.readthedocs.io/en/stable/network-management.html#using-a-forked-development-network
thor-ragnarok
@thor-ragnarok
yes I am aware of this thanks - unfortunately doesn't fulfil my criteria - was hoping i could easily hook up py-evm to my local node db somehow and just run tnxs through the evm without committing the state of my node db.
Giuseppe Cerami
@Peppece
hello, whenever i run the tests the output shows that spaces and tabs are mixed. Could that prevent the scripts from running or the tests from succeeding? The part of the output that lets me know this is not displayed as an error, so I'm assuming the answer is no, but is that so?
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<Christoph Burgdorf (cburgdorf)> @Peepece Mixed spaces and tabs shouldn't have any effect on pytest. But the linting job in CI will fail so you'll have to fix these inconsistencies eventually.
Giuseppe Cerami
@Peppece
@cburgdorf just noticed! I get only the linting job failing with ERROR: InvocationError for command /home/circleci/repo/.tox/py38-lint/bin/flake8 eth tests scripts. Is that it?
oh and I also get ERROR: InvocationError for command /usr/bin/make validate-docs and the docs failing. No idea why
Giuseppe Cerami
@Peppece
Hello, I am writing tests. One problem, in order to actually verify them, opcodes need to be executed and my opcodes live in the BerlinVM, which doesn't exist yet. Should I simply put some boilerplate there or create an issue or something?
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<Christoph Burgdorf (cburgdorf)> There's a wip BerlinVM in ethereum/py-evm#1933
<Christoph Burgdorf (cburgdorf)> I would recommend that you base your work on #1933 and then rebase everything (the combination of 1933 + your commits) on top of master. That way, you have all the pre-existing Berlin work while at the same time keeping things up to date with master
Giuseppe Cerami
@Peppece
guys, I have reinstalled all components due to a problem with the directory
after having installed, I get weird errors when running tests, such as from hypothesis import ( E ModuleNotFoundError: No module named 'hypothesis' when running pytest database
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<carver, Jason Carver> Maybe you installed without the dev extra tag? Try again with pip install -e .[dev]
Giuseppe Cerami
@Peppece
that's it! I had escaped the brackets with \, but it seems like it didnt produce the same result as before. thanks
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<Piper Merriam> If anyone wants to tinker with implementing code merklization: ethereum/py-evm#1958
Voith Mascarenhas
@voith
I’d like to give it a shot.
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<Piper Merriam> @voith go for it. Made a bounty for you if you're interested. Please go claim it if you are.
Alita Moore
@alita-moore
I'm looking into the possibility of building a plugin for py-evm that would give more control over calling individual opcodes and logging. This is for optimizing close to metal methods (curve / cryptography). Part of this is in developing custom op-codes and interfacing them with the greater py-evm, and then being able to call them arbitrarily. Can I just use an instance of BaseComputation and overwrite as many builtin opcodes / custom opcodes as I feel like? If so, is there an example of this being done?
Alita Moore
@alita-moore
So I got a prototype of what I mean working, is there a better way to do this? https://github.com/alita-moore/BLS12-381-Huff/blob/1f5baa0d576d7dc0a240d6f8ea99d6c3fc06d13e/src/scratch.py#L1
Voith Mascarenhas
@voith
Thanks @pipermerriam. However, I am not interested in the bounty. I have left a comment on the issue.
Voith Mascarenhas
@voith
Hey @alita-moore. This test file has some great examples for your use case:
https://github.com/ethereum/py-evm/blob/master/tests/core/opcodes/test_opcodes.py
I converted your code to use utilities from test_opcodes.py
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)
Voith Mascarenhas
@voith
and here’s how you can add an opcode:
import copy
from typing import (
    Type,
)

from eth_utils.toolz import merge

from eth import constants
from eth.vm.computation import BaseComputation
from eth.vm.forks.istanbul import IstanbulVM
from eth.vm.forks.istanbul.computation import IstanbulComputation
from eth.vm.forks.istanbul.opcodes import ISTANBUL_OPCODES
from eth.vm.forks.istanbul.state import IstanbulState
from eth.vm.opcode import as_opcode
from eth.vm.state import BaseState


SUBTRACT_OPCODE_VALUE = 0xa5
SUBTRACT_MNEMONIC = 'SUBTRACT'

def sub(computation: BaseComputation) -> None:
    left, right = computation.stack_pop_ints(2)

    result = (left - right) & constants.UINT_256_MAX

    computation.stack_push_int(result)

UPDATED_OPCODES = {
    SUBTRACT_OPCODE_VALUE: as_opcode(
        logic_fn=sub,
        mnemonic=SUBTRACT_MNEMONIC,
        gas_cost=constants.GAS_LOW,
    )
}


CUSTOM_OPCODES = merge(
    copy.deepcopy(ISTANBUL_OPCODES),
    UPDATED_OPCODES,
)

class CustomComputation(IstanbulComputation):
    opcodes = CUSTOM_OPCODES

class CustomState(IstanbulState):
    computation_class = CustomComputation

class CustomVm(IstanbulVM):
    _state_class: Type[BaseState] = CustomState
Alita Moore
@alita-moore
@voith ah yeah that's a good file. Cool! When I want to call the opcodes independently (for use with a step-wise api) is the best way to do that like this:
Alita Moore
@alita-moore
# ... your code
def gen_context(VM):
  CANONICAL_ADDRESS_A = to_canonical_address("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
  CANONICAL_ADDRESS_B = to_canonical_address("0xcd1722f3947def4cf144679da39c4c32bdc35681")
  state = VM.state
  message = Message(
    to=CANONICAL_ADDRESS_A,
    sender=CANONICAL_ADDRESS_B,
    create_address=None,
    value=0,
    data=b'',
    code=b'',
    gas=1000000,
  )
  tx_context = VM._state_class.transaction_context_class(gas_price=1, origin=CANONICAL_ADDRESS_B)
  return state, message, tx_context

#########################
VM = CustomVM()
state, message, tx = gen_context(VM)
computation = VM._state_class.computation_class(state, message, tx)

computation.stack_push_int(1)
computation.stack_push_int(1)
computation.opcodes["SUBTRACT"](computation)
result = computation.stack_pop1_int()
also what's the best way to get debug-level information about the exact bytes in the stack / memory?
Voith Mascarenhas
@voith
How about this:
code = assemble(
    opcode_values.PUSH1,
    0x1,
    opcode_values.PUSH1,
    0x1,
    SUBTRACT_OPCODE_VALUE
)

computation = setup_computation(CustomVm, CANONICAL_ADDRESS_B, code)
comp = computation.apply_message(
        computation.state,
        computation.msg,
        computation.transaction_context,
    )
result = comp.stack_pop1_any()
print(result)
Alita Moore
@alita-moore
huh, where is setup_computation defined?
Voith Mascarenhas
@voith
It’s not a public method, It’s in the test file I linkeed to earlier
from tests.core.opcodes.test_opcodes import setup_computation
Alita Moore
@alita-moore
got it, okay, does the address matter?
(i don't intend on doing anything above opcode / memory level)
Voith Mascarenhas
@voith
eth.vm.Message needs a create_address. I used it as a placeholder. Although I’m not sure what happens if any EOA is used.
PS: I’m new to this project too. I’m trying to learn by trying to answer your question. So don’t take my answer as the final word :P

also what’s the best way to get debug-level information about the exact bytes in the stack / memory?

You can take inspiration from this project: https://github.com/status-im/vyper-debug. Although it only works for vyper.

Alita Moore
@alita-moore
huh interesting, yeah that'll be a great starting point! Haha no worries, I'm sure you know more than me!
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<jwasinger> I am not familiar with py-evm but is there a tracer which outputs contents of memory/stack after each step?
Voith Mascarenhas
@voith
not sure if the trace transaction API has been implemented
Alita Moore
@alita-moore
I'm going to be implementing my own tracing structure, but it would be very helpful to just be able to say computation.stack() and get a bytearray of the current stack in all its glory and same thing for memroy
Voith Mascarenhas
@voith
@alita-moore A project I’d suggest looking at is eth-brownie. It has a pretty good debug API.
https://eth-brownie.readthedocs.io/en/stable/core-transactions.html#call-traces
Alita Moore
@alita-moore
oh dang yes it does
thanks
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<carver, Jason Carver> Direct access to the stack attribute is private, so the API might change at any time. But currently, you can get the raw stack values with something like [raw_val for val_type, raw_val in computation._stack.values]
<carver, Jason Carver> @alita-moore
Voith Mascarenhas
@voith
@carver Are there plans to add a tracer to py-evm?
Eth-Gitter-Bridge
@Eth-Gitter-Bridge
<carver, Jason Carver> Yeah, definitely makes sense to add. It's just not at the top of the to-do list at the moment
Voith Mascarenhas
@voith
:+1:
Alita Moore
@alita-moore
awesome, thanks!
do you think computation will always have a _stack option?