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

Merge main into v2 #289

Merged
merged 48 commits into from
Aug 1, 2024
Merged

Merge main into v2 #289

merged 48 commits into from
Aug 1, 2024

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Aug 1, 2024

No description provided.

mitschabaude and others added 30 commits July 1, 2024 18:24
…oordinates for better representation of PointAtInfinity
…o use object destructuring for cleaner code and improve readability
…ineOnCurve function to destructure parameters and use them directly in calculations
…ntAtInfinity functions as they are not being used in the codebase
…t token usage permissions

The MayUseToken type and object were added to represent the permissions for token usage in a transaction. It includes two boolean fields: parentsOwnToken to indicate if the parent owns the token, and inheritFromParent to specify if the token usage should be inherited from the parent.

The check method was also added to enforce the constraint that a transaction cannot both have the parent own the token and inherit the token usage from the parent at the same time.

This addition provides a structured way to handle token usage permissions within the transaction leaves.
  - Check if parentsOwnToken and inheritFromParent are instances of Bool
  - Throw an error if the fields are not of type Bool
  - This ensures that the correct types are passed to the MayUseToken object, preventing potential runtime errors due to incorrect types being used in the check function
…ermissions

The MayUseToken type was added to the derivedLeafTypesSignable function to represent the token usage permissions for a zkApp account. It includes two boolean fields:
- parentsOwnToken: indicates if the parent account owns the token
- inheritFromParent: indicates if the token usage permission should be inherited from the parent account

This allows for more granular control over token usage permissions in zkApp accounts.

feat(transaction-leaves): export MayUseToken type in transaction leaf type definitions

The MayUseToken type is now exported from the transaction-leaves-bigint.ts and transaction-leaves-json.ts files. This makes the type available for use in other parts of the project that deal with transaction leaves and zkApp account permissions.

feat(gen): include MayUseToken in generated transaction types

The generated transaction types in transaction-bigint.ts and transaction.ts now include the MayUseToken type in the CustomTypes definition. This ensures that the MayUseToken type is properly integrated into the generated transaction types and can be used when working with transactions.
…inheritFromParent fields

The type checking of the `parentsOwnToken` and `inheritFromParent` fields in the `MayUseToken` object was simplified by using the `Bool.check()` method instead of manually checking the types and throwing an error. This change improves code readability and maintainability by utilizing the built-in type checking functionality provided by the `Bool` class.
MartinMinkov and others added 18 commits July 16, 2024 14:11
…en object

The check function is no longer needed in the MayUseToken object, as the validation logic can be handled elsewhere in the codebase. This change simplifies the MayUseToken object and improves separation of concerns.
…ify MayUseToken type

The createMayUseToken function was removed as it was not providing any additional functionality. The MayUseToken type was simplified to directly use the signable function with the parentsOwnToken and inheritFromParent fields of type Bool. This change reduces the complexity of the code without changing its behavior.
[Main] Fix MayUseToken vulnerability in AccountUpdates
Accept .provable and some other type improvements
Update AffineCurve equal method to account for points at infinity
fix(finite-field): optimize equal method by avoiding modulo operation when possible
refactor(finite-field): use more descriptive variable names in equal method

The isSquare and sqrt methods were not taking the input modulo p, which could lead to incorrect results for inputs outside the field. The equal method was performing a modulo operation unnecessarily in some cases, which could be avoided by first checking if the inputs are already in the correct range. The variable names in the equal method were also improved for clarity.
… and isSquare methods

The commit adds two new test cases to the finite field unit tests:

1. It asserts that calling `sqrt` with a non-canonical zero (i.e., `p`) should return the same result as calling it with a canonical zero (`0n`). This ensures that the `sqrt` method handles non-canonical zero inputs correctly.

2. It asserts that calling `isSquare` with a non-canonical zero (`p`) should return the same result as calling it with a canonical zero (`0n`). This ensures that the `isSquare` method treats non-canonical zero inputs the same way as canonical zero.

These tests were added to improve the robustness of the finite field implementation by verifying that it correctly handles non-canonical zero values, which are equivalent to the canonical zero value in the field.
…stead of p - x for improved readability and consistency with other functions

fix(finite-field): use mod in isEven function to ensure the result is always within the field range and avoid potential issues with large numbers
…g input to ensure it's in the field

The changes in the `sqrt` and `isSquare` functions were made to ensure that the input value is always within the finite field before performing any operations. This is done by modding the input value by the field's prime modulus `p` at the beginning of each function.

The reason for this change is to handle cases where the input value might be outside the field, which could lead to incorrect results or even errors. By modding the input, we guarantee that all operations are performed on values within the field, ensuring the correctness of the results.

This refactoring improves the robustness and reliability of the `sqrt` and `isSquare` functions, making them more consistent with the expected behavior of finite field arithmetic.
- Assert that negating non-canonical zero (p) returns canonical zero (0n)
- Assert that non-canonical zero (p) is considered even

These additional test cases ensure that the finite field implementation handles non-canonical zero correctly by treating it as equivalent to the canonical zero representation.
…the number modulo p before checking the least significant bit

This fixes a bug where the isEven function would incorrectly classify numbers greater than the field size as even. By first reducing the number modulo p, we ensure that the least significant bit correctly determines the parity of the number within the field.
Fix and finite field operations (isSquare, sqrt)
@mitschabaude mitschabaude merged commit 5cb7ede into v2 Aug 1, 2024
1 check passed
@mitschabaude mitschabaude deleted the merge/main-v2-0 branch August 1, 2024 09:52
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.

4 participants