Skip to content

Commit

Permalink
feat: erc721 signature for referendum
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Sep 16, 2024
1 parent d95b854 commit 6c20b15
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions contracts/Referendum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract Referendum is
bytes32 private constant VERIFIED_ROLE = keccak256("VERIFIED_ROLE");

// Error to be thrown when the submission initiator is invalid.
error InvalidSignature();
error InvalidSubmissionSignature();

/// @dev Event emitted when a content is submitted for referendum.
/// @param contentId The ID of the content submitted.
Expand Down Expand Up @@ -127,22 +127,21 @@ contract Referendum is
T.EIP712Signature calldata sig
) external {
// https://eips.ethereum.org/EIPS/eip-712
uint256 nonce = _useNonce(initiator);
bytes32 structHash = keccak256(
abi.encode(
C.REFERENDUM_SUBMIT_TYPEHASH,
contentId,
initiator,
_useNonce(initiator)
nonce
)
);


// retrieve the signer from digest and signature to check if the signature correspond to expected signer.
bytes32 digest = _hashTypedDataV4(structHash); // expected keccak256("\x19\x01" ‖ domainSeparator ‖ hashStruct(message))

Check failure on line 141 in contracts/Referendum.sol

View workflow job for this annotation

GitHub Actions / solhint linting

Line length must be no more than 120 but current length is 128
// retrieve the signer from digest and input signature to check if the signature correspond to expected signer
address signer = ecrecover(digest, sig.v, sig.r, sig.s);

// TODO move to lib
if (signer != initiator) {
revert InvalidSignature();
revert InvalidSubmissionSignature();
}

submit(contentId, initiator);
Expand Down

0 comments on commit 6c20b15

Please sign in to comment.