ref-fvm
ref-fvm copied to clipboard
EVM runtime: Map FVM context info to EVM opcodes
Implement opcodes that query the transaction context:
-
ORIGIN
-
CALLVALUE
-
ADDRESS
-
BLOCK_NUMBER
-
TIMESTAMP
-
CALLER
-
BLOCKHASH
-
CHAINID
-
BASEFEE
-
DIFFICULTY
-
GASLIMIT
These should be simple, except for the address ones, where we'll eventually need to return the f4 address.
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 agas::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:
- Putting these attributes behind a
chain_data()
syscall. These are really "environmental attributes" not scoped to the message (unlike InvocationContext). - 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)
Now tracking more granularly in https://github.com/filecoin-project/ref-fvm/issues/864 and https://github.com/filecoin-project/ref-fvm/issues/865.