feat: EIP-712 structured signing + on-chain signature verification for mintOriginal#39
Open
pradhyum6144 wants to merge 1 commit intoc2siorg:mainfrom
Open
Conversation
…ion to mintOriginal The mintOriginal() function previously accepted a plain string signature parameter and stored it without any on-chain verification, allowing anyone with an active device address to mint with a fake signature. This commit adds cryptographic proof that the device actually signed the mint request. Changes: - Inherit OpenZeppelin EIP712 in LensMintERC1155 with domain "LensMintERC1155" v1 - Add ECDSA.recover verification against EIP-712 typed data digest in mintOriginal() - Add mapping(bytes32 => bool) usedImageHashes to prevent replay of the same image - Add per-device nonce tracking for additional replay protection - Change mintOriginal() signature to accept (bytes32 imageHash, uint8 v, bytes32 r, bytes32 s) - Expose domainSeparator() view for off-chain signing compatibility - Add 15 Foundry tests covering valid signing, replay rejection, tampered params, wrong signer, wrong nonce, unregistered/deactivated device scenarios - Update existing MintEditionDebug tests to use EIP-712 vm.sign flow - Update web3Service.js with EIP-712 signTypedData and new contract ABI - Fix evm_version paris -> cancun in foundry.toml (resolves mcopy errors) Closes c2siorg#2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mintOriginal()inLensMintERC1155.sol, fixing the core vulnerability where the signature parameter was stored but never verified — allowing anyone with an active device address to mint with a fake signature string like"0xsignature123"mapping(bytes32 => bool) usedImageHashes(prevents the same image from being minted twice) and per-devicenonces(prevents signature reuse)web3Service.js) to useethers.Wallet.signTypedData()with the matching EIP-712 domain, and updates the ABI to the newmintOriginal(address, string, bytes32, uint256, uint8, bytes32, bytes32)signatureWhat changed
Contract (
LensMintERC1155.sol)EIP712("LensMintERC1155", "1")MINT_ORIGINAL_TYPEHASHfor the structured type:MintOriginal(address to, string ipfsHash, bytes32 imageHash, uint256 maxEditions, uint256 nonce)mintOriginal()now accepts(uint8 v, bytes32 r, bytes32 s)instead ofstring _signature, reconstructs the EIP-712 digest on-chain, and verifiesECDSA.recover(digest, v, r, s) == msg.senderimageHashchanged fromstringtobytes32for gas efficiency and proper cryptographic comparisondomainSeparator()view function for off-chain signing compatibilityTests (
LensMintEIP712.t.sol— 15 new tests)testMintOriginalWithValidSignaturetestNonceIncrementsAfterMinttestMintTwoDifferentImagestestEditionMintStillWorkstestRevertOnDuplicateImageHashtestRevertOnFakeSignaturetestRevertOnWrongSignerKeytestRevertOnSignatureFromDifferentDevicetestRevertOnTamperedParamstestRevertOnTamperedIpfsHashtestRevertOnWrongNoncetestRevertOnUnregisteredDevicetestRevertOnDeactivatedDevicetestDomainSeparatorIsConsistenttestUsedImageHashTrackingBackend (
web3Service.js)signMintOriginal()method builds the EIP-712 domain + types and callswallet.signTypedData()mintOriginal()now signs before calling the contract with(v, r, s)paramsConfig (
foundry.toml)evm_versionchanged fromparis→cancun(fixesmcopyinstruction errors with latest OpenZeppelin, related to forge test fails with mcopy instruction error due to EVM version mismatch #10)Why EIP-712 over EIP-191
to,ipfsHash,imageHashCloses #2
Test plan
forge test— 15 new + 3 updated existing)sign_hash→ EIP-712 format)