Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM won't wait for 'step' event handler to finish before continuing execution #2290

Closed
thevaizman opened this issue Sep 17, 2022 · 3 comments

Comments

@thevaizman
Copy link

thevaizman commented Sep 17, 2022

Hey, was trying to bump our version of ethereumjs in our evm.codes project.

I am using the latest (6.0.0) @ethereumjs/vm and the latest (1.0.0) @ethereumjs/evm packages.
When my handler to the step event is called with a function as the 2nd arg, the EVM won't wait until the function is called and will just keep executing till the end.

My event handler declaration:

    const contFunc = () => {};

    vm.evm.events!.on('step', (e: InterpreterStep) => {
      _stepInto(e, contFunc)
    })

My handler function:

  const _stepInto = (
    { depth, pc, gasLeft, opcode, stack, memory }: InterpreterStep,
    continueFunc: () => void,
  ) => {

    // skip internal calls
    if (depth !== 0) {
      continueFunc()
      return
    }
  }

From the docs, I understand that EVM execution should wait until I call continueFunc() in my handler, but this is not the case. The execution just continues. I do know for sure that my _stepInto() handler is called as I can see console.logs from there.

I know that the event emitting properties of EVM/VM changed in the last few versions, could it be a bug? Or am I doing something wrong?

Would appreciate your help, as you were always extremely helpful for us! :) @jochem-brouwer @holgerd77

@jochem-brouwer
Copy link
Member

You need to add a second argument to the event listener.

vm.events.on('step', async (e: InterpreterStep, contFun: Function) => {await someFun(); contFun()})

@thevaizman
Copy link
Author

Thanks a lot for the quick answer @jochem-brouwer! For future reference of people who may be getting into the same problem and bump into this ticket, when using Function, it ended up asking me for a different type for the 2nd argument of the event handler, but it's now working after I used:

    vm.evm.events!.on('step', (e: InterpreterStep, contFunc: ((result?: any) => void) | undefined) => {
      _stepInto(e, contFunc)
    })

@holgerd77
Copy link
Member

Is this sufficiently described in the code docs? Otherwise it would be good to add.

Will add as an eventual TODO to #2105

@holgerd77 holgerd77 mentioned this issue Sep 19, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants