Skip to content

Commit 61bc2f3

Browse files
committed
refactor(bridge): use ArbRetryableTx#getSubmissionPrice
1 parent 457b060 commit 61bc2f3

File tree

4 files changed

+88
-17
lines changed

4 files changed

+88
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
## 0.1.0 (2021-12-04)
1+
## 0.1.0 (2021-12-10)
22

3-
- feat: add arbitrum L1 bridge and dependencies ([283e748](https://github.com/kleros/kleros-v2/commit/283e748))
4-
- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))
5-
- fix(IArbitrator): appeals removed from the standard ([02c20ce](https://github.com/kleros/kleros-v2/commit/02c20ce))
6-
- fix(IArbitrator): change name to arbitration cost ([0ba4f29](https://github.com/kleros/kleros-v2/commit/0ba4f29))
7-
- fix(IArbitrator): interface simplification ([e81fb8b](https://github.com/kleros/kleros-v2/commit/e81fb8b))
8-
- fix(IArbitrator): replaced appealCost with fundingStatus ([f189dd9](https://github.com/kleros/kleros-v2/commit/f189dd9))
3+
- refactor(bridge): use ArbRetryableTx#getSubmissionPrice ([0de6272](https://github.com/kleros/kleros-v2/commit/0de6272))
4+
- refactor(sdk): rename ([3241d10](https://github.com/kleros/kleros-v2/commit/3241d10))
5+
- feat: add arbitrum L1 bridge and dependencies ([b412772](https://github.com/kleros/kleros-v2/commit/b412772))
6+
- feat: add arbitrum L2 bridge ([457b060](https://github.com/kleros/kleros-v2/commit/457b060))
97
- feat: modern toolchain setup and simple RNG smart contracts ([17f6a76](https://github.com/kleros/kleros-v2/commit/17f6a76))
108
- feat(Arbitration): standard update ([ed930de](https://github.com/kleros/kleros-v2/commit/ed930de))
119
- fix(Arbitrator): memory to calldata ([4770b1f](https://github.com/kleros/kleros-v2/commit/4770b1f))

contracts/src/bridge/arbitrum/L1Bridge.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
// SPDX-License-Identifier: Apache-2.0
1+
// SPDX-License-Identifier: MIT
2+
23
pragma solidity ^0.8.0;
34

45
import "./interfaces/IInbox.sol";
6+
import "./interfaces/IArbRetryableTx.sol";
57

68
contract L1Bridge {
79
address public l2Target;
810
IInbox public inbox;
11+
IArbRetryableTx constant arbRetryableTx = IArbRetryableTx(address(110));
912

1013
event RetryableTicketCreated(uint256 indexed ticketId);
1114

12-
constructor(address _l2Target, address _inbox) public {
15+
constructor(address _l2Target, address _inbox) {
1316
l2Target = _l2Target;
1417
inbox = IInbox(_inbox);
1518
}
@@ -27,24 +30,21 @@ contract L1Bridge {
2730
* of at least CallValue + MaxSubmissionCost + (GasPrice x MaxGas).
2831
*
2932
* @param _calldata The L2 encoded message data.
30-
* @param _maxSubmissionCost Amount of ETH allocated to pay for the base submission fee.
31-
* The base submission fee to cover the storage costs of keeping
32-
* their ticket’s calldata in the retry buffer.
3333
* @param _maxGas Gas limit for immediate L2 execution attempt.
3434
* @param _gasPriceBid L2 Gas price bid for immediate L2 execution attempt.
3535
* @return Unique id to track the message request/transaction.
3636
*/
3737
function sendCrossDomainMessage(
3838
bytes memory _calldata,
39-
uint256 _maxSubmissionCost,
4039
uint256 _maxGas,
4140
uint256 _gasPriceBid
4241
) external payable returns (uint256) {
43-
// Perhaps Inbox#sendContractTransaction can be used here instead.
42+
(uint256 baseSubmissionCost, ) = arbRetryableTx.getSubmissionPrice(_calldata.length);
43+
4444
uint256 ticketID = inbox.createRetryableTicket{value: msg.value}(
4545
l2Target,
4646
0,
47-
_maxSubmissionCost,
47+
baseSubmissionCost,
4848
msg.sender,
4949
msg.sender,
5050
_maxGas,

contracts/src/bridge/arbitrum/L2Bridge.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// SPDX-License-Identifier: Apache-2.0
1+
// SPDX-License-Identifier: MIT
2+
23
pragma solidity ^0.8.0;
34

45
import "./interfaces/IArbSys.sol";
@@ -9,7 +10,7 @@ contract L2Bridge {
910

1011
event L2ToL1TxCreated(uint256 indexed withdrawalId);
1112

12-
constructor(address _l1Target) public {
13+
constructor(address _l1Target) {
1314
l1Target = _l1Target;
1415
}
1516

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
pragma solidity >=0.7.0;
2+
3+
/**
4+
* @title precompiled contract in every Arbitrum chain for retryable transaction related data retrieval and interactions. Exists at 0x000000000000000000000000000000000000006E
5+
*/
6+
interface IArbRetryableTx {
7+
/**
8+
* @notice Redeem a redeemable tx.
9+
* Revert if called by an L2 contract, or if txId does not exist, or if txId reverts.
10+
* If this returns, txId has been completed and is no longer available for redemption.
11+
* If this reverts, txId is still available for redemption (until it times out or is canceled).
12+
@param txId unique identifier of retryable message: keccak256(keccak256(ArbchainId, inbox-sequence-number), uint(0) )
13+
*/
14+
function redeem(bytes32 txId) external;
15+
16+
/**
17+
* @notice Return the minimum lifetime of redeemable txn.
18+
* @return lifetime in seconds
19+
*/
20+
function getLifetime() external view returns (uint256);
21+
22+
/**
23+
* @notice Return the timestamp when ticketId will age out, or zero if ticketId does not exist.
24+
* The timestamp could be in the past, because aged-out tickets might not be discarded immediately.
25+
* @param ticketId unique ticket identifier
26+
* @return timestamp for ticket's deadline
27+
*/
28+
function getTimeout(bytes32 ticketId) external view returns (uint256);
29+
30+
/**
31+
* @notice Return the price, in wei, of submitting a new retryable tx with a given calldata size.
32+
* @param calldataSize call data size to get price of (in wei)
33+
* @return (price, nextUpdateTimestamp). Price is guaranteed not to change until nextUpdateTimestamp.
34+
*/
35+
function getSubmissionPrice(uint256 calldataSize) external view returns (uint256, uint256);
36+
37+
/**
38+
* @notice Return the price, in wei, of extending the lifetime of ticketId by an additional lifetime period. Revert if ticketId doesn't exist.
39+
* @param ticketId unique ticket identifier
40+
* @return (price, nextUpdateTimestamp). Price is guaranteed not to change until nextUpdateTimestamp.
41+
*/
42+
function getKeepalivePrice(bytes32 ticketId) external view returns (uint256, uint256);
43+
44+
/**
45+
@notice Deposits callvalue into the sender's L2 account, then adds one lifetime period to the life of ticketId.
46+
* If successful, emits LifetimeExtended event.
47+
* Revert if ticketId does not exist, or if the timeout of ticketId is already at least one lifetime period in the future, or if the sender has insufficient funds (after the deposit).
48+
* @param ticketId unique ticket identifier
49+
* @return New timeout of ticketId.
50+
*/
51+
function keepalive(bytes32 ticketId) external payable returns (uint256);
52+
53+
/**
54+
* @notice Return the beneficiary of ticketId.
55+
* Revert if ticketId doesn't exist.
56+
* @param ticketId unique ticket identifier
57+
* @return address of beneficiary for ticket
58+
*/
59+
function getBeneficiary(bytes32 ticketId) external view returns (address);
60+
61+
/**
62+
* @notice Cancel ticketId and refund its callvalue to its beneficiary.
63+
* Revert if ticketId doesn't exist, or if called by anyone other than ticketId's beneficiary.
64+
* @param ticketId unique ticket identifier
65+
*/
66+
function cancel(bytes32 ticketId) external;
67+
68+
event TicketCreated(bytes32 indexed ticketId);
69+
event LifetimeExtended(bytes32 indexed ticketId, uint256 newTimeout);
70+
event Redeemed(bytes32 indexed ticketId);
71+
event Canceled(bytes32 indexed ticketId);
72+
}

0 commit comments

Comments
 (0)