Skip to content

refactor(Barretenberg): Static Analysis of Goblin Recursive Verifier#14610

Merged
DanielKotov merged 25 commits into
nextfrom
dk/goblin_recursive_verifier_PR
Jun 24, 2025
Merged

refactor(Barretenberg): Static Analysis of Goblin Recursive Verifier#14610
DanielKotov merged 25 commits into
nextfrom
dk/goblin_recursive_verifier_PR

Conversation

@DanielKotov

Copy link
Copy Markdown
Contributor

This time Recursive Verifier was tested by static analysis tool.

There was found bug with using of insecure function "pow" that was removed. Also there was the bug in function compute_barycentric_evaluations, that appeared because of vector wasn't initialized correctly by default constructor.

Finally, there were many cases with unused variables in the circuit and they can be described this way: variable is often a result of sequential multiplications on some challenge, but there's no need to do the last multiplication, because we add new variables in the gate that won't be used in the circuit.

And there was a try to improve static analyzer performance again, maybe it became faster by some seconds, result weren't stable to get visible data.

fixed_variables.insert(this->to_real(ultra_circuit_builder, left_idx));
} else if (!q_m.is_zero() || q_1 != FF::one() || !q_2.is_zero() || !q_3.is_zero() || !q_4.is_zero()) {
// this is not the gate for fix_witness, so we have to process this gate
// gate_variables.reserve(8);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line please

*/
template <typename FF>
inline void Graph_<FF>::process_gate_variables(UltraCircuitBuilder& ultra_circuit_builder,
inline void Graph_<FF>::process_gate_variables([[maybe_unused]] UltraCircuitBuilder& ultra_circuit_builder,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this then?

* 4) Special handling for sorted constraints in delta range blocks
*/
template <typename FF> Graph_<FF>::Graph_(bb::UltraCircuitBuilder& ultra_circuit_constructor)
template <typename FF> Graph_<FF>::Graph_(bb::UltraCircuitBuilder& ultra_circuit_constructor, bool graph)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the "graph" variable mean? I think there should be a better name

// Compute the evaluation of the vanishing polynomia Z_H(X) at X =
// gemini_evaluation_challenge
const FF vanishing_poly_eval = gemini_evaluation_challenge.pow(SUBGROUP_SIZE) - FF(1);
auto compute_vanishing_poly_eval = [&]() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inefficient, please use field's implementation of pow. If it's broken, then we need to fix it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, at least use square and multiply

@DanielKotov DanielKotov force-pushed the dk/goblin_recursive_verifier_PR branch from f226dbb to b54e8be Compare June 2, 2025 15:37
@DanielKotov DanielKotov force-pushed the dk/goblin_recursive_verifier_PR branch 3 times, most recently from e96f36c to d4dee54 Compare June 11, 2025 16:01
commitments.emplace_back(claim.commitment);
batched_eval += alpha_pow * claim.opening_pair.evaluation;
alpha_pow *= alpha;
if (idx < opening_claims.size() - 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

}
}
if (shifted_exponent != 0) {
if (shifted_exponent >= 2) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suyash67 here's an example of a bug that Daniel's tool finds automatically

CommitmentLabels commitment_labels;

const BF accumulated_result = transcript->template receive_from_prover<BF>("accumulated_result");
if constexpr (IsUltraBuilder<Builder>) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de-instantiate Translator with MegaCircuitBuilder pls, it's not needed, then you'd avoid this constexpr

  • add a comment explaining what's going on

github-merge-queue Bot pushed a commit that referenced this pull request Jun 17, 2025
Made sure that the current impl of `field_t` `pow()` matches the audited
(and
[deprecated](#14563))
implementation of `bigfield` `pow()`.

The `pow` method taking const integers as an argument is taken from
#14610
@DanielKotov DanielKotov force-pushed the dk/goblin_recursive_verifier_PR branch 2 times, most recently from 142a763 to 8ab1127 Compare June 17, 2025 12:18
@DanielKotov DanielKotov force-pushed the dk/goblin_recursive_verifier_PR branch from b6de4d3 to f21205c Compare June 18, 2025 10:16

@iakovenkos iakovenkos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@DanielKotov DanielKotov added this pull request to the merge queue Jun 18, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 18, 2025
@DanielKotov DanielKotov force-pushed the dk/goblin_recursive_verifier_PR branch 2 times, most recently from 69a8266 to 621c979 Compare June 19, 2025 10:34
@DanielKotov DanielKotov force-pushed the dk/goblin_recursive_verifier_PR branch from 1e71761 to ae610e6 Compare June 19, 2025 14:40
@DanielKotov DanielKotov force-pushed the dk/goblin_recursive_verifier_PR branch from 5339cf9 to f72f11b Compare June 24, 2025 12:11
@DanielKotov DanielKotov added this pull request to the merge queue Jun 24, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 24, 2025
@DanielKotov DanielKotov added this pull request to the merge queue Jun 24, 2025
@DanielKotov DanielKotov removed this pull request from the merge queue due to a manual request Jun 24, 2025
@DanielKotov DanielKotov added this pull request to the merge queue Jun 24, 2025
Merged via the queue into next with commit 282da3b Jun 24, 2025
4 checks passed
@DanielKotov DanielKotov deleted the dk/goblin_recursive_verifier_PR branch June 24, 2025 14:40
danielntmd pushed a commit to danielntmd/aztec-packages that referenced this pull request Jul 16, 2025
Made sure that the current impl of `field_t` `pow()` matches the audited
(and
[deprecated](AztecProtocol#14563))
implementation of `bigfield` `pow()`.

The `pow` method taking const integers as an argument is taken from
AztecProtocol#14610
danielntmd pushed a commit to danielntmd/aztec-packages that referenced this pull request Jul 16, 2025
…ztecProtocol#14610)

This time Recursive Verifier was tested by static analysis tool.

There was found bug with using of insecure function "pow" that was
removed. Also there was the bug in function
compute_barycentric_evaluations, that appeared because of vector wasn't
initialized correctly by default constructor.

Finally, there were many cases with unused variables in the circuit and
they can be described this way: variable is often a result of sequential
multiplications on some challenge, but there's no need to do the last
multiplication, because we add new variables in the gate that won't be
used in the circuit.

And there was a try to improve static analyzer performance again, maybe
it became faster by some seconds, result weren't stable to get visible
data.

---------

Co-authored-by: iakovenkos <sergey.s.yakovenko@gmail.com>
AztecBot pushed a commit to AztecProtocol/barretenberg that referenced this pull request Dec 3, 2025
Made sure that the current impl of `field_t` `pow()` matches the audited
(and
[deprecated](AztecProtocol/aztec-packages#14563))
implementation of `bigfield` `pow()`.

The `pow` method taking const integers as an argument is taken from
AztecProtocol/aztec-packages#14610
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants