Skip to content

Commit

Permalink
Allow decoding of multiSend transactions with empty data (#1358)
Browse files Browse the repository at this point in the history
If a batched transaction of a `multiSend` contains "empty" `data`, it will be explicitly returned as `"0x"` instead of attempting to `slice` it with the same byte offsets.
  • Loading branch information
iamacook authored Apr 3, 2024
1 parent 6f31681 commit 061dd25
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,61 @@ describe('MultiSendDecoder', () => {

expect(target.mapMultiSendTransactions(data)).toStrictEqual(transactions);
});

it('maps empty multiSend transactions correctly (real world edge case)', () => {
// Sepolia txHash 0x456d10fa3aff95195177f9c6593a38c612f26854ccd4ae69dd585aa1b9486790
const example1 =
'0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000aa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
// Sepolia txHash 0xa5dd2ebff8c270268f218c70e3aaae29f9570cf2a29fb4bdb17638653852b064
const example2 =
'0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000aa0006373d5e45ad31bd354cebfa8db4ed2c75b8708e000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000006373d5e45ad31bd354cebfa8db4ed2c75b8708e00000000000000000000000000000000000000000000000000b1a2bc2ec50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
// Sepolia txHash 0x833ee631f939f149b3fe7f30beec0fb89b40ee327f84a22cc7d86eac5793b88c
const example3 =
'0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000aa0006373d5e45ad31bd354cebfa8db4ed2c75b8708e00000000000000000000000000000000000000000000000000000000001e848000000000000000000000000000000000000000000000000000000000000000000006373d5e45ad31bd354cebfa8db4ed2c75b8708e00000000000000000000000000000000000000000000000000000000001e8480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';

expect(target.mapMultiSendTransactions(example1)).toStrictEqual([
{
data: '0x',
operation: 0,
to: '0x0000000000000000000000000000000000000000',
value: BigInt('100000000000000'),
},
{
data: '0x',
operation: 0,
to: '0x0000000000000000000000000000000000000000',
value: BigInt('1000000000000000'),
},
]);
expect(target.mapMultiSendTransactions(example2)).toStrictEqual([
{
data: '0x',
operation: 0,
to: '0x06373d5e45AD31BD354CeBfA8dB4eD2c75B8708e',
value: BigInt('10000000000000000'),
},
{
data: '0x',
operation: 0,
to: '0x06373d5e45AD31BD354CeBfA8dB4eD2c75B8708e',
value: BigInt('50000000000000000'),
},
]);
expect(target.mapMultiSendTransactions(example3)).toStrictEqual([
{
data: '0x',
operation: 0,
to: '0x06373d5e45AD31BD354CeBfA8dB4eD2c75B8708e',
value: BigInt('2000000'),
},
{
data: '0x',
operation: 0,
to: '0x06373d5e45AD31BD354CeBfA8dB4eD2c75B8708e',
value: BigInt('2000000'),
},
]);
});
});

describe('isMultiSend', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/domain/contracts/decoders/multi-send-decoder.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export class MultiSendDecoder extends AbiDecoder<typeof MultiSendCallOnly130> {
(cursor += MultiSendDecoder.DATA_LENGTH_SIZE),
);

const data = slice(
transactions,
cursor,
(cursor += hexToNumber(dataLength)),
);
const dataLengthNumber = hexToNumber(dataLength);
const data =
dataLengthNumber === 0
? '0x'
: slice(transactions, cursor, (cursor += dataLengthNumber));

mapped.push({
operation: hexToNumber(operation),
Expand Down

0 comments on commit 061dd25

Please sign in to comment.