ref-fvm icon indicating copy to clipboard operation
ref-fvm copied to clipboard

EVM runtime: Map FVM context info to EVM opcodes

Open karim-agha opened this issue 2 years ago • 2 comments

Implement opcodes that query the transaction context:

  • ORIGIN
  • CALLVALUE
  • ADDRESS
  • BLOCK_NUMBER
  • TIMESTAMP
  • CALLER
  • BLOCKHASH
  • CHAINID
  • BASEFEE
  • DIFFICULTY
  • GASLIMIT

karim-agha avatar Jun 14 '22 15:06 karim-agha

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

raulk avatar Jun 15 '22 00:06 raulk

Notes / checklist.

Done

  • [x] ORIGIN => requires a new syscall: #300.
  • [x] CALLVALUE => maps to the value received in the transaction context, in native FIL.
  • [x] ADDRESS => returns the ID address in EVM form of the receiver.
  • [x] BLOCK_NUMBER => epoch.
  • [x] CALLER => returns the ID address in EVM form of the caller.
  • [x] BASEFEE => return the basefee
  • [x] DIFFICULTY => return 0
  • [x] 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 #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 avatar Aug 08 '22 11:08 raulk

Now tracking more granularly in https://github.com/filecoin-project/ref-fvm/issues/864 and https://github.com/filecoin-project/ref-fvm/issues/865.

raulk avatar Sep 12 '22 18:09 raulk