feat(contracts): implement meta-tx replay attack protection with EIP-712 - #219
Merged
Conversation
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.
Close #176
Pull Request Document
Meta-TX Replay Attack Protection Implementation
🎯 Summary
Implements comprehensive replay attack prevention for meta-transaction handling in TruthBounty contracts. Adds EIP-712 signature verification, per-user nonce tracking, and multi-layer replay protection mechanisms.
Related Issue: #CO-176
📝 Description
Problem
The original
MetaTxExamplecontract lacked replay attack protection, allowing:Solution
Implemented multi-layer replay attack prevention using:
Per-User Nonce System (
mapping(address => uint256))Used Signature Tracking (
mapping(bytes32 => bool))Chain ID in Domain Separator
Deadline Validation
🔧 Changes
Smart Contracts
contracts/MetaTxExample.solEIP712contract inheritancenoncesmapping for per-user replay protectionusedSignaturesmapping for signature digest trackingTRANSFER_TYPEHASHconstant for EIP-712executeTransfer()with:getNonce()andgetDomainSeparator()getters_executeTransfer()Service Layer
meta-tx/meta-tx.service.tsprepareTransfer()for structured data preparationverifySignature()for signature validationrelayTransaction()with proper validationgetNonce()andisSignatureUsed()gettersmeta-tx/meta-tx.controller.tsPOST /meta-tx/relay- Relay meta-transactionPOST /meta-tx/nonce- Get current user noncePOST /meta-tx/prepare- Prepare transfer data for signingTests
test/MetaTxExample.test.ts(New - 22 tests)meta-tx/tests/meta-tx.service.spec.ts(Updated - 16 tests)test/fuzz/MetaTxReplayAttackFuzz.sol(New - 11 tests)✅ Acceptance Criteria
Implementation is functional
Tests passed
No regressions
🧪 Testing
Run Unit Tests
Run Fuzz Tests
Test Coverage Summary
🔐 Security Review
Replay Attack Prevention
Signature Verification
Input Validation
📊 Files Changed
🚀 Integration Guide
For Smart Contract Developers
ERC2771ContextandEIP712noncesandusedSignaturesmappingsFor dApp Developers
For API Users
📚 Documentation
executeTransfer()signature changed fromexecuteMetaTx(requestData, signature)toexecuteTransfer(from, to, amount, deadline, signature)✨ Future Improvements
📋 Checklist