Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Apr 12, 2023
1 parent 9b1d132 commit 5e03688
Show file tree
Hide file tree
Showing 52 changed files with 1,670 additions and 1,688 deletions.
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/acir_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "merkle_membership_constraint.hpp"
#include "pedersen.hpp"
#include "hash_to_field.hpp"
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <cstdint>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <cstdint>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/pedersen.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "acir_proofs.hpp"
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"
#include "barretenberg/srs/reference_string/pippenger_reference_string.hpp"
#include "barretenberg/plonk/proof_system/verification_key/sol_gen.hpp"

Expand Down
83 changes: 83 additions & 0 deletions cpp/src/barretenberg/dsl/types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#pragma once
#include "barretenberg/plonk/composer/splitting_tmp/ultra_plonk_composer.hpp"
#include "barretenberg/plonk/proof_system/constants.hpp"
#include "barretenberg/plonk/composer/standard_composer.hpp"
#include "barretenberg/plonk/composer/turbo_composer.hpp"
#include "barretenberg/plonk/composer/ultra_composer.hpp"
#include "barretenberg/plonk/proof_system/prover/prover.hpp"
#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp"
#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp"
#include "barretenberg/stdlib/primitives/bit_array/bit_array.hpp"
#include "barretenberg/stdlib/primitives/bool/bool.hpp"
#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp"
#include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp"
#include "barretenberg/stdlib/primitives/uint/uint.hpp"
#include "barretenberg/stdlib/primitives/witness/witness.hpp"
#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp"
#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp"
#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp"
#include "barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp"
#include "barretenberg/stdlib/merkle_tree/hash_path.hpp"
#include "barretenberg/stdlib/encryption/schnorr/schnorr.hpp"
#include "barretenberg/stdlib/primitives/curves/bn254.hpp"
#include "barretenberg/stdlib/primitives/curves/secp256k1.hpp"
#include "barretenberg/stdlib/primitives/memory/rom_table.hpp"
#include "barretenberg/stdlib/recursion/verifier/program_settings.hpp"
#include "barretenberg/stdlib/primitives/memory/ram_table.hpp"
#include "barretenberg/stdlib/primitives/memory/rom_table.hpp"
#include "barretenberg/stdlib/primitives/memory/dynamic_array.hpp"

namespace acir_format {

using NoirComposer = plonk::UltraComposer;

using Prover = std::conditional_t<
std::same_as<NoirComposer, plonk::UltraComposer>,
plonk::UltraWithKeccakProver,
std::conditional_t<std::same_as<NoirComposer, plonk::TurboComposer>, plonk::TurboProver, plonk::Prover>>;

using Verifier = std::conditional_t<
std::same_as<NoirComposer, plonk::UltraComposer>,
plonk::UltraWithKeccakVerifier,
std::conditional_t<std::same_as<NoirComposer, plonk::TurboComposer>, plonk::TurboVerifier, plonk::Verifier>>;

using witness_ct = proof_system::plonk::stdlib::witness_t<NoirComposer>;
using public_witness_ct = proof_system::plonk::stdlib::public_witness_t<NoirComposer>;
using bool_ct = proof_system::plonk::stdlib::bool_t<NoirComposer>;
using byte_array_ct = proof_system::plonk::stdlib::byte_array<NoirComposer>;
using packed_byte_array_ct = proof_system::plonk::stdlib::packed_byte_array<NoirComposer>;
using field_ct = proof_system::plonk::stdlib::field_t<NoirComposer>;
using suint_ct = proof_system::plonk::stdlib::safe_uint_t<NoirComposer>;
using uint8_ct = proof_system::plonk::stdlib::uint8<NoirComposer>;
using uint16_ct = proof_system::plonk::stdlib::uint16<NoirComposer>;
using uint32_ct = proof_system::plonk::stdlib::uint32<NoirComposer>;
using uint64_ct = proof_system::plonk::stdlib::uint64<NoirComposer>;
using bit_array_ct = proof_system::plonk::stdlib::bit_array<NoirComposer>;
using fq_ct = proof_system::plonk::stdlib::bigfield<NoirComposer, barretenberg::Bn254FqParams>;
using biggroup_ct = proof_system::plonk::stdlib::element<NoirComposer, fq_ct, field_ct, barretenberg::g1>;
using point_ct = proof_system::plonk::stdlib::point<NoirComposer>;
using pedersen_commitment = proof_system::plonk::stdlib::pedersen_commitment<NoirComposer>;
using group_ct = proof_system::plonk::stdlib::group<NoirComposer>;
using bn254 = proof_system::plonk::stdlib::bn254<NoirComposer>;
using secp256k1_ct = proof_system::plonk::stdlib::secp256k1<NoirComposer>;

namespace merkle_tree {
using namespace proof_system::plonk::stdlib::merkle_tree;
using hash_path = proof_system::plonk::stdlib::merkle_tree::hash_path<NoirComposer>;
} // namespace merkle_tree

namespace schnorr {
using signature_bits = proof_system::plonk::stdlib::schnorr::signature_bits<NoirComposer>;
} // namespace schnorr

// Ultra-composer specific typesv
using rom_table_ct = proof_system::plonk::stdlib::rom_table<plonk::UltraComposer>;

// NOTE: In ultra setting, recursive verifier settings are incompatible with the settings used by Noir.
// TODO: remove?
using recursive_inner_verifier_settings =
std::conditional_t<std::same_as<NoirComposer, plonk::UltraComposer>,
proof_system::plonk::stdlib::recursion::recursive_ultra_verifier_settings<bn254>,
proof_system::plonk::stdlib::recursion::recursive_turbo_verifier_settings<bn254>>;

} // namespace acir_format
1 change: 0 additions & 1 deletion cpp/src/barretenberg/honk/proof_system/verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <cstddef>
#include <memory>
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/plonk/proof_system/constants.hpp"
#include "./verifier.hpp"
#include "barretenberg/plonk/proof_system/public_inputs/public_inputs.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
Expand Down
1 change: 0 additions & 1 deletion cpp/src/barretenberg/honk/proof_system/verifier.test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "barretenberg/numeric/bitop/get_msb.hpp"
#include "barretenberg/plonk/proof_system/constants.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/honk/flavor/flavor.hpp"
#include "prover.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#pragma once
#include "join_split_tx.hpp"
#include "barretenberg/srs/reference_string/mem_reference_string.hpp"
#include "barretenberg/stdlib/types/types.hpp"

namespace join_split_example {
namespace proofs {
namespace join_split {

using namespace proof_system::plonk::stdlib::merkle_tree;
using namespace proof_system::plonk::stdlib::types;

void init_proving_key(std::shared_ptr<proof_system::ReferenceStringFactory> const& crs_factory, bool mock);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "../notes/circuit/value/value_note.hpp"
#include "../notes/circuit/account/account_note.hpp"
#include "../notes/circuit/claim/claim_note.hpp"
#include "barretenberg/stdlib/primitives/bool/bool.hpp"
#include "barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp"
#include "verify_signature.hpp"
#include "barretenberg/stdlib/merkle_tree/membership.hpp"

Expand All @@ -20,14 +22,16 @@ using namespace proof_system::plonk::stdlib::merkle_tree;
* The note does not need to exist in the tree if it's not real, or if it's consumed (i.e. propagated = input).
* Return the nullifier for the input note. If the input note is consumed, the nullifier becomes 0.
*/
field_ct process_input_note(field_ct const& account_private_key,
field_ct const& merkle_root,
merkle_tree::hash_path const& hash_path,
suint_ct const& index,
value::value_note const& note,
bool_ct is_propagated,
bool_ct is_note_in_use)
template <typename Comopser>
stdlib::field_t<Composer> process_input_note(stdlib::field_t<Composer> const& account_private_key,
stdlib::field_t<Composer> const& merkle_root,
stdlib::merkle_tree::hash_path<Composer> const& hash_path,
stdlib::safe_uint_t<Composer> const& index,
value::value_note const& note,
stdlib::bool_t<Composer> is_propagated,
stdlib::bool_t<Composer> is_note_in_use)
{
using bool_ct = stdlib::bool_t<Comopser>;
const bool_ct valid_value = note.value == 0 || is_note_in_use;
valid_value.assert_equal(true, "padding note non zero");

Expand All @@ -39,8 +43,14 @@ field_ct process_input_note(field_ct const& account_private_key,
return compute_nullifier(note.commitment, account_private_key, is_note_in_use);
}

join_split_outputs join_split_circuit_component(join_split_inputs const& inputs)
template <typename Composer>
join_split_outputs<Composer> join_split_circuit_component(join_split_inputs<Composer> const& inputs)
{
using field_ct = stdlib::field_t<Composer>;
using bool_ct = stdlib::bool_t<Composer>;
using point_ct = stdlib::point<Composer>;
using suint_ct = stdlib::safe_uint_t<Composer>;

const bool_ct is_deposit = inputs.proof_id == field_ct(ProofIds::DEPOSIT);
const bool_ct is_withdraw = inputs.proof_id == field_ct(ProofIds::WITHDRAW);
const bool_ct is_send = inputs.proof_id == field_ct(ProofIds::SEND);
Expand Down Expand Up @@ -269,6 +279,12 @@ join_split_outputs join_split_circuit_component(join_split_inputs const& inputs)

void join_split_circuit(Composer& composer, join_split_tx const& tx)
{
using field_ct = stdlib::field_t<Composer>;
using bool_ct = stdlib::bool_t<Composer>;
using point_ct = stdlib::point<Composer>;
using suint_ct = stdlib::safe_uint_t<Composer>;
using witness_ct = stdlib::witness_t<Composer>;

join_split_inputs inputs = {
.proof_id = witness_ct(&composer, tx.proof_id),
.public_value = suint_ct(witness_ct(&composer, tx.public_value), NOTE_VALUE_BIT_LENGTH, "public_value"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#pragma once
#include "barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp"
#include "join_split_tx.hpp"
#include "../notes/circuit/value/witness_data.hpp"
#include "../notes/circuit/claim/witness_data.hpp"
#include "barretenberg/crypto/schnorr/schnorr.hpp"
#include "barretenberg/stdlib/types/types.hpp"

namespace join_split_example {
namespace proofs {
namespace join_split {

using namespace proof_system::plonk::stdlib::types;
template <typename Composer> struct join_split_inputs {
using field_ct = field_t<Composer>;
using suint_ct = stdlib::safe_uint_t<Composer>;

struct join_split_inputs {
field_ct proof_id;
suint_ct public_value;
field_ct public_owner;
Expand All @@ -33,12 +34,13 @@ struct join_split_inputs {
merkle_tree::hash_path account_note_path;
field_ct account_private_key;
suint_ct alias_hash;
bool_ct account_required;
bool_t<Composer> account_required;
field_ct backward_link;
field_ct allow_chain;
};

struct join_split_outputs {
template <typename Composer> struct join_split_outputs {
using field_ct = field_t<Composer>;
field_ct nullifier1;
field_ct nullifier2;
field_ct output_note1;
Expand All @@ -49,9 +51,10 @@ struct join_split_outputs {
field_ct defi_deposit_value;
};

join_split_outputs join_split_circuit_component(join_split_inputs const& inputs);
template <typename Composer>
join_split_outputs<Composer> join_split_circuit_component(join_split_inputs<Composer> const& inputs);

void join_split_circuit(Composer& composer, join_split_tx const& tx);
template <typename Composer> void join_split_circuit(Composer& composer, join_split_tx const& tx);

} // namespace join_split
} // namespace proofs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#include "../notes/native/value/value_note.hpp"
#include "barretenberg/crypto/schnorr/schnorr.hpp"
#include "barretenberg/stdlib/merkle_tree/hash_path.hpp"
#include "barretenberg/stdlib/types/types.hpp"

namespace join_split_example {
namespace proofs {
namespace join_split {

using namespace proof_system::plonk::stdlib::types;

struct join_split_tx {
uint32_t proof_id;
uint256_t public_value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "mock_circuit.hpp"
#include "../join_split/join_split_tx.hpp"
#include "barretenberg/common/test.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace proof_system::plonk::stdlib::types;
using namespace proof_system::plonk::stdlib;

namespace rollup {
namespace proofs {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "barretenberg/stdlib/types/types.hpp"
#include "commit.hpp"

namespace join_split_example {
Expand All @@ -8,8 +7,6 @@ namespace notes {
namespace circuit {
namespace account {

using namespace proof_system::plonk::stdlib::types;

struct account_note {
field_ct account_alias_hash;
point_ct account_public_key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#pragma once
#include "barretenberg/stdlib/types/types.hpp"
#include "../../constants.hpp"
#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp"
#include "barretenberg/stdlib/primitives/point/point.hpp"
#include "barretenberg/join_split_example/proofs/notes/constants.hpp"

namespace join_split_example {
namespace proofs {
namespace notes {
namespace circuit {
namespace account {

using namespace proof_system::plonk::stdlib::types;
using namespace proof_system::plonk::stdlib;

inline auto commit(field_ct const& account_alias_hash,
point_ct const& account_public_key,
point_ct const& signing_pub_key)
template <typename Composer>
inline auto commit(field_t<Composer> const& account_alias_hash,
point<Composer> const& account_public_key,
point<Composer> const& signing_pub_key)
{
return pedersen_commitment::compress(
return pedersen_commitment<Composer>::compress(
{
account_alias_hash,
account_public_key.x,
signing_pub_key.x,
},
GeneratorIndex::ACCOUNT_NOTE_COMMITMENT);
join_split_example::proofs::notes::GeneratorIndex::ACCOUNT_NOTE_COMMITMENT);
}

} // namespace account
Expand Down
Loading

0 comments on commit 5e03688

Please sign in to comment.