Skip to content

Commit caf5ab5

Browse files
committed
fix: remove unneeded empty bytes from callhook data
1 parent ce0d0a3 commit caf5ab5

File tree

4 files changed

+6
-24
lines changed

4 files changed

+6
-24
lines changed

contracts/gateway/L1GraphTokenGateway.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,14 @@ contract L1GraphTokenGateway is Initializable, GraphTokenGateway, L1ArbitrumMess
316316
uint256 _amount,
317317
bytes memory _data
318318
) public pure returns (bytes memory) {
319-
bytes memory emptyBytes;
320-
321319
return
322320
abi.encodeWithSelector(
323321
ITokenGateway.finalizeInboundTransfer.selector,
324322
_l1Token,
325323
_from,
326324
_to,
327325
_amount,
328-
abi.encode(emptyBytes, _data)
326+
_data
329327
);
330328
}
331329

contracts/l2/gateway/L2GraphTokenGateway.sol

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ contract L2GraphTokenGateway is GraphTokenGateway, L2ArbitrumMessenger, Reentran
171171
L2GraphToken(calculateL2TokenAddress(l1GRT)).bridgeMint(_to, _amount);
172172

173173
if (_data.length > 0) {
174-
bytes memory callhookData;
175-
{
176-
(, callhookData) = abi.decode(_data, (bytes, bytes));
177-
}
178-
ICallhookReceiver(_to).onTokenTransfer(_from, _amount, callhookData);
174+
ICallhookReceiver(_to).onTokenTransfer(_from, _amount, _data);
179175
}
180176

181177
emit DepositFinalized(_l1Token, _from, _to, _amount);

test/gateway/l1GraphTokenGateway.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,7 @@ describe('L1GraphTokenGateway', () => {
339339
const selector = l1GraphTokenGateway.interface.getSighash('finalizeInboundTransfer')
340340
const params = utils.defaultAbiCoder.encode(
341341
['address', 'address', 'address', 'uint256', 'bytes'],
342-
[
343-
grt.address,
344-
tokenSender.address,
345-
l2Receiver.address,
346-
toGRT('10'),
347-
utils.defaultAbiCoder.encode(['bytes', 'bytes'], [emptyCallHookData, callHookData]),
348-
],
342+
[grt.address, tokenSender.address, l2Receiver.address, toGRT('10'), callHookData],
349343
)
350344
const outboundData = utils.hexlify(utils.concat([selector, params]))
351345

test/l2/l2GraphTokenGateway.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ describe('L2GraphTokenGateway', () => {
3939

4040
const senderTokens = toGRT('1000')
4141
const defaultData = '0x'
42-
const notEmptyCallHookData = utils.defaultAbiCoder.encode(
42+
const defaultDataWithNotEmptyCallHookData = utils.defaultAbiCoder.encode(
4343
['uint256', 'uint256'],
4444
[toBN('1337'), toBN('42')],
4545
)
46-
const defaultDataWithNotEmptyCallHookData = utils.defaultAbiCoder.encode(
47-
['bytes', 'bytes'],
48-
['0x', notEmptyCallHookData],
49-
)
5046

5147
before(async function () {
5248
;[
@@ -419,7 +415,6 @@ describe('L2GraphTokenGateway', () => {
419415
['uint256', 'uint256'],
420416
[toBN('0'), toBN('42')],
421417
)
422-
const data = utils.defaultAbiCoder.encode(['bytes', 'bytes'], ['0x', callHookData])
423418
const mockL1GatewayL2Alias = await getL2SignerFromL1(mockL1Gateway.address)
424419
await me.signer.sendTransaction({
425420
to: await mockL1GatewayL2Alias.getAddress(),
@@ -432,13 +427,12 @@ describe('L2GraphTokenGateway', () => {
432427
tokenSender.address,
433428
callhookReceiverMock.address,
434429
toGRT('10'),
435-
data,
430+
callHookData,
436431
)
437432
await expect(tx).revertedWith('FOO_IS_ZERO')
438433
})
439434
it('reverts if trying to call a callhook in a contract that does not implement onTokenTransfer', async function () {
440435
const callHookData = utils.defaultAbiCoder.encode(['uint256'], [toBN('0')])
441-
const data = utils.defaultAbiCoder.encode(['bytes', 'bytes'], ['0x', callHookData])
442436
const mockL1GatewayL2Alias = await getL2SignerFromL1(mockL1Gateway.address)
443437
await me.signer.sendTransaction({
444438
to: await mockL1GatewayL2Alias.getAddress(),
@@ -452,7 +446,7 @@ describe('L2GraphTokenGateway', () => {
452446
tokenSender.address,
453447
rewardsManager.address,
454448
toGRT('10'),
455-
data,
449+
callHookData,
456450
)
457451
await expect(tx).revertedWith(
458452
"function selector was not recognized and there's no fallback function",

0 commit comments

Comments
 (0)