@arbitrum/nitro-contracts 1.0.0-beta.6 → 1.0.0-beta.7

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arbitrum/nitro-contracts",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "Layer 2 precompiles and rollup for Arbitrum Nitro",
5
5
  "author": "Offchain Labs, Inc.",
6
6
  "license": "BUSL-1.1",
@@ -7,4 +7,8 @@ pragma solidity ^0.8.0;
7
7
  interface IDelayedMessageProvider {
8
8
  /// @dev event emitted when a inbox message is added to the Bridge's delayed accumulator
9
9
  event InboxMessageDelivered(uint256 indexed messageNum, bytes data);
10
+
11
+ /// @dev event emitted when a inbox message is added to the Bridge's delayed accumulator
12
+ /// same as InboxMessageDelivered but the batch data is available in tx.input
13
+ event InboxMessageDeliveredFromOrigin(uint256 indexed messageNum);
10
14
  }
@@ -61,6 +61,7 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
61
61
  /// this modifier is not intended to use to be used for security (since this opens the allowList to
62
62
  /// a smart contract phishing risk).
63
63
  modifier onlyAllowed() {
64
+ // solhint-disable-next-line avoid-tx-origin
64
65
  if (allowListEnabled && !isAllowed[tx.origin]) revert NotAllowedOrigin(tx.origin);
65
66
  _;
66
67
  }
@@ -114,14 +115,23 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
114
115
  }
115
116
 
116
117
  /**
117
- * @dev DEPRECATED in favor of sendL2Message
118
+ * @notice Send a generic L2 message to the chain
119
+ * @dev This method is an optimization to avoid having to emit the entirety of the messageData in a log. Instead validators are expected to be able to parse the data from the transaction's input
118
120
  * @param messageData Data of the message being sent
119
121
  */
120
122
  function sendL2MessageFromOrigin(bytes calldata messageData)
121
123
  external
124
+ whenNotPaused
125
+ onlyAllowed
122
126
  returns (uint256)
123
127
  {
124
- return sendL2Message(messageData);
128
+ // solhint-disable-next-line avoid-tx-origin
129
+ if (msg.sender != tx.origin) revert NotOrigin();
130
+ if (messageData.length > MAX_DATA_SIZE)
131
+ revert DataTooLarge(messageData.length, MAX_DATA_SIZE);
132
+ uint256 msgNum = deliverToBridge(L2_MSG, msg.sender, keccak256(messageData));
133
+ emit InboxMessageDeliveredFromOrigin(msgNum);
134
+ return msgNum;
125
135
  }
126
136
 
127
137
  /**
@@ -130,7 +140,7 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
130
140
  * @param messageData Data of the message being sent
131
141
  */
132
142
  function sendL2Message(bytes calldata messageData)
133
- public
143
+ external
134
144
  override
135
145
  whenNotPaused
136
146
  onlyAllowed
@@ -461,11 +471,7 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
461
471
  ) internal returns (uint256) {
462
472
  if (_messageData.length > MAX_DATA_SIZE)
463
473
  revert DataTooLarge(_messageData.length, MAX_DATA_SIZE);
464
- uint256 msgNum = deliverToBridge(
465
- _kind,
466
- AddressAliasHelper.applyL1ToL2Alias(_sender),
467
- keccak256(_messageData)
468
- );
474
+ uint256 msgNum = deliverToBridge(_kind, _sender, keccak256(_messageData));
469
475
  emit InboxMessageDelivered(msgNum, _messageData);
470
476
  return msgNum;
471
477
  }
@@ -475,6 +481,11 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
475
481
  address sender,
476
482
  bytes32 messageDataHash
477
483
  ) internal returns (uint256) {
478
- return bridge.enqueueDelayedMessage{value: msg.value}(kind, sender, messageDataHash);
484
+ return
485
+ bridge.enqueueDelayedMessage{value: msg.value}(
486
+ kind,
487
+ AddressAliasHelper.applyL1ToL2Alias(sender),
488
+ messageDataHash
489
+ );
479
490
  }
480
491
  }
@@ -23,6 +23,7 @@ abstract contract GasRefundEnabled {
23
23
  uint256 calldataSize = 0;
24
24
  // if triggered in a contract call, the spender may be overrefunded by appending dummy data to the call
25
25
  // so we check if it is a top level call, which would mean the sender paid calldata as part of tx.input
26
+ // solhint-disable-next-line avoid-tx-origin
26
27
  if (msg.sender == tx.origin) {
27
28
  assembly {
28
29
  calldataSize := calldatasize()
@@ -28,10 +28,16 @@ contract InboxStub is IInbox {
28
28
  }
29
29
 
30
30
  /**
31
- * @dev DEPRECATED in favor of sendL2Message
31
+ * @notice Send a generic L2 message to the chain
32
+ * @dev This method is an optimization to avoid having to emit the entirety of the messageData in a log. Instead validators are expected to be able to parse the data from the transaction's input
33
+ * @param messageData Data of the message being sent
32
34
  */
33
35
  function sendL2MessageFromOrigin(bytes calldata messageData) external returns (uint256) {
34
- return sendL2Message(messageData);
36
+ // solhint-disable-next-line avoid-tx-origin
37
+ require(msg.sender == tx.origin, "origin only");
38
+ uint256 msgNum = deliverToBridge(L2_MSG, msg.sender, keccak256(messageData));
39
+ emit InboxMessageDeliveredFromOrigin(msgNum);
40
+ return msgNum;
35
41
  }
36
42
 
37
43
  /**
@@ -39,7 +45,7 @@ contract InboxStub is IInbox {
39
45
  * @dev This method can be used to send any type of message that doesn't require L1 validation
40
46
  * @param messageData Data of the message being sent
41
47
  */
42
- function sendL2Message(bytes calldata messageData) public override returns (uint256) {
48
+ function sendL2Message(bytes calldata messageData) external override returns (uint256) {
43
49
  uint256 msgNum = deliverToBridge(L2_MSG, msg.sender, keccak256(messageData));
44
50
  emit InboxMessageDelivered(msgNum, messageData);
45
51
  return msgNum;
@@ -38,7 +38,7 @@ interface ArbSys {
38
38
  * @notice Returns 0 since Nitro has no concept of storage gas
39
39
  * @return int 0
40
40
  */
41
- function getStorageGasAvailable() external returns (uint256);
41
+ function getStorageGasAvailable() external view returns (uint256);
42
42
 
43
43
  /**
44
44
  * @notice check if current call is coming from l1
@@ -623,6 +623,7 @@ contract RollupUserLogic is AbsRollupUserLogic, IRollupUser {
623
623
  function withdrawStakerFunds() external override onlyValidator whenNotPaused returns (uint256) {
624
624
  uint256 amount = withdrawFunds(msg.sender);
625
625
  // This is safe because it occurs after all checks and effects
626
+ // solhint-disable-next-line avoid-low-level-calls
626
627
  (bool success, ) = msg.sender.call{value: amount}("");
627
628
  require(success, "TRANSFER_FAILED");
628
629
  return amount;
@@ -185,6 +185,7 @@ contract ValidatorWallet is OwnableUpgradeable, DelegateCallAware, GasRefundEnab
185
185
 
186
186
  /// @dev allows the owner to withdraw eth held by this contract
187
187
  function withdrawEth(uint256 amount, address destination) external onlyOwner {
188
+ // solhint-disable-next-line avoid-low-level-calls
188
189
  (bool success, ) = destination.call{value: amount}("");
189
190
  if (!success) revert WithdrawEthFail(destination);
190
191
  }