Skip to content
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

ORMPUpgradeablePort #218

Merged
merged 40 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b8af70b
upgrade ormp lib
hujw77 Mar 12, 2024
c7da737
fix #204
hujw77 Mar 12, 2024
121b90c
fix #215
hujw77 Mar 12, 2024
38183da
revert
hujw77 Mar 12, 2024
2b3703e
revert
hujw77 Mar 12, 2024
0769724
refactor
hujw77 Mar 12, 2024
5124b02
doc
hujw77 Mar 12, 2024
bfc644c
retryable ormp port
hujw77 Mar 13, 2024
610ec2c
retryable ormp port
hujw77 Mar 13, 2024
5f3f38c
revert base changes
hujw77 Mar 13, 2024
b9e50a6
check auth when clear
hujw77 Mar 13, 2024
b7ea269
check auth when clear
hujw77 Mar 13, 2024
8ceb33e
prevent replay
hujw77 Mar 13, 2024
7e96fd9
prevent replay
hujw77 Mar 13, 2024
db5b55f
simply
hujw77 Mar 13, 2024
b1779dc
simply
hujw77 Mar 13, 2024
417b07c
simply
hujw77 Mar 13, 2024
5e16b34
deploy ormp ur
hujw77 Mar 13, 2024
fb9c23d
fix conflicts
hujw77 Mar 15, 2024
4d2b8c8
upgrade lib ormp
hujw77 Mar 15, 2024
ce0a1f0
fix
hujw77 Mar 18, 2024
c040b11
upgradeable and retryable ormp port
hujw77 Mar 21, 2024
74435be
retryable dapp demo
hujw77 Mar 21, 2024
33da242
upgrade lib ormp
hujw77 Mar 21, 2024
3277af9
fix test
hujw77 Mar 21, 2024
798c157
doc
hujw77 Mar 21, 2024
6829d4f
doc
hujw77 Mar 21, 2024
8da96ec
doc
hujw77 Mar 21, 2024
abf0b13
doc
hujw77 Mar 21, 2024
96aec62
doc
hujw77 Mar 21, 2024
e18e273
fix
hujw77 Mar 22, 2024
5821252
rm dones
hujw77 Mar 22, 2024
6c7a33d
clean
hujw77 Mar 22, 2024
11ddef3
clean
hujw77 Mar 22, 2024
89b337e
clean
hujw77 Mar 22, 2024
e870bcb
clean
hujw77 Mar 22, 2024
7899fda
pin solc version to 0.8.17
hujw77 Mar 22, 2024
1a1a23a
pin solc version to 0.8.17
hujw77 Mar 22, 2024
1ab078d
fix
hujw77 Mar 25, 2024
cd25955
add event
hujw77 Mar 25, 2024
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
7 changes: 4 additions & 3 deletions SUPPORTED.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## Canonical Cross-chain Deployment Addresses
| Port | Name | Canonical Cross-chain Deployment Address |
|----------|---------|--------------------------------------------|
| ORMPPort | ORMP | 0x0000000005d961F950adA391C1511c92bbc64D9F |
| Port | Name | Canonical Cross-chain Deployment Address |
|---------------------------------|------------|--------------------------------------------|
| ORMPPort | ORMP | 0x0000000005d961F950adA391C1511c92bbc64D9F |
| ORMPUpgradeableAndRetryablePort | ORMP-UR | 0x000000000EA450D971d3A68c754Fb5C212d3101b |

## Supported Chains
### Mainnet
Expand Down
20 changes: 13 additions & 7 deletions bin/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ get_uri() {
# forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[11155111,44]" $uri --chain-id 421614 --broadcast --skip-simulation --legacy
# forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[44,421614]" $uri --chain-id 11155111 --broadcast

export PORT_KEY="MULTIPORT_ADDR"
uri=$(get_uri "QmQsKZG4SSbqZ12a1VpZRsURrHbRe5mVbZZQ7GmLs42ZRN")
forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[421614,11155111]" $uri --chain-id 43 --broadcast -g 200
forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[11155111,44]" $uri --chain-id 421614 --broadcast --skip-simulation --legacy
export PORT_KEY="ORMPURPORT_ADDR"
uri=$(get_uri "QmX8rYZP1u5paFfJdaEe75DLdZXmjs8FSkC7mrN6vefc32")
# forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[421614,11155111]" $uri --chain-id 43 --broadcast -g 200
forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[11155111,44]" $uri --chain-id 421614 --broadcast --skip-simulation
forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[44,421614]" $uri --chain-id 11155111 --broadcast

forge script script/config/MultiPortConfig.s.sol:MultiPortConfig --chain-id 43 --broadcast -g 200
forge script script/config/MultiPortConfig.s.sol:MultiPortConfig --chain-id 421614 --broadcast --skip-simulation --legacy
forge script script/config/MultiPortConfig.s.sol:MultiPortConfig --chain-id 11155111 --broadcast
# export PORT_KEY="MULTIPORT_ADDR"
# uri=$(get_uri "QmQsKZG4SSbqZ12a1VpZRsURrHbRe5mVbZZQ7GmLs42ZRN")
# forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[421614,11155111]" $uri --chain-id 43 --broadcast -g 200
# forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[11155111,44]" $uri --chain-id 421614 --broadcast --skip-simulation --legacy
# forge script script/config/PortConfig.s.sol:PortConfig --sig "run(uint256[],string)" "[44,421614]" $uri --chain-id 11155111 --broadcast
#
# forge script script/config/MultiPortConfig.s.sol:MultiPortConfig --chain-id 43 --broadcast -g 200
# forge script script/config/MultiPortConfig.s.sol:MultiPortConfig --chain-id 421614 --broadcast --skip-simulation --legacy
# forge script script/config/MultiPortConfig.s.sol:MultiPortConfig --chain-id 11155111 --broadcast

# export PORT_KEY="XACCOUNTFACTORY_ADDR"
# uri=$(get_uri "QmahfNo9m9TqHUxARhug93Ubzn3HVutfQ9bDAxWq9ksJhy")
Expand Down
6 changes: 6 additions & 0 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ set -eo pipefail
# forge script script/deploy/DeployXAccountFactory.s.sol:DeployXAccountFactory --chain-id 11155111 --broadcast --verify --legacy
# forge script script/deploy/DeployXAccountFactory.s.sol:DeployXAccountFactory --chain-id 43 --broadcast --verify

# Deploy ormp port on testnet
# forge script script/deploy/DeployORMPPort.s.sol:DeployORMPPort --chain-id 43 --broadcast --verify --legacy --skip-simulation
# forge script script/deploy/DeployORMPPort.s.sol:DeployORMPPort --chain-id 421614 --broadcast --verify --legacy --skip-simulation
# forge script script/deploy/DeployORMPPort.s.sol:DeployORMPPort --chain-id 11155111 --broadcast --verify --legacy

# Deploy ormp-ur port on testnet
# forge script script/deploy/DeployORMPURPort.s.sol:DeployORMPURPort --chain-id 43 --broadcast --verify --legacy
# forge script script/deploy/DeployORMPURPort.s.sol:DeployORMPURPort --chain-id 421614 --broadcast --verify --legacy --skip-simulation
# forge script script/deploy/DeployORMPURPort.s.sol:DeployORMPURPort --chain-id 11155111 --broadcast --verify --legacy

# forge script script/deploy/DeployORMPPort.s.sol:DeployORMPPort --chain-id 1 --broadcast --verify --slow
# forge script script/deploy/DeployORMPPort.s.sol:DeployORMPPort --chain-id 44 --broadcast --verify --slow
# forge script script/deploy/DeployORMPPort.s.sol:DeployORMPPort --chain-id 46 --broadcast --verify --slow
Expand Down
2 changes: 1 addition & 1 deletion lib/ORMP
Submodule ORMP updated from 8c6361 to e0aeb2
78 changes: 78 additions & 0 deletions script/deploy/DeployORMPURPort.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {stdJson} from "forge-std/StdJson.sol";
import {Script} from "forge-std/Script.sol";
import {console2 as console} from "forge-std/console2.sol";
import {Common} from "create3-deploy/script/Common.s.sol";
import {ScriptTools} from "create3-deploy/script/ScriptTools.sol";

import "../../src/ports/ORMPUpgradeableAndRetryablePort.sol";

interface III {
function owner() external view returns (address);
function transferOwnership(address newOwner) external;
function pendingOwner() external view returns (address);
}

contract DeployORMPURPort is Common {
using stdJson for string;
using ScriptTools for string;

address ORMP;
address ADDR;
bytes32 SALT;

string c3;
string config;
string instanceId;
string outputName;
address deployer;
address dao;

function name() public pure override returns (string memory) {
return "DeployORMPURPort";
}

function setUp() public override {
super.setUp();

instanceId = vm.envOr("INSTANCE_ID", string("deploy_ormp_ur_port.c"));
outputName = "deploy_ormp_ur_port.a";
config = ScriptTools.readInput(instanceId);
c3 = ScriptTools.readInput("../c3");
ORMP = c3.readAddress(".ORMP_ADDR");
ADDR = c3.readAddress(".ORMPURPORT_ADDR");
SALT = c3.readBytes32(".ORMPURPORT_SALT");

deployer = config.readAddress(".DEPLOYER");
dao = config.readAddress(".DAO");
}

function run() public {
require(deployer == msg.sender, "!deployer");

deploy();
// setConfig();

ScriptTools.exportContract(outputName, "DAO", dao);
ScriptTools.exportContract(outputName, "ORMPUR_PORT", ADDR);
}

function deploy() public broadcast returns (address) {
string memory name_ = config.readString(".metadata.name");
bytes memory byteCode = type(ORMPPort).creationCode;
bytes memory initCode = bytes.concat(byteCode, abi.encode(deployer, ORMP, name_));
address port = _deploy3(SALT, initCode);
require(port == ADDR, "!addr");
require(III(ADDR).owner() == deployer);
console.log("ORMPPort deployed: %s", port);
return port;
}

function setConfig() public broadcast {
III(ADDR).transferOwnership(dao);
require(III(ADDR).pendingOwner() == dao, "!dao");
// TODO:: dao.acceptOwnership()
}
}
7 changes: 7 additions & 0 deletions script/input/11155111/deploy_ormp_ur_port.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"DEPLOYER": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"metadata": {
"name": "ORMP-UR"
}
}
7 changes: 7 additions & 0 deletions script/input/421614/deploy_ormp_ur_port.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"DEPLOYER": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"metadata": {
"name": "ORMP-UR"
}
}
7 changes: 7 additions & 0 deletions script/input/43/deploy_ormp_ur_port.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"DEPLOYER": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"metadata": {
"name": "ORMP-UR"
}
}
2 changes: 2 additions & 0 deletions script/input/c3.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"PORTREGISTRY_SALT": "0xa9578bb3432e82a6797cc7ff405700ed7f45aee1737bf2b9c04a6f4054723395",
"ORMPPORT_ADDR": "0x0000000005d961F950adA391C1511c92bbc64D9F",
"ORMPPORT_SALT": "0xe9cab07c7534f6d34500c7fc83b0d4205012e3e7cc3c1cf1d74f67858d413740",
"ORMPURPORT_ADDR": "0x000000000EA450D971d3A68c754Fb5C212d3101b",
"ORMPURPORT_SALT": "0x6da6ca9d7ad25e6d11f456555cdb5b4bc167bbe4788d32b39d547daccdaf24b8",
"MULTIPORT_ADDR": "0x00005e5FCC932F3a5B7A3665bC99Bab0d1Ff0477",
"MULTIPORT_SALT": "0x55dd52ed08c902216c638e6c8768264718084b250c674379327aa7e2800a9ce2",
"SAFEMSGPORTMODULE_ADDR": "0x0000BB6920aA050733b7e368FA7DF6d7FAA88142",
Expand Down
4 changes: 4 additions & 0 deletions script/output/11155111/deploy_ormp_ur_port.a-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORMPUR_PORT": "0x000000000EA450D971d3A68c754Fb5C212d3101b"
}
4 changes: 4 additions & 0 deletions script/output/421614/deploy_ormp_ur_port.a-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORMPUR_PORT": "0x000000000EA450D971d3A68c754Fb5C212d3101b"
}
4 changes: 4 additions & 0 deletions script/output/43/deploy_ormp_ur_port.a-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORMPUR_PORT": "0x000000000EA450D971d3A68c754Fb5C212d3101b"
}
10 changes: 5 additions & 5 deletions src/ports/ORMPPort.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ contract ORMPPort is Ownable2Step, Application, BaseMessagePort, PortLookup {
override
{
(uint256 gasLimit, address refund, bytes memory ormpParams) = abi.decode(params, (uint256, address, bytes));
bytes memory encoded = abi.encodeWithSelector(ORMPPort.recv.selector, fromDapp, toDapp, message);
IORMP(TRUSTED_ORMP).send{value: msg.value}(
bytes memory encoded = abi.encodeWithSelector(this.recv.selector, fromDapp, toDapp, message);
IORMP(protocol()).send{value: msg.value}(
toChainId, _checkedToPort(toChainId), gasLimit, encoded, refund, ormpParams
);
}

function recv(address fromDapp, address toDapp, bytes calldata message) external payable onlyORMP {
function recv(address fromDapp, address toDapp, bytes calldata message) public payable virtual onlyORMP {
uint256 fromChainId = _fromChainId();
require(_xmsgSender() == _checkedFromPort(fromChainId), "!auth");
_recv(fromChainId, fromDapp, toDapp, message);
Expand All @@ -68,7 +68,7 @@ contract ORMPPort is Ownable2Step, Application, BaseMessagePort, PortLookup {
returns (uint256)
{
(uint256 gasLimit,, bytes memory ormpParams) = abi.decode(params, (uint256, address, bytes));
bytes memory encoded = abi.encodeWithSelector(ORMPPort.recv.selector, msg.sender, toDapp, message);
return IORMP(TRUSTED_ORMP).fee(toChainId, address(this), gasLimit, encoded, ormpParams);
bytes memory encoded = abi.encodeWithSelector(this.recv.selector, msg.sender, toDapp, message);
return IORMP(protocol()).fee(toChainId, address(this), gasLimit, encoded, ormpParams);
}
}
82 changes: 82 additions & 0 deletions src/ports/ORMPUpgradeableAndRetryablePort.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "ORMP/src/user/UpgradeableApplication.sol";
import "./ORMPPort.sol";

contract ORMPUpgradeableAndRetryablePort is ORMPPort, UpgradeableApplication, ReentrancyGuard {
/// @dev msgHash => isDispathedInPort.
mapping(bytes32 => bool) public dones;
hujw77 marked this conversation as resolved.
Show resolved Hide resolved

event MessageDispatchedInPort(bytes32 indexed msgHash);
event ClearFailedMessage(bytes32 indexed msgHash);

constructor(address dao, address ormp, string memory name) ORMPPort(dao, ormp, name) UpgradeableApplication(ormp) {}

function protocol() public view override(Application, UpgradeableApplication) returns (address) {
return super.protocol();
}

function setORMP(address ormp) external onlyOwner {
_setORMP(ormp);
}

function retryFailedMessage(Message calldata message) external payable nonReentrant {
hujw77 marked this conversation as resolved.
Show resolved Hide resolved
bytes32 msgHash = _checkMessage(message);
(, address fromDapp, address toDapp, bytes memory payload) =
abi.decode(message.encoded, (bytes4, address, address, bytes));
_recv(message.fromChainId, fromDapp, toDapp, payload);
_markDone(msgHash);
}

function _checkMessage(Message calldata message) internal view returns (bytes32 msgHash) {
msgHash = hash(message);
require(IORMP(protocol()).dones(msgHash) == true, "!done");
hujw77 marked this conversation as resolved.
Show resolved Hide resolved
require(LOCAL_CHAINID() == message.toChainId, "!toChainId");
require(address(this) == message.to, "!to");
uint256 fromChainId = message.fromChainId;
require(message.from == _checkedFromPort(fromChainId), "!xAuth");
}
hujw77 marked this conversation as resolved.
Show resolved Hide resolved

function _markDone(bytes32 msgHash) internal {
require(dones[msgHash] == false, "done");
dones[msgHash] = true;
emit MessageDispatchedInPort(msgHash);
}

function recv(address fromDapp, address toDapp, bytes calldata message) public payable override {
super.recv(fromDapp, toDapp, message);
bytes32 msgHash = _messageId();
_markDone(msgHash);
}

function clearFailedMessage(Message calldata message) external {
bytes32 msgHash = _checkMessage(message);
(,, address toDapp,) = abi.decode(message.encoded, (bytes4, address, address, bytes));
require(toDapp == msg.sender, "!auth");
_clear(msgHash);
}

function _clear(bytes32 msgHash) internal {
require(dones[msgHash] == false, "done");
dones[msgHash] = true;
emit ClearFailedMessage(msgHash);
}
}
Loading