Skip to content

fix: remove unneeded empty bytes from callhook data #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions contracts/gateway/L1GraphTokenGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,14 @@ contract L1GraphTokenGateway is Initializable, GraphTokenGateway, L1ArbitrumMess
uint256 _amount,
bytes memory _data
) public pure returns (bytes memory) {
bytes memory emptyBytes;

return
abi.encodeWithSelector(
ITokenGateway.finalizeInboundTransfer.selector,
_l1Token,
_from,
_to,
_amount,
abi.encode(emptyBytes, _data)
_data
);
}

Expand Down
6 changes: 1 addition & 5 deletions contracts/l2/gateway/L2GraphTokenGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ contract L2GraphTokenGateway is GraphTokenGateway, L2ArbitrumMessenger, Reentran
L2GraphToken(calculateL2TokenAddress(l1GRT)).bridgeMint(_to, _amount);

if (_data.length > 0) {
bytes memory callhookData;
{
(, callhookData) = abi.decode(_data, (bytes, bytes));
}
ICallhookReceiver(_to).onTokenTransfer(_from, _amount, callhookData);
ICallhookReceiver(_to).onTokenTransfer(_from, _amount, _data);
}

emit DepositFinalized(_l1Token, _from, _to, _amount);
Expand Down
8 changes: 1 addition & 7 deletions test/gateway/l1GraphTokenGateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,7 @@ describe('L1GraphTokenGateway', () => {
const selector = l1GraphTokenGateway.interface.getSighash('finalizeInboundTransfer')
const params = utils.defaultAbiCoder.encode(
['address', 'address', 'address', 'uint256', 'bytes'],
[
grt.address,
tokenSender.address,
l2Receiver.address,
toGRT('10'),
utils.defaultAbiCoder.encode(['bytes', 'bytes'], [emptyCallHookData, callHookData]),
],
[grt.address, tokenSender.address, l2Receiver.address, toGRT('10'), callHookData],
)
const outboundData = utils.hexlify(utils.concat([selector, params]))

Expand Down
12 changes: 3 additions & 9 deletions test/l2/l2GraphTokenGateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ describe('L2GraphTokenGateway', () => {

const senderTokens = toGRT('1000')
const defaultData = '0x'
const notEmptyCallHookData = utils.defaultAbiCoder.encode(
const defaultDataWithNotEmptyCallHookData = utils.defaultAbiCoder.encode(
['uint256', 'uint256'],
[toBN('1337'), toBN('42')],
)
const defaultDataWithNotEmptyCallHookData = utils.defaultAbiCoder.encode(
['bytes', 'bytes'],
['0x', notEmptyCallHookData],
)

before(async function () {
;[
Expand Down Expand Up @@ -419,7 +415,6 @@ describe('L2GraphTokenGateway', () => {
['uint256', 'uint256'],
[toBN('0'), toBN('42')],
)
const data = utils.defaultAbiCoder.encode(['bytes', 'bytes'], ['0x', callHookData])
const mockL1GatewayL2Alias = await getL2SignerFromL1(mockL1Gateway.address)
await me.signer.sendTransaction({
to: await mockL1GatewayL2Alias.getAddress(),
Expand All @@ -432,13 +427,12 @@ describe('L2GraphTokenGateway', () => {
tokenSender.address,
callhookReceiverMock.address,
toGRT('10'),
data,
callHookData,
)
await expect(tx).revertedWith('FOO_IS_ZERO')
})
it('reverts if trying to call a callhook in a contract that does not implement onTokenTransfer', async function () {
const callHookData = utils.defaultAbiCoder.encode(['uint256'], [toBN('0')])
const data = utils.defaultAbiCoder.encode(['bytes', 'bytes'], ['0x', callHookData])
const mockL1GatewayL2Alias = await getL2SignerFromL1(mockL1Gateway.address)
await me.signer.sendTransaction({
to: await mockL1GatewayL2Alias.getAddress(),
Expand All @@ -452,7 +446,7 @@ describe('L2GraphTokenGateway', () => {
tokenSender.address,
rewardsManager.address,
toGRT('10'),
data,
callHookData,
)
await expect(tx).revertedWith(
"function selector was not recognized and there's no fallback function",
Expand Down