-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add base64 example for gate counts #28
Draft
jzaki
wants to merge
1
commit into
master
Choose a base branch
from
jz/base64_example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[workspace] | ||
members = [ | ||
"base64_example", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "base64_example" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.36.0" | ||
|
||
[dependencies] | ||
base64 = {tag = "v0.3.0", git = "https://github.com/noir-lang/noir_base64.git"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
base64_encoded = "" | ||
input = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
input = "The quick brown fox jumps over the lazy dog, while 42 ravens perch atop a rusty mailbox." | ||
base64_encoded = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZywgd2hpbGUgNDIgcmF2ZW5zIHBlcmNoIGF0b3AgYSBydXN0eSBtYWlsYm94Lg==" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
input = "The quick br" | ||
base64_encoded = "VGhlIHF1aWNrIGJy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Base64 example use and bb benchmarking | ||
|
||
This makes use of [this](https://github.com/noir-lang/noir_base64.git) base64 library (see Nargo.toml for version) | ||
|
||
The lib covers several encode/decode tests, whereas this program has some extra code to facilitate benchmarking the gate counts of a proving backend. Comparisons can be made against other proving backends if desired. | ||
|
||
## Test setups for gate counts | ||
|
||
Assuming you have `nargo` and a compatible proving backend (eg nargo v0.36.0 and barretenberg bb v0.58.0): | ||
|
||
- Choose the desired number of encode/decode runs by setting the corresponding `global` variables in src/main.nr | ||
- Choose the input strings via the `comptime global` variables (the lengths are managed automatically at compile time) | ||
- To ensure the test values are expected lengths: | ||
- `nargo test` | ||
- Ensure these test values are in a corresponding Prover toml file eg (`Prover_SHORT.toml`) | ||
- Execute the program referring to the prover toml file for inputs: | ||
- `nargo execute -p Prover_SHORT.toml` | ||
- Note there's an optional param that you can use to specify the name of the witness file generated | ||
- Optional: `nargo execute -p Prover_SHORT.toml base64_example_SHORT.gz` | ||
- If using barretenberg, check the gate count referring to the newly created program: | ||
- `bb gates -b ../target/base64_example.json` | ||
- Note: you can similarly specify a non-default witness file to use with the program | ||
- Optional: `bb gates -b ../target/base64_example.json -w ../target/base64_example_SHORT` | ||
- Repeat this for different runs of encoding and decoding, of different length inputs to collect results | ||
- (Automating this is left as an exercise for the reader ;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
mod test_inputs; | ||
use base64::{BASE64_ENCODER, BASE64_DECODER}; | ||
|
||
// Choose number of encode and/or decode runs | ||
pub global ENCODE_RUNS: u32 = 3; | ||
pub global DECODE_RUNS: u32 = 0; | ||
|
||
// Choose size, and use corresponding Prover.toml during execution | ||
comptime global TEST_INPUT = test_inputs::TEST_INPUT_SHORT; | ||
comptime global TEST_BASE64_ENCODED = test_inputs::TEST_BASE64_ENCODED_SHORT; | ||
|
||
comptime global U: u32 = comptime { TEST_INPUT.as_bytes().len() }; | ||
comptime global B: u32 = comptime { | ||
let mut q = U / 3; | ||
let r = U - q * 3; | ||
if (r > 0) { q += 1; }; // round up since encoded base64 gets padded | ||
q * 4 | ||
}; | ||
|
||
fn main(input: str<U>, base64_encoded: str<B>) { | ||
for _ in 0..ENCODE_RUNS { | ||
let _encoded: [u8; B] = BASE64_ENCODER.encode(input.as_bytes()); | ||
} | ||
for _ in 0..DECODE_RUNS { | ||
let _decoded: [u8; U] = BASE64_DECODER.decode(base64_encoded.as_bytes()); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
main(TEST_INPUT, TEST_BASE64_ENCODED); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//SHORT | ||
pub comptime global TEST_INPUT_SHORT = "The quick br"; | ||
pub comptime global TEST_BASE64_ENCODED_SHORT = "VGhlIHF1aWNrIGJy"; | ||
|
||
//LONG | ||
pub comptime global TEST_INPUT_LONG = | ||
"The quick brown fox jumps over the lazy dog, while 42 ravens perch atop a rusty mailbox."; | ||
pub comptime global TEST_BASE64_ENCODED_LONG = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZywgd2hpbGUgNDIgcmF2ZW5zIHBlcmNoIGF0b3AgYSBydXN0eSBtYWlsYm94Lg=="; | ||
|
||
//LONG LONG | ||
// pub comptime global TEST_INPUT_LONG_LONG = | ||
// "The quick brown fox jumps over the lazy dog, while 42 ravens perch atop a rusty mailbox."; | ||
// pub comptime global TEST_BASE64_ENCODED_LONG_LONG = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZywgd2hpbGUgNDIgcmF2ZW5zIHBlcmNoIGF0b3AgYSBydXN0eSBtYWlsYm94Lg=="; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we suggest running this, do you think we should provide some context as to what the output of
bb gates
means? Or link to a place that explains it?