Applying this function at the end of /test/TestSnowmanAirdrop.t.sol to know what the correct and wrong digest output HASH.
function testFrontendSignatureVerification() public {
vm.startPrank(alice);
snow.approve(address(airdrop), 1);
vm.stopPrank();
bytes32 FRONTEND_MESSAGE_TYPEHASH = keccak256("SnowmanClaim(address receiver, uint256 amount)");
bytes32 DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256("Snowman Airdrop"),
keccak256("1"),
block.chainid,
address(airdrop)
)
);
uint256 amount = snow.balanceOf(alice);
bytes32 structHash = keccak256(
abi.encode(
FRONTEND_MESSAGE_TYPEHASH,
alice,
amount
)
);
bytes32 frontendDigest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
structHash
)
);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alKey, frontendDigest);
bytes32 contractDigest = airdrop.getMessageHash(alice);
console2.log("Frontend Digest (correct format):");
console2.logBytes32(frontendDigest);
console2.log("Contract Digest (with typo):");
console2.logBytes32(contractDigest);
assertFalse(
frontendDigest == contractDigest,
"Digests should differ due to typo in MESSAGE_TYPEHASH"
);
vm.prank(satoshi);
vm.expectRevert(SnowmanAirdrop.SA__InvalidSignature.selector);
airdrop.claimSnowman(alice, AL_PROOF, v, r, s);
assertEq(nft.balanceOf(alice), 0);
}