Skip to content

Conversation

@cryptopapi997
Copy link

@cryptopapi997 cryptopapi997 commented Oct 31, 2025

Inspired by #408 , we can steal adapt these ideas to optimize the bn254 syscalls as well, since those all overwrite the full memory buffer as well. For the compression syscalls that return a fixed size array, we can utilize the same MaybeUninit trick. For the addition, multiplication, and pairing syscalls we can alloc a vec once at the beginning instead of allocing an array and then converting that to a vec. This results in the following CU diffs:

operation Δ CU
add -27
mul -27
pairing -13
g1_compress -4
g2_compress -8
g1_decompress -8
g2_decompress -22

Note: I didn't apply this to the deprecated bn254 syscalls, but can do as well.
Note 2: Technically these optimizations could be applied inside the actual syscall implementation too instead of the wrapper functions interfacing with them for a couple extra CUs. However, this seemed more low risk, and idk if a SIMD would apply in that case so I went with this for now.

Copy link
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, looks great to me! Just the one comment, @samkim-crypto can you also take a look?

@joncinque
Copy link
Collaborator

Noting for anyone watching, that the Vec::with_capacity -> as_mut_ptr() -> set_len() flow is very well demonstrated here: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.as_mut_ptr

Copy link
Contributor

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

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

Just one small clarification below, but everything looks fine to me!

@samkim-crypto samkim-crypto self-requested a review November 15, 2025 01:48
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