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

vm.sign and cast wallet sign produce different signatures given the same data. #6794

Closed
2 tasks done
HareemSaad opened this issue Jan 14, 2024 · 2 comments · Fixed by #7180
Closed
2 tasks done

vm.sign and cast wallet sign produce different signatures given the same data. #6794

HareemSaad opened this issue Jan 14, 2024 · 2 comments · Fixed by #7180
Labels
T-bug Type: bug

Comments

@HareemSaad
Copy link

Component

Forge, Cast

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (477b345 2023-12-18T00:22:09.434601489Z)

What command(s) is the bug in?

cast wallet sign

Operating System

Linux

Describe the bug

This is the typed data hash that I am trying to sign 0x868df30ebcbde6a6e7f33c8d8bfd704884c74739295b1fea15b8a20815028a18. when signing with cast I get a different signature vs when signing with vm.sign I get a different output.

when calling cast

cast wallet sign 0x868df30ebcbde6a6e7f33c8d8bfd704884c74739295b1fea15b8a20815028a18 --private-key $MODERATOR_KEY

I get the signature 0x70edc0ec8b7bddf618e91b3fb...041ca33e11b

when executing from foundry

(uint8 v, bytes32 r, bytes32 s) = vm.sign(
            vm.envUint("MODERATOR_KEY"), 
            ECDSA.toTypedDataHash(
                DOMAIN, 
                messageHash
            )
        );
        bytes memory moderator1Signature = abi.encodePacked(r, s, v);

I get this answer 0xe90e83e7ccffa3752...835b4f691b

If i produce the signature using wagmi i get the same signature as when produced from cast, but the contract only accepts the signature produced from the vm.sign. (For context I use SignatureChecker.isValidSignatureNow to verify signatures & yes I checked datahash is the same)

How can I create uniform signatures?

@DaniPopes
Copy link
Member

cast wallet sign prefixes your message with the EIP-712 prefix

      Messages starting with 0x are expected to be hex encoded, which get decoded before being signed. The message will be prefixed with the Ethereum Signed Message header and hashed before signing.

I've implemented --no-hash in #7180 to pass sign the hash directly. This can only be signed with private keys since the others don't expose this method directly.

@mattstam
Copy link

This can only be signed with private keys since the others don't expose this method directly.

FYI for anyone who needs to sign with non-private keys, one workaround is to use ffi in code, as shown here: https://github.com/succinctlabs/succinctx/blob/df2ef8b643d43e0ec20166ed35b8cf7d67301903/contracts/script/misc/Base.s.sol#L201

@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants