Skip to content

Commit

Permalink
fix: Account for missing indices in flattened witness map (#1907)
Browse files Browse the repository at this point in the history
* Fix witness. Exclude vk/pk.

* Precompile circuits and flat witnesses for test vectors, for bb consumption.

* Add witness data.

* clean

* README
  • Loading branch information
charlielye authored Jul 10, 2023
1 parent 3734e25 commit 3972410
Show file tree
Hide file tree
Showing 123 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ result
*.vk
**/Verifier.toml
**/target
!crates/nargo_cli/tests/test_data/*/target
!crates/nargo_cli/tests/test_data/*/target/witness.tr
8 changes: 7 additions & 1 deletion crates/nargo_cli/src/cli/fs/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ fn serialize_witness_map(witnesses: WitnessMap) -> Result<Vec<u8>, FilesystemErr
#[cfg(feature = "flat_witness")]
fn serialize_witness_map(witnesses: WitnessMap) -> Result<Vec<u8>, FilesystemError> {
let mut buf: Vec<u8> = Vec::new();
for (_, value) in witnesses {
let mut counter = 1;
for (index, value) in witnesses {
while counter < index.witness_index() {
buf.extend(vec![0; 32]);
counter += 1;
}
buf.extend_from_slice(&value.to_be_bytes());
counter += 1;
}
Ok(buf)
}
1 change: 1 addition & 0 deletions crates/nargo_cli/tests/test_data/1_mul/target/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":[205,148,77,74,195,64,20,199,109,155,52,31,45,162,224,1,122,132,153,76,210,76,118,109,253,194,141,160,39,48,137,83,12,198,20,194,180,184,205,13,146,137,30,65,81,87,30,193,107,20,60,140,27,5,69,152,69,231,21,102,86,3,3,195,255,189,223,251,189,135,253,207,157,131,234,125,150,199,233,237,108,113,127,178,44,210,195,56,207,171,167,203,233,249,233,113,35,58,35,201,99,87,246,216,27,85,111,211,50,227,55,119,140,103,105,219,180,235,9,82,59,184,211,109,196,122,66,208,216,247,89,232,49,76,112,140,188,40,161,1,242,131,100,76,49,197,1,13,174,61,74,8,163,62,13,163,36,10,81,132,125,194,240,60,136,200,252,251,27,67,57,8,170,94,143,178,146,165,60,91,177,234,229,98,185,224,25,43,248,35,72,141,134,81,171,231,107,235,205,63,193,63,151,190,249,33,193,107,202,216,247,175,254,177,87,166,102,64,176,223,5,96,255,187,178,186,21,234,200,77,1,0,11,32,7,116,115,32,116,48,77,8,236,150,214,202,91,150,46,202,59,182,76,121,91,166,188,3,175,188,101,65,176,223,211,81,121,27,64,121,7,32,199,86,154,163,74,172,7,212,96,213,28,46,236,214,120,62,43,86,172,228,194,29,128,111,73,119,0,97,202,80,195,253,239,14,27,77,72,254,25,243,6,96,68,1,218,93,215,95],"proving_key":[],"verification_key":[]}
Binary file not shown.
1 change: 1 addition & 0 deletions crates/nargo_cli/tests/test_data/2_div/target/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":[237,87,75,74,195,80,20,53,253,37,253,164,105,17,105,113,20,119,144,215,36,109,50,179,245,135,19,65,119,208,198,87,12,214,22,74,90,156,102,7,73,163,75,80,212,145,75,112,27,130,139,81,48,69,138,240,80,222,9,6,233,27,37,4,14,247,220,123,222,57,55,55,219,111,27,59,254,115,111,212,119,46,123,147,235,195,217,216,217,235,143,70,254,221,89,247,228,232,32,92,8,42,227,99,134,245,49,171,250,143,251,238,148,58,158,59,167,254,195,233,108,226,185,116,236,221,70,65,184,120,221,213,248,14,17,184,33,52,76,33,25,254,66,114,249,40,8,248,43,97,204,34,175,250,79,221,169,235,93,92,81,207,117,162,32,66,16,255,192,208,181,182,97,208,78,139,18,157,244,181,150,61,176,76,205,48,7,109,139,88,196,180,204,243,150,165,235,212,50,172,142,61,176,59,154,77,12,157,146,161,105,235,195,24,36,15,192,40,240,67,48,58,87,96,73,60,183,218,214,48,226,47,37,147,11,1,61,217,228,23,37,94,48,2,72,48,188,117,32,154,179,118,182,31,29,81,74,218,217,164,148,58,155,4,192,40,38,234,108,69,150,179,137,9,56,155,136,112,182,173,255,234,108,18,160,142,68,154,195,75,44,11,32,38,2,234,40,97,109,255,254,120,60,167,83,111,81,42,127,187,41,188,108,75,101,196,77,169,128,197,0,97,86,9,83,50,201,21,153,35,210,178,146,216,86,1,49,223,236,31,173,38,195,248,44,223,121,246,1,178,124,168,202,47,140,236,146,89,193,86,85,225,162,254,236,45,239,132,26,105,244,110,1,32,26,25,128,209,252,53,21,45,166,98,196,84,8,44,245,191,84,8,32,214,0,12,169,153,198,149,8,241,103,47,3,48,148,100,82,95,169,193,109,68,169,33,108,164,158,194,212,87,234,97,74,38,9,79,125,64,187,131,224,29],"proving_key":[],"verification_key":[]}
Binary file not shown.
1 change: 1 addition & 0 deletions crates/nargo_cli/tests/test_data/3_add/target/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":[205,151,203,78,194,64,24,133,165,148,75,75,75,112,233,174,143,208,233,5,102,118,130,183,184,49,209,55,128,58,196,70,132,132,20,226,182,111,208,139,62,130,70,93,249,8,190,134,137,15,163,49,146,192,102,22,204,33,206,172,154,76,114,114,254,111,206,252,255,244,97,255,107,239,32,125,31,76,134,209,237,96,118,127,186,152,70,71,195,201,36,125,186,234,95,156,157,228,69,197,17,108,106,162,205,170,147,190,30,199,115,30,37,241,146,167,47,151,139,89,18,243,105,242,88,102,69,241,121,232,202,45,82,1,104,104,210,18,110,153,101,91,139,144,213,71,77,255,16,112,212,157,244,173,63,143,147,155,59,158,196,81,153,151,242,133,215,106,249,15,62,223,237,6,1,239,121,156,248,100,232,122,108,68,67,55,8,71,93,74,40,9,105,120,237,81,223,231,52,160,61,54,98,61,151,145,192,231,100,28,50,127,188,178,45,143,111,163,178,172,4,152,170,0,52,52,64,182,58,187,128,35,107,74,47,0,97,5,0,238,168,152,156,42,8,176,172,143,58,0,206,90,227,125,62,159,46,249,60,41,234,13,120,27,169,55,16,109,164,9,14,3,164,178,102,174,200,73,110,196,60,7,68,180,137,141,215,250,92,7,216,163,186,34,51,217,52,68,51,217,112,118,200,128,152,255,203,96,181,2,171,37,98,208,210,224,215,206,178,16,215,206,82,113,186,152,128,92,180,10,192,153,170,4,135,143,127,23,211,1,112,12,192,219,198,84,49,57,198,246,26,222,159,6,177,1,62,218,210,124,153,168,105,74,99,146,183,7,25,28,118,91,212,52,219,248,159,57,219,70,224,179,85,124,171,0,76,101,217,55],"proving_key":[],"verification_key":[]}
Binary file not shown.
1 change: 1 addition & 0 deletions crates/nargo_cli/tests/test_data/4_sub/target/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":[205,148,77,78,195,48,16,133,149,52,73,171,114,137,28,193,142,147,198,217,209,242,39,54,72,112,131,36,184,194,34,164,82,228,86,108,125,3,255,192,146,37,8,88,113,4,174,193,109,96,81,164,86,149,178,168,103,81,175,44,141,244,244,222,55,79,243,116,244,34,191,102,77,89,223,207,22,143,231,203,182,62,41,155,70,190,222,76,175,46,206,180,241,226,158,161,223,55,28,196,242,227,148,119,172,22,124,197,228,251,245,114,33,56,107,197,179,85,198,252,28,35,183,135,189,63,13,130,38,105,202,242,132,97,130,75,148,20,21,205,80,154,85,19,138,41,206,104,118,155,80,66,24,77,105,94,84,69,142,10,156,18,134,231,89,65,230,107,17,127,111,27,248,255,99,149,114,23,9,131,239,30,142,65,44,63,167,29,23,119,15,76,240,218,106,235,14,47,12,53,0,190,208,217,8,218,74,166,44,128,41,15,160,91,62,128,198,120,239,40,201,58,10,222,133,227,106,42,48,0,101,5,88,210,248,16,155,51,0,2,236,234,35,2,128,179,113,120,223,46,219,21,235,132,137,134,224,103,36,26,66,156,145,17,112,25,64,146,141,244,129,108,114,171,230,26,160,162,0,184,149,250,5],"proving_key":[],"verification_key":[]}
Binary file not shown.
1 change: 1 addition & 0 deletions crates/nargo_cli/tests/test_data/5_over/target/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2]},"return_type":null,"return_witnesses":[]},"bytecode":[205,152,203,78,194,80,16,134,45,21,185,95,10,133,70,227,130,165,203,150,182,112,186,243,110,220,152,232,27,0,30,98,35,98,66,42,113,219,55,104,139,62,130,70,93,249,8,188,134,137,15,99,66,36,129,152,116,225,249,9,115,86,36,36,39,51,255,124,51,255,244,60,237,124,111,236,249,159,135,131,78,239,246,240,254,241,244,97,216,59,234,12,6,254,203,213,193,197,217,73,24,73,141,152,63,19,13,255,253,216,29,241,158,231,142,185,255,118,249,112,239,185,124,232,61,79,194,201,215,190,46,118,12,73,10,132,47,209,39,193,255,47,49,230,63,54,229,105,140,8,114,156,66,155,13,255,227,96,228,122,55,119,220,115,123,51,93,76,189,101,89,188,221,228,134,105,116,244,166,211,101,182,110,217,221,22,51,152,97,51,251,186,201,76,147,51,139,181,157,174,211,214,29,195,50,185,209,183,29,179,255,27,141,36,133,145,248,45,219,226,218,46,101,22,76,34,241,146,203,17,160,88,128,56,72,138,147,0,84,93,6,220,145,4,136,179,48,53,94,207,135,99,62,242,162,228,214,159,78,17,85,44,185,133,232,148,20,24,6,72,102,169,144,72,37,151,48,15,1,152,167,176,120,45,152,18,36,60,121,189,158,52,63,44,147,158,174,50,205,52,141,52,173,92,54,206,122,179,9,120,103,229,114,136,206,202,173,194,64,68,131,74,3,184,200,70,128,154,210,238,240,204,154,209,159,111,50,133,124,28,250,249,93,56,250,133,2,2,253,2,69,244,51,0,46,242,17,160,166,20,197,145,17,126,17,1,44,141,246,92,32,98,137,172,84,92,169,243,23,137,56,191,82,142,27,127,101,188,243,43,10,98,252,41,20,59,188,8,224,162,12,112,126,133,118,135,151,136,56,127,181,18,135,126,5,239,252,213,42,2,253,42,69,244,75,0,46,42,0,231,39,41,14,226,139,0,48,91,88,137,226,123,91,81,64,96,222,159,29,71,5,20,169,38,156,74,139,246,190,208,130,172,69,106,109,165,107,81,141,200,90,164,213,227,188,161,142,95,139,52,13,225,13,26,197,241,87,3,112,81,7,172,69,26,193,23,102,85,69,148,93,165,248,194,12,8,42,8,126,0],"proving_key":[],"verification_key":[]}
Binary file not shown.
1 change: 1 addition & 0 deletions crates/nargo_cli/tests/test_data/6/target/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"array","length":5,"type":{"kind":"integer","sign":"unsigned","width":8}},"visibility":"private"},{"name":"result","type":{"kind":"array","length":32,"type":{"kind":"integer","sign":"unsigned","width":8}},"visibility":"public"}],"param_witnesses":{"result":[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"x":[1,2,3,4,5]},"return_type":null,"return_witnesses":[]},"bytecode":[205,218,103,115,148,85,24,198,113,80,129,208,123,111,161,217,203,110,234,198,74,232,189,247,158,132,13,89,18,18,8,155,16,8,4,86,16,4,65,114,54,4,65,16,4,9,37,8,6,65,16,4,65,144,200,192,161,119,8,189,125,13,143,227,43,71,231,204,56,249,159,153,123,223,94,51,215,60,207,117,255,118,95,237,154,243,85,171,85,84,57,27,42,235,150,145,148,146,222,45,43,175,87,78,102,74,247,164,140,140,80,201,176,196,65,189,123,170,112,213,8,75,248,146,45,124,217,22,190,98,11,171,217,194,234,182,176,134,45,140,176,133,53,109,97,45,91,88,219,22,214,177,133,117,109,97,61,91,88,223,22,54,176,133,13,109,97,35,91,216,216,22,54,177,133,77,109,97,51,91,216,220,22,182,176,133,45,109,97,43,91,216,218,22,182,177,133,109,109,97,59,91,216,222,22,70,218,194,14,182,176,163,45,236,100,11,59,219,194,46,255,21,110,31,222,39,49,42,54,46,92,108,126,50,204,15,131,249,250,155,47,185,249,42,87,84,137,124,245,181,215,223,120,243,173,183,223,121,247,61,143,55,42,58,38,54,46,222,151,240,254,7,31,126,244,241,39,93,19,187,117,239,209,243,255,181,245,234,221,167,111,191,254,3,6,14,26,60,100,232,176,225,35,70,142,26,61,102,236,184,241,19,38,78,154,60,37,41,57,101,170,63,84,154,152,29,8,166,205,240,7,3,41,69,133,69,225,219,93,163,61,113,49,49,254,248,40,191,55,218,155,228,137,74,72,246,197,122,98,98,147,227,124,94,159,55,214,23,59,53,202,23,29,237,247,197,248,226,19,146,19,226,61,9,222,152,104,191,55,53,54,33,58,213,243,247,167,186,233,240,84,238,227,237,5,60,71,106,165,31,195,19,218,213,35,144,237,79,9,6,114,253,161,237,125,51,115,253,217,193,112,234,180,127,76,166,138,42,255,182,169,211,20,240,190,105,192,251,226,111,150,166,132,92,18,103,94,3,96,222,27,120,142,128,27,230,129,233,56,134,192,116,2,67,186,64,230,129,116,37,228,146,56,243,8,128,121,31,224,57,50,220,48,207,152,129,99,200,152,65,96,200,20,200,60,35,83,9,185,36,206,188,38,192,188,47,240,28,89,110,152,103,205,196,49,100,205,36,48,204,18,200,60,107,150,18,114,73,156,121,45,128,121,63,224,57,178,221,48,207,158,141,99,200,158,77,96,8,10,100,158,29,84,66,46,137,51,175,13,48,239,15,60,71,142,27,230,57,185,56,134,156,92,2,195,28,129,204,115,230,40,33,151,196,153,215,1,152,15,0,158,35,207,13,243,188,185,56,134,188,185,4,134,121,2,153,231,205,83,66,46,137,51,175,11,48,31,8,60,71,190,27,230,249,243,113,12,249,243,9,12,11,4,50,207,95,160,132,92,18,103,94,15,96,62,8,120,142,2,55,204,11,22,226,24,10,22,18,24,244,34,129,206,11,244,34,37,228,150,56,244,250,0,244,193,196,225,67,110,164,235,144,254,20,7,241,87,41,162,125,177,64,237,230,229,22,43,41,23,197,189,55,0,188,15,33,214,89,226,200,251,18,253,25,79,194,148,34,36,150,74,244,190,68,47,85,82,46,138,123,111,8,120,31,74,172,179,204,145,247,101,250,115,158,132,41,69,72,44,151,232,125,153,94,174,164,92,20,247,222,8,240,62,140,88,103,133,35,239,43,244,23,60,9,83,138,144,88,41,209,251,10,189,82,73,185,40,238,189,49,224,125,56,177,206,42,71,222,87,233,47,121,18,166,20,33,177,90,162,247,85,122,181,146,114,81,220,123,19,192,251,8,98,157,66,71,222,11,181,226,73,152,82,132,68,88,162,247,66,29,86,82,46,138,123,111,10,120,31,73,172,83,228,200,123,145,94,195,147,48,165,8,137,98,137,222,139,116,177,146,114,81,220,123,51,192,251,40,98,157,181,142,188,175,213,95,241,36,76,41,66,98,157,68,239,107,245,58,37,229,162,184,247,230,128,247,209,196,58,235,29,121,95,175,191,230,73,152,82,132,196,6,137,222,215,235,13,74,202,69,113,239,45,0,239,99,136,117,54,58,242,190,81,127,195,147,48,165,8,137,77,18,189,111,212,155,148,148,139,226,222,91,2,222,199,18,235,108,118,228,125,179,254,150,39,97,74,17,18,91,36,122,223,172,183,40,41,23,197,189,183,2,188,143,35,214,217,234,200,251,86,253,29,79,194,148,34,36,182,73,244,190,85,111,83,82,46,138,123,111,13,120,31,79,172,83,226,200,123,137,222,206,147,48,165,8,137,29,18,189,151,232,29,74,202,69,113,239,109,0,239,19,136,117,118,58,242,190,83,239,226,73,152,82,132,68,169,68,239,59,117,169,146,114,81,220,123,91,192,251,68,98,157,221,142,188,239,214,223,243,36,76,41,66,98,143,68,239,187,245,30,37,229,162,184,247,118,128,247,73,196,58,123,29,121,223,171,127,224,73,152,82,132,68,153,68,239,123,117,153,146,114,81,220,123,123,192,251,100,98,157,125,142,188,239,211,63,242,36,76,41,66,98,191,68,239,251,244,126,37,229,162,184,247,72,192,251,20,98,157,3,142,188,31,208,63,241,36,76,41,66,226,160,68,239,7,244,65,37,229,162,184,247,14,128,247,36,98,157,67,142,188,31,210,63,243,36,76,41,66,226,176,68,239,135,244,97,37,229,162,184,247,142,128,247,100,98,157,35,142,188,31,209,191,240,36,76,41,66,226,168,68,239,71,244,81,37,229,162,184,247,78,128,247,20,98,157,99,142,188,31,211,191,242,36,76,41,66,226,184,68,239,199,244,113,37,229,162,184,247,206,128,247,169,196,58,39,28,121,63,161,127,227,73,152,82,132,196,73,137,222,79,232,147,74,202,69,113,239,93,0,239,126,98,157,83,142,188,159,210,191,243,36,76,41,66,226,180,68,239,167,244,105,37,229,162,255,242,94,233,183,59,77,188,90,57,81,114,86,228,62,199,137,146,147,196,62,231,68,238,115,152,40,57,74,236,163,69,238,179,159,40,57,72,236,115,94,228,62,123,136,146,50,98,159,11,34,247,217,65,148,148,18,251,92,20,185,207,22,162,100,27,177,207,37,145,251,108,32,74,54,17,251,92,22,185,79,49,81,178,142,216,231,138,200,125,86,19,37,97,98,159,171,34,247,89,78,148,172,36,246,185,38,114,159,197,68,201,82,98,159,235,18,247,89,64,204,179,136,152,231,134,196,121,230,0,29,243,136,117,110,74,92,103,22,208,17,36,214,185,37,242,167,231,38,81,114,139,216,231,182,200,125,174,19,37,55,136,125,238,136,220,231,42,81,114,141,216,231,174,200,125,46,19,37,87,136,125,42,68,238,115,145,40,185,68,236,115,79,228,62,231,137,146,11,196,62,247,69,238,115,142,40,209,196,62,15,36,238,147,73,204,115,150,152,231,161,72,62,15,136,146,135,196,62,143,68,238,115,143,40,185,79,236,243,88,228,62,119,137,146,10,98,159,39,34,247,185,77,148,220,33,246,121,42,114,159,39,68,201,83,98,159,103,34,247,121,68,148,60,38,246,121,46,113,159,52,160,35,157,152,248,133,72,61,207,136,146,231,132,158,23,142,254,169,84,174,255,224,255,204,99,74,145,63,243,156,145,248,79,165,114,125,6,121,185,114,90,188,34,176,2,147,87,84,137,172,94,35,162,102,173,218,117,234,214,171,223,160,97,163,198,77,154,54,107,222,162,101,171,214,109,218,182,107,31,217,161,99,167,206,93,10,255,4],"proving_key":[],"verification_key":[]}
Binary file not shown.
Loading

0 comments on commit 3972410

Please sign in to comment.