Skip to content

Create struct Program + EncodeToAny + DecodeFromAny#8

Open
caiiiycuk wants to merge 2 commits intomainfrom
caiiiycuk-wasm
Open

Create struct Program + EncodeToAny + DecodeFromAny#8
caiiiycuk wants to merge 2 commits intomainfrom
caiiiycuk-wasm

Conversation

@caiiiycuk
Copy link
Collaborator

No description provided.

@caiiiycuk caiiiycuk requested a review from 71104 as a code owner February 9, 2026 13:30
}
}

#[derive(Debug, Default, PartialEq)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

@71104 71104 Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would happen when the user queries the code of a program that doesn't exist, so return an error in that case.

Copy link
Member

@71104 71104 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants