-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
`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.
88c4011
to
91c0362
Compare
There was a problem hiding this 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(), |
There was a problem hiding this comment.
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?)
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: Kapil <[email protected]>
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 singlePoseidon2HashType
, 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'sProgramIdentifier
.With this we also remove
hash.rs
fromguest
crate since we move its functions over to the sdk now.