Skip to content

Commit fea0b63

Browse files
Remove redundant logging and analysis from analyze-decoded-values.ts script to streamline output. The script now focuses on essential decoded values without unnecessary commentary, enhancing clarity and conciseness.
1 parent 2bcd718 commit fea0b63

1 file changed

Lines changed: 2 additions & 63 deletions

File tree

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk'
2-
import { ethers } from 'ethers'
32

43
/**
54
* Script to analyze the decoded values and understand the decoding issue
@@ -47,72 +46,12 @@ async function main() {
4746
])
4847

4948
console.log('Current decoded values:')
49+
console.log('- Counter:', counterResult[0])
50+
console.log('- Decoded Counter:', decodedCounterResult[0])
5051
console.log('- Address 1:', address1Result[0])
5152
console.log('- Address 2:', address2Result[0])
5253
console.log('- Number:', numberResult[0])
5354
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')
11655
}
11756

11857
main().catch(console.error)

0 commit comments

Comments
 (0)