Skip to content

Commit ba05ae3

Browse files
committed
Fix ABI decoder edge cases
1 parent 0d336e1 commit ba05ae3

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎frontend/src/utils/abiDecode.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ export function decodeInputData(input: string | undefined | null, abi?: AbiItem[
3636
// Matched selector but decode failed — still return the function name
3737
return {
3838
name: item.name,
39-
args: inputs.map((inp, i) => ({
40-
name: inp.name || `arg${i}`,
41-
type: inp.type,
42-
value: `0x${calldata.slice(i * 64, (i + 1) * 64)}`,
43-
})),
39+
args: inputs.map((inp, i) => {
40+
const chunk = calldata.slice(i * 64, (i + 1) * 64).padEnd(64, '0');
41+
return {
42+
name: inp.name || `arg${i}`,
43+
type: inp.type,
44+
value: `0x${chunk}`,
45+
};
46+
}),
4447
};
4548
}
4649

@@ -95,6 +98,8 @@ function decodeType(
9598
let value = BigInt('0x' + wordHex);
9699

97100
if (!isUnsigned) {
101+
const mask = (1n << BigInt(bits)) - 1n;
102+
value &= mask;
98103
const signBit = 1n << BigInt(bits - 1);
99104
if ((value & signBit) !== 0n) {
100105
value -= 1n << BigInt(bits);

0 commit comments

Comments
 (0)