-
Notifications
You must be signed in to change notification settings - Fork 146
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
c4: gas optimization fixes #742
Conversation
Signed-off-by: Tomás Migone <[email protected]>
… extra gas Signed-off-by: Tomás Migone <[email protected]>
…fic string literal once Signed-off-by: Tomás Migone <[email protected]>
…nt in a require() Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
…guments should be at the top of the function Signed-off-by: Tomás Migone <[email protected]>
…ak256(), should use immutable rather than constant Signed-off-by: Tomás Migone <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just a couple details
@pcarranzav wait im not done yet 😵💫 |
Codecov ReportBase: 91.58% // Head: 91.58% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## pcv/c4-699-m149-initializers #742 +/- ##
=============================================================
Coverage 91.58% 91.58%
=============================================================
Files 42 42
Lines 1997 1997
Branches 357 359 +2
=============================================================
Hits 1829 1829
Misses 168 168
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
…red to a modifier or function Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
Ah sorry I jumped the gun again @tmigone 😆 |
Signed-off-by: Tomás Migone <[email protected]>
To be fair i didn't set it to draft :P |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 💯
Would be nice to get an extra pair of eyes on the assembly changes in GraphProxy though 😨
yes, that's so scary that I wondered wether or not to include them cc @abarmat |
@@ -36,7 +36,6 @@ contract BridgeEscrow is Initializable, GraphUpgradeable, Managed { | |||
* @param _spender Address of the spender that will be revoked | |||
*/ | |||
function revokeAll(address _spender) external onlyGovernor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmigone do we have a test for calling revokeAll?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we have one here:
contracts/test/gateway/bridgeEscrow.test.ts
Lines 67 to 75 in 0f553c9
it("revokes a spender's permission to transfer GRT held by the contract", async function () { | |
await bridgeEscrow.connect(governor.signer).approveAll(spender.address) | |
await bridgeEscrow.connect(governor.signer).revokeAll(spender.address) | |
// We shouldn't be able to transfer _anything_ | |
const tx = grt | |
.connect(spender.signer) | |
.transferFrom(bridgeEscrow.address, tokenReceiver.address, BigNumber.from('1')) | |
await expect(tx).revertedWith('ERC20: transfer amount exceeds allowance') | |
}) |
@@ -28,6 +28,14 @@ contract Managed { | |||
mapping(bytes32 => address) private addressCache; | |||
uint256[10] private __gap; | |||
|
|||
// Immutables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to be immutable than const? as there are no parametrization happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case it's the same as we are using bytes32
to store the value (https://docs.soliditylang.org/en/v0.8.11/contracts.html#constant-and-immutable-state-variables).
I went with immutable
because the reports suggested it, but should be the same as far as I understand.
…y approved amount Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
Signed-off-by: Tomás Migone <[email protected]>
0f553c9
to
e3a668e
Compare
@@ -238,8 +238,7 @@ contract L2GraphTokenGateway is GraphTokenGateway, L2ArbitrumMessenger, Reentran | |||
if (_data.length > 0) { | |||
bytes memory callhookData; | |||
{ | |||
bytes memory gatewayData; | |||
(gatewayData, callhookData) = abi.decode(_data, (bytes, bytes)); | |||
(, callhookData) = abi.decode(_data, (bytes, bytes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pcarranzav do you remember the content of gatewayData? where was this coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that data is just sent by the Arbitrum router when creating the default bridge + L2 tokens, so we don't need it but we keep the format for compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in more detail:
The data is decoded here: https://github.com/OffchainLabs/arbitrum/blob/master/packages/arb-bridge-peripherals/contracts/tokenbridge/arbitrum/gateway/L2ArbitrumGateway.sol#L235-L255
And then used here: https://github.com/OffchainLabs/arbitrum/blob/master/packages/arb-bridge-peripherals/contracts/tokenbridge/arbitrum/gateway/L2ERC20Gateway.sol#L79-L102
Which then initializes the L2 token here: https://github.com/OffchainLabs/arbitrum/blob/288488a64d0510d7eb7f9f83b346fa00feb1bb02/packages/arb-bridge-peripherals/contracts/tokenbridge/arbitrum/StandardArbERC20.sol#L44-L80
require(_amount != 0, "INVALID_ZERO_AMOUNT"); | ||
require(_l1Token == address(token), "TOKEN_NOT_GRT"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to delay this check after the next line as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, noted to be added in a future PR
See https://www.notion.so/edgeandnode/Code4rena-gas-report-notes-3cae3d2fc0304724aec0311b791fa1a7 for details.