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

Revert ECDSA hash/packing logic to previous iteration #1669

Merged
merged 8 commits into from
Jun 4, 2024

Conversation

MartinMinkov
Copy link
Contributor

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.

* In contrast, this method just takes the message hash (a curve scalar) as input, giving you flexibility in
* choosing the hashing algorithm.
*/
verifySignedHashV2(
Copy link
Contributor Author

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.

Copy link
Contributor

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(
Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

nice

Curve: CurveAffine,
signature: Ecdsa.Signature,
msgHash: Field3,
publicKey: Point,
multiScalarMul: (
Copy link
Contributor Author

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)

… 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
Copy link
Contributor

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

some comments!

Comment on lines 99 to 102
* let isValid = sig.verify(msg, pk);
* isValid.assertTrue('signature verifies');
* ```
* @deprecated There is a security vulnerability in this method. Use {@link verifyV2} instead.
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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

Copy link
Contributor Author

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 } }
Copy link
Contributor

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?

Suggested change
} = { G: { windowSize: 4 }, P: { windowSize: 4 } }
} = { G: { windowSize: 4 }, P: { windowSize: 3 } }

it should use fewer constraints

Copy link
Contributor Author

@MartinMinkov MartinMinkov Jun 4, 2024

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(
Copy link
Contributor

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],
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

Lgtm! Thanks @MartinMinkov

@MartinMinkov MartinMinkov merged commit 5687030 into main Jun 4, 2024
14 checks passed
@MartinMinkov MartinMinkov deleted the fix/ecdsa-fix branch June 4, 2024 17:41
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.

2 participants