Skip to content

Commit

Permalink
Use id to identify bigints between Noir and BB
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic committed Jan 22, 2024
1 parent 5aa2cb8 commit 6c4c451
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 68 deletions.
30 changes: 15 additions & 15 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,39 +207,39 @@ struct BlackBoxFuncCall {
};

struct BigIntAdd {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

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

struct BigIntNeg {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

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

struct BigIntMul {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

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

struct BigIntDiv {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

friend bool operator==(const BigIntDiv&, const BigIntDiv&);
std::vector<uint8_t> bincodeSerialize() const;
Expand All @@ -248,16 +248,16 @@ struct BlackBoxFuncCall {

struct BigIntFromLeBytes {
std::vector<Circuit::FunctionInput> inputs;
std::vector<Circuit::FunctionInput> modulus;
Circuit::Witness output;
std::vector<uint8_t> modulus;
uint32_t output;

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

struct BigIntToLeBytes {
Circuit::FunctionInput input;
uint32_t input;
std::vector<Circuit::Witness> outputs;

friend bool operator==(const BigIntToLeBytes&, const BigIntToLeBytes&);
Expand Down
30 changes: 15 additions & 15 deletions noir/acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,39 +207,39 @@ namespace Circuit {
};

struct BigIntAdd {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

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

struct BigIntNeg {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

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

struct BigIntMul {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

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

struct BigIntDiv {
Circuit::FunctionInput lhs;
Circuit::FunctionInput rhs;
Circuit::Witness output;
uint32_t lhs;
uint32_t rhs;
uint32_t output;

friend bool operator==(const BigIntDiv&, const BigIntDiv&);
std::vector<uint8_t> bincodeSerialize() const;
Expand All @@ -248,16 +248,16 @@ namespace Circuit {

struct BigIntFromLeBytes {
std::vector<Circuit::FunctionInput> inputs;
std::vector<Circuit::FunctionInput> modulus;
Circuit::Witness output;
std::vector<uint8_t> modulus;
uint32_t output;

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

struct BigIntToLeBytes {
Circuit::FunctionInput input;
uint32_t input;
std::vector<Circuit::Witness> outputs;

friend bool operator==(const BigIntToLeBytes&, const BigIntToLeBytes&);
Expand Down
58 changes: 29 additions & 29 deletions noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,32 @@ pub enum BlackBoxFuncCall {
key_hash: FunctionInput,
},
BigIntAdd {
lhs: FunctionInput,
rhs: FunctionInput,
output: Witness,
lhs: u32,
rhs: u32,
output: u32,
},
BigIntNeg {
lhs: FunctionInput,
rhs: FunctionInput,
output: Witness,
lhs: u32,
rhs: u32,
output: u32,
},
BigIntMul {
lhs: FunctionInput,
rhs: FunctionInput,
output: Witness,
lhs: u32,
rhs: u32,
output: u32,
},
BigIntDiv {
lhs: FunctionInput,
rhs: FunctionInput,
output: Witness,
lhs: u32,
rhs: u32,
output: u32,
},
BigIntFromLeBytes {
inputs: Vec<FunctionInput>,
modulus: Vec<FunctionInput>,
output: Witness,
modulus: Vec<u8>,
output: u32,
},
BigIntToLeBytes {
input: FunctionInput,
input: u32,
outputs: Vec<Witness>,
},
}
Expand Down Expand Up @@ -195,15 +195,14 @@ impl BlackBoxFuncCall {
| BlackBoxFuncCall::PedersenCommitment { inputs, .. }
| BlackBoxFuncCall::PedersenHash { inputs, .. }
| BlackBoxFuncCall::BigIntFromLeBytes { inputs, .. } => inputs.to_vec(),
BlackBoxFuncCall::BigIntToLeBytes { input, .. } => vec![*input],
BlackBoxFuncCall::AND { lhs, rhs, .. }
| BlackBoxFuncCall::XOR { lhs, rhs, .. }
| BlackBoxFuncCall::BigIntAdd { lhs, rhs, .. }
| BlackBoxFuncCall::BigIntNeg { lhs, rhs, .. }
| BlackBoxFuncCall::BigIntMul { lhs, rhs, .. }
| BlackBoxFuncCall::BigIntDiv { lhs, rhs, .. } => {
BlackBoxFuncCall::AND { lhs, rhs, .. } | BlackBoxFuncCall::XOR { lhs, rhs, .. } => {
vec![*lhs, *rhs]
}
BlackBoxFuncCall::BigIntAdd { .. }
| BlackBoxFuncCall::BigIntNeg { .. }
| BlackBoxFuncCall::BigIntMul { .. }
| BlackBoxFuncCall::BigIntDiv { .. }
| BlackBoxFuncCall::BigIntToLeBytes { .. } => Vec::new(),
BlackBoxFuncCall::FixedBaseScalarMul { low, high, .. } => vec![*low, *high],
BlackBoxFuncCall::EmbeddedCurveAdd {
input1_x, input1_y, input2_x, input2_y, ..
Expand Down Expand Up @@ -298,17 +297,18 @@ impl BlackBoxFuncCall {
| BlackBoxFuncCall::SchnorrVerify { output, .. }
| BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
| BlackBoxFuncCall::PedersenHash { output, .. }
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. }
| BlackBoxFuncCall::BigIntAdd { output, .. }
| BlackBoxFuncCall::BigIntNeg { output, .. }
| BlackBoxFuncCall::BigIntMul { output, .. }
| BlackBoxFuncCall::BigIntDiv { output, .. }
| BlackBoxFuncCall::BigIntFromLeBytes { output, .. } => vec![*output],
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
BlackBoxFuncCall::FixedBaseScalarMul { outputs, .. }
| BlackBoxFuncCall::PedersenCommitment { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveDouble { outputs, .. } => vec![outputs.0, outputs.1],
BlackBoxFuncCall::RANGE { .. } | BlackBoxFuncCall::RecursiveAggregation { .. } => {
BlackBoxFuncCall::RANGE { .. }
| BlackBoxFuncCall::RecursiveAggregation { .. }
| BlackBoxFuncCall::BigIntFromLeBytes { .. }
| BlackBoxFuncCall::BigIntAdd { .. }
| BlackBoxFuncCall::BigIntNeg { .. }
| BlackBoxFuncCall::BigIntMul { .. }
| BlackBoxFuncCall::BigIntDiv { .. } => {
vec![]
}
BlackBoxFuncCall::BigIntToLeBytes { outputs, .. } => outputs.to_vec(),
Expand Down
16 changes: 7 additions & 9 deletions noir/acvm-repo/acvm/src/compiler/transformers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,16 @@ pub(super) fn transform_internal(
Opcode::BlackBoxFuncCall(ref func) => {
match func {
acir::circuit::opcodes::BlackBoxFuncCall::AND { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::XOR { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntAdd { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntNeg { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntMul { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntDiv { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntFromLeBytes {
output, ..
} => {
| acir::circuit::opcodes::BlackBoxFuncCall::XOR { output, .. } => {
transformer.mark_solvable(*output);
}
acir::circuit::opcodes::BlackBoxFuncCall::RANGE { .. }
| acir::circuit::opcodes::BlackBoxFuncCall::RecursiveAggregation { .. } => (),
| acir::circuit::opcodes::BlackBoxFuncCall::RecursiveAggregation { .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntFromLeBytes { .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntAdd { .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntNeg { .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntMul { .. }
| acir::circuit::opcodes::BlackBoxFuncCall::BigIntDiv { .. } => (),
acir::circuit::opcodes::BlackBoxFuncCall::SHA256 { outputs, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::Keccak256 { outputs, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::Keccak256VariableLength {
Expand Down

0 comments on commit 6c4c451

Please sign in to comment.