-
Notifications
You must be signed in to change notification settings - Fork 2
Helper functions for future confidential transactions on secp256k1 #28
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
Open
LesterEvSe
wants to merge
7
commits into
dev
Choose a base branch
from
feat/add-point-ops
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90eb675
feat: add `u64_widen` helper function
LesterEvSe 116cce1
feat: add ec operations and test them, add asserts for u1
LesterEvSe 935a5d5
refactor: delete unused file
LesterEvSe 83536bc
refactor(u64): restore gt and ge in u64_test.simf
LesterEvSe 244bc82
refactor: naming for elliptic curve operations
LesterEvSe 74387d7
refactor: rename u64_widen into u64_into_u256 and fix test case
LesterEvSe 9edd20d
refactor: rename the test
LesterEvSe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| use crate::lib::logical_operations::and; | ||
| use crate::lib::asserts::{assert_eq_1, assert_eq_256}; | ||
|
|
||
| /// Compress an affine point to `(parity, x)`, where `parity = 1` iff `y` is odd. | ||
| pub fn ge_to_point(p: Ge) -> Point { | ||
| let (x, y): (Fe, Fe) = p; | ||
|
|
||
| match jet::fe_is_odd(y) { | ||
| true => (1, x), | ||
| false => (0, x), | ||
| } | ||
| } | ||
|
|
||
| /// Decompress a `Point` into a Jacobian point with `z = 1`. | ||
| pub fn point_to_gej(p: Point) -> Gej { | ||
| (unwrap(jet::decompress(p)), 1) | ||
| } | ||
|
|
||
| /// Convert the point into affine coordinates. | ||
| pub fn safe_gej_normalize(p: Gej) -> Ge { | ||
| unwrap(jet::gej_normalize(p)) | ||
| } | ||
|
|
||
| /// Subtract two field elements. | ||
| pub fn fe_sub(a: Fe, b: Fe) -> Fe { | ||
| jet::fe_add(a, jet::fe_negate(b)) | ||
| } | ||
|
|
||
| /// Subtract two scalars. | ||
| pub fn scalar_sub(a: Scalar, b: Scalar) -> Scalar { | ||
| jet::scalar_add(a, jet::scalar_negate(b)) | ||
| } | ||
|
|
||
| /// Subtract two points. | ||
| pub fn gej_sub(p: Gej, q: Gej) -> Gej { | ||
| jet::gej_add(p, jet::gej_negate(q)) | ||
| } | ||
|
|
||
| /// Field equality modulo `p`. | ||
| pub fn fe_eq(a: Fe, b: Fe) -> bool { | ||
| jet::fe_is_zero(fe_sub(a, b)) | ||
| } | ||
|
|
||
| /// Scalar equality modulo `n`. | ||
| pub fn scalar_eq(a: Scalar, b: Scalar) -> bool { | ||
| jet::scalar_is_zero(scalar_sub(a, b)) | ||
| } | ||
|
|
||
| /// Affine point equality. | ||
| pub fn ge_eq(a: Ge, b: Ge) -> bool { | ||
| let (ax, ay): (Fe, Fe) = a; | ||
| let (bx, by): (Fe, Fe) = b; | ||
| and(fe_eq(ax, bx), fe_eq(ay, by)) | ||
| } | ||
|
|
||
| /// Check if two points are equal. | ||
| pub fn point_point_eq(a: Point, b: Point) -> bool { | ||
| let (ap, ax): (u1, u256) = a; | ||
| let (bp, bx): (u1, u256) = b; | ||
| and(jet::eq_256(ax, bx), jet::eq_1(ap, bp)) | ||
| } | ||
|
|
||
| /// Check if two points represent the same point | ||
| pub fn gej_point_eq(a: Gej, p: Point) -> bool { | ||
| jet::gej_ge_equiv(a, unwrap(jet::decompress(p))) | ||
| } | ||
|
|
||
| /// Field equality modulo `p`. | ||
| pub fn assert_fe_eq(a: Fe, b: Fe) { | ||
| assert!(fe_eq(a, b)); | ||
| } | ||
|
|
||
| /// Scalar equality modulo `n`. | ||
| pub fn assert_scalar_eq(a: Scalar, b: Scalar) { | ||
| assert!(scalar_eq(a, b)); | ||
| } | ||
|
|
||
| /// Affine point equality. | ||
| pub fn assert_ge_eq(a: Ge, b: Ge) { | ||
| let (ax, ay): (Fe, Fe) = a; | ||
| let (bx, by): (Fe, Fe) = b; | ||
|
|
||
| assert_fe_eq(ax, bx); | ||
| assert_fe_eq(ay, by); | ||
| } | ||
|
|
||
| /// Check if two points are equal. | ||
| pub fn assert_point_eq(a: Point, b: Point) { | ||
| let (ap, ax): (u1, u256) = a; | ||
| let (bp, bx): (u1, u256) = b; | ||
|
|
||
| assert_eq_256(ax, bx); | ||
| assert_eq_1(ap, bp); | ||
| } | ||
|
|
||
| /// Check if two points represent the same point. | ||
| pub fn assert_gej_point_eq(a: Gej, p: Point) { | ||
| assert!(gej_point_eq(a, p)); | ||
| } | ||
|
|
||
| /// Check if two points represent the same point. | ||
| pub fn assert_gej_eq(a: Gej, b: Gej) { | ||
| assert!(jet::gej_equiv(a, b)); | ||
| } | ||
|
|
||
| /// Check if two points represent the same point. | ||
| pub fn assert_gej_ge_eq(a: Gej, b: Ge) { | ||
| assert!(jet::gej_ge_equiv(a, b)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.