-
Notifications
You must be signed in to change notification settings - Fork 233
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
feat: Add gate profiler for noir circuits #7004
Changes from 50 commits
f6d65af
14aa792
455dcbb
1b7753e
7a20a94
319c980
64453b8
fc7b22a
5da2664
159605d
1ba3b38
db6db28
0b3d59e
987c683
15f2c2b
e98efed
12b9c17
75885c8
2456442
c6d0e77
3180711
0a18f3a
dba410e
12370a7
a932bb1
073039d
aab0497
553272a
f1f2743
f2eec54
62b41e6
a48d748
86e008e
6f1a07e
7e778b2
ea459c7
1137d53
2c361db
36f9b66
b1a71e1
1f48133
5093fdd
83293cc
ead7db9
66026fd
d3f231c
ba784f5
9cc4691
b387e18
7ae3e34
f26fdfa
ebe4985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,44 @@ | |
|
||
namespace acir_format { | ||
|
||
/** | ||
* @brief Indices of the original opcode that originated each constraint in AcirFormat. | ||
* @details Contains one array of indices per opcode type. The length of each array is equal to the number of | ||
* constraints of that type. The relationship between the opcodes and constraints is assumed to be one to one, except | ||
* for block constraints. | ||
*/ | ||
struct AcirFormatOriginalOpcodeIndices { | ||
std::vector<size_t> logic_constraints; | ||
std::vector<size_t> range_constraints; | ||
std::vector<size_t> aes128_constraints; | ||
std::vector<size_t> sha256_constraints; | ||
std::vector<size_t> sha256_compression; | ||
std::vector<size_t> schnorr_constraints; | ||
std::vector<size_t> ecdsa_k1_constraints; | ||
std::vector<size_t> ecdsa_r1_constraints; | ||
std::vector<size_t> blake2s_constraints; | ||
std::vector<size_t> blake3_constraints; | ||
std::vector<size_t> keccak_constraints; | ||
std::vector<size_t> keccak_permutations; | ||
std::vector<size_t> pedersen_constraints; | ||
std::vector<size_t> pedersen_hash_constraints; | ||
std::vector<size_t> poseidon2_constraints; | ||
std::vector<size_t> multi_scalar_mul_constraints; | ||
std::vector<size_t> ec_add_constraints; | ||
std::vector<size_t> recursion_constraints; | ||
std::vector<size_t> honk_recursion_constraints; | ||
std::vector<size_t> bigint_from_le_bytes_constraints; | ||
std::vector<size_t> bigint_to_le_bytes_constraints; | ||
std::vector<size_t> bigint_operations; | ||
std::vector<size_t> poly_triple_constraints; | ||
std::vector<size_t> quad_constraints; | ||
// Multiple opcode indices per block: | ||
std::vector<std::vector<size_t>> block_constraints; | ||
|
||
friend bool operator==(AcirFormatOriginalOpcodeIndices const& lhs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to be explicit on == ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I didn't do this the parent struct complains about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDK why the parent is explicit though |
||
AcirFormatOriginalOpcodeIndices const& rhs) = default; | ||
}; | ||
|
||
struct AcirFormat { | ||
// The number of witnesses in the circuit | ||
uint32_t varnum; | ||
|
@@ -72,6 +110,13 @@ struct AcirFormat { | |
quad_constraints; | ||
std::vector<BlockConstraint> block_constraints; | ||
|
||
// Number of gates added to the circuit per original opcode. | ||
// Has length equal to num_acir_opcodes. | ||
std::vector<size_t> gates_per_opcode = {}; | ||
sirasistant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Indices of the original opcode that originated each constraint in AcirFormat. | ||
AcirFormatOriginalOpcodeIndices original_opcode_indices; | ||
|
||
// For serialization, update with any new fields | ||
MSGPACK_FIELDS(varnum, | ||
public_inputs, | ||
|
@@ -142,18 +187,21 @@ struct AcirProgramStack { | |
}; | ||
|
||
template <typename Builder = bb::UltraCircuitBuilder> | ||
Builder create_circuit(const AcirFormat& constraint_system, | ||
Builder create_circuit(AcirFormat& constraint_system, | ||
size_t size_hint = 0, | ||
WitnessVector const& witness = {}, | ||
bool honk_recursion = false, | ||
std::shared_ptr<bb::ECCOpQueue> op_queue = std::make_shared<bb::ECCOpQueue>()); | ||
std::shared_ptr<bb::ECCOpQueue> op_queue = std::make_shared<bb::ECCOpQueue>(), | ||
bool collect_gates_per_opcode = false); | ||
|
||
template <typename Builder> | ||
void build_constraints(Builder& builder, | ||
AcirFormat const& constraint_system, | ||
bool has_valid_witness_assignments, | ||
bool honk_recursion = false); // honk_recursion means we will honk to recursively verify this | ||
// circuit. This distinction is needed to not add the default | ||
// aggregation object when we're not using the honk RV. | ||
void build_constraints( | ||
Builder& builder, | ||
AcirFormat& constraint_system, | ||
bool has_valid_witness_assignments, | ||
bool honk_recursion = false, | ||
bool collect_gates_per_opcode = false); // honk_recursion means we will honk to recursively verify this | ||
// circuit. This distinction is needed to not add the default | ||
// aggregation object when we're not using the honk RV. | ||
|
||
} // namespace acir_format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question also for other reviewers: in general I recommend adding
/*param=*/{}
for any literal value or when the param name is not clear. This does wonders for readability (e.g. here, reviewing). However, VS already fills in the name for you.What's the recommendation? (from my side, I think I still prefer adding the comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I typically don't do it for languages that have language servers that provide this info, but as you guys prefer