Skip to content

Commit

Permalink
feat!: Switch to new pedersen implementation (#3151)
Browse files Browse the repository at this point in the history
Co-authored-by: vezenovm <mvezenov@gmail.com>
  • Loading branch information
kevaundray and vezenovm authored Oct 24, 2023
1 parent a2c8ebd commit 35fb3f7
Show file tree
Hide file tree
Showing 21 changed files with 232 additions and 152 deletions.
4 changes: 2 additions & 2 deletions acvm-repo/acvm_js/test/shared/pedersen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const initialWitnessMap = new Map([[1, '0x0000000000000000000000000000000

export const expectedWitnessMap = new Map([
[1, '0x0000000000000000000000000000000000000000000000000000000000000001'],
[2, '0x09489945604c9686e698cb69d7bd6fc0cdb02e9faae3e1a433f1c342c1a5ecc4'],
[3, '0x24f50d25508b4dfb1e8a834e39565f646e217b24cb3a475c2e4991d1bb07a9d8'],
[2, '0x083e7911d835097629f0067531fc15cafd79a89beecb39903f69572c636f4a5a'],
[3, '0x1a7f5efaad7f315c25a918f30cc8d7333fccab7ad7c90f14de81bcc528f9935d'],
]);
132 changes: 66 additions & 66 deletions acvm-repo/acvm_js/test/shared/schnorr_verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,72 @@ export const bytecode = Uint8Array.from([
]);

export const initialWitnessMap = new Map([
[1, '0x17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5'],
[2, '0x0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74'],
[3, '0x0000000000000000000000000000000000000000000000000000000000000005'],
[4, '0x00000000000000000000000000000000000000000000000000000000000000ca'],
[5, '0x000000000000000000000000000000000000000000000000000000000000001f'],
[6, '0x0000000000000000000000000000000000000000000000000000000000000092'],
[7, '0x0000000000000000000000000000000000000000000000000000000000000051'],
[8, '0x00000000000000000000000000000000000000000000000000000000000000f2'],
[9, '0x00000000000000000000000000000000000000000000000000000000000000f6'],
[10, '0x0000000000000000000000000000000000000000000000000000000000000045'],
[11, '0x000000000000000000000000000000000000000000000000000000000000002b'],
[12, '0x000000000000000000000000000000000000000000000000000000000000006b'],
[13, '0x00000000000000000000000000000000000000000000000000000000000000f9'],
[14, '0x0000000000000000000000000000000000000000000000000000000000000099'],
[15, '0x00000000000000000000000000000000000000000000000000000000000000c6'],
[16, '0x000000000000000000000000000000000000000000000000000000000000002c'],
[17, '0x000000000000000000000000000000000000000000000000000000000000000e'],
[18, '0x000000000000000000000000000000000000000000000000000000000000006f'],
[19, '0x00000000000000000000000000000000000000000000000000000000000000bf'],
[20, '0x0000000000000000000000000000000000000000000000000000000000000079'],
[21, '0x0000000000000000000000000000000000000000000000000000000000000089'],
[22, '0x00000000000000000000000000000000000000000000000000000000000000a6'],
[23, '0x00000000000000000000000000000000000000000000000000000000000000a0'],
[24, '0x0000000000000000000000000000000000000000000000000000000000000067'],
[25, '0x0000000000000000000000000000000000000000000000000000000000000012'],
[26, '0x00000000000000000000000000000000000000000000000000000000000000b5'],
[27, '0x00000000000000000000000000000000000000000000000000000000000000f3'],
[28, '0x00000000000000000000000000000000000000000000000000000000000000e9'],
[29, '0x00000000000000000000000000000000000000000000000000000000000000e2'],
[30, '0x000000000000000000000000000000000000000000000000000000000000005f'],
[31, '0x0000000000000000000000000000000000000000000000000000000000000043'],
[32, '0x0000000000000000000000000000000000000000000000000000000000000010'],
[33, '0x0000000000000000000000000000000000000000000000000000000000000025'],
[34, '0x0000000000000000000000000000000000000000000000000000000000000080'],
[35, '0x0000000000000000000000000000000000000000000000000000000000000055'],
[36, '0x000000000000000000000000000000000000000000000000000000000000004c'],
[37, '0x0000000000000000000000000000000000000000000000000000000000000013'],
[38, '0x00000000000000000000000000000000000000000000000000000000000000fd'],
[39, '0x000000000000000000000000000000000000000000000000000000000000001e'],
[40, '0x000000000000000000000000000000000000000000000000000000000000004d'],
[41, '0x00000000000000000000000000000000000000000000000000000000000000c0'],
[42, '0x0000000000000000000000000000000000000000000000000000000000000035'],
[43, '0x000000000000000000000000000000000000000000000000000000000000008a'],
[44, '0x00000000000000000000000000000000000000000000000000000000000000cd'],
[45, '0x0000000000000000000000000000000000000000000000000000000000000045'],
[46, '0x0000000000000000000000000000000000000000000000000000000000000021'],
[47, '0x00000000000000000000000000000000000000000000000000000000000000ec'],
[48, '0x00000000000000000000000000000000000000000000000000000000000000a3'],
[49, '0x0000000000000000000000000000000000000000000000000000000000000053'],
[50, '0x00000000000000000000000000000000000000000000000000000000000000c2'],
[51, '0x0000000000000000000000000000000000000000000000000000000000000054'],
[52, '0x0000000000000000000000000000000000000000000000000000000000000089'],
[53, '0x00000000000000000000000000000000000000000000000000000000000000b8'],
[54, '0x00000000000000000000000000000000000000000000000000000000000000dd'],
[55, '0x00000000000000000000000000000000000000000000000000000000000000b0'],
[56, '0x0000000000000000000000000000000000000000000000000000000000000079'],
[57, '0x00000000000000000000000000000000000000000000000000000000000000b3'],
[58, '0x000000000000000000000000000000000000000000000000000000000000001b'],
[59, '0x000000000000000000000000000000000000000000000000000000000000003f'],
[60, '0x0000000000000000000000000000000000000000000000000000000000000046'],
[61, '0x0000000000000000000000000000000000000000000000000000000000000036'],
[62, '0x0000000000000000000000000000000000000000000000000000000000000010'],
[63, '0x00000000000000000000000000000000000000000000000000000000000000b0'],
[64, '0x00000000000000000000000000000000000000000000000000000000000000fa'],
[65, '0x0000000000000000000000000000000000000000000000000000000000000027'],
[66, '0x00000000000000000000000000000000000000000000000000000000000000ef'],
[1, '0x04b260954662e97f00cab9adb773a259097f7a274b83b113532bce27fa3fb96a'],
[2, '0x2fd51571db6c08666b0edfbfbc57d432068bccd0110a39b166ab243da0037197'],
[3, '0x000000000000000000000000000000000000000000000000000000000000002e'],
[4, '0x00000000000000000000000000000000000000000000000000000000000000ce'],
[5, '0x0000000000000000000000000000000000000000000000000000000000000052'],
[6, '0x00000000000000000000000000000000000000000000000000000000000000aa'],
[7, '0x0000000000000000000000000000000000000000000000000000000000000087'],
[8, '0x000000000000000000000000000000000000000000000000000000000000002a'],
[9, '0x0000000000000000000000000000000000000000000000000000000000000049'],
[10, '0x000000000000000000000000000000000000000000000000000000000000009d'],
[11, '0x0000000000000000000000000000000000000000000000000000000000000050'],
[12, '0x000000000000000000000000000000000000000000000000000000000000007c'],
[13, '0x000000000000000000000000000000000000000000000000000000000000009a'],
[14, '0x00000000000000000000000000000000000000000000000000000000000000aa'],
[15, '0x00000000000000000000000000000000000000000000000000000000000000df'],
[16, '0x0000000000000000000000000000000000000000000000000000000000000023'],
[17, '0x0000000000000000000000000000000000000000000000000000000000000034'],
[18, '0x0000000000000000000000000000000000000000000000000000000000000010'],
[19, '0x000000000000000000000000000000000000000000000000000000000000008a'],
[20, '0x0000000000000000000000000000000000000000000000000000000000000047'],
[21, '0x0000000000000000000000000000000000000000000000000000000000000063'],
[22, '0x00000000000000000000000000000000000000000000000000000000000000e8'],
[23, '0x0000000000000000000000000000000000000000000000000000000000000037'],
[24, '0x0000000000000000000000000000000000000000000000000000000000000054'],
[25, '0x0000000000000000000000000000000000000000000000000000000000000096'],
[26, '0x000000000000000000000000000000000000000000000000000000000000003e'],
[27, '0x00000000000000000000000000000000000000000000000000000000000000d5'],
[28, '0x00000000000000000000000000000000000000000000000000000000000000ae'],
[29, '0x0000000000000000000000000000000000000000000000000000000000000024'],
[30, '0x000000000000000000000000000000000000000000000000000000000000002d'],
[31, '0x0000000000000000000000000000000000000000000000000000000000000020'],
[32, '0x0000000000000000000000000000000000000000000000000000000000000080'],
[33, '0x000000000000000000000000000000000000000000000000000000000000004d'],
[34, '0x0000000000000000000000000000000000000000000000000000000000000047'],
[35, '0x00000000000000000000000000000000000000000000000000000000000000a5'],
[36, '0x00000000000000000000000000000000000000000000000000000000000000bb'],
[37, '0x00000000000000000000000000000000000000000000000000000000000000f6'],
[38, '0x00000000000000000000000000000000000000000000000000000000000000c3'],
[39, '0x000000000000000000000000000000000000000000000000000000000000000b'],
[40, '0x000000000000000000000000000000000000000000000000000000000000003b'],
[41, '0x0000000000000000000000000000000000000000000000000000000000000065'],
[42, '0x00000000000000000000000000000000000000000000000000000000000000c9'],
[43, '0x0000000000000000000000000000000000000000000000000000000000000001'],
[44, '0x0000000000000000000000000000000000000000000000000000000000000085'],
[45, '0x0000000000000000000000000000000000000000000000000000000000000006'],
[46, '0x000000000000000000000000000000000000000000000000000000000000009e'],
[47, '0x000000000000000000000000000000000000000000000000000000000000002f'],
[48, '0x0000000000000000000000000000000000000000000000000000000000000010'],
[49, '0x00000000000000000000000000000000000000000000000000000000000000e6'],
[50, '0x0000000000000000000000000000000000000000000000000000000000000030'],
[51, '0x000000000000000000000000000000000000000000000000000000000000004a'],
[52, '0x0000000000000000000000000000000000000000000000000000000000000018'],
[53, '0x000000000000000000000000000000000000000000000000000000000000007c'],
[54, '0x00000000000000000000000000000000000000000000000000000000000000d0'],
[55, '0x00000000000000000000000000000000000000000000000000000000000000ab'],
[56, '0x0000000000000000000000000000000000000000000000000000000000000031'],
[57, '0x00000000000000000000000000000000000000000000000000000000000000d5'],
[58, '0x0000000000000000000000000000000000000000000000000000000000000063'],
[59, '0x0000000000000000000000000000000000000000000000000000000000000084'],
[60, '0x00000000000000000000000000000000000000000000000000000000000000a3'],
[61, '0x00000000000000000000000000000000000000000000000000000000000000a6'],
[62, '0x00000000000000000000000000000000000000000000000000000000000000d5'],
[63, '0x0000000000000000000000000000000000000000000000000000000000000091'],
[64, '0x000000000000000000000000000000000000000000000000000000000000000d'],
[65, '0x000000000000000000000000000000000000000000000000000000000000009c'],
[66, '0x00000000000000000000000000000000000000000000000000000000000000f9'],
[67, '0x0000000000000000000000000000000000000000000000000000000000000000'],
[68, '0x0000000000000000000000000000000000000000000000000000000000000001'],
[69, '0x0000000000000000000000000000000000000000000000000000000000000002'],
Expand Down
57 changes: 5 additions & 52 deletions acvm-repo/barretenberg_blackbox_solver/build.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,14 @@
use std::{
fs::File,
io::{Cursor, Read},
path::{Path, PathBuf},
};
use std::path::PathBuf;

const BARRETENBERG_ARCHIVE: &str = "BARRETENBERG_ARCHIVE";
const BARRETENBERG_BIN_DIR: &str = "BARRETENBERG_BIN_DIR";

const BARRETENBERG_ARCHIVE_FALLBACK: &str = "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.5.0/acvm_backend.wasm.tar.gz";
// const ARCHIVE_SHA256: &str = "1xpycikqlvsjcryi3hkbc4mwmmdz7zshw6f76vyf1qssq53asyfx";

fn unpack_wasm(archive_path: &Path, target_dir: &Path) -> Result<(), String> {
if archive_path.exists() && archive_path.is_file() {
let archive = File::open(archive_path).map_err(|_| "Could not read archive")?;
unpack_archive(archive, target_dir);

Ok(())
} else {
Err(format!("Unable to locate {BARRETENBERG_ARCHIVE} - Please set the BARRETENBERG_BIN_DIR env var to the directory where it exists, or ensure it's located at {}", archive_path.display()))
}
}

fn unpack_archive<T: Read>(archive: T, target_dir: &Path) {
use flate2::read::GzDecoder;
use tar::Archive;

let gz_decoder = GzDecoder::new(archive);
let mut archive = Archive::new(gz_decoder);

archive.unpack(target_dir).unwrap();
}

/// Try to download the specified URL into a buffer which is returned.
fn download_binary_from_url(url: &str) -> Result<Cursor<Vec<u8>>, String> {
let response = reqwest::blocking::get(url).map_err(|error| error.to_string())?;

let bytes = response.bytes().unwrap();
Ok(Cursor::new(bytes.to_vec()))
}

fn main() -> Result<(), String> {
let out_dir = std::env::var("OUT_DIR").unwrap();

match std::env::var(BARRETENBERG_ARCHIVE) {
Ok(archive_path) => {
unpack_wasm(&PathBuf::from(archive_path), &PathBuf::from(&out_dir))?;
println!("cargo:rustc-env={BARRETENBERG_BIN_DIR}={out_dir}");
Ok(())
}
Err(_) => {
let wasm_bytes = download_binary_from_url(BARRETENBERG_ARCHIVE_FALLBACK)
.expect("download should succeed");
let dest_path = PathBuf::from(out_dir.clone()).join("acvm_backend.wasm");

unpack_archive(wasm_bytes, &PathBuf::from(&out_dir));
println!("cargo:rustc-env={BARRETENBERG_BIN_DIR}={out_dir}");
println!("cargo:rustc-env={BARRETENBERG_BIN_DIR}={out_dir}");
std::fs::copy("./src/acvm_backend.wasm", dest_path).unwrap();

Ok(())
}
}
Ok(())
}
Binary file not shown.
7 changes: 4 additions & 3 deletions acvm-repo/barretenberg_blackbox_solver/src/wasm/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ impl Pedersen for Barretenberg {
#[test]
fn pedersen_hash_to_point() -> Result<(), Error> {
let barretenberg = Barretenberg::new();
let (x, y) = barretenberg.encrypt(vec![FieldElement::zero(), FieldElement::one()], 0)?;
let (x, y) = barretenberg
.encrypt(vec![FieldElement::from(1 as u128), FieldElement::from(1 as u128)], 1)?;
let expected_x = FieldElement::from_hex(
"0x0c5e1ddecd49de44ed5e5798d3f6fb7c71fe3d37f5bee8664cf88a445b5ba0af",
"0x12afb43195f5c621d1d2cabb5f629707095c5307fd4185a663d4e80bb083e878",
)
.unwrap();
let expected_y = FieldElement::from_hex(
"0x230294a041e26fe80b827c2ef5cb8784642bbaa83842da2714d62b1f3c4f9752",
"0x25793f5b5e62beb92fd18a66050293a9fd554a2ff13bceba0339cae1a038d7c1",
)
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
# Custom filter with various file extensions that we rely upon to build packages
# Currently: `.nr`, `.sol`, `.sh`, `.json`, `.md`
# Currently: `.nr`, `.sol`, `.sh`, `.json`, `.md` and `.wasm`
filter = path: type:
(builtins.match ".*\.(nr|sol|sh|json|md)$" path != null) || (craneLib.filterCargoSources path type);
(builtins.match ".*\.(nr|sol|sh|json|md|wasm)$" path != null) || (craneLib.filterCargoSources path type);
};

# TODO(#1198): It'd be nice to include these flags when running `cargo clippy` in a devShell.
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tooling/nargo_cli/tests/acir_artifacts/schnorr/target/witness.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ x = "0"
y = "1"
salt = "42"

out_x = "0x0c5e1ddecd49de44ed5e5798d3f6fb7c71fe3d37f5bee8664cf88a445b5ba0af"
out_y = "0x230294a041e26fe80b827c2ef5cb8784642bbaa83842da2714d62b1f3c4f9752"
out_x = "0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402"
out_y = "0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126"
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
message = [0,1,2,3,4,5,6,7,8,9]
message = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
message_field = "0x010203040506070809"
pub_key_x = "0x17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5"
pub_key_y = "0x0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74"
pub_key_x = "0x04b260954662e97f00cab9adb773a259097f7a274b83b113532bce27fa3fb96a"
pub_key_y = "0x2fd51571db6c08666b0edfbfbc57d432068bccd0110a39b166ab243da0037197"
signature = [
5, 202, 31, 146, 81, 242, 246, 69, 43, 107, 249, 153, 198, 44, 14, 111, 191, 121, 137, 166,
160, 103, 18, 181, 243, 233, 226, 95, 67, 16, 37, 128, 85, 76, 19, 253, 30, 77, 192, 53, 138,
205, 69, 33, 236, 163, 83, 194, 84, 137, 184, 221, 176, 121, 179, 27, 63, 70, 54, 16, 176,
250, 39, 239,
]
1,
13,
119,
112,
212,
39,
233,
41,
84,
235,
255,
93,
245,
172,
186,
83,
157,
253,
76,
77,
33,
128,
178,
15,
214,
67,
105,
107,
177,
234,
77,
48,
27,
237,
155,
84,
39,
84,
247,
27,
22,
8,
176,
230,
24,
115,
145,
220,
254,
122,
135,
179,
171,
4,
214,
202,
64,
199,
19,
84,
239,
138,
124,
12,
]
Loading

0 comments on commit 35fb3f7

Please sign in to comment.