|
1 | 1 | import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk' |
2 | | -import { ethers } from 'ethers' |
3 | 2 |
|
4 | 3 | /** |
5 | 4 | * Script to analyze the decoded values and understand the decoding issue |
@@ -47,72 +46,12 @@ async function main() { |
47 | 46 | ]) |
48 | 47 |
|
49 | 48 | console.log('Current decoded values:') |
| 49 | + console.log('- Counter:', counterResult[0]) |
| 50 | + console.log('- Decoded Counter:', decodedCounterResult[0]) |
50 | 51 | console.log('- Address 1:', address1Result[0]) |
51 | 52 | console.log('- Address 2:', address2Result[0]) |
52 | 53 | console.log('- Number:', numberResult[0]) |
53 | 54 | console.log('---') |
54 | | - |
55 | | - // What we expected to send |
56 | | - console.log('Expected values:') |
57 | | - console.log('- Address 1: 0x1234567890123456789012345678901234567890') |
58 | | - console.log('- Address 2: 0x9876543210987654321098765432109876543210') |
59 | | - console.log('- Number: 123456789012345678901234567890') |
60 | | - console.log('---') |
61 | | - |
62 | | - // Analyze the decoded values |
63 | | - console.log('Analysis:') |
64 | | - |
65 | | - // Address 1 is 0x20 = 32 in decimal |
66 | | - console.log('\nAddress 1 (0x20 = 32):') |
67 | | - console.log('- This is suspiciously the standard ABI offset value') |
68 | | - console.log('- In ABI encoding, dynamic data starts with a 32-byte offset pointer') |
69 | | - |
70 | | - // Address 2 is 0xc2 = 194 in decimal |
71 | | - console.log('\nAddress 2 (0xc2 = 194):') |
72 | | - console.log('- 194 bytes = 0xc2 in hex') |
73 | | - console.log('- This might be the length of the hex string data') |
74 | | - |
75 | | - // Let's check what our actual message would look like |
76 | | - const address1 = '0x1234567890123456789012345678901234567890' |
77 | | - const address2 = '0x9876543210987654321098765432109876543210' |
78 | | - const number = ethers.BigNumber.from('123456789012345678901234567890') |
79 | | - |
80 | | - // Our packed message |
81 | | - const packedMessage = ethers.utils.solidityPack( |
82 | | - ['bytes32', 'bytes32', 'uint256'], |
83 | | - [ethers.utils.hexZeroPad(address1, 32), ethers.utils.hexZeroPad(address2, 32), number] |
84 | | - ) |
85 | | - |
86 | | - console.log('\nOur packed message:') |
87 | | - console.log('- Length:', packedMessage.length - 2, 'characters (excluding 0x)') |
88 | | - console.log('- As bytes:', (packedMessage.length - 2) / 2, 'bytes') |
89 | | - console.log('- Hex:', packedMessage) |
90 | | - |
91 | | - // ABI encoded version |
92 | | - const abiEncoded = ethers.utils.defaultAbiCoder.encode(['string'], [packedMessage]) |
93 | | - console.log('\nABI-encoded version:') |
94 | | - console.log('- Total length:', abiEncoded.length - 2, 'characters') |
95 | | - console.log('- As bytes:', (abiEncoded.length - 2) / 2, 'bytes') |
96 | | - console.log('- First 64 chars:', '0x' + abiEncoded.substring(2, 66)) |
97 | | - console.log('- Offset (first 32 bytes):', '0x' + abiEncoded.substring(2, 66)) |
98 | | - console.log('- String length (next 32 bytes):', '0x' + abiEncoded.substring(66, 130)) |
99 | | - |
100 | | - // Decode the values |
101 | | - const offset = parseInt(abiEncoded.substring(2, 66), 16) |
102 | | - const strLength = parseInt(abiEncoded.substring(66, 130), 16) |
103 | | - console.log('- Offset value:', offset, '(0x' + offset.toString(16) + ')') |
104 | | - console.log('- String length value:', strLength, '(0x' + strLength.toString(16) + ')') |
105 | | - |
106 | | - console.log('\nConclusion:') |
107 | | - console.log('The Move contract is reading the ABI encoding metadata instead of the actual data!') |
108 | | - console.log("- It's reading byte 0 as address1 (getting the offset = 0x20 = 32)") |
109 | | - console.log("- It's reading byte 32 as address2 (getting part of the length field = 0xc2 = 194)") |
110 | | - console.log('- The large number is likely from reading subsequent ABI encoding bytes') |
111 | | - console.log('\nThe contract needs to:') |
112 | | - console.log('1. Skip the ABI encoding wrapper (first 64+ bytes)') |
113 | | - console.log('2. Parse the hex string inside') |
114 | | - console.log('3. Convert the hex string to bytes') |
115 | | - console.log('4. Then decode the addresses and number from those bytes') |
116 | 55 | } |
117 | 56 |
|
118 | 57 | main().catch(console.error) |
0 commit comments