Skip to content
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

Stateless Feature #265

Merged
merged 2 commits into from
Aug 28, 2024
Merged

Stateless Feature #265

merged 2 commits into from
Aug 28, 2024

Conversation

seemenkina
Copy link
Contributor

@seemenkina seemenkina commented Aug 15, 2024

UPD: Ready for review, integration into rln-wasm will be in follow PR

Based on issues for release 0.6.0

Main changes:

  • Now when the flag stateless is specified, the tree for rln will be unavailable

  • Added new constructors + took into consideration whether wasm32 is enabled or not :

    zerokit/rln/src/public.rs

    Lines 118 to 119 in 46dac03

    #[cfg(all(not(target_arch = "wasm32"), feature = "stateless"))]
    pub fn new() -> Result<RLN> {
    and

    zerokit/rln/src/public.rs

    Lines 213 to 214 in 46dac03

    #[cfg(all(target_arch = "wasm32", not(feature = "stateless")))]
    pub fn new_with_params(tree_height: usize, zkey_vec: Vec<u8>, vk_vec: Vec<u8>) -> Result<RLN> {
    and

    zerokit/rln/src/public.rs

    Lines 265 to 266 in 46dac03

    #[cfg(all(not(target_arch = "wasm32"), feature = "stateless"))]
    pub fn new_with_params(circom_vec: Vec<u8>, zkey_vec: Vec<u8>, vk_vec: Vec<u8>) -> Result<RLN> {

  • The function to generate the proof without using tree was already written so I used it without changing the name

    pub fn generate_rln_proof_with_witness<R: Read, W: Write>(

  • There is a function for verification without tree in rln too, also used it without changing the name:

    pub fn verify_with_roots<R: Read>(&self, mut input_data: R, mut roots_data: R) -> Result<bool> {

  • All tree functions inside public and ffi are hidden under the condition that the stateless flag is not set

  • Split tests into submodules to allow testing of functionality with/without trees

@seemenkina seemenkina self-assigned this Aug 15, 2024
Copy link

Benchmark for 90e8844

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 868.1±12.17ns 875.0±13.61ns +0.79%
FullMerkleTree::get 3.5±0.11ns 3.5±0.09ns 0.00%
FullMerkleTree::get_empty_leaves_indices 7.7±0.04ns 7.8±0.23ns +1.30%
FullMerkleTree::get_subtree_root 3.7±0.08ns 3.8±0.15ns +2.70%
FullMerkleTree::override_range 1335.8±19.66ns 1365.7±29.88ns +2.24%
FullMerkleTree::set 865.4±14.81ns 873.4±17.63ns +0.92%
OptimalMerkleTree::compute_root 1011.2±16.22ns 1010.1±7.33ns -0.11%
OptimalMerkleTree::delete 1010.6±14.38ns 1011.3±13.29ns +0.07%
OptimalMerkleTree::get 23.7±0.33ns 23.2±0.20ns -2.11%
OptimalMerkleTree::get_empty_leaves_indices 7.5±0.16ns 7.4±0.09ns -1.33%
OptimalMerkleTree::get_subtree_root 24.2±0.35ns 24.2±0.63ns 0.00%
OptimalMerkleTree::override_range 4.1±0.09µs 4.2±0.05µs +2.44%
OptimalMerkleTree::set 1007.5±7.29ns 1016.0±6.25ns +0.84%

Copy link

Benchmark for 90e8844

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 15.2±0.58ms 15.3±0.13ms +0.66%
OptimalMerkleTree::::full_height_gen 581.7±19.39µs 578.8±5.16µs -0.50%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 326.2±5.49ns 324.4±3.41ns -0.55%
Pmtree::get_empty_leaves_indices 8.4±0.11ns 8.4±0.06ns 0.00%
Pmtree::get_subtree_root 493.0±8.40ns 501.4±37.39ns +1.70%
Pmtree::override_range 234.5±3.68µs 230.2±3.61µs -1.83%
Pmtree::set 54.5±0.80µs 54.4±0.82µs -0.18%
Pmtree:delete 54.4±0.34µs 54.4±0.74µs 0.00%
Set/FullMerkleTree::::set/1 557.0±5.43µs 558.8±11.02µs +0.32%
Set/FullMerkleTree::::set/10 5.6±0.01ms 5.6±0.12ms 0.00%
Set/FullMerkleTree::::set/100 55.8±1.40ms 55.6±0.17ms -0.36%
Set/FullMerkleTree::::set_range/1 562.7±33.95µs 555.7±6.17µs -1.24%
Set/FullMerkleTree::::set_range/10 757.2±6.42µs 755.4±6.58µs -0.24%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.3±0.01ms 0.00%
Set/OptimalMerkleTree::::set/1 556.4±5.79µs 555.7±6.91µs -0.13%
Set/OptimalMerkleTree::::set/10 5.6±0.02ms 5.6±0.03ms 0.00%
Set/OptimalMerkleTree::::set/100 55.6±0.13ms 55.6±0.09ms 0.00%
Set/OptimalMerkleTree::::set_range/1 557.3±14.76µs 556.2±5.98µs -0.20%
Set/OptimalMerkleTree::::set_range/10 5.6±0.01ms 5.6±0.02ms 0.00%
Set/OptimalMerkleTree::::set_range/100 56.0±1.72ms 55.7±0.13ms -0.54%
vk::vk_from_ark_serialized 1610.5±20.19ns 1595.8±13.20ns -0.91%
zkey::zkey_from_raw 3.4±0.00s 3.4±0.01s 0.00%

@rymnc
Copy link
Contributor

rymnc commented Aug 15, 2024

nice
cc: @alrevuelta if you want to test with go-waku-light when this is ready for review

@rymnc
Copy link
Contributor

rymnc commented Aug 16, 2024

please can you also add this to the list of generated artifacts in the nightly release workflow?

@seemenkina
Copy link
Contributor Author

please can you also add this to the list of generated artifacts in the nightly release workflow?

sure
btw I also can fix test error

Copy link

Benchmark for 56c291a

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 867.2±12.86ns 859.5±13.50ns -0.89%
FullMerkleTree::get 3.5±0.07ns 3.4±0.05ns -2.86%
FullMerkleTree::get_empty_leaves_indices 7.7±0.13ns 7.8±0.22ns +1.30%
FullMerkleTree::get_subtree_root 3.7±0.10ns 3.7±0.17ns 0.00%
FullMerkleTree::override_range 1339.7±12.90ns 1344.3±21.19ns +0.34%
FullMerkleTree::set 863.4±11.37ns 879.6±11.03ns +1.88%
OptimalMerkleTree::compute_root 1009.7±19.12ns 1006.0±4.41ns -0.37%
OptimalMerkleTree::delete 1013.4±30.84ns 1002.3±15.60ns -1.10%
OptimalMerkleTree::get 23.7±0.31ns 23.8±0.62ns +0.42%
OptimalMerkleTree::get_empty_leaves_indices 7.4±0.14ns 7.4±0.13ns 0.00%
OptimalMerkleTree::get_subtree_root 24.2±0.47ns 24.2±0.38ns 0.00%
OptimalMerkleTree::override_range 4.1±0.03µs 4.2±0.15µs +2.44%
OptimalMerkleTree::set 1007.7±6.43ns 1000.8±13.83ns -0.68%

Copy link

Benchmark for 85a58e9

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 858.7±7.55ns 877.5±13.10ns +2.19%
FullMerkleTree::get 10.2±0.03ns 3.5±0.06ns -65.69%
FullMerkleTree::get_empty_leaves_indices 7.8±0.14ns 7.7±0.09ns -1.28%
FullMerkleTree::get_subtree_root 10.2±0.02ns 3.7±0.08ns -63.73%
FullMerkleTree::override_range 1345.7±11.19ns 1342.5±44.97ns -0.24%
FullMerkleTree::set 875.6±36.79ns 864.2±6.68ns -1.30%
OptimalMerkleTree::compute_root 1015.5±6.90ns 1009.5±14.80ns -0.59%
OptimalMerkleTree::delete 1002.4±16.28ns 1009.7±12.56ns +0.73%
OptimalMerkleTree::get 30.9±0.44ns 23.7±0.23ns -23.30%
OptimalMerkleTree::get_empty_leaves_indices 7.5±0.41ns 7.4±0.12ns -1.33%
OptimalMerkleTree::get_subtree_root 31.3±1.09ns 24.2±0.34ns -22.68%
OptimalMerkleTree::override_range 4.1±0.08µs 4.1±0.06µs 0.00%
OptimalMerkleTree::set 1002.0±36.79ns 1008.7±8.91ns +0.67%

Copy link

Benchmark for 85a58e9

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 15.5±0.25ms 15.1±0.15ms -2.58%
OptimalMerkleTree::::full_height_gen 581.6±3.94µs 577.2±26.80µs -0.76%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 326.8±5.48ns 326.5±6.19ns -0.09%
Pmtree::get_empty_leaves_indices 8.4±0.14ns 8.4±0.13ns 0.00%
Pmtree::get_subtree_root 495.0±7.41ns 488.2±6.78ns -1.37%
Pmtree::override_range 231.1±3.69µs 233.8±5.01µs +1.17%
Pmtree::set 55.0±0.79µs 54.4±0.44µs -1.09%
Pmtree:delete 54.4±0.59µs 54.4±0.48µs 0.00%
Set/FullMerkleTree::::set/1 555.4±7.09µs 552.9±3.17µs -0.45%
Set/FullMerkleTree::::set/10 5.6±0.01ms 5.6±0.03ms 0.00%
Set/FullMerkleTree::::set/100 55.7±0.12ms 55.9±1.21ms +0.36%
Set/FullMerkleTree::::set_range/1 557.0±5.78µs 555.6±3.49µs -0.25%
Set/FullMerkleTree::::set_range/10 755.5±7.30µs 756.8±6.40µs +0.17%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.3±0.01ms 0.00%
Set/OptimalMerkleTree::::set/1 555.7±2.34µs 556.2±5.70µs +0.09%
Set/OptimalMerkleTree::::set/10 5.6±0.02ms 5.6±0.03ms 0.00%
Set/OptimalMerkleTree::::set/100 55.7±0.11ms 55.7±0.34ms 0.00%
Set/OptimalMerkleTree::::set_range/1 556.6±2.96µs 556.5±7.71µs -0.02%
Set/OptimalMerkleTree::::set_range/10 5.6±0.01ms 5.6±0.01ms 0.00%
Set/OptimalMerkleTree::::set_range/100 55.8±0.12ms 55.8±0.14ms 0.00%
vk::vk_from_ark_serialized 1567.0±8.82ns 1615.7±11.17ns +3.11%
zkey::zkey_from_raw 3.4±0.00s 3.4±0.01s 0.00%

Copy link

Benchmark for a27567a

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 860.8±8.66ns 864.0±18.34ns +0.37%
FullMerkleTree::get 3.4±0.06ns 3.4±0.05ns 0.00%
FullMerkleTree::get_empty_leaves_indices 7.8±0.14ns 7.7±0.06ns -1.28%
FullMerkleTree::get_subtree_root 3.7±0.10ns 3.6±0.20ns -2.70%
FullMerkleTree::override_range 1344.5±21.96ns 1380.0±25.57ns +2.64%
FullMerkleTree::set 870.1±11.67ns 873.6±12.42ns +0.40%
OptimalMerkleTree::compute_root 1002.7±9.39ns 1002.8±8.60ns +0.01%
OptimalMerkleTree::delete 1003.7±10.28ns 1001.9±8.96ns -0.18%
OptimalMerkleTree::get 23.7±0.36ns 23.5±0.12ns -0.84%
OptimalMerkleTree::get_empty_leaves_indices 7.4±0.07ns 7.5±0.18ns +1.35%
OptimalMerkleTree::get_subtree_root 24.2±0.10ns 24.2±0.21ns 0.00%
OptimalMerkleTree::override_range 4.1±0.02µs 4.2±0.12µs +2.44%
OptimalMerkleTree::set 1000.0±7.81ns 1006.4±40.68ns +0.64%

Copy link

Benchmark for a27567a

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 13.6±0.06ms 14.9±0.19ms +9.56%
OptimalMerkleTree::::full_height_gen 581.0±3.43µs 576.6±3.86µs -0.76%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 321.2±3.75ns 319.8±5.47ns -0.44%
Pmtree::get_empty_leaves_indices 8.4±0.51ns 8.4±0.13ns 0.00%
Pmtree::get_subtree_root 489.5±12.52ns 488.0±11.35ns -0.31%
Pmtree::override_range 231.0±4.11µs 230.0±3.11µs -0.43%
Pmtree::set 54.6±1.72µs 54.3±0.40µs -0.55%
Pmtree:delete 54.5±1.15µs 54.7±0.60µs +0.37%
Set/FullMerkleTree::::set/1 555.9±2.49µs 555.5±5.75µs -0.07%
Set/FullMerkleTree::::set/10 5.6±0.02ms 5.6±0.02ms 0.00%
Set/FullMerkleTree::::set/100 55.7±0.17ms 55.6±0.05ms -0.18%
Set/FullMerkleTree::::set_range/1 555.1±5.90µs 554.3±6.51µs -0.14%
Set/FullMerkleTree::::set_range/10 755.2±3.43µs 755.3±4.98µs +0.01%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.3±0.01ms 0.00%
Set/OptimalMerkleTree::::set/1 557.9±3.68µs 555.5±6.35µs -0.43%
Set/OptimalMerkleTree::::set/10 5.6±0.02ms 5.6±0.02ms 0.00%
Set/OptimalMerkleTree::::set/100 55.7±0.32ms 55.7±0.19ms 0.00%
Set/OptimalMerkleTree::::set_range/1 557.0±3.14µs 554.9±3.84µs -0.38%
Set/OptimalMerkleTree::::set_range/10 5.6±0.27ms 5.6±0.01ms 0.00%
Set/OptimalMerkleTree::::set_range/100 55.9±0.46ms 55.7±0.12ms -0.36%
vk::vk_from_ark_serialized 1656.0±20.25ns 1570.6±13.41ns -5.16%
zkey::zkey_from_raw 3.4±0.00s 3.4±0.01s 0.00%

Copy link

Benchmark for f650b9d

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 875.8±13.25ns 879.6±70.84ns +0.43%
FullMerkleTree::get 3.5±0.06ns 3.5±0.08ns 0.00%
FullMerkleTree::get_empty_leaves_indices 7.4±0.09ns 7.4±0.09ns 0.00%
FullMerkleTree::get_subtree_root 3.7±0.08ns 3.8±0.13ns +2.70%
FullMerkleTree::override_range 1335.6±20.12ns 1335.0±21.46ns -0.04%
FullMerkleTree::set 861.2±9.85ns 862.1±11.73ns +0.10%
OptimalMerkleTree::compute_root 1054.7±13.76ns 1020.2±16.46ns -3.27%
OptimalMerkleTree::delete 1039.3±13.62ns 1024.4±6.94ns -1.43%
OptimalMerkleTree::get 23.3±0.16ns 23.4±0.34ns +0.43%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.14ns 7.1±0.15ns 0.00%
OptimalMerkleTree::get_subtree_root 23.6±1.09ns 23.5±0.40ns -0.42%
OptimalMerkleTree::override_range 4.1±0.07µs 4.2±0.13µs +2.44%
OptimalMerkleTree::set 1041.5±59.12ns 1025.0±17.85ns -1.58%

Copy link

Benchmark for f650b9d

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 15.0±0.12ms 15.1±0.12ms +0.67%
OptimalMerkleTree::::full_height_gen 576.5±3.00µs 576.3±6.96µs -0.03%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 324.4±5.69ns 322.6±2.92ns -0.55%
Pmtree::get_empty_leaves_indices 8.4±0.11ns 8.4±0.14ns 0.00%
Pmtree::get_subtree_root 477.7±9.18ns 475.4±7.80ns -0.48%
Pmtree::override_range 242.5±3.81µs 237.3±3.65µs -2.14%
Pmtree::set 54.0±0.32µs 54.3±0.58µs +0.56%
Pmtree:delete 54.9±4.63µs 53.9±0.41µs -1.82%
Set/FullMerkleTree::::set/1 556.7±14.48µs 554.4±2.61µs -0.41%
Set/FullMerkleTree::::set/10 5.7±0.63ms 5.5±0.01ms -3.51%
Set/FullMerkleTree::::set/100 55.7±0.20ms 55.5±0.15ms -0.36%
Set/FullMerkleTree::::set_range/1 555.2±3.51µs 555.2±5.95µs 0.00%
Set/FullMerkleTree::::set_range/10 755.9±7.76µs 753.1±3.25µs -0.37%
Set/FullMerkleTree::::set_range/100 3.3±0.04ms 3.3±0.01ms 0.00%
Set/OptimalMerkleTree::::set/1 558.9±3.37µs 555.1±4.95µs -0.68%
Set/OptimalMerkleTree::::set/10 5.6±0.08ms 5.6±0.01ms 0.00%
Set/OptimalMerkleTree::::set/100 55.9±0.49ms 55.6±0.12ms -0.54%
Set/OptimalMerkleTree::::set_range/1 558.3±3.60µs 555.6±4.20µs -0.48%
Set/OptimalMerkleTree::::set_range/10 5.6±0.01ms 5.5±0.02ms -1.79%
Set/OptimalMerkleTree::::set_range/100 55.9±0.22ms 55.6±0.50ms -0.54%
vk::vk_from_ark_serialized 1582.0±7.59ns 1604.4±9.63ns +1.42%
zkey::zkey_from_raw 3.4±0.02s 3.4±0.01s 0.00%

Copy link

Benchmark for 4369d3f

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 876.1±13.51ns 860.4±6.09ns -1.79%
FullMerkleTree::get 3.4±0.07ns 3.4±0.07ns 0.00%
FullMerkleTree::get_empty_leaves_indices 7.4±0.06ns 7.5±0.17ns +1.35%
FullMerkleTree::get_subtree_root 3.7±0.07ns 3.7±0.09ns 0.00%
FullMerkleTree::override_range 1340.9±34.53ns 1345.8±8.06ns +0.37%
FullMerkleTree::set 872.3±16.06ns 865.8±12.79ns -0.75%
OptimalMerkleTree::compute_root 1051.4±18.82ns 1014.7±15.91ns -3.49%
OptimalMerkleTree::delete 1048.5±25.17ns 1034.2±16.18ns -1.36%
OptimalMerkleTree::get 23.4±0.20ns 22.8±0.20ns -2.56%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.12ns 7.1±0.12ns 0.00%
OptimalMerkleTree::get_subtree_root 23.4±0.38ns 23.6±0.40ns +0.85%
OptimalMerkleTree::override_range 4.1±0.02µs 4.2±0.06µs +2.44%
OptimalMerkleTree::set 1041.9±4.79ns 1009.4±14.10ns -3.12%

@seemenkina seemenkina marked this pull request as ready for review August 23, 2024 14:05
Copy link

Benchmark for 4369d3f

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 13.7±0.12ms 15.8±0.22ms +15.33%
OptimalMerkleTree::::full_height_gen 573.8±6.64µs 574.9±11.26µs +0.19%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 319.7±3.67ns 322.8±5.36ns +0.97%
Pmtree::get_empty_leaves_indices 8.4±0.08ns 8.4±0.09ns 0.00%
Pmtree::get_subtree_root 472.3±7.41ns 479.2±8.87ns +1.46%
Pmtree::override_range 237.7±5.21µs 232.1±4.05µs -2.36%
Pmtree::set 54.0±0.27µs 54.0±0.94µs 0.00%
Pmtree:delete 53.8±0.40µs 54.1±0.50µs +0.56%
Set/FullMerkleTree::::set/1 556.8±8.01µs 557.2±5.78µs +0.07%
Set/FullMerkleTree::::set/10 5.5±0.01ms 5.6±0.02ms +1.82%
Set/FullMerkleTree::::set/100 55.4±0.08ms 55.5±1.59ms +0.18%
Set/FullMerkleTree::::set_range/1 556.2±5.88µs 555.8±6.98µs -0.07%
Set/FullMerkleTree::::set_range/10 752.8±6.22µs 755.6±4.89µs +0.37%
Set/FullMerkleTree::::set_range/100 3.2±0.00ms 3.3±0.01ms +3.13%
Set/OptimalMerkleTree::::set/1 555.7±5.98µs 559.0±6.98µs +0.59%
Set/OptimalMerkleTree::::set/10 5.6±0.02ms 5.6±0.02ms 0.00%
Set/OptimalMerkleTree::::set/100 55.8±0.06ms 56.0±0.05ms +0.36%
Set/OptimalMerkleTree::::set_range/1 555.3±6.08µs 556.8±8.58µs +0.27%
Set/OptimalMerkleTree::::set_range/10 5.6±0.02ms 5.6±0.01ms 0.00%
Set/OptimalMerkleTree::::set_range/100 56.2±2.93ms 55.7±0.15ms -0.89%
vk::vk_from_ark_serialized 1582.0±29.26ns 1599.5±18.31ns +1.11%
zkey::zkey_from_raw 3.4±0.00s 3.4±0.01s 0.00%

@seemenkina seemenkina merged commit 0d56424 into master Aug 28, 2024
10 checks passed
@seemenkina seemenkina deleted the stateless-feature branch August 28, 2024 10:41
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