Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into zpedro/docs_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed May 10, 2024
2 parents bab6ba2 + 84b9fcd commit e885ced
Show file tree
Hide file tree
Showing 180 changed files with 6,274 additions and 2,007 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95d4d133d1eb5e0eb44cd928d8183d890e970a13
b541e793e20fa3c991e0328ec2ff7926bdcdfd45
28 changes: 28 additions & 0 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,34 @@ fn handle_black_box_function(avm_instrs: &mut Vec<AvmInstruction>, operation: &B
..Default::default()
});
}
BlackBoxOp::ToRadix {
input,
radix,
output,
} => {
let num_limbs = output.size;
let input_offset = input.0;
let output_offset = output.pointer.0;
assert!(radix <= &256u32, "Radix must be less than or equal to 256");

avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::TORADIXLE,
indirect: Some(FIRST_OPERAND_INDIRECT),
tag: None,
operands: vec![
AvmOperand::U32 {
value: input_offset as u32,
},
AvmOperand::U32 {
value: output_offset as u32,
},
AvmOperand::U32 { value: *radix },
AvmOperand::U32 {
value: num_limbs as u32,
},
],
})
}
_ => panic!("Transpiler doesn't know how to process {:?}", operation),
}
}
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/acir_tests/flows/all_cmds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand All @@ -19,4 +19,4 @@ $BIN contract -k vk $BFLAG -o - | grep "Verification Key Hash" > /dev/null
OUTPUT=$($BIN proof_as_fields -k vk -p proof -o - | jq .)
[ -n "$OUTPUT" ] || exit 1
OUTPUT=$($BIN vk_as_fields -k vk -o - | jq .)
[ -n "$OUTPUT" ] || exit 1
[ -n "$OUTPUT" ] || exit 1
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/prove_and_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ VFLAG=${VERBOSE:+-v}

# This is the fastest flow, because it only generates pk/vk once, gate count once, etc.
# It may not catch all class of bugs.
$BIN prove_and_verify $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify $VFLAG -c $CRS_PATH -b ./target/program.json
4 changes: 2 additions & 2 deletions barretenberg/acir_tests/flows/prove_and_verify_goblin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/program.json

# This command can be used to run all of the tests in sequence with the debugger
# lldb-16 -o run -b -- $BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/acir.gz
# lldb-16 -o run -b -- $BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/program.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_goblin_ultra_honk $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_goblin_ultra_honk $VFLAG -c $CRS_PATH -b ./target/program.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_ultra_honk $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_ultra_honk $VFLAG -c $CRS_PATH -b ./target/program.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_ultra_honk_program $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_ultra_honk_program $VFLAG -c $CRS_PATH -b ./target/program.json
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/prove_then_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/acir_tests/flows/sol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export PROOF_AS_FIELDS="$(pwd)/proof_fields.json"
$BIN prove -o proof
$BIN write_vk -o vk
$BIN proof_as_fields -k vk -c $CRS_PATH -p $PROOF
$BIN contract -k vk -c $CRS_PATH -b ./target/acir.gz -o Key.sol
$BIN contract -k vk -c $CRS_PATH -b ./target/program.json -o Key.sol

# Export the paths to the environment variables for the js test runner
export KEY_PATH="$(pwd)/Key.sol"
Expand All @@ -20,4 +20,4 @@ export BASE_PATH=$(realpath "../../../sol/src/ultra/BaseUltraVerifier.sol")
# index.js will start an anvil, on a random port
# Deploy the verifier then send a test transaction
export TEST_NAME=$(basename $(pwd))
node ../../sol-test/src/index.js
node ../../sol-test/src/index.js
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/write_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -eu
export TEST_NAME=$(basename $(pwd))

$BIN write_vk -o vk
$BIN contract -k vk -c $CRS_PATH -b ./target/acir.gz -o $TEST_NAME.sol
$BIN contract -k vk -c $CRS_PATH -b ./target/program.json -o $TEST_NAME.sol
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/gen_inner_proof_inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $BIN vk_as_fields $VFLAG -c $CRS_PATH
echo "Generate proof to file..."
[ -d "$PROOF_DIR" ] || mkdir $PWD/proofs
[ -e "$PROOF_PATH" ] || touch $PROOF_PATH
$BIN prove $VFLAG -c $CRS_PATH -b ./target/acir.gz -o "./proofs/$PROOF_NAME" $RFLAG
$BIN prove $VFLAG -c $CRS_PATH -b ./target/program.json -o "./proofs/$PROOF_NAME" $RFLAG

echo "Write proof as fields for recursion..."
$BIN proof_as_fields $VFLAG -c $CRS_PATH -p "./proofs/$PROOF_NAME"
Expand Down
14 changes: 11 additions & 3 deletions barretenberg/acir_tests/headless-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ function formatAndPrintLog(message: string): void {
}

const readBytecodeFile = (path: string): Uint8Array => {
const data = fs.readFileSync(path);
const buffer = gunzipSync(data);
return buffer;
const extension = path.substring(path.lastIndexOf('.') + 1);

if (extension == 'json') {
const encodedCircuit = JSON.parse(fs.readFileSync(path, 'utf8'));
const decompressed = gunzipSync(Uint8Array.from(atob(encodedCircuit.bytecode), c => c.charCodeAt(0)));
return decompressed;
}

const encodedCircuit = fs.readFileSync(path);
const decompressed = gunzipSync(encodedCircuit);
return decompressed;
};

const readWitnessFile = (path: string): Uint8Array => {
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/run_acir_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ else
continue
fi

if [[ ! -f ./$TEST_NAME/target/acir.gz || ! -f ./$TEST_NAME/target/witness.gz ]]; then
if [[ ! -f ./$TEST_NAME/target/program.json || ! -f ./$TEST_NAME/target/witness.gz ]]; then
echo -e "\033[33mSKIPPED\033[0m (uncompiled)"
continue
fi
Expand Down
11 changes: 10 additions & 1 deletion barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#pragma once
#include "exec_pipe.hpp"
#include <filesystem>

/**
* We can assume for now we're running on a unix like system and use the following to extract the bytecode.
*/
inline std::vector<uint8_t> get_bytecode(const std::string& bytecodePath)
{
std::filesystem::path filePath = bytecodePath;
if (filePath.extension() == ".json") {
// Try reading json files as if they are a Nargo build artifact
std::string command = "jq -r '.bytecode' \"" + bytecodePath + "\" | base64 -d | gunzip -c";
return exec_pipe(command);
}

// For other extensions, assume file is a raw ACIR program
std::string command = "gunzip -c \"" + bytecodePath + "\"";
return exec_pipe(command);
}
}
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ int main(int argc, char* argv[])

std::string command = args[0];

std::string bytecode_path = get_option(args, "-b", "./target/acir.gz");
std::string bytecode_path = get_option(args, "-b", "./target/program.json");
std::string witness_path = get_option(args, "-w", "./target/witness.gz");
std::string proof_path = get_option(args, "-p", "./proofs/proof");
std::string vk_path = get_option(args, "-k", "./target/vk");
Expand Down
74 changes: 69 additions & 5 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,6 @@ struct BlackBoxOp {
Program::HeapVector inputs;
Program::HeapArray iv;
Program::HeapArray key;
Program::MemoryAddress length;
Program::HeapVector outputs;

friend bool operator==(const AES128Encrypt&, const AES128Encrypt&);
Expand Down Expand Up @@ -896,6 +895,16 @@ struct BlackBoxOp {
static Sha256Compression bincodeDeserialize(std::vector<uint8_t>);
};

struct ToRadix {
Program::MemoryAddress input;
uint32_t radix;
Program::HeapArray output;

friend bool operator==(const ToRadix&, const ToRadix&);
std::vector<uint8_t> bincodeSerialize() const;
static ToRadix bincodeDeserialize(std::vector<uint8_t>);
};

std::variant<AES128Encrypt,
Sha256,
Blake2s,
Expand All @@ -916,7 +925,8 @@ struct BlackBoxOp {
BigIntFromLeBytes,
BigIntToLeBytes,
Poseidon2Permutation,
Sha256Compression>
Sha256Compression,
ToRadix>
value;

friend bool operator==(const BlackBoxOp&, const BlackBoxOp&);
Expand Down Expand Up @@ -3939,9 +3949,6 @@ inline bool operator==(const BlackBoxOp::AES128Encrypt& lhs, const BlackBoxOp::A
if (!(lhs.key == rhs.key)) {
return false;
}
if (!(lhs.length == rhs.length)) {
return false;
}
if (!(lhs.outputs == rhs.outputs)) {
return false;
}
Expand Down Expand Up @@ -5141,6 +5148,63 @@ Program::BlackBoxOp::Sha256Compression serde::Deserializable<Program::BlackBoxOp

namespace Program {

inline bool operator==(const BlackBoxOp::ToRadix& lhs, const BlackBoxOp::ToRadix& rhs)
{
if (!(lhs.input == rhs.input)) {
return false;
}
if (!(lhs.radix == rhs.radix)) {
return false;
}
if (!(lhs.output == rhs.output)) {
return false;
}
return true;
}

inline std::vector<uint8_t> BlackBoxOp::ToRadix::bincodeSerialize() const
{
auto serializer = serde::BincodeSerializer();
serde::Serializable<BlackBoxOp::ToRadix>::serialize(*this, serializer);
return std::move(serializer).bytes();
}

inline BlackBoxOp::ToRadix BlackBoxOp::ToRadix::bincodeDeserialize(std::vector<uint8_t> input)
{
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<BlackBoxOp::ToRadix>::deserialize(deserializer);
if (deserializer.get_buffer_offset() < input.size()) {
throw_or_abort("Some input bytes were not read");
}
return value;
}

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::BlackBoxOp::ToRadix>::serialize(const Program::BlackBoxOp::ToRadix& obj,
Serializer& serializer)
{
serde::Serializable<decltype(obj.input)>::serialize(obj.input, serializer);
serde::Serializable<decltype(obj.radix)>::serialize(obj.radix, serializer);
serde::Serializable<decltype(obj.output)>::serialize(obj.output, serializer);
}

template <>
template <typename Deserializer>
Program::BlackBoxOp::ToRadix serde::Deserializable<Program::BlackBoxOp::ToRadix>::deserialize(
Deserializer& deserializer)
{
Program::BlackBoxOp::ToRadix obj;
obj.input = serde::Deserializable<decltype(obj.input)>::deserialize(deserializer);
obj.radix = serde::Deserializable<decltype(obj.radix)>::deserialize(deserializer);
obj.output = serde::Deserializable<decltype(obj.output)>::deserialize(deserializer);
return obj;
}

namespace Program {

inline bool operator==(const BlockId& lhs, const BlockId& rhs)
{
if (!(lhs.value == rhs.value)) {
Expand Down
8 changes: 8 additions & 0 deletions barretenberg/ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const MAX_CIRCUIT_SIZE = 2 ** 19;
const threads = +process.env.HARDWARE_CONCURRENCY! || undefined;

function getBytecode(bytecodePath: string) {
const extension = bytecodePath.substring(bytecodePath.lastIndexOf('.') + 1);

if (extension == 'json') {
const encodedCircuit = JSON.parse(readFileSync(bytecodePath, 'utf8'));
const decompressed = gunzipSync(Buffer.from(encodedCircuit.bytecode, 'base64'));
return decompressed;
}

const encodedCircuit = readFileSync(bytecodePath);
const decompressed = gunzipSync(encodedCircuit);
return decompressed;
Expand Down
15 changes: 14 additions & 1 deletion docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ Aztec is in full-speed development. Literally every version breaks compatibility

The type signature for `SharedMutable` changed from `SharedMutable<T, DELAY>` to `SharedMutable<T, INITIAL_DELAY>`. The behavior is the same as before, except the delay can now be changed after deployment by calling `schedule_delay_change`.

### [Aztec.nr] get_public_key oracle replaced with get_ivpk_m

When implementing changes according to a [new key scheme](https://yp-aztec.netlify.app/docs/addresses-and-keys/keys) we had to change oracles.
What used to be called encryption public key is now master incoming viewing public key.

```diff
- use dep::aztec::oracles::get_public_key::get_public_key;
+ use dep::aztec::keys::getters::get_ivpk_m;

- let encryption_pub_key = get_public_key(self.owner);
+ let ivpk_m = get_ivpk_m(context, self.owner);
```

## 0.38.0

### [Aztec.nr] Emmiting encrypted logs
### [Aztec.nr] Emitting encrypted logs

The `emit_encrypted_log` function is now a context method.

Expand Down
1 change: 0 additions & 1 deletion docs/docs/protocol-specs/transactions/tx-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Output of the last iteration of the private kernel circuit. Includes _accumulate
<!-- prettier-ignore -->
| Field | Type | Description |
|-------|------|-------------|
| aggregationObject | AggregationObject | Aggregated proof of all the previous kernel iterations. |
| newNoteHashes | Field[] | The new note hashes made in this transaction. |
| newNullifiers | Field[] | The new nullifiers made in this transaction. |
| nullifiedNoteHashes | Field[] | The note hashes which are nullified by a nullifier in the above list. |
Expand Down
7 changes: 4 additions & 3 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
protocol_types::{address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key},
context::PrivateContext, hash::poseidon2_hash
};

Expand Down Expand Up @@ -40,13 +41,13 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
// docs:start:encrypted
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
// docs:end:encrypted
Expand Down
Loading

0 comments on commit e885ced

Please sign in to comment.