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

Implement additional features to the "group" element type #2394

Merged
merged 11 commits into from
Jun 7, 2023
Merged

Conversation

collinc97
Copy link
Collaborator

@collinc97 collinc97 commented May 24, 2023

Changes implemented to be compatible with https://github.com/AleoHQ/snarkVM/pull/1576

Motivation

This PR introduces new commit_to_grouphash_many (placeholder), hash_to_group, and hash_to_scalar opcodes.

partially addresses #2386

Changelog

As part of this PR, all hash.* and commit.* opcodes now return a field type as the default, and we introduce commit_to_grouphash_to_group, and hash_to_scalar for other return types (that are cryptographically safe).

The existing opcodes commit.ped64 and commit.ped128 have had their return type changed from group to field, to adhere to the updated design.

Aleo instructions commit opcodes

commit_to_group.bhp256
commit_to_group.bhp512
commit_to_group.bhp768
commit_to_group.bhp1024
commit_to_group.ped64
commit_to_group.ped128

Leo commit methods

let a: group = BHP256::commit_to_group(ANY, SCALAR);
let a: group = BHP512::commit_to_group(ANY, SCALAR);
let a: group = BHP768::commit_to_group(ANY, SCALAR);
let a: group = BHP1024::commit_to_group(ANY, SCALAR);
let a: group = Pedersen64::commit_to_group(ANY, SCALAR);
let a: group = Pedersen128::commit_to_group(ANY, SCALAR);

Aleo instructions hash opcodes

hash_to_group.bhp256
hash_to_group.bhp512
hash_to_group.bhp768
hash_to_group.bhp1024
hash_to_group.ped64
hash_to_group.ped128
hash_to_group.psd2
hash_to_group.psd4
hash_to_group.psd8
hash_to_scalar.psd2
hash_to_scalar.psd4
hash_to_scalar.psd8

Leo hash methods

let a: group = BHP256::hash_to_group(ANY);
let a: group = BHP512::hash_to_group(ANY);
let a: group = BHP768::hash_to_group(ANY);
let a: group = BHP1024::hash_to_group(ANY);
let a: group = Pedersen64::hash_to_group(ANY);
let a: group = Pedersen128::hash_to_group(ANY);
let a: group = Poseidon2::hash_to_group(ANY);
let a: group = Poseidon4::hash_to_group(ANY);
let a: group = Poseidon8::hash_to_group(ANY);
let a: scalar = Poseidon2::hash_to_scalar(ANY);
let a: scalar = Poseidon4::hash_to_scalar(ANY);
let a: scalar = Poseidon8::hash_to_scalar(ANY);

@collinc97 collinc97 changed the title Staging updates DRAFT Implement additional features to the "group" element type May 25, 2023
@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Merging #2394 (e390194) into testnet3 (ae12c35) will increase coverage by 0.07%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##           testnet3    #2394      +/-   ##
============================================
+ Coverage     78.57%   78.65%   +0.07%     
============================================
  Files           154      154              
  Lines          4691     4708      +17     
  Branches       4690     4707      +17     
============================================
+ Hits           3686     3703      +17     
  Misses         1005     1005              
Impacted Files Coverage Δ
compiler/ast/src/functions/core_function.rs 100.00% <ø> (ø)
compiler/span/src/symbol.rs 84.61% <ø> (ø)
compiler/compiler/tests/execute.rs 86.88% <100.00%> (+0.21%) ⬆️
compiler/passes/src/type_checking/checker.rs 95.83% <100.00%> (-0.25%) ⬇️

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@collinc97 collinc97 marked this pull request as ready for review June 6, 2023 19:01
let scalar_value: scalar = 1scalar;
// let string_value: string = "helloworld";

// BHP256 hash_to_group tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like these should be BHP1024

let scalar_value: scalar = 1scalar;
// let string_value: string = "helloworld";

// BHP256 hash_to_group tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like these should be BHP512

Copy link
Collaborator

@bendyarm bendyarm left a comment

Choose a reason for hiding this comment

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

There were 3 BHP test files that look like they need some find/replace attention. (Added direct comments on them already.)

Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 31 to 48
// BHP256 hash_to_group tests
let a: group = BHP256::hash_to_group(addr_value);
let b: group = BHP256::hash_to_group(bool_value);
let c: group = BHP256::hash_to_group(field_value);
// let d: group = BHP256::hash_to_group(group_value);
let e: group = BHP256::hash_to_group(i8_value);
let f: group = BHP256::hash_to_group(i16_value);
let g: group = BHP256::hash_to_group(i32_value);
let h: group = BHP256::hash_to_group(i64_value);
let i: group = BHP256::hash_to_group(i128_value);
let j: group = BHP256::hash_to_group(u8_value);
let k: group = BHP256::hash_to_group(u16_value);
let l: group = BHP256::hash_to_group(u32_value);
let m: group = BHP256::hash_to_group(u64_value);
let n: group = BHP256::hash_to_group(u128_value);
let o: group = BHP256::hash_to_group(scalar_value);
// let p: group = BHP256::hash_to_group(string_value);
let q: group = BHP256::hash_to_group(Foo { a: 1u128, b: 1u128 });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// BHP256 hash_to_group tests
let a: group = BHP256::hash_to_group(addr_value);
let b: group = BHP256::hash_to_group(bool_value);
let c: group = BHP256::hash_to_group(field_value);
// let d: group = BHP256::hash_to_group(group_value);
let e: group = BHP256::hash_to_group(i8_value);
let f: group = BHP256::hash_to_group(i16_value);
let g: group = BHP256::hash_to_group(i32_value);
let h: group = BHP256::hash_to_group(i64_value);
let i: group = BHP256::hash_to_group(i128_value);
let j: group = BHP256::hash_to_group(u8_value);
let k: group = BHP256::hash_to_group(u16_value);
let l: group = BHP256::hash_to_group(u32_value);
let m: group = BHP256::hash_to_group(u64_value);
let n: group = BHP256::hash_to_group(u128_value);
let o: group = BHP256::hash_to_group(scalar_value);
// let p: group = BHP256::hash_to_group(string_value);
let q: group = BHP256::hash_to_group(Foo { a: 1u128, b: 1u128 });
// BHP512 hash_to_group tests
let a: group = BHP512::hash_to_group(addr_value);
let b: group = BHP512::hash_to_group(bool_value);
let c: group = BHP512::hash_to_group(field_value);
// let d: group = BHP512::hash_to_group(group_value);
let e: group = BHP512::hash_to_group(i8_value);
let f: group = BHP512::hash_to_group(i16_value);
let g: group = BHP512::hash_to_group(i32_value);
let h: group = BHP512::hash_to_group(i64_value);
let i: group = BHP512::hash_to_group(i128_value);
let j: group = BHP512::hash_to_group(u8_value);
let k: group = BHP512::hash_to_group(u16_value);
let l: group = BHP512::hash_to_group(u32_value);
let m: group = BHP512::hash_to_group(u64_value);
let n: group = BHP512::hash_to_group(u128_value);
let o: group = BHP512::hash_to_group(scalar_value);
// let p: group = BHP512::hash_to_group(string_value);
let q: group = BHP512::hash_to_group(Foo { a: 1u128, b: 1u128 });

Comment on lines 31 to 48
// BHP256 hash_to_group tests
let a: group = BHP256::hash_to_group(addr_value);
let b: group = BHP256::hash_to_group(bool_value);
let c: group = BHP256::hash_to_group(field_value);
// let d: group = BHP256::hash_to_group(group_value);
let e: group = BHP256::hash_to_group(i8_value);
let f: group = BHP256::hash_to_group(i16_value);
let g: group = BHP256::hash_to_group(i32_value);
let h: group = BHP256::hash_to_group(i64_value);
let i: group = BHP256::hash_to_group(i128_value);
let j: group = BHP256::hash_to_group(u8_value);
let k: group = BHP256::hash_to_group(u16_value);
let l: group = BHP256::hash_to_group(u32_value);
let m: group = BHP256::hash_to_group(u64_value);
let n: group = BHP256::hash_to_group(u128_value);
let o: group = BHP256::hash_to_group(scalar_value);
// let p: group = BHP256::hash_to_group(string_value);
let q: group = BHP256::hash_to_group(Foo { a: 1u128, b: 1u128 });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// BHP256 hash_to_group tests
let a: group = BHP256::hash_to_group(addr_value);
let b: group = BHP256::hash_to_group(bool_value);
let c: group = BHP256::hash_to_group(field_value);
// let d: group = BHP256::hash_to_group(group_value);
let e: group = BHP256::hash_to_group(i8_value);
let f: group = BHP256::hash_to_group(i16_value);
let g: group = BHP256::hash_to_group(i32_value);
let h: group = BHP256::hash_to_group(i64_value);
let i: group = BHP256::hash_to_group(i128_value);
let j: group = BHP256::hash_to_group(u8_value);
let k: group = BHP256::hash_to_group(u16_value);
let l: group = BHP256::hash_to_group(u32_value);
let m: group = BHP256::hash_to_group(u64_value);
let n: group = BHP256::hash_to_group(u128_value);
let o: group = BHP256::hash_to_group(scalar_value);
// let p: group = BHP256::hash_to_group(string_value);
let q: group = BHP256::hash_to_group(Foo { a: 1u128, b: 1u128 });
// BHP1024 hash_to_group tests
let a: group = BHP1024::hash_to_group(addr_value);
let b: group = BHP1024::hash_to_group(bool_value);
let c: group = BHP1024::hash_to_group(field_value);
// let d: group = BHP1024::hash_to_group(group_value);
let e: group = BHP1024::hash_to_group(i8_value);
let f: group = BHP1024::hash_to_group(i16_value);
let g: group = BHP1024::hash_to_group(i32_value);
let h: group = BHP1024::hash_to_group(i64_value);
let i: group = BHP1024::hash_to_group(i128_value);
let j: group = BHP1024::hash_to_group(u8_value);
let k: group = BHP1024::hash_to_group(u16_value);
let l: group = BHP1024::hash_to_group(u32_value);
let m: group = BHP1024::hash_to_group(u64_value);
let n: group = BHP1024::hash_to_group(u128_value);
let o: group = BHP1024::hash_to_group(scalar_value);
// let p: group = BHP1024::hash_to_group(string_value);
let q: group = BHP1024::hash_to_group(Foo { a: 1u128, b: 1u128 });

Comment on lines 31 to 48
// BHP256 hash_to_group tests
let a: group = BHP256::hash_to_group(addr_value);
let b: group = BHP256::hash_to_group(bool_value);
let c: group = BHP256::hash_to_group(field_value);
// let d: group = BHP256::hash_to_group(group_value);
let e: group = BHP256::hash_to_group(i8_value);
let f: group = BHP256::hash_to_group(i16_value);
let g: group = BHP256::hash_to_group(i32_value);
let h: group = BHP256::hash_to_group(i64_value);
let i: group = BHP256::hash_to_group(i128_value);
let j: group = BHP256::hash_to_group(u8_value);
let k: group = BHP256::hash_to_group(u16_value);
let l: group = BHP256::hash_to_group(u32_value);
let m: group = BHP256::hash_to_group(u64_value);
let n: group = BHP256::hash_to_group(u128_value);
let o: group = BHP256::hash_to_group(scalar_value);
// let p: group = BHP256::hash_to_group(string_value);
let q: group = BHP256::hash_to_group(Foo { a: 1u128, b: 1u128 });
Copy link
Collaborator

@bendyarm bendyarm Jun 7, 2023

Choose a reason for hiding this comment

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

Suggested change
// BHP256 hash_to_group tests
let a: group = BHP256::hash_to_group(addr_value);
let b: group = BHP256::hash_to_group(bool_value);
let c: group = BHP256::hash_to_group(field_value);
// let d: group = BHP256::hash_to_group(group_value);
let e: group = BHP256::hash_to_group(i8_value);
let f: group = BHP256::hash_to_group(i16_value);
let g: group = BHP256::hash_to_group(i32_value);
let h: group = BHP256::hash_to_group(i64_value);
let i: group = BHP256::hash_to_group(i128_value);
let j: group = BHP256::hash_to_group(u8_value);
let k: group = BHP256::hash_to_group(u16_value);
let l: group = BHP256::hash_to_group(u32_value);
let m: group = BHP256::hash_to_group(u64_value);
let n: group = BHP256::hash_to_group(u128_value);
let o: group = BHP256::hash_to_group(scalar_value);
// let p: group = BHP256::hash_to_group(string_value);
let q: group = BHP256::hash_to_group(Foo { a: 1u128, b: 1u128 });
// BHP768 hash_to_group tests
let a: group = BHP768::hash_to_group(addr_value);
let b: group = BHP768::hash_to_group(bool_value);
let c: group = BHP768::hash_to_group(field_value);
// let d: group = BHP768::hash_to_group(group_value);
let e: group = BHP768::hash_to_group(i8_value);
let f: group = BHP768::hash_to_group(i16_value);
let g: group = BHP768::hash_to_group(i32_value);
let h: group = BHP768::hash_to_group(i64_value);
let i: group = BHP768::hash_to_group(i128_value);
let j: group = BHP768::hash_to_group(u8_value);
let k: group = BHP768::hash_to_group(u16_value);
let l: group = BHP768::hash_to_group(u32_value);
let m: group = BHP768::hash_to_group(u64_value);
let n: group = BHP768::hash_to_group(u128_value);
let o: group = BHP768::hash_to_group(scalar_value);
// let p: group = BHP768::hash_to_group(string_value);
let q: group = BHP768::hash_to_group(Foo { a: 1u128, b: 1u128 });

Copy link
Collaborator

@bendyarm bendyarm left a comment

Choose a reason for hiding this comment

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

Added ```suggestion comments.

@bendyarm bendyarm self-requested a review June 7, 2023 18:18
Copy link
Collaborator

@bendyarm bendyarm left a comment

Choose a reason for hiding this comment

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

Looks good.

@collinc97 collinc97 merged commit 4e71f60 into testnet3 Jun 7, 2023
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