-
Notifications
You must be signed in to change notification settings - Fork 145
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
Revert ECDSA hash/packing logic to previous iteration #1669
Conversation
1934f02
to
e6b6019
Compare
* In contrast, this method just takes the message hash (a curve scalar) as input, giving you flexibility in | ||
* choosing the hashing algorithm. | ||
*/ | ||
verifySignedHashV2( |
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.
Was it necessary to add a new verifySignedHashV2
function here? It seems so since the deprecated verify
was being used here, but not sure if it's necessary to reflect everywhere.
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.
yeah thanks for adding this as well!
* - The initial aggregator `ia`, see {@link initialAggregator}. By default, `ia` is computed deterministically on the fly. | ||
*/ | ||
function verifyEcdsa( | ||
function verifyEcdsaGeneric( |
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.
Refactored some of the duplicated logic between both verify functions and specified behaviour with a hashed
parameter, which guards the code that is responsible for the vulnerability
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.
nice
e6b6019
to
c209daa
Compare
Curve: CurveAffine, | ||
signature: Ecdsa.Signature, | ||
msgHash: Field3, | ||
publicKey: Point, | ||
multiScalarMul: ( |
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.
Adds a parameter to specify the version of multiScalarMul
we want (passing in hashed
as true
or false
)
c209daa
to
844c00a
Compare
… ecdsa.unit-test.ts): replace deprecated verify and verifySignedHash methods with verifyV2 and verifySignedHashV2 to address security vulnerability
…in Ecdsa class due to security vulnerability fix and enhancement
844c00a
to
21f6ebd
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.
some comments!
* let isValid = sig.verify(msg, pk); | ||
* isValid.assertTrue('signature verifies'); | ||
* ``` | ||
* @deprecated There is a security vulnerability in this method. Use {@link verifyV2} instead. |
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.
could you completely remove any other doccomments here except the deprecation notice? we don't want to encourage people to use it
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.
/** | ||
* Verify the ECDSA signature given the message hash (a {@link Scalar}) and public key (a {@link Curve} point). | ||
* | ||
* This is a building block of {@link EcdsaSignature.verify}, where the input message is also hashed. | ||
* In contrast, this method just takes the message hash (a curve scalar) as input, giving you flexibility in | ||
* choosing the hashing algorithm. | ||
* @deprecated There is a security vulnerability in this method. Use {@link verifySignedHashV2} instead. |
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.
could you completely remove any other doccomments here except the deprecation notice? we don't want to encourage people to use it
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.
* for variable public key, there is a possible use case: if the public key is a public input, then its multiples could also be. | ||
* in that case, passing them in would avoid computing them in-circuit and save a few constraints. | ||
* - The initial aggregator `ia`, see {@link initialAggregator}. By default, `ia` is computed deterministically on the fly. | ||
* @deprecated There is a security vulnerability with this function, allowing a prover to modify witness values than what is expected. Use {@link verifyEcdsaV2} instead. |
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.
could you completely remove any other doccomments here except the deprecation notice? we don't want to encourage people to use it
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.
G?: { windowSize: number; multiples?: Point[] }; | ||
P?: { windowSize: number; multiples?: Point[] }; | ||
ia?: point; | ||
} = { G: { windowSize: 4 }, P: { windowSize: 4 } } |
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.
could you try changing the default back to this?
} = { G: { windowSize: 4 }, P: { windowSize: 4 } } | |
} = { G: { windowSize: 4 }, P: { windowSize: 3 } } |
it should use fewer constraints
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.
Fixed here!
Here is the lower constraints
* - The initial aggregator `ia`, see {@link initialAggregator}. By default, `ia` is computed deterministically on the fly. | ||
*/ | ||
function verifyEcdsa( | ||
function verifyEcdsaGeneric( |
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.
nice
? points[j] | ||
: arrayGetGeneric( | ||
HashedPoint.provable, | ||
hashedTables[j], |
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.
it costs constraints to create the hashedTables
(on line 521), which we only need in the deprecated case.
could you also add a check there and make it an empty array when hashed = false
?
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.
…ods and their documentation
…object to optimize elliptic curve calculations
…hashed condition to optimize memory usage and improve performance
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! Thanks @MartinMinkov
This PR reverts the changes made in #1376 and #1377 due to a vulnerability found in the ECSDA logic and how a vulnerability can occur when unpacking data in a specific way.