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

EVM Storage: Hashing as syscall

Open aakoshh opened this issue 3 years ago • 2 comments

Part of https://github.com/filecoin-project/ref-fvm/issues/859

Even though https://github.com/filecoin-project/ref-fvm/issues/890 disables key hashing in the HAMT, ~it will still calculate hashes for the CID of Nodes.~

Normal HAMT usage will still do hashing of keys, which native smart contracts would be using. This could be done as a syscall, rather than in Wasm, similarly to I guess how the EVM opcodes are implemented. See https://github.com/filecoin-project/ref-fvm/issues/374

Hashing would not have any effect on the storage footprint per se, but it's related to performance and overall gas cost. Its effect can be measured as part of the gas model epic and memory expansion epic under Syscall pricing and Execution gas refinement.

aakoshh avatar Sep 19 '22 13:09 aakoshh

Even though https://github.com/filecoin-project/ref-fvm/issues/890 disables key hashing in the HAMT, it will still calculate hashes for the CID of Nodes. This could be done as a syscall, rather than in Wasm, similarly to I guess how the EVM opcodes are implemented.

For cids, the HAMT delegates to the blockstore. In the case of the actors, that turns out to be

https://github.com/filecoin-project/builtin-actors/blob/18c2291d4ccfac409e05270bd1d33d40fe196d65/runtime/src/runtime/actor_blockstore.rs#L18

Basically:

  • The HAMT will "put" a block and tell the system what codec to use.
  • The system will return the CID.

Stebalien avatar Sep 19 '22 22:09 Stebalien

Ah, brilliant, thanks for pointing that out @Stebalien. Okay then this ticket makes no sense in the context of the EVM, because all we need is not to call hashing at all. I changed the description to mention other actors instead that will use the HAMT as intended.

aakoshh avatar Sep 20 '22 07:09 aakoshh

Fixed by https://github.com/filecoin-project/builtin-actors/pull/712

Stebalien avatar Oct 07 '22 15:10 Stebalien