Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
4e9112da
Commit
4e9112da
authored
Feb 17, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Break out `perMessageReentrancyGuard` into library
parent
441bb2c0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
41 deletions
+104
-41
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+0
-1
ReentrancyGuard.sol
...contracts-bedrock/contracts/libraries/ReentrancyGuard.sol
+47
-0
ReentrancyGuard.t.sol
...es/contracts-bedrock/contracts/test/ReentrancyGuard.t.sol
+49
-0
CrossDomainMessenger.sol
...acts-bedrock/contracts/universal/CrossDomainMessenger.sol
+3
-39
check-l2.ts
packages/contracts-bedrock/tasks/check-l2.ts
+5
-1
No files found.
packages/contracts-bedrock/.gas-snapshot
View file @
4e9112da
...
@@ -239,7 +239,6 @@ MintManager_mint_Test:test_mint_moreThanCap_reverts() (gas: 142478)
...
@@ -239,7 +239,6 @@ MintManager_mint_Test:test_mint_moreThanCap_reverts() (gas: 142478)
MintManager_upgrade_Test:test_upgrade_fromNotOwner_reverts() (gas: 10929)
MintManager_upgrade_Test:test_upgrade_fromNotOwner_reverts() (gas: 10929)
MintManager_upgrade_Test:test_upgrade_fromOwner_succeeds() (gas: 23411)
MintManager_upgrade_Test:test_upgrade_fromOwner_succeeds() (gas: 23411)
MintManager_upgrade_Test:test_upgrade_toZeroAddress_reverts() (gas: 10958)
MintManager_upgrade_Test:test_upgrade_toZeroAddress_reverts() (gas: 10958)
OptimismPortal_Sherlock87_Test:test_finalizeWithdrawalTransaction_gasTooLowBrick_succeeds() (gas: 1073643)
OptimismMintableERC20_Test:test_bridge_succeeds() (gas: 7643)
OptimismMintableERC20_Test:test_bridge_succeeds() (gas: 7643)
OptimismMintableERC20_Test:test_burn_notBridge_reverts() (gas: 11142)
OptimismMintableERC20_Test:test_burn_notBridge_reverts() (gas: 11142)
OptimismMintableERC20_Test:test_burn_succeeds() (gas: 50960)
OptimismMintableERC20_Test:test_burn_succeeds() (gas: 50960)
...
...
packages/contracts-bedrock/contracts/libraries/ReentrancyGuard.sol
0 → 100644
View file @
4e9112da
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
/**
* @title ReentrancyGuard
* @notice A contract that provides custom reentrancy guard modifiers.
*/
contract ReentrancyGuard {
/**
* @notice Modifier for a per-message reentrancy guard.
*/
modifier perMessageNonReentrant(bytes32 _msgHash) {
bytes32 _hashMsgHash;
assembly {
// Re-hash the `_msgHash` with the `0xcafebabe` salt to reduce the possibility
// of collisions with existing storage slots.
mstore(0x00, _msgHash)
mstore(0x20, 0xcafebabe)
_hashMsgHash := keccak256(0x00, 0x40)
// Check if the reentrancy lock for the `_msgHash` is set. If so, revert.
if sload(_hashMsgHash) {
// MEMORY SAFETY: We're reverting, so it's fine that we're clobbering the free memory
// pointer.
// Store selector for "Error(string)" in scratch space
mstore(0x00, 0x08c379a0)
// Store pointer to the string in scratch space
mstore(0x20, 0x20)
// Add the length of the "ReentrancyGuard: reentrant call" string (31 bytes)
mstore(0x40, 0x1f)
// Store "ReentrancyGuard: reentrant call" in the zero slot
// (plus a 0 byte for padding)
mstore(0x60, 0x5265656e7472616e637947756172643a207265656e7472616e742063616c6c00)
// Revert with 'Error("ReentrancyGuard: reentrant call")'
revert(0x1c, 0x64)
}
// Trigger the reentrancy lock for `_msgHash`.
sstore(_hashMsgHash, 0x01)
}
_;
assembly {
// Clear the reentrancy lock for `_msgHash`
sstore(_hashMsgHash, 0x00)
}
}
}
packages/contracts-bedrock/contracts/test/ReentrancyGuard.t.sol
0 → 100644
View file @
4e9112da
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.15;
import { Test } from "forge-std/Test.sol";
import { ReentrancyGuard } from "../libraries/ReentrancyGuard.sol";
contract ReentrancyGuard_Test is Test {
/// @dev The message hash passed to `noReentrance`
bytes32 internal constant MSG_HASH = keccak256(abi.encode("MESSAGE_HASH"));
NonReentrant internal reentrant;
function setUp() public {
reentrant = new NonReentrant();
}
function test_perMessageNonReentrant_reverts() public {
vm.expectRevert("ReentrancyGuard: reentrant call");
reentrant.noReentrance(MSG_HASH);
}
fallback() external {
reentrant.noReentrance(MSG_HASH);
}
}
contract NonReentrant is ReentrancyGuard {
function noReentrance(bytes32 _hash) external perMessageNonReentrant(_hash) {
assembly {
let success := call(
gas(),
caller(),
0,
0,
0,
0,
0
)
returndatacopy(0x00, 0x00, returndatasize())
switch success
case 0 {
revert(0x00, returndatasize())
}
default {
return(0x00, returndatasize())
}
}
}
}
packages/contracts-bedrock/contracts/universal/CrossDomainMessenger.sol
View file @
4e9112da
...
@@ -14,6 +14,7 @@ import { SafeCall } from "../libraries/SafeCall.sol";
...
@@ -14,6 +14,7 @@ import { SafeCall } from "../libraries/SafeCall.sol";
import { Hashing } from "../libraries/Hashing.sol";
import { Hashing } from "../libraries/Hashing.sol";
import { Encoding } from "../libraries/Encoding.sol";
import { Encoding } from "../libraries/Encoding.sol";
import { Constants } from "../libraries/Constants.sol";
import { Constants } from "../libraries/Constants.sol";
import { ReentrancyGuard } from "../libraries/ReentrancyGuard.sol";
/**
/**
* @custom:legacy
* @custom:legacy
...
@@ -44,7 +45,8 @@ abstract contract CrossDomainMessenger is
...
@@ -44,7 +45,8 @@ abstract contract CrossDomainMessenger is
CrossDomainMessengerLegacySpacer,
CrossDomainMessengerLegacySpacer,
OwnableUpgradeable,
OwnableUpgradeable,
PausableUpgradeable,
PausableUpgradeable,
ReentrancyGuardUpgradeable
ReentrancyGuardUpgradeable,
ReentrancyGuard
{
{
/**
/**
* @notice Current message version identifier.
* @notice Current message version identifier.
...
@@ -176,44 +178,6 @@ abstract contract CrossDomainMessenger is
...
@@ -176,44 +178,6 @@ abstract contract CrossDomainMessenger is
*/
*/
event FailedRelayedMessage(bytes32 indexed msgHash);
event FailedRelayedMessage(bytes32 indexed msgHash);
/**
* @notice Modifier for a per-message reentrancy guard.
*/
modifier perMessageNonReentrant(bytes32 _msgHash) {
bytes32 _hashMsgHash;
assembly {
// Re-hash the `_msgHash` with the `0xcafebabe` salt to reduce the possibility
// of collisions with existing storage slots.
mstore(0x00, _msgHash)
mstore(0x20, 0xcafebabe)
_hashMsgHash := keccak256(0x00, 0x40)
// Check if the reentrancy lock for the `_msgHash` is set. If so, revert.
if sload(_hashMsgHash) {
// SAFETY: We're reverting, so it's fine that we're clobbering the free memory
// pointer.
// Store selector for "Error(string)" in scratch space
mstore(0x00, 0x08c379a0)
// Store pointer to the string in scratch space
mstore(0x20, 0x20)
// Add the length of the "ReentrancyGuard: reentrant call" string (31 bytes)
mstore(0x40, 0x1f)
// Store "ReentrancyGuard: reentrant call" in the zero slot (plus a 0 byte for padding)
mstore(0x60, 0x5265656e7472616e637947756172643a207265656e7472616e742063616c6c00)
// Revert with 'Error("ReentrancyGuard: reentrant call")'
revert(0x1c, 0x64)
}
// Trigger the reentrancy lock for `_msgHash`.
sstore(_hashMsgHash, 0x01)
}
_;
assembly {
// Clear the reentrancy lock for `_msgHash`
sstore(_hashMsgHash, 0x00)
}
}
/**
/**
* @param _otherMessenger Address of the messenger on the paired chain.
* @param _otherMessenger Address of the messenger on the paired chain.
*/
*/
...
...
packages/contracts-bedrock/tasks/check-l2.ts
View file @
4e9112da
...
@@ -242,7 +242,11 @@ const check = {
...
@@ -242,7 +242,11 @@ const check = {
signer
signer
)
)
await
assertSemver
(
L2CrossDomainMessenger
,
'
L2CrossDomainMessenger
'
,
'
1.1.0
'
)
await
assertSemver
(
L2CrossDomainMessenger
,
'
L2CrossDomainMessenger
'
,
'
1.1.0
'
)
const
xDomainMessageSenderSlot
=
await
signer
.
provider
.
getStorageAt
(
const
xDomainMessageSenderSlot
=
await
signer
.
provider
.
getStorageAt
(
predeploys
.
L2CrossDomainMessenger
,
predeploys
.
L2CrossDomainMessenger
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment