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

feat!: ACIR bytecode encoding with Base64 #1935

Merged
merged 9 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ tower = "0.4"
url = "2.2.0"
wasm-bindgen = { version = "=0.2.86", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3.33"
base64 = "0.21.2"

[patch.crates-io]
async-lsp = { git = "https://github.com/oxalica/async-lsp", rev = "09dbcc11046f7a188a80137f8d36484d86c78c78" }
acvm = { git = "https://github.com/noir-lang/acvm", branch = "kh-bincode-artifact-from-0.18.1-cfa8a5f"}
1 change: 1 addition & 0 deletions crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ toml.workspace = true
serde.workspace = true
thiserror.workspace = true
noirc_errors.workspace = true
base64.workspace = true
11 changes: 6 additions & 5 deletions crates/nargo/src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! These artifacts are intended to remain independent of any applications being built on top of Noir.
//! Should any projects require/desire a different artifact format, it's expected that they will write a transformer
//! to generate them using these artifacts as a starting point.

use acvm::acir::circuit::Circuit;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use base64::Engine;
use serde::{Deserializer, Serializer};

pub mod contract;
pub mod program;
Expand All @@ -17,15 +17,16 @@ where
{
let mut circuit_bytes: Vec<u8> = Vec::new();
circuit.write(&mut circuit_bytes).unwrap();

circuit_bytes.serialize(s)
let encoded_b64 = base64::engine::general_purpose::STANDARD.encode(circuit_bytes);
s.serialize_str(&encoded_b64)
}

fn deserialize_circuit<'de, D>(deserializer: D) -> Result<Circuit, D::Error>
where
D: Deserializer<'de>,
{
let circuit_bytes = Vec::<u8>::deserialize(deserializer)?;
let bytecode_b64: String = serde::Deserialize::deserialize(deserializer)?;
let circuit_bytes = base64::engine::general_purpose::STANDARD.decode(bytecode_b64).unwrap();
let circuit = Circuit::read(&*circuit_bytes).unwrap();
Ok(circuit)
}
2 changes: 1 addition & 1 deletion crates/nargo_cli/tests/test_data/1_mul/target/main.json
Original file line number Diff line number Diff line change
@@ -1 +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":null,"verification_key":null}
{"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":"H4sIAAAAAAAA/9VVW67CIBQ8t49bXzGauACXwClg4c+laGPd/xIsEZQ0+sVgdJKGnoRO5zADbIloR3f8jU/hx31UF5O69HX4xuHoR5EGjjXEvFIclBq6dmDJZ9Ha3mihdH8wbFgbfWmNlINRprO97YRlJQe+aiuvnrjCaRRBH7p3p7GiJ1B6aYJEXg4v/yNHHQenngTFTTi9CQrC0CoD7zrTwpdYU7kGG4nShV4/9CarfU7RuWno+w8Yp7GhJ5A+EY73kcv5yDELISh8sY9qN+Hkf5bD0CYD74Z+44CZgY1E6frU+qX6XGbyIlXXgrAHlYPjXNLrfSjSwIEbvQ9X9N0Xlet7laFvpP8UAd0/2p8YN9ELeU32DAAA","proving_key":null,"verification_key":null}
Binary file modified crates/nargo_cli/tests/test_data/1_mul/target/witness.tr
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/nargo_cli/tests/test_data/2_div/target/main.json
Original file line number Diff line number Diff line change
@@ -1 +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":null,"verification_key":null}
{"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":"H4sIAAAAAAAA/+1Y207DMAz12m3tYB1MCG3iqfxB3MuavvErVLT//wk0IpHSiPGwnFRFcKSptbQd+9iOY+2FiF7pC6vxE+lnbtmRY8faNt8l6/cKb/op/MArHJcIFWMEjHE9cmycnMITGmknueMjDpiYUlyqqm+Knkt+F0XbyVpUdXeRLLmW9Uchy7KXlWzarm1Ey1XZ81C35aDJNkCuLZDL5HNL0wOytvLrNpyvT8OP5n0i/GEL0VerQH0l/MDI/P0PVuxgTUaOlGYYrMpJ7vhY8mBNgVw7wg/WHU0Ha0JhB2sSgPeZ/t5gTYFxzZU/X80xUHMCjOuOsBeTguK8p+/PofADG270OdyD+yiE7n0A3cj6kwW0fmR9zAIV4o6IaVkL2aBhbHLgGSObl8PIkZnCR9rILftA1y9n4Qe+lnjfgp7od1wuwI2dMyDX+XaNQmustEb+KX/iNkyaF6X5BKzrmebpP+EHRv4DkwG5Hgi/3CjOR/2OnmOGGz3HjrTs5UbpPgbQjaw/WUDrR9fHxie98z5EwxcAAA==","proving_key":null,"verification_key":null}
Binary file modified crates/nargo_cli/tests/test_data/2_div/target/witness.tr
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/nargo_cli/tests/test_data/3_add/target/main.json
Original file line number Diff line number Diff line change
@@ -1 +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":null,"verification_key":null}
{"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":"H4sIAAAAAAAA/9VWUW6DMAx1A91KgWr73B9HiEkoyd+uMjS4/xEGXbJlbNOk5aWiT0KJJfRiPzuOH4noid6xmz/h1iawxcrOnO3/9RBufXarjAPvgFwCxyVphUhe9pv9zJGHicid0BQIDQqCl8P2P/AqedZ67NuRFb/I1g6mk7obzoYNd6Z7bY1So9Gmt4PtpWWtRp46q6YgCJCPX4TOwH7ugFzA4uKHK+kn48A5uPBRubiWfrF+ZolyEevXHVA//yAsnPduj+5jnhvdxw7gOkoR9yFB3Mj8UwB0/Mj8rAcZsK8mp+0PH8eZo/DBC2c09H3KQyfyuF1xPHQ1c5ShOCV9jrtoQZbDKsLf7Ipu42UEFgSX4CLYsn7jdIEFdhsuCNthbqH+iniu1nFxDfTrhMuF/aupIzWU/8OHr7QCiFcuuTn54IUzml8EkXG4FEKdQOia0lyqFPGn8HPBGyTRHLHEEgAA","proving_key":null,"verification_key":null}
Binary file modified crates/nargo_cli/tests/test_data/3_add/target/witness.tr
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/nargo_cli/tests/test_data/4_sub/target/main.json
Original file line number Diff line number Diff line change
@@ -1 +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":null,"verification_key":null}
{"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":"H4sIAAAAAAAA/9VVbQ6CMAwtA5RgvINHWPcB2z+vInHc/whC7Mwkxj8tP3gJ6ZqQ1/a9ZrsAwBXeqJZPUbwVudrkNeX53wxF8U5R84BVwWX14FwaTUKLD23iFLx2fhoCBvTBP02wNgUXxjjFUUd0NuHso52JTPH7wnyADaR424WjKY1oSGgohGYW+xRdi7U/eLlCt3I9fgldC/dZCWqpBLl6/oyGZsR/+mkesBFefClfezjG/tU7ecHt6ySoX34QVs4znaXvscwtfY91wnu0x9zdDnNL+g8FpOeX9qfEC7Jq2noVCQAA","proving_key":null,"verification_key":null}
Binary file modified crates/nargo_cli/tests/test_data/4_sub/target/witness.tr
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/nargo_cli/tests/test_data/5_over/target/main.json
Original file line number Diff line number Diff line change
@@ -1 +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":null,"verification_key":null}
{"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":"H4sIAAAAAAAA/+1Yy07DMBDcOoW+36UViANHjt7GSZ0bv0JF+v+fgA22FKJyyiyKJVaq0lWrsXd2xuv2iYhe6TsG7qXC86WRq5DHzwbh+2/hqbsFNzGBuJpa0RGX45uhw8iahGUtwoYhpxtk5bo0pj6fas75XZ+qiy20KS6lZcuFLT5ONs9ra+y5ulRnXbHJa74WVX4Niw9+aUJX3Ech4jNsUzkDNxK1r1T4U0DNZECsOyB/KuB4zHu67UPdLThio304AutIou6RQN3I/lMj0PUj+6Po5+BD7zWj3g7TGHbiMMYeSJqMcf/JMDOHMY3Fq5AoIUL8YjPCO3lGfzMJu+4TKAiegkWA4k/aVBPqr6niNW/hMOaxeBWSZyFC/GILwptqQWmYCigInoNFkAJ/wJGNnHgWafT/Sa/tymEsPZA0Gcv+k2E2DmMdi1chkbr2+MU2hD+hN5TGCQMUBK/BIkDxJ22qFfXXVHHi7RzGNhavQiJ17fGL7Qhvqh2lYSqgIHgLFkEK/CF/iwEPOCtldPS/uktAL+rrV1R7YF8fcDWWCd2USmoFCNf63nhOxa+NwMaJXRuPDuMQi1chkbo2+sWOhJ9wR0rjhAYKgg9gESD5Q+vGO3YvoJs9yehGon6Jffr4BFcEKAq9IAAA","proving_key":null,"verification_key":null}
Binary file modified crates/nargo_cli/tests/test_data/5_over/target/witness.tr
Binary file not shown.
Loading