forked from CeloMexico/celo-mx
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug-contract-sigs.cjs
More file actions
59 lines (49 loc) Β· 3.09 KB
/
debug-contract-sigs.cjs
File metadata and controls
59 lines (49 loc) Β· 3.09 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
const { ethers } = require('ethers');
async function debugContractSignatures() {
const provider = new ethers.JsonRpcProvider('https://alfajores-forno.celo-testnet.org');
const contractAddress = '0x4193D2f9Bf93495d4665C485A3B8AadAF78CDf29';
console.log('π Analyzing contract at:', contractAddress);
// Get contract code to see if it exists
const code = await provider.getCode(contractAddress);
console.log('π Contract bytecode length:', code.length);
console.log('β
Contract exists:', code !== '0x');
// Test common function signatures
const testFunctions = [
// enroll function variations
{ name: 'enroll(uint256)', sig: '0xf57d585b', params: '0000000000000000000000000000000000000000000000000000000000016f51' }, // 93521
{ name: 'claim(uint256)', sig: '0x379607f5', params: '0000000000000000000000000000000000000000000000000000000000016f51' },
{ name: 'mint(address,uint256)', sig: '0x40c10f19', params: '000000000000000000000000eafbb9bef20c5d8b5cd52ef9d8703e7c902ac24c0000000000000000000000000000000000000000000000000000000000016f51' },
// read function variations
{ name: 'isEnrolled(address,uint256)', sig: '0xd2fb762b', params: '000000000000000000000000eafbb9bef20c5d8b5cd52ef9d8703e7c902ac24c0000000000000000000000000000000000000000000000000000000000016f51' },
{ name: 'hasBadge(address,uint256)', sig: '0x6352211e', params: '000000000000000000000000eafbb9bef20c5d8b5cd52ef9d8703e7c902ac24c0000000000000000000000000000000000000000000000000000000000016f51' },
{ name: 'balanceOf(address,uint256)', sig: '0x00fdd58e', params: '000000000000000000000000eafbb9bef20c5d8b5cd52ef9d8703e7c902ac24c0000000000000000000000000000000000000000000000000000000000016f51' },
{ name: 'balanceOf(address)', sig: '0x70a08231', params: '000000000000000000000000eafbb9bef20c5d8b5cd52ef9d8703e7c902ac24c' },
// owner/admin functions
{ name: 'owner()', sig: '0x8da5cb5b', params: '' },
{ name: 'name()', sig: '0x06fdde03', params: '' },
{ name: 'symbol()', sig: '0x95d89b41', params: '' },
];
console.log('\nπ§ͺ Testing function signatures:');
for (const func of testFunctions) {
try {
const data = '0x' + func.sig.substring(2) + func.params;
const result = await provider.call({
to: contractAddress,
data: data
});
console.log(`β
${func.name}: SUCCESS - ${result}`);
// Try to decode common return types
if (result && result !== '0x') {
if (result.length === 66) { // 32 bytes = uint256 or bool
const asBigInt = BigInt(result);
const asBool = asBigInt === 1n;
console.log(` π As uint256: ${asBigInt.toString()}`);
console.log(` π As bool: ${asBool}`);
}
}
} catch (error) {
console.log(`β ${func.name}: FAILED - ${error.message}`);
}
}
}
debugContractSignatures().catch(console.error);