You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
In this document, we discuss how to commit ckb-vm and later open a commitment in a ckb contract.
POC code here
What to commit?
Basic two parts
We use the definition from ckb-vm code here
How to commit?
We hash all the elements listed in the above two parts to get a single hash, that's the vm commitment.
How to commit memory?
We use sparse merkle tree for our memory, and the
size
andsmt.root
is our commitment to a memory.Thanks to well designed ckb-vm code, we're only needed to implement
Memory
trait.Similary to flat memory implementation in ckb-vm code here
Flat memory has two parts
We can store both of two parts in smt. Using following methods to generate key
Detail in code here
How to open in contract?
We can generate smt proof for all updated key-values in memory smt. For rest of elements in the vm definition,
provide pre-images and we're done.
With all pre-images and smt proof, we're able to execute vm instruction in contract.
Detail memory code here
Detail machine restore code here
How to execute an instruction (step) in contract?
Again, thanks to well designed ckb-vm code. We ported it to
no_std
environment with small modifications, then simpily execute it.Detail code here
Execution code in contract here
Further optimizations
Beta Was this translation helpful? Give feedback.
All reactions