Skip to content

Add the native arbitrum bridge #6

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

Merged
merged 5 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add arbitrum L1 bridge and dependencies
  • Loading branch information
shalzz committed Dec 4, 2021
commit b4127722f4d6e440ba02d3ca5469d102565a9374
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
.yarn

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down Expand Up @@ -187,4 +188,4 @@ tags
# and uncomment the following lines
# .pnp.*

# End of https://www.toptal.com/developers/gitignore/api/vim,node,visualstudiocode,yarn
# End of https://www.toptal.com/developers/gitignore/api/vim,node,visualstudiocode,yarn
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
## 0.1.0 (2021-12-04)

- feat: add arbitrum L1 bridge and dependencies ([283e748](https://github.com/kleros/kleros-v2/commit/283e748))
- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))
- fix(IArbitrator): appeals removed from the standard ([02c20ce](https://github.com/kleros/kleros-v2/commit/02c20ce))
- fix(IArbitrator): change name to arbitration cost ([0ba4f29](https://github.com/kleros/kleros-v2/commit/0ba4f29))
- fix(IArbitrator): interface simplification ([e81fb8b](https://github.com/kleros/kleros-v2/commit/e81fb8b))
- fix(IArbitrator): replaced appealCost with fundingStatus ([f189dd9](https://github.com/kleros/kleros-v2/commit/f189dd9))
- feat: modern toolchain setup and simple RNG smart contracts ([17f6a76](https://github.com/kleros/kleros-v2/commit/17f6a76))
- feat(Arbitration): standard update ([ed930de](https://github.com/kleros/kleros-v2/commit/ed930de))
- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))
- fix(IArbitrator): appeals removed from the standard ([02c20ce](https://github.com/kleros/kleros-v2/commit/02c20ce))
- fix(IArbitrator): change name to arbitration cost ([0ba4f29](https://github.com/kleros/kleros-v2/commit/0ba4f29))
- fix(IArbitrator): interface simplification ([e81fb8b](https://github.com/kleros/kleros-v2/commit/e81fb8b))
- fix(IArbitrator): replaced appealCost with fundingStatus ([f189dd9](https://github.com/kleros/kleros-v2/commit/f189dd9))
- chore: added GitHub code scanning ([4a70475](https://github.com/kleros/kleros-v2/commit/4a70475))
- chore: added the hardhat config for layer 2 networks, added hardhat-deploy and mocha ([a12ea0e](https://github.com/kleros/kleros-v2/commit/a12ea0e))
- test: added a test for IncrementalNG ([65a996b](https://github.com/kleros/kleros-v2/commit/65a996b))
Expand Down
5 changes: 4 additions & 1 deletion contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
cache
artifacts

## Hardhat typechain bindings/types
typechain

# Hardhat deploy files
deployments/localhost
deployments/hardhat
Expand Down Expand Up @@ -170,4 +173,4 @@ tags
# .yarn/cache
# .pnp.*

# End of https://www.toptal.com/developers/gitignore/api/vim,node,visualstudiocode,yarn
# End of https://www.toptal.com/developers/gitignore/api/vim,node,visualstudiocode,yarn
2 changes: 1 addition & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {

const config: HardhatUserConfig = {
solidity: {
version: "0.8.9",
version: "0.8.10",
settings: {
optimizer: {
enabled: true,
Expand Down
57 changes: 57 additions & 0 deletions contracts/src/bridge/arbitrum/L1Bridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "./interfaces/IInbox.sol";

contract L1Bridge {
address public l2Target;
IInbox public inbox;

event RetryableTicketCreated(uint256 indexed ticketId);

constructor(address _l2Target, address _inbox) public {
l2Target = _l2Target;
inbox = IInbox(_inbox);
}

/**
* Sends an arbitrary message from one domain to another.
*
* @dev The caller needs to pay some ETH to cover the gas costs
* of the call on L2. Excess ETH that is not used by gas costs will
* be refunded to the `msg.sender` address on L2.
*
* @notice if a user does not desire immediate redemption, they should
* provide a DepositValue of at least CallValue + MaxSubmissionCost.
* If they do desire immediate execution, they should provide a DepositValue
* of at least CallValue + MaxSubmissionCost + (GasPrice x MaxGas).
*
* @param _calldata The L2 encoded message data.
* @param _maxSubmissionCost Amount of ETH allocated to pay for the base submission fee.
* The base submission fee to cover the storage costs of keeping
* their ticket’s calldata in the retry buffer.
* @param _maxGas Gas limit for immediate L2 execution attempt.
* @param _gasPriceBid L2 Gas price bid for immediate L2 execution attempt.
* @return Unique id to track the message request/transaction.
*/
function sendCrossDomainMessage(
bytes memory _calldata,
uint256 _maxSubmissionCost,
uint256 _maxGas,
uint256 _gasPriceBid
) external payable returns (uint256) {
uint256 ticketID = inbox.createRetryableTicket{value: msg.value}(
l2Target,
0,
_maxSubmissionCost,
msg.sender,
msg.sender,
_maxGas,
_gasPriceBid,
_calldata
);

emit RetryableTicketCreated(ticketID);
return ticketID;
}
}
65 changes: 65 additions & 0 deletions contracts/src/bridge/arbitrum/interfaces/IBridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2021, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pragma solidity ^0.8.0;

interface IBridge {
event MessageDelivered(
uint256 indexed messageIndex,
bytes32 indexed beforeInboxAcc,
address inbox,
uint8 kind,
address sender,
bytes32 messageDataHash
);

event BridgeCallTriggered(address indexed outbox, address indexed destAddr, uint256 amount, bytes data);

event InboxToggle(address indexed inbox, bool enabled);

event OutboxToggle(address indexed outbox, bool enabled);

function deliverMessageToInbox(
uint8 kind,
address sender,
bytes32 messageDataHash
) external payable returns (uint256);

function executeCall(
address destAddr,
uint256 amount,
bytes calldata data
) external returns (bool success, bytes memory returnData);

// These are only callable by the admin
function setInbox(address inbox, bool enabled) external;

function setOutbox(address inbox, bool enabled) external;

// View functions

function activeOutbox() external view returns (address);

function allowedInboxes(address inbox) external view returns (bool);

function allowedOutboxes(address outbox) external view returns (bool);

function inboxAccs(uint256 index) external view returns (bytes32);

function messageCount() external view returns (uint256);
}
81 changes: 81 additions & 0 deletions contracts/src/bridge/arbitrum/interfaces/IInbox.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2021, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pragma solidity ^0.8.0;

import "./IBridge.sol";
import "./IMessageProvider.sol";

interface IInbox is IMessageProvider {
function sendL2Message(bytes calldata messageData) external returns (uint256);

function sendUnsignedTransaction(
uint256 maxGas,
uint256 gasPriceBid,
uint256 nonce,
address destAddr,
uint256 amount,
bytes calldata data
) external returns (uint256);

function sendContractTransaction(
uint256 maxGas,
uint256 gasPriceBid,
address destAddr,
uint256 amount,
bytes calldata data
) external returns (uint256);

function sendL1FundedUnsignedTransaction(
uint256 maxGas,
uint256 gasPriceBid,
uint256 nonce,
address destAddr,
bytes calldata data
) external payable returns (uint256);

function sendL1FundedContractTransaction(
uint256 maxGas,
uint256 gasPriceBid,
address destAddr,
bytes calldata data
) external payable returns (uint256);

function createRetryableTicket(
address destAddr,
uint256 arbTxCallValue,
uint256 maxSubmissionCost,
address submissionRefundAddress,
address valueRefundAddress,
uint256 maxGas,
uint256 gasPriceBid,
bytes calldata data
) external payable returns (uint256);

function depositEth(uint256 maxSubmissionCost) external payable returns (uint256);

function bridge() external view returns (IBridge);

function pauseCreateRetryables() external;

function unpauseCreateRetryables() external;

function startRewriteAddress() external;

function stopRewriteAddress() external;
}
25 changes: 25 additions & 0 deletions contracts/src/bridge/arbitrum/interfaces/IMessageProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2021, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pragma solidity ^0.8.0;

interface IMessageProvider {
event InboxMessageDelivered(uint256 indexed messageNum, bytes data);

event InboxMessageDeliveredFromOrigin(uint256 indexed messageNum);
}
50 changes: 50 additions & 0 deletions contracts/src/bridge/arbitrum/interfaces/IOutbox.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2021, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pragma solidity ^0.8.0;

interface IOutbox {
event OutboxEntryCreated(
uint256 indexed batchNum,
uint256 outboxEntryIndex,
bytes32 outputRoot,
uint256 numInBatch
);
event OutBoxTransactionExecuted(
address indexed destAddr,
address indexed l2Sender,
uint256 indexed outboxEntryIndex,
uint256 transactionIndex
);

function l2ToL1Sender() external view returns (address);

function l2ToL1Block() external view returns (uint256);

function l2ToL1EthBlock() external view returns (uint256);

function l2ToL1Timestamp() external view returns (uint256);

function l2ToL1BatchNum() external view returns (uint256);

function l2ToL1OutputId() external view returns (bytes32);

function processOutgoingMessages(bytes calldata sendsData, uint256[] calldata sendLengths) external;

function outboxEntryExists(uint256 batchNum) external view returns (bool);
}
10 changes: 0 additions & 10 deletions contracts/typechain/index.ts

This file was deleted.