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

chore: revert deletion of the old bbup #9146

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
117 changes: 117 additions & 0 deletions barretenberg/cpp/installation/bbup
Original file line number Diff line number Diff line change
@@ -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 <<EOF
The installer for bb.
Update or revert to a specific bb version with ease.
USAGE:
bb <OPTIONS>
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
48 changes: 48 additions & 0 deletions barretenberg/cpp/installation/install
Original file line number Diff line number Diff line change
@@ -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."
140 changes: 140 additions & 0 deletions barretenberg/cpp/src/barretenberg/bb/readme.md
Original file line number Diff line number Diff line change
@@ -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 <command>_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.
Loading