Skip to content

Commit

Permalink
feat!: update bindings for pedersen with hash_index (#28)
Browse files Browse the repository at this point in the history
* feat(bb): update bb pointer

* chore: update bb

* chore: update pointer to latest bb

* test: fixed tests for new pedersen impl

* chore: update ci bb

* chore: update bb pointer

* chore: updated bb pointer in ci
  • Loading branch information
sirasistant authored May 31, 2023
1 parent 73d9a20 commit c04e3f4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
with:
repository: AztecProtocol/barretenberg
path: barretenberg
ref: 87aeb375d7b434e0faf47abb79f97753ab760987
ref: aebfe95c547b0022a9baed3901e945bb386503be

- name: Setup Linux environment
if: matrix.os == 'ubuntu-latest'
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn main() -> Result<()> {
.allowlist_function("acir_proofs_verify_proof")
.allowlist_function("pedersen_plookup_compress_fields")
.allowlist_function("pedersen_plookup_compress")
.allowlist_function("pedersen_plookup_commit")
.allowlist_function("pedersen_plookup_commit_with_hash_index")
.allowlist_function("new_pippenger")
.allowlist_function("compute_public_key")
.allowlist_function("construct_signature")
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod tests {
f_one[31] = 1;
let got = pedersen::compress_native(&f_zero, &f_one);
assert_eq!(
"11831f49876c313f2a9ec6d8d521c7ce0b6311c852117e340bfe27fd1ac096ef",
"0c5e1ddecd49de44ed5e5798d3f6fb7c71fe3d37f5bee8664cf88a445b5ba0af",
hex::encode(got)
);
}
Expand Down
20 changes: 12 additions & 8 deletions src/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn compress_many(inputs: &[[u8; 32]]) -> [u8; 32] {
result
}

pub fn encrypt(inputs_buffer: &[[u8; 32]]) -> ([u8; 32], [u8; 32]) {
pub fn encrypt(inputs_buffer: &[[u8; 32]], hash_index: u32) -> ([u8; 32], [u8; 32]) {
let mut buffer = Vec::new();
let buffer_len = inputs_buffer.len() as u32;
let mut result = [0_u8; 64];
Expand All @@ -42,7 +42,11 @@ pub fn encrypt(inputs_buffer: &[[u8; 32]]) -> ([u8; 32], [u8; 32]) {
}

unsafe {
pedersen_plookup_commit(buffer.as_ptr() as *const u8, result.as_mut_ptr());
pedersen_plookup_commit_with_hash_index(
buffer.as_ptr() as *const u8,
result.as_mut_ptr(),
hash_index,
);
}
let s: [u8; 32] = (result[0..32]).try_into().unwrap();
let e: [u8; 32] = (result[32..64]).try_into().unwrap();
Expand All @@ -69,17 +73,17 @@ mod tests {
Test {
input_left: f_zero,
input_right: f_one,
expected_hex: "11831f49876c313f2a9ec6d8d521c7ce0b6311c852117e340bfe27fd1ac096ef",
expected_hex: "0c5e1ddecd49de44ed5e5798d3f6fb7c71fe3d37f5bee8664cf88a445b5ba0af",
},
Test {
input_left: f_one,
input_right: f_one,
expected_hex: "1044a769e185fcdf077c8289a6bf87c5c77ff9561cab69d39fadd90a07ee4af4",
expected_hex: "0e1793a0c122887bcb53c84776f4704c26bc093b25eaa9c7847a672c65e314ae",
},
Test {
input_left: f_one,
input_right: f_zero,
expected_hex: "17d213c8fe83e89a2f3190933d437a3e231124e0383e6dc6a7b6e6358833e427",
expected_hex: "0c93b3f27730b2e331e634af15bc9d5a769688921f30b36ca926b35a96b3306c",
},
];

Expand All @@ -99,9 +103,9 @@ mod tests {
f_one[31] = 1;
let inputs: Vec<[u8; 32]> = vec![f_zero, f_one];

let (x, y) = encrypt(&inputs);
let expected_x = "11831f49876c313f2a9ec6d8d521c7ce0b6311c852117e340bfe27fd1ac096ef";
let expected_y = "0ecf9d98be4597a88c46a7e0fa8836b57a7dcb41ee30f8d8787b11cc259c83fa";
let (x, y) = encrypt(&inputs, 0);
let expected_x = "0c5e1ddecd49de44ed5e5798d3f6fb7c71fe3d37f5bee8664cf88a445b5ba0af";
let expected_y = "230294a041e26fe80b827c2ef5cb8784642bbaa83842da2714d62b1f3c4f9752";
assert_eq!(expected_x, hex::encode(x));
assert_eq!(expected_y, hex::encode(y));
}
Expand Down

0 comments on commit c04e3f4

Please sign in to comment.