-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
109 lines (97 loc) · 3.7 KB
/
Copy pathindex.html
File metadata and controls
109 lines (97 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Function Selector Checker</title>
<script src="https://cdn.jsdelivr.net/npm/ethers@6.10.0/dist/ethers.umd.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-900 text-white font-mono p-4">
<div class="max-w-xl mx-auto">
<h1 class="text-2xl font-bold mb-4">🔍 Function Selector Checker</h1>
<!-- Single function selector calculator -->
<div class="mb-8">
<label class="block mb-2">Function Signature</label>
<input
id="sigInput"
type="text"
placeholder="transfer(address,uint256)"
class="w-full p-2 rounded bg-gray-800 border border-gray-600"
/>
<button
onclick="calculateSelector()"
class="mt-2 px-4 py-2 bg-blue-600 rounded hover:bg-blue-700"
>
Calculate Selector
</button>
<div class="mt-4">
<p>Selector:</p>
<div id="selectorResult" class="bg-gray-800 p-2 rounded break-all"></div>
<button
onclick="copySelector()"
class="mt-2 px-3 py-1 bg-green-600 rounded hover:bg-green-700"
>
Copy Selector
</button>
</div>
</div>
<!-- Collision checker -->
<div class="mb-8">
<h2 class="text-xl font-bold mb-2"> Collision Checker</h2>
<label class="block mb-2">Function Signature A</label>
<input
id="sigA"
type="text"
placeholder="approve(address,uint256)"
class="w-full p-2 rounded bg-gray-800 border border-gray-600 mb-2"
/>
<label class="block mb-2">Function Signature B</label>
<input
id="sigB"
type="text"
placeholder="transfer(address,uint256)"
class="w-full p-2 rounded bg-gray-800 border border-gray-600"
/>
<button
onclick="checkCollision()"
class="mt-2 px-4 py-2 bg-red-600 rounded hover:bg-red-700"
>
Check Collision
</button>
<div class="mt-4" id="collisionResult"></div>
</div>
<!-- Educational note -->
<div class="text-sm text-gray-400">
Function selector collisions can lead to critical vulnerabilities in proxy
patterns or fallback calls. Always verify selector uniqueness. Built by
<a href="https://github.com/yourusername" class="underline">Zaki</a>.
</div>
</div>
<script>
function calculateSelector() {
const sig = document.getElementById("sigInput").value.trim();
if (!sig) return;
const hash = ethers.keccak256(ethers.toUtf8Bytes(sig));
const selector = hash.slice(0, 10);
document.getElementById("selectorResult").innerText = selector;
}
function copySelector() {
const selector = document.getElementById("selectorResult").innerText;
navigator.clipboard.writeText(selector);
alert("Selector copied!");
}
function checkCollision() {
const sigA = document.getElementById("sigA").value.trim();
const sigB = document.getElementById("sigB").value.trim();
if (!sigA || !sigB) return;
const selA = ethers.keccak256(ethers.toUtf8Bytes(sigA)).slice(0, 10);
const selB = ethers.keccak256(ethers.toUtf8Bytes(sigB)).slice(0, 10);
const res = selA === selB
? ` Collision detected! Both have selector ${selA}`
: ` No collision. Selector A: ${selA}, Selector B: ${selB}`;
document.getElementById("collisionResult").innerText = res;
}
</script>
</body>
</html>