Skip to content

feat: supports EIP-712 and EIP-1271 signatures to claim airdrop #160

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

Open
wants to merge 7 commits into
base: staging
Choose a base branch
from

Conversation

smol-ninja
Copy link
Member

@smol-ninja smol-ninja commented Jun 2, 2025

Sorry for the massive PR @andreivladbrg. It was very complicated than I thought, both writing source code and then testing it. Now its ready for your review. I will recommend to read the PR description first.

This should be merged after the following PR:


Changelog

Source code

Tests

  • Generates users.recipient using createUserAndKey function as we need private key to create signatures.
  • DRY'ifies some sections in Base test contract and Integration base contract
  • Adds getIndexInMerkleTree and getMerkleProof functions replacing hardcoded use of INDEX1 and index1Proof to avoid manual errors
  • I only added important tests for claimViaSig and ignored what is already being thoroughly tested through claim and claimTo. This is also why I didn't write fuzz tests for it.
  • Refactors users type. See Types.sol for details.

Some notes

  • Foundry currently does not support EIP-712 hashing (refer to Cheatcode: EIP712 canonical hashing foundry-rs/foundry#4818), so its only possible to generate off-chain. I thought of writing TS code to do it but then since that foundry PR is going to get merged soon, we can do hash verification using Foundry cheatcode itself.
  • tests/utils/Utilities.sol contain signature utilities but note that it uses solidity whereas the correct approach is to use eth_signTypedData_v4 so its not being tested. I will wait for foundry to release the new cheatcode for that. Nevertheless, using approach below, I have verified that signature are correctly generated.

To generate EIP-712 signature, run the following in your browser:

Load your address:
const address = (await ethereum.request({ method: 'eth_requestAccounts' }))[0];
Define "TypedData":
const typedData = {
  types: {
    EIP712Domain: [
      { name: "name", type: "string" },
      { name: "chainId", type: "uint256" },
      { name: "verifyingContract", type: "address" },
    ],
    Claim: [
      { name: "index", type: "uint256" },
      { name: "recipient", type: "address" },
      { name: "to", type: "address" },
      { name: "amount", type: "uint128" },
    ],
  },
  domain: {
    name: "Sablier Airdrops Protocol",
    chainId: 1, // Chain on which the contract is deployed
    verifyingContract: "0x03cdcCF81765783bE8c15886d0931C816c3A6BC7", // The address of the campaign
  },
  primaryType: "Claim",
  message: {
    index: 2, // The index of the signer in the Merkle tree
    recipient: "0x39EF0Bbb69b81a9EB148530946E94C69012a29C2", // The address of the airdrop recipient
    to: "0xEAF39695973254D21c8956037c0BAf5FdDA92eC6", // The address where recipient wants to transfer the tokens
    amount: "1000000000000000000000" // The amount of tokens allocated to the recipient
  },
}
Call "eth_signTypedData_v4":
ethereum.request({
  method: "eth_signTypedData_v4",
  params: [
    address,
    JSON.stringify(typedData)
  ]
})
.then(signature => {
  console.log("Signature:", signature);
})
.catch(err => {
  console.error(err);
});

It will then show you something like this:

Screenshot 2025-06-02 at 16 59 07

Once you sign it, it will then display the signature in the console.

Some reference:

@smol-ninja smol-ninja marked this pull request as draft June 2, 2025 15:39
@smol-ninja smol-ninja changed the title feat: support EIP-712 and EIP-1271 signatures for claiming airdrop feat: support EIP-712 and EIP-1271 signatures to claim airdrop Jun 2, 2025
refactor: adds a shared function that reverts if `to` address is zero
@smol-ninja smol-ninja force-pushed the feat/claim-via-sig branch from 9cbce83 to 7c415c1 Compare June 2, 2025 16:07
@smol-ninja smol-ninja changed the title feat: support EIP-712 and EIP-1271 signatures to claim airdrop feat: supports EIP-712 and EIP-1271 signatures to claim airdrop Jun 2, 2025
@smol-ninja smol-ninja marked this pull request as ready for review June 3, 2025 21:25
Copilot

This comment was marked as resolved.

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.

1 participant