Skip to content

feat(avm): ToRadix gadget#12528

Merged
sirasistant merged 23 commits intomasterfrom
arv/to_radix_gadget
Mar 10, 2025
Merged

feat(avm): ToRadix gadget#12528
sirasistant merged 23 commits intomasterfrom
arv/to_radix_gadget

Conversation

@sirasistant
Copy link
Contributor

@sirasistant sirasistant commented Mar 6, 2025

Implements a gadget to decompose fields in LE radixes, and integrates this gadget into scalar mul.
The tricky part about the gadget is avoiding overflows in the last non padding limb. In order to avoid that we have precomputed the 255 possible decompositions of P (radix goes from 2 to 256 inclusive) and we compare that the accumulator must be under P if we reach the unsafe limb.


+-------+-------+------+--------+------------+------+-------------+----------+------------------+-------+------------+-----------+-------+-----+-----+---------+
| value | radix | limb | p_limb | limb_index | acc  | acc_under_p | exponent | not_padding_limb | found | safe_limbs | is_unsafe | start | end | sel | not_end |
+-------+-------+------+--------+------------+------+-------------+----------+------------------+-------+------------+-----------+-------+-----+-----+---------+
|     0 |     0 |    0 |      0 |          0 |    0 |           0 | 0        |                0 |     0 |          0 |         0 |     0 |   0 |   0 |       0 |
|  1337 |    10 |    7 |      7 |          0 |    7 |           0 | 1        |                1 |     0 |         76 |         0 |     1 |   0 |   1 |       1 |
|  1337 |    10 |    3 |      1 |          1 |   37 |           0 | 10       |                1 |     0 |         76 |         0 |     0 |   0 |   1 |       1 |
|  1337 |    10 |    3 |      6 |          2 |  337 |           1 | 100      |                1 |     0 |         76 |         0 |     0 |   0 |   1 |       1 |
|  1337 |    10 |    1 |      5 |          3 | 1337 |           1 | 1000     |                1 |     1 |         76 |         0 |     0 |   0 |   1 |       1 |
|  1337 |    10 |    0 |      9 |          4 | 1337 |           1 | 10000    |                1 |     1 |         76 |         0 |     0 |   0 |   1 |       1 |
|  1337 |    10 |    0 |      2 |         76 | 1337 |           1 | 10**76   |                1 |     1 |         76 |         1 |     0 |   0 |   1 |       1 |
|  1337 |    10 |    0 |      0 |         77 | 1337 |           0 | 0        |                0 |     1 |         76 |         0 |     0 |   1 |   1 |       0 |
|     0 |     0 |    0 |      0 |          0 |    0 |           0 | 0        |                0 |     0 |          0 |         0 |     0 |   0 |   0 |       0 |
+-------+-------+------+--------+------------+------+-------------+----------+------------------+-------+------------+-----------+-------+-----+-----+---------+


Bench


Running bin/relations_acc_bench
Run on (192 X 3599.39 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x96)
  L1 Instruction 32 KiB (x96)
  L2 Unified 512 KiB (x96)
  L3 Unified 32768 KiB (x12)
Load Average: 18.30, 23.96, 21.02
-------------------------------------------------------------------------------
Benchmark                                     Time             CPU   Iterations
-------------------------------------------------------------------------------
alu_acc                                   0.139 us        0.139 us      5053009
bc_decomposition_acc                       13.4 us         13.4 us        51950
bc_decomposition_interactions_acc          1.24 us         1.24 us       563554
bc_hashing_acc                            0.848 us        0.848 us       831879
bc_hashing_interactions_acc                1.54 us         1.54 us       456115
bc_retrieval_acc                          0.024 us        0.024 us     21634002
bc_retrieval_interactions_acc             0.936 us        0.935 us       765095
bitwise_acc                                1.54 us         1.54 us       446026
bitwise_interactions_acc                  0.930 us        0.930 us       760097
class_id_derivation_acc                   0.176 us        0.176 us      3988480
class_id_derivation_interactions_acc       1.04 us         1.04 us       678844
ecc_acc                                    2.60 us         2.60 us       268246
execution_acc                             0.522 us        0.522 us      1341997
instr_fetching_acc                         7.15 us         7.15 us        97965
instr_fetching_interactions_acc            3.94 us         3.94 us       177737
poseidon2_hash_acc                         2.04 us         2.04 us       346984
poseidon2_hash_interactions_acc           0.744 us        0.744 us       938393
poseidon2_perm_acc                         46.3 us         46.3 us        15488
range_check_acc                            2.69 us         2.69 us       249636
range_check_interactions_acc               3.58 us         3.58 us       197211
scalar_mul_acc                             2.15 us         2.15 us       325391
scalar_mul_interactions_acc                2.12 us         2.12 us       331354
sha256_acc                                 6.36 us         6.36 us       112293
sha256_interactions_acc                   0.406 us        0.406 us      1736291
to_radix_acc                               3.57 us         3.56 us       195897
to_radix_interactions_acc                  1.90 us         1.90 us       369766

@sirasistant sirasistant changed the title feat(avm): ToRadix gadget feat(avm): ToRadix gadget (WIP) Mar 6, 2025
@sirasistant sirasistant changed the title feat(avm): ToRadix gadget (WIP) feat(avm): ToRadix gadget Mar 6, 2025
@sirasistant sirasistant marked this pull request as ready for review March 7, 2025 09:29
Copy link
Contributor

@fcarreiro fcarreiro left a comment

Choose a reason for hiding this comment

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

I'll do a deeper review on Monday but I guess @IlyasRidhuan will check the PIL.

Could you run the benchmarks and add it to the description?

Copy link
Contributor

@IlyasRidhuan IlyasRidhuan left a comment

Choose a reason for hiding this comment

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

PIL LGTM, just one comment but that doesnt change functionality.

Comment on lines +44 to +46
std::transform(limbs.begin(), limbs.end(), bits.begin(), [](uint8_t val) {
return val != 0; // Convert nonzero values to `true`, zero to `false`
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is fine for now but in reality, this conversion will have to probably be either done and/or constrained by the caller. (someone has to constrain it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pil ensures that limb will be less than radix, so to radix pil constrains that for radix = 2, limb is boolean. A different topic is memory tagging to u1, that needs to be done by the opcode, but it's not gadget business hehehe

@sirasistant sirasistant force-pushed the arv/to_radix_gadget branch from 29a38f8 to 9a394e1 Compare March 10, 2025 15:47
@sirasistant sirasistant merged commit 02a7171 into master Mar 10, 2025
6 checks passed
@sirasistant sirasistant deleted the arv/to_radix_gadget branch March 10, 2025 17:09
sklppy88 pushed a commit that referenced this pull request Mar 11, 2025
🤖 I have created a new Aztec Packages release
---


##
[0.79.0](v0.78.1...v0.79.0)
(2025-03-11)


### ⚠ BREAKING CHANGES

* aggregate data for batch calls
([#12562](#12562))

### Features

* add extra attributes to target_info
([#12583](#12583))
([c296422](c296422))
* add optional oracle resolver url in `acvm_cli`
(noir-lang/noir#7630)
([cc6cdbb](cc6cdbb))
* allow to pay via sponsored fpc from cli
([#12598](#12598))
([877de5c](877de5c))
* array concat method (noir-lang/noir#7199)
([cc6cdbb](cc6cdbb))
* **avm:** ToRadix gadget
([#12528](#12528))
([02a7171](02a7171))
* aztec-up -v flag
([#12590](#12590))
([6a41565](6a41565))
* **bb:** consider polynomial end_index when constructing partially
evaluated multivariates
([#12530](#12530))
([abd22cd](abd22cd))
* **config:** add fallbacks
([#12593](#12593))
([f2f9ef3](f2f9ef3))
* **p2p:** add trusted peers mechanics
([#12447](#12447))
([d67f7e8](d67f7e8))
* **p2p:** peer manager peer count metrics
([#12575](#12575))
([b4891c1](b4891c1))
* provision alerts
([#12561](#12561))
([2ea1767](2ea1767))
* Resolve callstacks in protocol circuit errors on wasm
([#12573](#12573))
([657299b](657299b))


### Bug Fixes

* aggregate data for batch calls
([#12562](#12562))
([bd0b3b6](bd0b3b6))
* broken kind transfer test
([#12611](#12611))
([6e91934](6e91934))
* Cl/release fixes 2
([#12595](#12595))
([fc597f4](fc597f4))
* Cl/release noir refs
([#12597](#12597))
([fdcfcaf](fdcfcaf))
* demote log
([#12626](#12626))
([bec8953](bec8953))
* deploy method test
([#12609](#12609))
([f2c06c2](f2c06c2))
* Do not report epoch as complete until blocks have synced
([#12638](#12638))
([2ddfa76](2ddfa76)),
closes
[#12625](#12625)
* Error on infinitely recursive types
(noir-lang/noir#7579)
([cc6cdbb](cc6cdbb))
* get L1 tx utils config from env
([#12620](#12620))
([d930c01](d930c01))
* Log overflow handling in reset
([#12579](#12579))
([283b624](283b624))
* metrics update
([#12571](#12571))
([80a5df2](80a5df2))
* **sandbox:** query release please manifest for version if in a docker
container
([#12591](#12591))
([db8ebc6](db8ebc6))
* **spartan:** setup needs kubectl
([#12580](#12580))
([753cb33](753cb33))
* update dead partial notes link
([#12629](#12629))
([5a1dc4c](5a1dc4c))
* update error message to display 128 bits as valid bit size
(noir-lang/noir#7626)
([cc6cdbb](cc6cdbb))
* update fallback transport
([#12470](#12470))
([88f0711](88f0711))


### Miscellaneous

* bump external pinned commits
(noir-lang/noir#7640)
([cc6cdbb](cc6cdbb))
* **ci3:** add helper for uncached test introspection
([#12618](#12618))
([9ac518b](9ac518b))
* **ci3:** better memsuspend_limit comment
([#12622](#12622))
([de84187](de84187))
* clean up upgrade test and other small things
([#12558](#12558))
([c28abe1](c28abe1))
* cleanup eth artifacts + misc aztec.js reorg
([#12563](#12563))
([6623244](6623244))
* **docs:** Updated accounts page
([#12019](#12019))
([d45dac9](d45dac9))
* Fix mac build
([#12610](#12610))
([adceed6](adceed6))
* gemini soundness regression test
([#12570](#12570))
([c654106](c654106))
* more sane e2e_prover/full timeout
([#12619](#12619))
([add9d35](add9d35))
* reactivate acir_test for `regression_5045`
([#12548](#12548))
([c89f89c](c89f89c))
* remove unnecessary trait bounds
(noir-lang/noir#7635)
([cc6cdbb](cc6cdbb))
* Rename `StructDefinition` to `TypeDefinition`
(noir-lang/noir#7614)
([cc6cdbb](cc6cdbb))
* replace relative paths to noir-protocol-circuits
([4f7f5c3](4f7f5c3))
* replace relative paths to noir-protocol-circuits
([0f68d11](0f68d11))
* replace relative paths to noir-protocol-circuits
([8f593ce](8f593ce))
* replace relative paths to noir-protocol-circuits
([251ae38](251ae38))
* rollup library cleanup
([#12621](#12621))
([361fc59](361fc59))
* **sandbox:** drop cheat-codes log level
([#12586](#12586))
([24f04c7](24f04c7))
* **sandbox:** expose anvil port
([#12599](#12599))
([955f1b0](955f1b0))
* **testnet:** updating script for ignition, change naming
([#12566](#12566))
([2d7b69d](2d7b69d))
* turn on masking in eccvm
([#12467](#12467))
([aacb91a](aacb91a))
* Update Bb line counting script
([#12350](#12350))
([7a41843](7a41843))
* update docs to reflect u128 type
(noir-lang/noir#7623)
([cc6cdbb](cc6cdbb))
* Validate blobs posted to sink belong to our L2
([#12587](#12587))
([9578f1e](9578f1e)),
closes
[#12497](#12497)


### Documentation

* update cli-wallet commands in profiler doc
([#12568](#12568))
([239a4fb](239a4fb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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