Skip to content
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

Merged
merged 17 commits into from
Nov 23, 2022
Merged

c4: gas optimization fixes #742

merged 17 commits into from
Nov 23, 2022

Conversation

tmigone
Copy link
Contributor

@tmigone tmigone commented Oct 24, 2022

@tmigone tmigone changed the base branch from dev to pcv/c4-699-m149-initializers October 24, 2022 17:14
@tmigone tmigone changed the title Tmigone/c4 gas c4: gas optimization fixes Oct 24, 2022
…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]>
Copy link
Member

@pcarranzav pcarranzav left a 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

contracts/governance/Governed.sol Outdated Show resolved Hide resolved
contracts/governance/Managed.sol Outdated Show resolved Hide resolved
@tmigone
Copy link
Contributor Author

tmigone commented Oct 24, 2022

@pcarranzav wait im not done yet 😵‍💫

@tmigone tmigone marked this pull request as draft October 24, 2022 18:49
@codecov
Copy link

codecov bot commented Oct 24, 2022

Codecov Report

Base: 91.58% // Head: 91.58% // No change to project coverage 👍

Coverage data is based on head (e3a668e) compared to base (85312a0).
Patch coverage: 96.15% of modified lines in pull request are covered.

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           
Flag Coverage Δ
unittests 91.58% <96.15%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
contracts/gateway/GraphTokenGateway.sol 100.00% <ø> (ø)
contracts/governance/Managed.sol 94.54% <85.71%> (ø)
contracts/gateway/BridgeEscrow.sol 100.00% <100.00%> (ø)
contracts/gateway/L1GraphTokenGateway.sol 100.00% <100.00%> (ø)
contracts/governance/Governed.sol 100.00% <100.00%> (ø)
contracts/l2/gateway/L2GraphTokenGateway.sol 100.00% <100.00%> (ø)
contracts/l2/token/GraphTokenUpgradeable.sol 100.00% <100.00%> (ø)
contracts/l2/token/L2GraphToken.sol 100.00% <100.00%> (ø)
contracts/upgrades/GraphProxy.sol 100.00% <100.00%> (ø)
contracts/upgrades/GraphUpgradeable.sol 100.00% <100.00%> (ø)

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pcarranzav
Copy link
Member

Ah sorry I jumped the gun again @tmigone 😆

@tmigone
Copy link
Contributor Author

tmigone commented Oct 24, 2022

To be fair i didn't set it to draft :P

@tmigone tmigone marked this pull request as ready for review October 24, 2022 19:41
@tmigone tmigone requested review from pcarranzav and abarmat October 24, 2022 19:41
Copy link
Member

@pcarranzav pcarranzav left a 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 😨

@tmigone
Copy link
Contributor Author

tmigone commented Oct 24, 2022

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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:

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
Copy link
Contributor

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

Copy link
Contributor Author

@tmigone tmigone Oct 24, 2022

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.

@@ -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));
Copy link
Contributor

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?

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require(_amount != 0, "INVALID_ZERO_AMOUNT");
require(_l1Token == address(token), "TOKEN_NOT_GRT");

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?

Copy link
Member

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

Base automatically changed from pcv/c4-699-m149-initializers to pcv/l2-bridge November 23, 2022 14:24
@pcarranzav pcarranzav merged commit e3a668e into pcv/l2-bridge Nov 23, 2022
@pcarranzav pcarranzav deleted the tmigone/c4-gas branch November 23, 2022 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants