Skip to content

feat(forge): implement vm.signTypedData cheatcode #10330

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

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

Haxry
Copy link
Contributor

@Haxry Haxry commented Apr 17, 2025

Motivation

Solution

closes #10281

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@Haxry Haxry requested a review from zerosnacks as a code owner April 17, 2025 14:07
@Haxry Haxry marked this pull request as draft April 17, 2025 14:10
@grandizzy
Copy link
Collaborator

@Haxry pls don't introduce ethers dep bit use alloy. Also pls add a test for the new cheatcodes and make sure priv key is redacted in traces, you can add here

"signDelegation" | "signAndAttachDelegation" => {

Thanks

@Haxry
Copy link
Contributor Author

Haxry commented Apr 19, 2025

@grandizzy
plz review !
are the changes ok ?
I'll add the test too !

@grandizzy
Copy link
Collaborator

@grandizzy plz review ! are the changes ok ? I'll add the test too !

yep, lgtm! I run cargo cheats and pushed commit to fix CI, would be great to have a test and then can be merged, maybe @aviggiano have a solidity test to use here?

@grandizzy grandizzy changed the title implemented vm.signTypedData feat(forge): implement vm.signTypedData cheatcode Apr 22, 2025
@grandizzy grandizzy added T-feature Type: feature C-forge Command: forge labels Apr 22, 2025
@aviggiano
Copy link

Hey
Thanks for implementing this feature. I'll test it on my project today

@grandizzy
Copy link
Collaborator

Hey Thanks for implementing this feature. I'll test it on my project today

Awesome, thanks. Mind that the PR wasn't merged yet so you'll need to build locally and test, was wondering if you could provide a sample for input / output to include as a test.

@Haxry
Copy link
Contributor Author

Haxry commented Apr 22, 2025

@aviggiano plz provide a sample test case to include in tests

@aviggiano
Copy link

aviggiano commented Apr 22, 2025

@Haxry I hope this example can help:

https://github.com/aviggiano/foundry-vm-signtypeddata/blob/db023ea33bfa4979a59a5fa00bfd85204a56e987/script/SignTypedData.s.sol#L23-L46

This is the current setup to sign with EIP712:

forge script script/SignTypedData.s.sol --rpc-url base -vvvvv --ffi

You should have a Ledger setup and unlocked. It will prompt you to "blind sign" using cast:

    ├─ [0] VM::ffi(["cast", "wallet", "sign", "--ledger", "--mnemonic-derivation-path", "m/44'/60'/0'/0/0", "--data", "{\"domain\":{\"chainId\":\"8453\",\"verifyingContract\":\"0xF3a292Dda3F524EA20b5faF2EE0A1c4abA665e4F\"},\"message\":{\"to\":\"0x4200000000000000000000000000000000000006\",\"value\":\"0\",\"data\":\"0x2e1a7d4d0000000000000000000000000000000000000000000000000000000000000000\",\"operation\":0,\"baseGas\":\"0\",\"gasPrice\":\"0\",\"gasToken\":\"0x0000000000000000000000000000000000000000\",\"refundReceiver\":\"0x0000000000000000000000000000000000000000\",\"nonce\":1,\"safeTxGas\":\"0\"},\"primaryType\":\"SafeTx\",\"types\":{\"SafeTx\":[{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"value\",\"type\":\"uint256\"},{\"name\":\"data\",\"type\":\"bytes\"},{\"name\":\"operation\",\"type\":\"uint8\"},{\"name\":\"safeTxGas\",\"type\":\"uint256\"},{\"name\":\"baseGas\",\"type\":\"uint256\"},{\"name\":\"gasPrice\",\"type\":\"uint256\"},{\"name\":\"gasToken\",\"type\":\"address\"},{\"name\":\"refundReceiver\",\"type\":\"address\"},{\"name\":\"nonce\",\"type\":\"uint256\"}]}}"])

The goal is to replace this FFI call to cast with vm.signTypedData

@grandizzy
Copy link
Collaborator

@Haxry I hope this example can help:

https://github.com/aviggiano/foundry-vm-signtypeddata/blob/db023ea33bfa4979a59a5fa00bfd85204a56e987/script/SignTypedData.s.sol#L23-L46

Confirm this works with the current cheatcode which requires a private key, one difference though is that the cheatcode returns v, r, s, of sig but I guess that's OK @aviggiano ?

I think we need also a cheatcode that would enable signing with the ledger and not by receiving priv key, @Haxry @aviggiano wdyt? thanks

@aviggiano
Copy link

aviggiano commented Apr 23, 2025

@grandizzy returning v, r, s is OK,

but requiring the private key is not sufficient for my use case, since the biggest motivation for this feature is being able to sign transactions with ledger.

So yeah, it would be important to have a cheatcode that does not require the private key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-feature Type: feature
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

feat(cheatcodes): add vm.signTypedData cheatcode to Foundry
3 participants