signature-replay
Skill này làm gì
Playbook này hướng dẫn rà soát các thông điệp đã ký, permit và meta-transaction trong hợp đồng thông minh. Playbook dành cho kiểm toán viên và lập trình viên dùng chữ ký để ủy quyền hành động.
Khi nào nên dùng
- ✓Khi một hợp đồng chấp nhận phê duyệt có chữ ký, permit hoặc meta-transaction.
- ✓Khi một chữ ký dành cho một blockchain nhưng có thể bị dùng trên blockchain khác.
- ✓Khi một hợp đồng kiểm tra chữ ký mà không theo dõi chữ ký nào đã được dùng.
Liên kết skill
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/signature-replay/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể kiểm tra xem các chữ ký permit của chúng tôi có thể bị dùng lại, hai lần hoặc trên chuỗi khác không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent kiểm tra xem mỗi thông điệp đã ký có nonce và chain ID không, và người ký được khôi phục có thể là địa chỉ zero không, rồi xác nhận bằng kiểm thử.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Signature Replay Playbook
EIP-712 signatures, permits, meta-transactions, and cross-chain bridges
all use ecrecover (or its variants). Each has well-known bugs.
Bug classes
1. Missing nonce → replay
function execute(uint256 amount, bytes calldata sig) external {
bytes32 h = keccak256(abi.encodePacked(msg.sender, amount));
address signer = ecrecover(h, ...);
require(signer == owner);
// ... withdraw amount
}
A valid signature can be replayed forever — anyone who saw it once can re-submit it. Fix: include a per-user / per-message nonce:
mapping(address => uint256) public nonces;
function execute(uint256 amount, uint256 nonce, bytes calldata sig) external {
require(nonce == nonces[msg.sender]);
nonces[msg.sender]++;
bytes32 h = keccak256(abi.encodePacked(msg.sender, amount, nonce));
// ...
}
2. Missing chain ID → cross-chain replay
A signature valid on Ethereum mainnet shouldn't work on Optimism, Base,
Arbitrum, etc. If chainid() not in the signed payload, signatures
replay across chains:
// VULNERABLE
bytes32 h = keccak256(abi.encodePacked(amount, deadline, nonce));
// SAFE — EIP-712 domain separator includes chainid
bytes32 h = _hashTypedDataV4(...); // OZ helper
This is especially bad for bridges — a signed message intended for chain A executes on chain B.
3. Signature malleability (ecrecover variants)
ecrecover accepts two valid s values for any signed message
(s and -s mod n). This means each signature has two valid forms.
If your contract uses the signature itself as a uniqueness key
(e.g., usedSigs[sig] = true), an attacker can find the malleable
version and bypass:
// VULNERABLE — uses sig as uniqueness key
mapping(bytes => bool) public used;
function execute(bytes calldata sig) external {
require(!used[sig]);
used[sig] = true;
address signer = ecrecover(...);
// ...
}
Fix: use the message hash (not the signature) as uniqueness key.
Modern OZ ECDSA library rejects high-s values, but home-rolled
ecrecover does not.
4. ecrecover zero address on invalid sig
address signer = ecrecover(h, v, r, s);
if (signer == owner) { /* approve */ }
Bug: if (v,r,s) is invalid, ecrecover returns address(0). If
owner is somehow address(0) (uninitialized!) → any malformed
signature works.
Fix: require(signer != address(0)).
5. Domain separator without chainid
EIP-712 domain separator should bind to the chain. If a protocol
caches DOMAIN_SEPARATOR in storage at deployment, hard-forks (which
change chainid) break it. OZ's EIP712 handles this; custom code often
doesn't.
// VULNERABLE — cached at deploy
bytes32 immutable DOMAIN_SEPARATOR = keccak256(abi.encode(
keccak256("EIP712Domain(...)"),
keccak256(bytes("Name")),
keccak256(bytes("1")),
1, // ← hardcoded chainid
address(this)
));
// SAFE — re-derive when chainid changes
function _domainSeparator() internal view returns (bytes32) {
return keccak256(abi.encode(..., block.chainid, ...));
}
6. Permit signature replay across forks / hard forks
ERC2612 permit is meta-tx for ERC20 approvals. If permit doesn't
include the EIP-712 domain separator correctly, it can be replayed on:
- Forked test chains
- L2s that copied the contract
- Hard forks (ETC, ETHW)
This is mostly resolved by OZ ERC20Permit, but custom permit impls are often wrong.
7. Replay across function selectors
A signed payload keccak256(amount, recipient) is the same regardless
of which function it authorizes. If two functions share the same
hash structure but different effects, the signature replays:
function withdraw(uint256 amt, address to, bytes sig) external {
bytes32 h = keccak256(abi.encodePacked(amt, to));
address s = ecrecover(h, ...);
require(s == owner);
payable(to).transfer(amt);
}
function mint(uint256 amt, address to, bytes sig) external {
bytes32 h = keccak256(abi.encodePacked(amt, to)); // SAME HASH
address s = ecrecover(h, ...);
require(s == owner);
_mint(to, amt);
}
// A withdraw signature works for mint, and vice versa
Fix: include function selector or unique typeID in the signed payload.
Audit steps
1. Find every ecrecover
grep -rn 'ecrecover\|ECDSA.recover\|recover(' src/
2. For each call site, verify the payload contains
- A nonce (or other per-user unique
Câu hỏi thường gặp
Nonce là gì?
Một số dùng một lần làm cho mỗi thông điệp đã ký chỉ dùng được một lần.
Vì sao chain ID lại quan trọng?
Nếu không có nó, một chữ ký hợp lệ trên blockchain này có thể bị phát lại trên blockchain khác.
Cách tiếp cận được khuyến nghị là gì?
Dùng chuẩn dữ liệu có kiểu EIP-712, trong đó chain ID nằm trong miền (domain) của nó.
Chi tiết
Mô tả gốc của tác giả
Signature replay attacks — missing nonces, missing chain ID, ecrecover zero address, signature malleability, cross-chain replay.
Độ phổ biến
- Sao GitHub
- 6.5k
- Vị trí xếp hạng
- #14012
- Giấy phép
- Apache-2.0
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
detector-overview
6.5kGiúp agent của bạn đọc code mà một công cụ quét đã đánh dấu, rồi quyết định điểm nào là lỗ hổng bảo mật thật và điểm nào là báo động giả.
exploiter-overview
6.5kGiúp agent của bạn ghép nhiều lỗ hổng bảo mật đã xác nhận thành một chuỗi kiểm thử và kiểm tra chuỗi đó có thể gây hậu quả đến đâu.
llm-redteam-overview
6.5kGiúp agent của bạn tìm đúng hướng dẫn red-team AI cho một bài kiểm thử, bao quát 15 nhóm chiến thuật từ prompt injection đến lạm dụng mô hình.
aatmf-t01-prompt-injection
6.5kGiải thích prompt injection, khi các chỉ dẫn ẩn cố ghi đè một hệ thống AI, để chuyên gia bảo mật có thể kiểm tra lỗi này.
Skill tương tự
reverse-engineer-anything
422kGiúp agent của bạn xem bên trong các app và package đã phát hành để giải thích tính năng, so sánh phiên bản hoặc hướng dẫn dựng lại bằng công cụ REA.
1password
394kGiúp agent của bạn cài đặt CLI của 1Password, đăng nhập, và đọc hoặc đưa thông tin bí mật vào mà không in giá trị ra cuộc trò chuyện.
healthcheck
394kGiúp agent của bạn rà soát bảo mật máy tính hoặc máy chủ đang chạy OpenClaw, như SSH, tường lửa, cập nhật và sao lưu, rồi đề xuất cách sửa an toàn.