From 3138078f0062d8426b3c45ac47646169317ab795 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:16:37 +0100 Subject: [PATCH] chore: revert deletion of the old bbup (#9146) This fixes noir CI as it relies on the old bbup and the new one does not work for us. --- barretenberg/cpp/installation/bbup | 117 +++++++++++++++ barretenberg/cpp/installation/install | 48 ++++++ .../cpp/src/barretenberg/bb/readme.md | 140 ++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100755 barretenberg/cpp/installation/bbup create mode 100755 barretenberg/cpp/installation/install create mode 100644 barretenberg/cpp/src/barretenberg/bb/readme.md diff --git a/barretenberg/cpp/installation/bbup b/barretenberg/cpp/installation/bbup new file mode 100755 index 00000000000..e26d38999f4 --- /dev/null +++ b/barretenberg/cpp/installation/bbup @@ -0,0 +1,117 @@ +#!/usr/bin/env bash +set -e + +BB_HOME=${BB_HOME-"$HOME/.bb"} + +main() { + need_cmd curl + + while [[ $1 ]]; do + case $1 in + --) shift; break;; + + -v|--version) shift; BBUP_VERSION=$1;; + -h|--help) + usage + exit 0 + ;; + *) + err "internal error: unknown option "$1"\n";; + esac; shift + done + + if [ -z "$BBUP_VERSION" ]; then + err "--version option is required" + fi + + BBUP_REPO=AztecProtocol/aztec-packages + + PLATFORM="$(uname -s)" + case $PLATFORM in + Linux) + PLATFORM="linux-gnu" + ;; + Darwin) + PLATFORM="apple-darwin" + ;; + *) + err "unsupported platform: $PLATFORM" + ;; + esac + + # Fetch system's architecture. + ARCHITECTURE="$(uname -m)" + + # Align ARM naming for release fetching. + if [ "${ARCHITECTURE}" = "arm64" ]; then + ARCHITECTURE="aarch64" # Align release naming. + fi + + # Reject unsupported architectures. + if [ "${ARCHITECTURE}" != "x86_64" ] && [ "${ARCHITECTURE}" != "aarch64" ]; then + err "unsupported architecure: $ARCHITECTURE-$PLATFORM" + fi + + BBUP_TAG=$BBUP_VERSION + # Normalize versions (handle channels, versions without v prefix) + if [[ "$BBUP_VERSION" == [[:digit:]]* ]]; then + # Add v prefix + BBUP_VERSION="v${BBUP_VERSION}" + BBUP_TAG="aztec-packages-${BBUP_VERSION}" + fi + + say "installing bb (version ${BBUP_VERSION} with tag ${BBUP_TAG})" + + RELEASE_URL="https://github.com/${BBUP_REPO}/releases/download/${BBUP_TAG}" + BIN_TARBALL_URL="${RELEASE_URL}/barretenberg-${ARCHITECTURE}-${PLATFORM}.tar.gz" + + # Download the binary's tarball and unpack it into the .bb directory. + say "downloading bb to '$BB_HOME'" + ensure curl -# -L $BIN_TARBALL_URL | tar -xzC $BB_HOME + + say "done" +} + +usage() { + cat 1>&2 < +OPTIONS: + -h, --help Print help information + -v, --version Install a specific version (required) +EOF +} + +say() { + printf 'bbup: %s\n' "$1" +} + +warn() { + say "warning: ${1}" >&2 +} + +err() { + say "$1" >&2 + exit 1 +} + +need_cmd() { + if ! check_cmd "$1"; then + err "need '$1' (command not found)" + fi +} + +check_cmd() { + command -v "$1" >/dev/null 2>&1 +} + +# Run a command that should never fail. If the command fails execution +# will immediately terminate with an error showing the failing +# command. +ensure() { + if ! "$@"; then err "command failed: $*"; fi +} + +main "$@" || exit 1 \ No newline at end of file diff --git a/barretenberg/cpp/installation/install b/barretenberg/cpp/installation/install new file mode 100755 index 00000000000..f426d041567 --- /dev/null +++ b/barretenberg/cpp/installation/install @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +set -e + +echo Installing bbup... + +BB_HOME=${BB_HOME-"$HOME/.bb"} + +BBUP_BIN_URL=${BBUP_BIN_URL-"https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/barretenberg/cpp/installation/bbup"} +BBUP_BIN_PATH="$BB_HOME/bbup" + +# Create the .bb directory and bbup binary if it doesn't exist. +mkdir -p $BB_HOME +curl -# -L $BBUP_BIN_URL -o $BBUP_BIN_PATH +chmod +x $BBUP_BIN_PATH + +# Store the correct profile file (i.e. .profile for bash or .zshrc for ZSH). +case $SHELL in +*/zsh) + PROFILE=$HOME/.zshrc + PREF_SHELL=zsh + ;; +*/bash) + PROFILE=$HOME/.bashrc + PREF_SHELL=bash + ;; +*/fish) + PROFILE=$HOME/.config/fish/config.fish + PREF_SHELL=fish + ;; +*/ash) + PROFILE=$HOME/.profile + PREF_SHELL=ash + ;; +*) + echo "bbup: could not detect shell, manually add ${BB_HOME} to your PATH." + exit 1 + ;; +esac + +# Only add bbup if it isn't already in PATH. +if [[ ":$PATH:" != *":${BB_HOME}:"* ]]; then + # Add the .bb directory to the path and ensure the old PATH variables remain. + echo >>$PROFILE && echo "export BB_HOME=\"$BB_HOME\"" >>$PROFILE + echo >>$PROFILE && echo "export PATH=\"\$PATH:\$BB_HOME\"" >>$PROFILE +fi + +echo && echo "Detected your preferred shell is ${PREF_SHELL} and added bbup to PATH. Run 'source ${PROFILE}' or start a new terminal session to use bbup." +echo "Then, simply run 'bbup' to install bb." \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/bb/readme.md b/barretenberg/cpp/src/barretenberg/bb/readme.md new file mode 100644 index 00000000000..eb1ff22b2c8 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/bb/readme.md @@ -0,0 +1,140 @@ +# BB + +### Why is this needed? + +Barretenberg is a library that allows one to create and verify proofs. One way to specify the circuit that one will use to create and verify +proofs over is to use the Barretenberg standard library. Another way, which pertains to this module is to supply the circuit description using an IR called [ACIR](https://github.com/noir-lang/acvm). + +This binary will take as input ACIR and witness values described in the IR to create proofs. + +### Installation + +1. Install `bbup` the installation script by running this in your terminal: + + ```bash + curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/barretenberg/cpp/installation/install | bash + ``` + +2. Reload your terminal shell environment: + + macOS: + ```bash + source ~/.zshrc + ``` + + Linux: + ```bash + source ~/.bashrc + ``` + +3. Install the version of `bb` compatible with your Noir version; with **Noir v0.34.0** for example: + + ```bash + bbup -v 0.55.0 + ``` + + Check the version compatibility section below for how to identify matching versions. + +4. Check if the installation was successful: + + ```bash + bb --version + ``` + +If installation was successful, the command would print the version of `bb` installed. + +### Usage prerequisites + +Certain `bb` commands will expect the tool `jq` to already be installed. If `jq -V` doesn't return a version number, install it from [here](https://jqlang.github.io/jq/download/). + +### Version compatibility with Noir + +TODO: https://github.com/AztecProtocol/aztec-packages/issues/7511 + +For quick reference: +- Noir v0.34.0 <> BB v0.55.0 +- Noir v0.33.0 <> BB v0.47.1 +- Noir v0.32.0 <> BB v0.46.1 +- Noir v0.31.0 <> BB v0.41.0 + +### Usage + +TODO: https://github.com/AztecProtocol/aztec-packages/issues/7600 + +All available `bb` commands: +https://github.com/AztecProtocol/aztec-packages/blob/barretenberg-v0.55.0/barretenberg/cpp/src/barretenberg/bb/main.cpp#L1369-L1512 + +#### FilePath vs Stdout + +For commands which allow you to send the output to a file using `-o {filePath}`, there is also the option to send the output to stdout by using `-o -`. + +#### Usage with UltraHonk + +Documented with Noir v0.33.0 <> BB v0.47.1: + +##### Proving and verifying + +1. Follow [the Noir docs](https://noir-lang.org/docs/getting_started/hello_noir/) to compile and generate witness of your Noir program + +2. Prove the valid execution of your Noir program running: + + ```bash + bb prove_ultra_honk -b ./target/hello_world.json -w ./target/witness-name.gz -o ./target/proof + ``` + +3. Compute the verification key for your Noir program running: + + ```bash + bb write_vk_ultra_honk -b ./target/hello_world.json -o ./target/vk + ``` + +4. Verify your proof running: + + ```bash + bb verify_ultra_honk -k ./target/vk -p ./target/proof + ``` + + If successful, the verification will complete in silence; if unsuccessful, the command will trigger logging of the corresponding error. + +Refer to all available `bb` commands linked above for full list of functionality. + +##### Generating proofs for verifying in Solidity + +Barretenberg UltraHonk comes with the capability to verify proofs in Solidity, i.e. in smart contracts on EVM chains. + +1. Follow [the Noir docs](https://noir-lang.org/docs/getting_started/hello_noir/) to compile and generate witness of your Noir program + +2. Prove the valid execution of your Noir program running: + + ```bash + bb prove_ultra_keccak_honk -b ./target/hello_world.json -w ./target/witness-name.gz -o ./target/proof + ``` + + > **Note:** `prove_ultra_keccak_honk` is used to generate UltraHonk proofs with Keccak hashes, as it is what the Solidity verifier is designed to be compatible with given the better gas efficiency when verifying on-chain; `prove_ultra_honk` in comparison generates proofs with Poseidon hashes, more efficient in recursions but not on-chain verifications. + +3. Compute the verification key for your Noir program running: + + ```bash + bb write_vk_ultra_honk -b ./target/hello_world.json -o ./target/vk + ``` + +4. Generate Solidity verifier + **WARNING:** Contract incomplete, do not use in production! + + ```bash + bb contract_ultra_honk -k ./target/vk -c $CRS_PATH -b ./target/hello_world.json -o ./target/Verifier.sol + ``` + +#### Usage with MegaHonk + +Use `bb _mega_honk`. + +Refer to all available `bb` commands linked above for full list of functionality. + +Note that MegaHonk: +- Generates insecure recursion circuits when Goblin recursive verifiers are not present +- Will not have a Solidity verifier, as the proving system is intended for use with apps deploying on Aztec only + +### Maximum circuit size + +Currently the binary downloads an SRS that can be used to prove the maximum circuit size. This maximum circuit size parameter is a constant in the code and has been set to $2^{23}$ as of writing. This maximum circuit size differs from the maximum circuit size that one can prove in the browser, due to WASM limits.