Skip to content

Commit

Permalink
feat: Optimize auxiliary relations slightly (#5517)
Browse files Browse the repository at this point in the history
We had (-1) * Univariate in some places in auxiliary relation.
Multiplication is much heavier than negation, so I replaced those
instances. It shaved off a second (~1%) off wasm benchmarks.
WASM benchmark:

![image](https://github.com/AztecProtocol/aztec-packages/assets/4798775/acecd275-8962-43fb-a737-91abb8b931ca)
  • Loading branch information
Rumata888 authored Apr 2, 2024
1 parent e1d7d11 commit 30be431
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ template <typename FF_> class AuxiliaryRelationImpl {

auto index_is_monotonically_increasing = index_delta * index_delta - index_delta; // deg 2

auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta; // deg 2
auto adjacent_values_match_if_adjacent_indices_match = (-index_delta + FF(1)) * record_delta; // deg 2

std::get<1>(accumulators) +=
adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2) * (q_aux * scaling_factor); // deg 5
Expand Down Expand Up @@ -286,7 +286,7 @@ template <typename FF_> class AuxiliaryRelationImpl {

auto value_delta = w_3_shift - w_3;
auto adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation =
(index_delta * FF(-1) + FF(1)) * value_delta * (next_gate_access_type * FF(-1) + FF(1)); // deg 3 or 4
(-index_delta + FF(1)) * value_delta * (-next_gate_access_type + FF(1)); // deg 3 or 4

// We can't apply the RAM consistency check identity on the final entry in the sorted list (the wires in the
// next gate would make the identity fail). We need to validate that its 'access type' bool is correct. Can't
Expand Down Expand Up @@ -316,7 +316,7 @@ template <typename FF_> class AuxiliaryRelationImpl {
* Else timestamp_check = 0
*/
auto timestamp_delta = w_2_shift - w_2;
auto RAM_timestamp_check_identity = (index_delta * FF(-1) + FF(1)) * timestamp_delta - w_3; // deg 3
auto RAM_timestamp_check_identity = (-index_delta + FF(1)) * timestamp_delta - w_3; // deg 3

/**
* The complete RAM/ROM memory identity
Expand Down

0 comments on commit 30be431

Please sign in to comment.