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 runtime: Map FVM context info to EVM opcodes #689

Closed
karim-agha opened this issue Jun 14, 2022 · 3 comments
Closed

EVM runtime: Map FVM context info to EVM opcodes #689

karim-agha opened this issue Jun 14, 2022 · 3 comments
Assignees
Labels
Kind: Epic A collection of issues. Topic: EVM runtime

Comments

@karim-agha
Copy link
Contributor

karim-agha commented Jun 14, 2022

See #689 (comment) for the updated view and state


Implement opcodes that query the transaction context:

  • ORIGIN
  • CALLVALUE
  • ADDRESS
  • BLOCK_NUMBER
  • TIMESTAMP
  • CALLER
  • BLOCKHASH
  • CHAINID
  • BASEFEE
  • DIFFICULTY
  • GASLIMIT
@karim-agha karim-agha self-assigned this Jun 14, 2022
@raulk
Copy link
Member

raulk commented Jun 15, 2022

These should be simple, except for the address ones, where we'll eventually need to return the f4 address.

@raulk raulk changed the title Map FVM context info to EVM opcodes EVM runtime: Map FVM context info to EVM opcodes Aug 8, 2022
@raulk raulk transferred this issue from filecoin-project/fvm-evm Aug 8, 2022
@raulk
Copy link
Member

raulk commented Aug 8, 2022

Notes / checklist.

Done

  • ORIGIN => requires a new syscall: Add a syscall to obtain the originator of a call #300.
  • CALLVALUE => maps to the value received in the transaction context, in native FIL.
  • ADDRESS => returns the ID address in EVM form of the receiver.
  • BLOCK_NUMBER => epoch.
  • CALLER => returns the ID address in EVM form of the caller.
  • BASEFEE => return the basefee
  • DIFFICULTY => return 0
  • SELFBALANCE => return balance of the current contract

Requires FVM work:

  • GASPRICE => sum of base_fee and gas_premium. Requires the gas_premium in the InvocationContext, so that it's returned in vm::context().
  • BALANCE => requires a syscall to obtain the balance of an arbitrary address.
  • GAS => return available gas. Requires a gas::available() syscall.

** Requires FVM, ffi, and client work: **

  • TIMESTAMP => the timestamp is an attribute in the block header; needs a syscall and snake through the ffi from the client.
  • BLOCKHASH => this is tricky. I don't think we can return just the hash of the first block in the parent tipset, as we probably lose some security in the face of a reorg that preserves the first block.
  • CHAINID => return value zero until Chainlist submission to reserve a chain ID #681?
  • GASLIMIT => returns the block's gas limit. We may need a syscall or a context parameter to return this value to avoid hardcoding the 15B gas assumption.

For the latter group consider:

  1. Putting these attributes behind a chain_data() syscall. These are really "environmental attributes" not scoped to the message (unlike InvocationContext).
  2. Adding them to the InvocationContext returned by vm::context(), but that would bloat the struct for cases that do not need to access all attributes (likely not a big deal, it'll be some ~64 bytes extra)

@raulk
Copy link
Member

raulk commented Sep 12, 2022

Now tracking more granularly in #864 and #865.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kind: Epic A collection of issues. Topic: EVM runtime
Projects
None yet
Development

No branches or pull requests

4 participants