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

chore: Use poseidon Hasher api #9888

Closed
wants to merge 2 commits into from
Closed

chore: Use poseidon Hasher api #9888

wants to merge 2 commits into from

Conversation

nventuro
Copy link
Contributor

Alternative approach to noir-lang/noir#6491 - instead of using the internals we use the new API. It seems like recent developments in the language re. generics and slices now let us do it.

Copy link
Contributor

Changes to public function bytecode sizes

Generated at commit: dc09db8b8016c8ded93a1a3266b4f8d257bc31cb, compared to commit: ada3e3aba6141411a8ca931f45cc2b9b7027585e

🧾 Summary (100% most significant diffs)

Program Bytecode size in bytes (+/-) %
FPC::constructor +1,246 ❌ +39.53%
TokenBridge::constructor +1,246 ❌ +38.55%
Claim::constructor +1,246 ❌ +38.12%
AvmTest::get_args_hash +677 ❌ +37.53%
Auth::get_scheduled_authorized +672 ❌ +34.62%
Auth::get_authorized +672 ❌ +32.93%
Auth::set_authorized_delay +1,840 ❌ +30.95%
Auth::set_authorized +1,840 ❌ +30.50%
Claim::public_dispatch +1,246 ❌ +29.48%
TokenBlacklist::get_roles +774 ❌ +27.91%
AvmInitializerTest::constructor +699 ❌ +27.47%
Auth::get_authorized_delay +656 ❌ +27.36%
TokenBlacklist::update_roles +1,845 ❌ +24.03%
AuthRegistry::consume +753 ❌ +23.37%
Token::burn_public +1,030 ❌ +21.97%
InclusionProofs::constructor +562 ❌ +21.44%
AvmInitializerTest::public_dispatch +699 ❌ +21.02%
NFT::transfer_in_public +703 ❌ +18.93%
Parent::public_nested_static_call +624 ❌ +18.55%
Uniswap::constructor +562 ❌ +18.39%
Auth::constructor +562 ❌ +18.15%
TokenBlacklist::mint_private +753 ❌ +17.54%
EasyPrivateVoting::constructor +562 ❌ +17.44%
TokenBlacklist::mint_public +758 ❌ +16.44%
Crowdfunding::init +562 ❌ +15.90%
AppSubscription::constructor +562 ❌ +15.23%
InclusionProofs::public_dispatch +619 ❌ +14.85%
NFT::constructor +703 ❌ +14.69%
Token::transfer_public +703 ❌ +14.65%
Token::constructor +703 ❌ +13.67%
Token::shield +703 ❌ +13.46%
EasyPrivateVoting::public_dispatch +760 ❌ +12.49%
TokenBlacklist::burn_public +732 ❌ +12.45%
AppSubscription::public_dispatch +562 ❌ +11.30%
FPC::public_dispatch +883 ❌ +10.56%
TokenBlacklist::transfer_public +658 ❌ +10.43%
Crowdfunding::public_dispatch +619 ❌ +9.96%
TokenBlacklist::shield +597 ❌ +9.30%
AuthRegistry::public_dispatch +753 ❌ +9.00%
TokenBlacklist::constructor +641 ❌ +8.10%
Parent::public_dispatch +619 ❌ +7.39%
Test::consume_message_from_arbitrary_sender_public +562 ❌ +7.06%
Test::consume_mint_public_message +562 ❌ +5.30%
Auth::public_dispatch +553 ❌ +5.13%
StatefulTest::public_dispatch +301 ❌ +3.71%
Test::public_dispatch +562 ❌ +2.85%
StatefulTest::public_constructor +103 ❌ +2.67%
TokenBlacklist::public_dispatch +394 ❌ +1.56%
NFT::public_dispatch +360 ❌ +1.37%
AvmTest::public_dispatch +791 ❌ +1.32%
Token::public_dispatch +429 ❌ +1.17%
TokenBridge::claim_public +103 ❌ +0.83%
TokenBridge::public_dispatch +161 ❌ +0.71%
Uniswap::swap_public +103 ❌ +0.66%
AvmTest::bulk_testing +2 ❌ +0.01%
Uniswap::_approve_bridge_and_exit_input_asset_to_L1 -9 ✅ -0.14%
Uniswap::public_dispatch -307 ✅ -1.23%

Full diff report 👇
Program Bytecode size in bytes (+/-) %
FPC::constructor 4,398 (+1,246) +39.53%
TokenBridge::constructor 4,478 (+1,246) +38.55%
Claim::constructor 4,515 (+1,246) +38.12%
AvmTest::get_args_hash 2,481 (+677) +37.53%
Auth::get_scheduled_authorized 2,613 (+672) +34.62%
Auth::get_authorized 2,713 (+672) +32.93%
Auth::set_authorized_delay 7,786 (+1,840) +30.95%
Auth::set_authorized 7,872 (+1,840) +30.50%
Claim::public_dispatch 5,473 (+1,246) +29.48%
TokenBlacklist::get_roles 3,547 (+774) +27.91%
AvmInitializerTest::constructor 3,244 (+699) +27.47%
Auth::get_authorized_delay 3,054 (+656) +27.36%
TokenBlacklist::update_roles 9,522 (+1,845) +24.03%
AuthRegistry::consume 3,975 (+753) +23.37%
Token::burn_public 5,719 (+1,030) +21.97%
InclusionProofs::constructor 3,183 (+562) +21.44%
AvmInitializerTest::public_dispatch 4,025 (+699) +21.02%
NFT::transfer_in_public 4,417 (+703) +18.93%
Parent::public_nested_static_call 3,988 (+624) +18.55%
Uniswap::constructor 3,618 (+562) +18.39%
Auth::constructor 3,659 (+562) +18.15%
TokenBlacklist::mint_private 5,047 (+753) +17.54%
EasyPrivateVoting::constructor 3,785 (+562) +17.44%
TokenBlacklist::mint_public 5,369 (+758) +16.44%
Crowdfunding::init 4,097 (+562) +15.90%
AppSubscription::constructor 4,252 (+562) +15.23%
InclusionProofs::public_dispatch 4,788 (+619) +14.85%
NFT::constructor 5,490 (+703) +14.69%
Token::transfer_public 5,500 (+703) +14.65%
Token::constructor 5,846 (+703) +13.67%
Token::shield 5,925 (+703) +13.46%
EasyPrivateVoting::public_dispatch 6,845 (+760) +12.49%
TokenBlacklist::burn_public 6,610 (+732) +12.45%
AppSubscription::public_dispatch 5,535 (+562) +11.30%
FPC::public_dispatch 9,245 (+883) +10.56%
TokenBlacklist::transfer_public 6,969 (+658) +10.43%
Crowdfunding::public_dispatch 6,831 (+619) +9.96%
TokenBlacklist::shield 7,013 (+597) +9.30%
AuthRegistry::public_dispatch 9,116 (+753) +9.00%
TokenBlacklist::constructor 8,557 (+641) +8.10%
Parent::public_dispatch 9,000 (+619) +7.39%
Test::consume_message_from_arbitrary_sender_public 8,517 (+562) +7.06%
Test::consume_mint_public_message 11,168 (+562) +5.30%
Auth::public_dispatch 11,335 (+553) +5.13%
StatefulTest::public_dispatch 8,423 (+301) +3.71%
Test::public_dispatch 20,313 (+562) +2.85%
StatefulTest::public_constructor 3,963 (+103) +2.67%
TokenBlacklist::public_dispatch 25,591 (+394) +1.56%
NFT::public_dispatch 26,593 (+360) +1.37%
AvmTest::public_dispatch 60,923 (+791) +1.32%
Token::public_dispatch 37,133 (+429) +1.17%
TokenBridge::claim_public 12,561 (+103) +0.83%
TokenBridge::public_dispatch 22,786 (+161) +0.71%
Uniswap::swap_public 15,804 (+103) +0.66%
AvmTest::bulk_testing 25,499 (+2) +0.01%
Uniswap::_approve_bridge_and_exit_input_asset_to_L1 6,442 (-9) -0.14%
Uniswap::public_dispatch 24,739 (-307) -1.23%

@@ -264,65 +266,50 @@ pub fn poseidon2_hash_with_separator<let N: u32, T>(inputs: [Field; N], separato
where
T: ToField,
{
// We manually hash the inputs here, since we cannot express with the type system a constant size inputs array of N + 1
Copy link
Member

Choose a reason for hiding this comment

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

Seems like the only reason you did this was because we didn't support arithmetic generics at the time you wrote these functions. You should be able to just do Poseidon2::hash([separator, ...inputs], N+1) (no spread syntax though).

@nventuro nventuro changed the title [chore] Use poseidon Hasher api chore: Use poseidon Hasher api Nov 12, 2024
@nventuro nventuro closed this Jan 17, 2025
@nventuro nventuro deleted the nv/hasher branch January 17, 2025 14:45
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.

2 participants