Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk(prog_id): Use a single Poseidon2HashType to represent a ProgramIdentifier #1350

Merged
merged 8 commits into from
Mar 11, 2024

Conversation

spiral-ladder
Copy link
Contributor

closes #1343

This commit updates Poseidon2HashType to represent 32 bytes instead of the current 4 bytes to be secure enough for production use; the previous 4 bytes were just for initial testing purposes.

This also entails changes with the ProgramIdentifier type, which now is just represented by a single Poseidon2HashType, but is still formed by the program rom hash, the memory init hash, and the entrypoint like before - these values are hashed once to form a program's ProgramIdentifier.

With this we also remove hash.rs from guest crate since we move its functions over to the sdk now.

`ProgramIdentifier`

This commit updates `Poseidon2HashType` to represent 32 bytes instead of
the current 4 bytes to be secure enough for production use; the previous
4 bytes were just for initial testing purposes.

This also entails changes with the `ProgramIdentifier`
type, which now is just represented by a single `Poseidon2HashType`, but
is still formed by the program rom hash, the memory init hash, and the
entrypoint like before - these values are hashed once to form a
program's `ProgramIdentifier`.

With this we also remove `hash.rs` from `guest` crate since we move its
functions over to the sdk now.
@spiral-ladder spiral-ladder force-pushed the bing/refactor-prog-id branch from 88c4011 to 91c0362 Compare March 10, 2024 10:40
@spiral-ladder spiral-ladder marked this pull request as ready for review March 11, 2024 01:56
Copy link
Collaborator

@matthiasgoergens matthiasgoergens left a comment

Choose a reason for hiding this comment

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

Looks good mostly. But I'm on mobile now, will need another look at it on my pc.

use crate::sys::poseidon2_hash;

let input = chain!(
program_rom_hash.to_le_bytes(),
Copy link
Collaborator

@matthiasgoergens matthiasgoergens Mar 11, 2024

Choose a reason for hiding this comment

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

Those are conceptually already field elements. Does it make sense to go back to bytes?

(Probably it doesn't make a difference?)

Copy link
Collaborator

@matthiasgoergens matthiasgoergens left a comment

Choose a reason for hiding this comment

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

Please see my comments about length of hash.

use crate::coretypes::DIGEST_BYTES;

// VM expects input length to be multiple of RATE
assert!(input.len() % RATE == 0);
Copy link
Contributor

@codeblooded1729 codeblooded1729 Mar 11, 2024

Choose a reason for hiding this comment

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

Maybe add a similar assert on native execution too?
We need to hash some content from event tape in order to generate canonical event tape. The assert might be handy to detect that we forgot to pad.
Eventually maybe we should work on adding the functionality to hash input of size which is not multiple of RATE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, let's do that.

@spiral-ladder spiral-ladder merged commit c73e563 into main Mar 11, 2024
9 checks passed
@spiral-ladder spiral-ladder deleted the bing/refactor-prog-id branch March 11, 2024 09:25
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.

Poseidon2HashType only has 32 bits
4 participants