foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.18k stars 1.7k forks source link

feat(cheatcodes): `P256` public key generator #7908

Closed pcaversaccio closed 1 month ago

pcaversaccio commented 4 months ago

Component

Forge

Describe the feature you would like

It would be very useful for testing of P256 signatures to have a forge function that can generate / derive the public key coordinates based on the secp256r1 curve from a random uint256 private key:

function generatePublicKeyP256(uint256 privateKey) external pure returns (uint256 publicKeyX, uint256 publicKeyY)

Maybe, we can think this further, and add an Enum for the elliptic curve used (e.g. secp256k1, secp256r1 etc.) to have the possibility to add further curves without breaking the API.

protocolwhisper commented 4 months ago

I'd love to work on this :)

yash-atreya commented 4 months ago

I'd love to work on this :)

Assigned

protocolwhisper commented 3 months ago

Quick question: Does this need to be here https://github.com/foundry-rs/foundry/blob/0b03a58b4a42b149a27e0b6cc1ff9559306f3603/crates/cheatcodes/src/utils.rs#L19 or in the forge crate? If it belongs in the forge crate, where should it be placed? @yash-atreya

mattsse commented 3 months ago

in the cheatcodes

see https://github.com/foundry-rs/foundry/blob/29e51120ac6e77a62242364a22108edea7274a2a/crates/cheatcodes/spec/src/vm.rs#L305-L307

and

https://github.com/foundry-rs/foundry/blob/29e51120ac6e77a62242364a22108edea7274a2a/crates/cheatcodes/src/evm.rs#L164-L169

for reference

zerosnacks commented 2 months ago

Hi @protocolwhisper how is it going? Do you need any pointers or have any questions?

protocolwhisper commented 2 months ago

Hi @zerosnacks, it's going well I've just submitted the pull requests + tests :) ; (Update) I need to modify the test

pcaversaccio commented 1 month ago

Can you please add the function to the vm interface in forge-std, otherwise hard to use 🙃