-
Notifications
You must be signed in to change notification settings - Fork 157
c4: gas optimization fixes #742
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
Changes from all commits
2c4ac9d
76865a4
18afb3a
ee5d3cb
71314dd
d5aece4
2ad9f4e
e0440a8
3805ca9
54157a7
7d29d6d
534d224
0b7ad55
d091781
1f85e12
27902cc
e3a668e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,8 @@ contract L1GraphTokenGateway is Initializable, GraphTokenGateway, L1ArbitrumMess | |
* @param _escrow Address of the BridgeEscrow | ||
*/ | ||
function setEscrowAddress(address _escrow) external onlyGovernor { | ||
require(_escrow != address(0) && Address.isContract(_escrow), "INVALID_ESCROW"); | ||
require(_escrow != address(0), "INVALID_ESCROW"); | ||
require(Address.isContract(_escrow), "MUST_BE_CONTRACT"); | ||
escrow = _escrow; | ||
emit EscrowAddressSet(_escrow); | ||
} | ||
|
@@ -202,8 +203,8 @@ contract L1GraphTokenGateway is Initializable, GraphTokenGateway, L1ArbitrumMess | |
bytes calldata _data | ||
) external payable override notPaused returns (bytes memory) { | ||
IGraphToken token = graphToken(); | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, noted to be added in a future PR |
||
require(_amount > 0, "INVALID_ZERO_AMOUNT"); | ||
require(_to != address(0), "INVALID_DESTINATION"); | ||
|
||
// nested scopes to avoid stack too deep errors | ||
|
@@ -284,7 +285,7 @@ contract L1GraphTokenGateway is Initializable, GraphTokenGateway, L1ArbitrumMess | |
* @return Base ether value required to keep retryable ticket alive | ||
* @return Additional data sent to L2 | ||
*/ | ||
function parseOutboundData(bytes memory _data) | ||
function parseOutboundData(bytes calldata _data) | ||
private | ||
view | ||
returns ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 I went with |
||
bytes32 private immutable CURATION = keccak256("Curation"); | ||
bytes32 private immutable EPOCH_MANAGER = keccak256("EpochManager"); | ||
bytes32 private immutable REWARDS_MANAGER = keccak256("RewardsManager"); | ||
bytes32 private immutable STAKING = keccak256("Staking"); | ||
bytes32 private immutable GRAPH_TOKEN = keccak256("GraphToken"); | ||
bytes32 private immutable GRAPH_TOKEN_GATEWAY = keccak256("GraphTokenGateway"); | ||
|
||
// -- Events -- | ||
|
||
event ParameterUpdated(string param); | ||
|
@@ -50,7 +58,7 @@ contract Managed { | |
} | ||
|
||
function _onlyGovernor() internal view { | ||
require(msg.sender == controller.getGovernor(), "Caller must be Controller governor"); | ||
require(msg.sender == controller.getGovernor(), "Only Controller governor"); | ||
} | ||
|
||
function _onlyController() internal view { | ||
|
@@ -111,47 +119,47 @@ contract Managed { | |
* @return Curation contract registered with Controller | ||
*/ | ||
function curation() internal view returns (ICuration) { | ||
return ICuration(_resolveContract(keccak256("Curation"))); | ||
return ICuration(_resolveContract(CURATION)); | ||
} | ||
|
||
/** | ||
* @dev Return EpochManager interface. | ||
* @return Epoch manager contract registered with Controller | ||
*/ | ||
function epochManager() internal view returns (IEpochManager) { | ||
return IEpochManager(_resolveContract(keccak256("EpochManager"))); | ||
return IEpochManager(_resolveContract(EPOCH_MANAGER)); | ||
} | ||
|
||
/** | ||
* @dev Return RewardsManager interface. | ||
* @return Rewards manager contract registered with Controller | ||
*/ | ||
function rewardsManager() internal view returns (IRewardsManager) { | ||
return IRewardsManager(_resolveContract(keccak256("RewardsManager"))); | ||
return IRewardsManager(_resolveContract(REWARDS_MANAGER)); | ||
} | ||
|
||
/** | ||
* @dev Return Staking interface. | ||
* @return Staking contract registered with Controller | ||
*/ | ||
function staking() internal view returns (IStaking) { | ||
return IStaking(_resolveContract(keccak256("Staking"))); | ||
return IStaking(_resolveContract(STAKING)); | ||
} | ||
|
||
/** | ||
* @dev Return GraphToken interface. | ||
* @return Graph token contract registered with Controller | ||
*/ | ||
function graphToken() internal view returns (IGraphToken) { | ||
return IGraphToken(_resolveContract(keccak256("GraphToken"))); | ||
return IGraphToken(_resolveContract(GRAPH_TOKEN)); | ||
} | ||
|
||
/** | ||
* @dev Return GraphTokenGateway (L1 or L2) interface. | ||
* @return Graph token gateway contract registered with Controller | ||
*/ | ||
function graphTokenGateway() internal view returns (ITokenGateway) { | ||
return ITokenGateway(_resolveContract(keccak256("GraphTokenGateway"))); | ||
return ITokenGateway(_resolveContract(GRAPH_TOKEN_GATEWAY)); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,7 @@ contract L2GraphTokenGateway is GraphTokenGateway, L2ArbitrumMessenger, Reentran | |
bytes calldata _data | ||
) public payable override notPaused nonReentrant returns (bytes memory) { | ||
require(_l1Token == l1GRT, "TOKEN_NOT_GRT"); | ||
require(_amount > 0, "INVALID_ZERO_AMOUNT"); | ||
require(_amount != 0, "INVALID_ZERO_AMOUNT"); | ||
require(msg.value == 0, "INVALID_NONZERO_VALUE"); | ||
require(_to != address(0), "INVALID_DESTINATION"); | ||
|
||
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 |
||
} | ||
ICallhookReceiver(_to).onTokenTransfer(_from, _amount, callhookData); | ||
} | ||
|
@@ -283,7 +282,7 @@ contract L2GraphTokenGateway is GraphTokenGateway, L2ArbitrumMessenger, Reentran | |
* @return Sender of the tx | ||
* @return Any other data sent to L1 | ||
*/ | ||
function parseOutboundData(bytes memory _data) private view returns (address, bytes memory) { | ||
function parseOutboundData(bytes calldata _data) private view returns (address, bytes memory) { | ||
address from; | ||
bytes memory extraData; | ||
if (msg.sender == l2Router) { | ||
|
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