Skip to content

Commit 6491392

Browse files
committed
add gas limit on L1 SentMessage; add whitelist for gas oracle contract
1 parent 1ddcd5c commit 6491392

23 files changed

+229
-106
lines changed

contracts/docs/apis/L1ScrollMessenger.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ The address of Rollup contract.
268268
function sendMessage(address _to, uint256 _value, bytes _message, uint256 _gasLimit) external payable
269269
```
270270

271-
Send cross chain message from L1 to L2.
271+
Send cross chain message from L1 to L2 or L2 to L1.
272272

273273

274274

@@ -435,7 +435,7 @@ Emitted when a cross domain message is relayed successfully.
435435
### SentMessage
436436

437437
```solidity
438-
event SentMessage(address indexed sender, address indexed target, uint256 value, uint256 messageNonce, bytes message)
438+
event SentMessage(address indexed sender, address indexed target, uint256 value, uint256 messageNonce, uint256 gasLimit, bytes message)
439439
```
440440

441441
Emitted when a cross domain message is sent.
@@ -450,6 +450,7 @@ Emitted when a cross domain message is sent.
450450
| target `indexed` | address | undefined |
451451
| value | uint256 | undefined |
452452
| messageNonce | uint256 | undefined |
453+
| gasLimit | uint256 | undefined |
453454
| message | bytes | undefined |
454455

455456
### Unpaused

contracts/docs/apis/L2ScrollMessenger.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ The address of fee vault, collecting cross domain messaging fee.
5555

5656

5757

58+
#### Returns
59+
60+
| Name | Type | Description |
61+
|---|---|---|
62+
| _0 | address | undefined |
63+
64+
### gasOracle
65+
66+
```solidity
67+
function gasOracle() external view returns (address)
68+
```
69+
70+
The address of L2MessageQueue.
71+
72+
73+
74+
5875
#### Returns
5976

6077
| Name | Type | Description |
@@ -281,7 +298,7 @@ function retryMessageWithProof(address _from, address _to, uint256 _value, uint2
281298
function sendMessage(address _to, uint256 _value, bytes _message, uint256 _gasLimit) external payable
282299
```
283300

284-
Send cross chain message from L2 to L1.
301+
Send cross chain message from L1 to L2 or L2 to L1.
285302

286303

287304

contracts/scripts/foundry/DeployL1BridgeContracts.s.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { RollupVerifier } from "../../src/libraries/verifier/RollupVerifier.sol"
1919
import { L1MessageQueue } from "../../src/L1/rollup/L1MessageQueue.sol";
2020
import { L2GasPriceOracle } from "../../src/L1/rollup/L2GasPriceOracle.sol";
2121
import { ScrollChain } from "../../src/L1/rollup/ScrollChain.sol";
22+
import { Whitelist } from "../../src/L2/predeploys/Whitelist.sol";
2223

2324
contract DeployL1BridgeContracts is Script {
2425
uint256 L1_DEPLOYER_PRIVATE_KEY = vm.envUint("L1_DEPLOYER_PRIVATE_KEY");
@@ -41,6 +42,7 @@ contract DeployL1BridgeContracts is Script {
4142
// note: the RollupVerifier library is deployed implicitly
4243

4344
deployProxyAdmin();
45+
deployL1Whitelist();
4446
deployL1MessageQueue();
4547
deployL2GasPriceOracle();
4648
deployScrollChain();
@@ -62,6 +64,13 @@ contract DeployL1BridgeContracts is Script {
6264
logAddress("L1_PROXY_ADMIN_ADDR", address(proxyAdmin));
6365
}
6466

67+
function deployL1Whitelist() internal {
68+
address owner = vm.addr(L1_DEPLOYER_PRIVATE_KEY);
69+
Whitelist whitelist = new Whitelist(owner);
70+
71+
logAddress("L1_WHITELIST_ADDR", address(whitelist));
72+
}
73+
6574
function deployScrollChain() internal {
6675
ScrollChain impl = new ScrollChain(CHAIN_ID_L2, MAX_TX_IN_ONE_BATCH, PADDING_TX_HASH);
6776
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(

contracts/scripts/foundry/DeployL2BridgeContracts.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ contract DeployL2BridgeContracts is Script {
137137
}
138138

139139
function deployL2ScrollMessenger() internal {
140-
L2ScrollMessenger impl = new L2ScrollMessenger(address(container), address(queue));
140+
L2ScrollMessenger impl = new L2ScrollMessenger(address(container), address(oracle), address(queue));
141141
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
142142
address(impl),
143143
address(proxyAdmin),

contracts/scripts/foundry/InitializeL1BridgeContracts.s.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ contract InitializeL1BridgeContracts is Script {
2323

2424
address L1_FEE_VAULT_ADDR = vm.envAddress("L1_FEE_VAULT_ADDR");
2525

26+
address L1_WHITELIST_ADDR = vm.envAddress("L1_WHITELIST_ADDR");
2627
address L1_ZK_ROLLUP_PROXY_ADDR = vm.envAddress("L1_ZK_ROLLUP_PROXY_ADDR");
2728
address L1_MESSAGE_QUEUE_PROXY_ADDR = vm.envAddress("L1_MESSAGE_QUEUE_PROXY_ADDR");
2829
address L2_GAS_PRICE_ORACLE_PROXY_ADDR = vm.envAddress("L2_GAS_PRICE_ORACLE_PROXY_ADDR");
@@ -55,6 +56,7 @@ contract InitializeL1BridgeContracts is Script {
5556

5657
// initialize L2GasPriceOracle
5758
L2GasPriceOracle(L2_GAS_PRICE_ORACLE_PROXY_ADDR).initialize();
59+
L2GasPriceOracle(L2_GAS_PRICE_ORACLE_PROXY_ADDR).updateWhitelist(L1_WHITELIST_ADDR);
5860

5961
// initialize L1MessageQueue
6062
L1MessageQueue(L1_MESSAGE_QUEUE_PROXY_ADDR).initialize(
@@ -69,6 +71,7 @@ contract InitializeL1BridgeContracts is Script {
6971
L1_ZK_ROLLUP_PROXY_ADDR,
7072
L1_MESSAGE_QUEUE_PROXY_ADDR
7173
);
74+
L1ScrollMessenger(payable(L1_SCROLL_MESSENGER_PROXY_ADDR)).updateWhitelist(L1_WHITELIST_ADDR);
7275

7376
// initialize L1GatewayRouter
7477
L1GatewayRouter(L1_GATEWAY_ROUTER_PROXY_ADDR).initialize(

contracts/scripts/foundry/InitializeL2BridgeContracts.s.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { L2WETHGateway } from "../../src/L2/gateways/L2WETHGateway.sol";
1414
import { L2MessageQueue } from "../../src/L2/predeploys/L2MessageQueue.sol";
1515
import { L2TxFeeVault } from "../../src/L2/predeploys/L2TxFeeVault.sol";
1616
import { L1BlockContainer } from "../../src/L2/predeploys/L1BlockContainer.sol";
17+
import { L1GasPriceOracle } from "../../src/L2/predeploys/L1GasPriceOracle.sol";
1718
import { Whitelist } from "../../src/L2/predeploys/Whitelist.sol";
1819
import { ScrollStandardERC20Factory } from "../../src/libraries/token/ScrollStandardERC20Factory.sol";
1920

@@ -31,6 +32,7 @@ contract InitializeL2BridgeContracts is Script {
3132

3233
address L2_TX_FEE_VAULT_ADDR = vm.envAddress("L2_TX_FEE_VAULT_ADDR");
3334
address L1_BLOCK_CONTAINER_ADDR = vm.envAddress("L1_BLOCK_CONTAINER_ADDR");
35+
address L1_GAS_PRICE_ORACLE_ADDR = vm.envAddress("L1_GAS_PRICE_ORACLE_ADDR");
3436
address L2_WHITELIST_ADDR = vm.envAddress("L2_WHITELIST_ADDR");
3537
address L2_MESSAGE_QUEUE_ADDR = vm.envAddress("L2_MESSAGE_QUEUE_ADDR");
3638

@@ -57,6 +59,9 @@ contract InitializeL2BridgeContracts is Script {
5759
// initialize L1BlockContainer
5860
L1BlockContainer(L1_BLOCK_CONTAINER_ADDR).updateWhitelist(L2_WHITELIST_ADDR);
5961

62+
// initialize L1GasPriceOracle
63+
L1GasPriceOracle(L1_GAS_PRICE_ORACLE_ADDR).updateWhitelist(L2_WHITELIST_ADDR);
64+
6065
// initialize L2ScrollMessenger
6166
L2ScrollMessenger(payable(L2_SCROLL_MESSENGER_PROXY_ADDR)).initialize(
6267
L1_SCROLL_MESSENGER_PROXY_ADDR,

contracts/src/L1/IL1ScrollMessenger.sol

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ pragma solidity ^0.8.0;
55
import { IScrollMessenger } from "../libraries/IScrollMessenger.sol";
66

77
interface IL1ScrollMessenger is IScrollMessenger {
8-
/**********
9-
* Events *
10-
**********/
11-
12-
/// @notice Emitted when a cross domain message is sent.
13-
/// @param sender The address of the sender who initiates the message.
14-
/// @param target The address of target contract to call.
15-
/// @param value The amount of value passed to the target contract.
16-
/// @param messageNonce The nonce of the message.
17-
/// @param message The calldata passed to the target contract.
18-
event SentMessage(address indexed sender, address indexed target, uint256 value, uint256 messageNonce, bytes message);
19-
208
/***********
219
* Structs *
2210
***********/
@@ -32,18 +20,6 @@ interface IL1ScrollMessenger is IScrollMessenger {
3220
* Public Mutated Functions *
3321
****************************/
3422

35-
/// @notice Send cross chain message from L1 to L2.
36-
/// @param target The address of account who recieve the message.
37-
/// @param value The amount of ether passed when call target contract.
38-
/// @param message The content of the message.
39-
/// @param gasLimit Gas limit required to complete the message relay on L2.
40-
function sendMessage(
41-
address target,
42-
uint256 value,
43-
bytes calldata message,
44-
uint256 gasLimit
45-
) external payable;
46-
4723
/// @notice Relay a L2 => L1 message with message proof.
4824
/// @param from The address of the sender of the message.
4925
/// @param to The address of the recipient of the message.

contracts/src/L1/L1ScrollMessenger.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/securit
66

77
import { IScrollChain } from "./rollup/IScrollChain.sol";
88
import { IL1MessageQueue } from "./rollup/IL1MessageQueue.sol";
9-
import { IL1ScrollMessenger, IScrollMessenger } from "./IL1ScrollMessenger.sol";
9+
import { IL1ScrollMessenger } from "./IL1ScrollMessenger.sol";
1010
import { ScrollConstants } from "../libraries/ScrollConstants.sol";
11+
import { IScrollMessenger } from "../libraries/IScrollMessenger.sol";
1112
import { ScrollMessengerBase } from "../libraries/ScrollMessengerBase.sol";
1213
import { WithdrawTrieVerifier } from "../libraries/verifier/WithdrawTrieVerifier.sol";
1314

@@ -72,7 +73,7 @@ contract L1ScrollMessenger is PausableUpgradeable, ScrollMessengerBase, IL1Scrol
7273
* Public Mutated Functions *
7374
****************************/
7475

75-
/// @inheritdoc IL1ScrollMessenger
76+
/// @inheritdoc IScrollMessenger
7677
function sendMessage(
7778
address _to,
7879
uint256 _value,
@@ -106,7 +107,7 @@ contract L1ScrollMessenger is PausableUpgradeable, ScrollMessengerBase, IL1Scrol
106107
bytes32 _xDomainCalldataHash = keccak256(_xDomainCalldata);
107108
isL1MessageSent[_xDomainCalldataHash] = true;
108109

109-
emit SentMessage(msg.sender, _to, _value, _messageNonce, _message);
110+
emit SentMessage(msg.sender, _to, _value, _messageNonce, _gasLimit, _message);
110111
}
111112

112113
/// @inheritdoc IL1ScrollMessenger

contracts/src/L1/rollup/L2GasPriceOracle.sol

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ pragma solidity ^0.8.0;
44

55
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
66

7+
import { IWhitelist } from "../../libraries/common/IWhitelist.sol";
8+
79
import { IL2GasPriceOracle } from "./IL2GasPriceOracle.sol";
810

911
contract L2GasPriceOracle is OwnableUpgradeable, IL2GasPriceOracle {
1012
/**********
1113
* Events *
1214
**********/
1315

16+
/// @notice Emitted when owner updates whitelist contract.
17+
/// @param _oldWhitelist The address of old whitelist contract.
18+
/// @param _newWhitelist The address of new whitelist contract.
19+
event UpdateWhitelist(address _oldWhitelist, address _newWhitelist);
20+
1421
/// @notice Emitted when current fee overhead is updated.
1522
/// @param overhead The current fee overhead updated.
1623
event OverheadUpdated(uint256 overhead);
@@ -51,6 +58,9 @@ contract L2GasPriceOracle is OwnableUpgradeable, IL2GasPriceOracle {
5158
/// @notice The latest known l2 base fee.
5259
uint256 public l2BaseFee;
5360

61+
/// @notice The address of whitelist contract.
62+
IWhitelist public whitelist;
63+
5464
/***************
5565
* Constructor *
5666
***************/
@@ -105,6 +115,20 @@ contract L2GasPriceOracle is OwnableUpgradeable, IL2GasPriceOracle {
105115
}
106116
}
107117

118+
/****************************
119+
* Public Mutated Functions *
120+
****************************/
121+
122+
/// @notice Allows the owner to modify the l2 base fee.
123+
/// @param _l2BaseFee The new l2 base fee.
124+
function setL2BaseFee(uint256 _l2BaseFee) external {
125+
require(whitelist.isSenderAllowed(msg.sender), "Not whitelisted sender");
126+
127+
l2BaseFee = _l2BaseFee;
128+
129+
emit L2BaseFeeUpdated(_l2BaseFee);
130+
}
131+
108132
/************************
109133
* Restricted Functions *
110134
************************/
@@ -127,11 +151,13 @@ contract L2GasPriceOracle is OwnableUpgradeable, IL2GasPriceOracle {
127151
emit ScalarUpdated(_scalar);
128152
}
129153

130-
/// Allows the owner to modify the l2 base fee.
131-
/// @param _l2BaseFee The new l2 base fee.
132-
function setL2BaseFee(uint256 _l2BaseFee) external onlyOwner {
133-
l2BaseFee = _l2BaseFee;
154+
/// @notice Update whitelist contract.
155+
/// @dev This function can only called by contract owner.
156+
/// @param _newWhitelist The address of new whitelist contract.
157+
function updateWhitelist(address _newWhitelist) external onlyOwner {
158+
address _oldWhitelist = address(whitelist);
134159

135-
emit L2BaseFeeUpdated(_l2BaseFee);
160+
whitelist = IWhitelist(_newWhitelist);
161+
emit UpdateWhitelist(_oldWhitelist, _newWhitelist);
136162
}
137163
}

contracts/src/L2/IL2ScrollMessenger.sol

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@ pragma solidity ^0.8.0;
55
import { IScrollMessenger } from "../libraries/IScrollMessenger.sol";
66

77
interface IL2ScrollMessenger is IScrollMessenger {
8-
/**********
9-
* Events *
10-
**********/
11-
12-
/// @notice Emitted when a cross domain message is sent.
13-
/// @param sender The address of the sender who initiates the message.
14-
/// @param target The address of target contract to call.
15-
/// @param value The amount of value passed to the target contract.
16-
/// @param messageNonce The nonce of the message.
17-
/// @param gasLimit The optional gas limit passed to L1.
18-
/// @param message The calldata passed to the target contract.
19-
event SentMessage(
20-
address indexed sender,
21-
address indexed target,
22-
uint256 value,
23-
uint256 messageNonce,
24-
uint256 gasLimit,
25-
bytes message
26-
);
27-
288
/***********
299
* Structs *
3010
***********/
@@ -38,18 +18,6 @@ interface IL2ScrollMessenger is IScrollMessenger {
3818
* Public Mutated Functions *
3919
****************************/
4020

41-
/// @notice Send cross chain message from L2 to L1.
42-
/// @param target The address of account who recieve the message.
43-
/// @param value The amount of ether passed when call target contract.
44-
/// @param message The content of the message.
45-
/// @param gasLimit Gas limit required to complete the message relay on L1.
46-
function sendMessage(
47-
address target,
48-
uint256 value,
49-
bytes calldata message,
50-
uint256 gasLimit
51-
) external payable;
52-
5321
/// @notice execute L1 => L2 message
5422
/// @dev Make sure this is only called by privileged accounts.
5523
/// @param from The address of the sender of the message.

0 commit comments

Comments
 (0)