vacp2p / rln-contract

RLN contract
Apache License 2.0
13 stars 6 forks source link

chore(rln-v2): use lazyImt for gas estimates #39

Open rymnc opened 6 months ago

rymnc commented 6 months ago

Description

As requested by @alrevuelta, following are gas estimates for insertions (see the test "ValidRegistration"). This contract can be further optimized by aggregating all the mappings into one struct.

Checklist

Ensure you completed all of the steps below before submitting your pull request:

alrevuelta commented 6 months ago

Interesting. Can see we go from 135760 to 210499. What's the before/after? I mean, what does 135760 gas refer to? Current TWN contract? Or LazyIMT without RLNv2?

Mind elaborating on the differences we would have: RLNv2 vs RLNv2_LAZYIMT? Would like to understand where the gas increase is coming from.

rymnc commented 6 months ago

the before is rln-v2, and after is rln-v2 with lazy imt.

rln-v2 vs rln-v1: rln-v2 uses an additional storage slot and hence costs more than rln-v1

alrevuelta commented 6 months ago

the before is rln-v2, and after is rln-v2 with lazy imt.

Interesting. And why the gas increase? Its quite significant. I'm comparing it with RLNv1 vs RLNv1_LazyImt that is around 90k vs 130k (44% more) vs 135760 to 210499 (55% more).

rymnc commented 6 months ago

we can compare rln-v2 lazyimt to rln-v1 lazyimt by looking at the snapshot from the other pr: [PASS] test__ValidRegistration(uint256) (runs: 1000, μ: 137904, ~: 137904) this is also due to the fact that we are using the poseidon hash to generate a rate commitment that is the leaf in the rln-v2 tree (as mentioned in yesterday's research call)