-
Notifications
You must be signed in to change notification settings - Fork 91
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
impl Absorb
for String
#138
Conversation
src/sponge/absorb.rs
Outdated
@@ -227,6 +228,16 @@ impl Absorb for isize { | |||
} | |||
} | |||
|
|||
impl Absorb for String { | |||
fn to_sponge_bytes(&self, dest: &mut Vec<u8>) { | |||
dest.extend_from_slice(self.as_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.
Presumably this absorbs the length too?
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.
I can also implement AbsorbWithLength
for String
and leave this as is, wdyt?
Then it's just the question of whether the caller knows about the trait AbsorbWithLength
, which arguably is not so obvious since most types only implement pure Absorb
.
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.
I do think we should absorb the length by default, because I don't want it to be the case that absorb two strings is the same as the absorbing the concatenation of the strings
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.
I've added the length by default to to_sponge_bytes
.
I left to_sponge_field_elements
as-is. It already prevents the scenario you mentioned: each substring gets mapped to a new field element, whereas a concat string gets mapped to a single element, so the resulting vectors even have different lengths.
Also, I don't think we should derive |
Sure, makes sense. We can impl |
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 modulo the nit about the length!
If one wants As an aside, it's bizarre I think folks have typically chosen &[u8] |
Description
Needed for deriving
Absorb
forLabeledCommitment
in poly-commit.closes: #XXXX
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the Github PR explorer