Skip to content

Conversation

@recmo
Copy link
Contributor

@recmo recmo commented Aug 21, 2025

@philsippl asked how Skyscraper would perform onchain. Turns out it's about 10x better than Posseidon. This is useful for Merkle trees that are efficient to handle on-chain and in circuit.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 21, 2025

CodSpeed WallTime Performance Report

Merging #147 will not alter performance

Comparing remco/skyscraper-evm (96916d9) with main (6f0e6e4)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 35 untouched benchmarks

@recmo recmo marked this pull request as ready for review August 21, 2025 14:57
@recmo
Copy link
Contributor Author

recmo commented Aug 21, 2025

@xrvdg You spend some time optimizing Skyscraper. Do you have any ideas we could try here?

Copy link
Collaborator

@xrvdg xrvdg left a comment

Choose a reason for hiding this comment

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

In the other skyscraper implementation we tuned the output range of the montgomery multiplication (modmul) to only reduce once the addition is done. Looks like we can do the opposite here: modmul does a full reduction and that leaves space within the u256 for the additions.

Comment on lines +145 to +146
r = rc_a + addmod(mulmod(mulmod(l, l, P), SIGMA_INV, P), r, P);
l = rc_b + addmod(mulmod(mulmod(r, r, P), SIGMA_INV, P), l, P);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these addmod are safe to be replaced by regular adds. After mulmod there is 4.29p space left before a u256 overflows. Afterwards it directly gets fed into the mulmod in sss_reduce_l which in turn reduces it.

Comment on lines +160 to +164
l = addmod(
rc_b,
addmod(mulmod(mulmod(r, r, P), SIGMA_INV, P), l, P),
P
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, only the outer addmod should be required.

Comment on lines +157 to +159
unchecked {
r = rc_a + addmod(mulmod(mulmod(l, l, P), SIGMA_INV, P), r, P);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on this line it looks like r doesn't have to be reduced for bb so it should be fine to drop the addmod here. Same reasoning as above.

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