-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix error when hexes of length 64 are used as signer secrets #28
Conversation
@@ -82,11 +82,7 @@ export class BlsSignerFactory { | |||
private constructor() {} | |||
|
|||
public getSigner(domain: Domain, secretHex?: string) { | |||
const secret = secretHex | |||
? secretHex.length == 66 | |||
? parseFr(secretHex) |
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.
After the mcl-wasm@1.0.0
update, parseFr
no longer works with hexes of length 64 (string length 66). It does work on hex values of length 1 (i.e. 0x1
) up to length 63, one less than what keccak256
produces.
@ChihChengLiang Do you know why this might have changed between mcl-wasm
versions, and if there are any implications to switching to just use setHashFr
?
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 don't know the changes in mcl-wasm
. Maybe #22 is related?
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 was unable to determine a way to validate that the hex is in range. So I ended up setting up the secret parsing for the signer as such:
- If the secret is missing/empty, generate a random one.
- Attempt to directly set the hex value. If this fails, fall back to hashing the secret.
I think this should cover the range of use cases and expected outputs.
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 like a good solution. @philsippl Would you like to provide a test case example value to make sure this change doesn't break your use case?
Change behavior of signer secret parsing to do a direct Fr string set, with a fallback of hashing the secret input on error. Add validateHex function. Add wider range of secret values to signer tests. Use mcl-wasm Typescript types instead of any.
559c558
to
0536a41
Compare
@ChihChengLiang Ready for your final review. |
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.
LGTM on my side.
@@ -82,11 +82,7 @@ export class BlsSignerFactory { | |||
private constructor() {} | |||
|
|||
public getSigner(domain: Domain, secretHex?: string) { | |||
const secret = secretHex | |||
? secretHex.length == 66 | |||
? parseFr(secretHex) |
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 like a good solution. @philsippl Would you like to provide a test case example value to make sure this change doesn't break your use case?
Going to merge and release this as is. @philsippl if this breaks your use case we can fix in follow up work. |
@jacque006 @ChihChengLiang not sure if you saw my comment from a few weeks back, so posting here again in the thread 👇
|
@philsippl Agreed, I like the split approach. Created #30 to address. |
Change behavior of signer secret parsing to do a direct Fr string set, with a fallback of hashing the secret input on error.
Add validateHex function.
Add wider range of secret values to signer tests.
Use mcl-wasm Typescript types instead of any.
Resolves #27