Create struct Program + EncodeToAny + DecodeFromAny#8
Create struct Program + EncodeToAny + DecodeFromAny#8
Conversation
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Default, PartialEq)] |
There was a problem hiding this comment.
Do we really need the PartialEq derivation? That will end up comparing the whole AST and we may trigger it inadvertently when storing Program objects inside data structures.
|
|
||
| #[derive(Debug, Default, PartialEq)] | ||
| pub struct Program { | ||
| module: libernet::wasm::ProgramModule, |
There was a problem hiding this comment.
As it stands, the Default construction of a Program relies on the Default construction of a libernet::wasm::ProgramModule being "empty". Right now that happens to be fairly accurate because a default-constructed ProgramModule will have no sections and no version number, but this assumption kind of breaks an abstraction layer and I'd rather not rely on it.
For context: the default construction of anything stored in an SMT is important because it's used in phantom nodes to simulate a complete tree.
Better approach: let's wrap the ProgramModule in an Option. If it's None it means the SMT leaf doesn't have a program for that address.
| module: libernet::wasm::ProgramModule, | |
| module: Option<libernet::wasm::ProgramModule>, |
In the coming PRs, when it's time to hash the module with Poseidon, if the Option is None just return the zero scalar. That's safe because no one in the world knows a preimage for zero on a cryptographic hash, and that will be the case for the foreseeable future (in fact, sending coins to the zero address is also a common means to effectively burn them in the blockchain world).
There was a problem hiding this comment.
@71104 I didn’t quite understand how to implement EncodeToAny when the module is None. Should I still encode it, or should I return an error?
There was a problem hiding this comment.
That would happen when the user queries the code of a program that doesn't exist, so return an error in that case.
No description provided.