Skip to content

Commit bb522a4

Browse files
authored
Merge pull request #366 from derekpierre/secreto
Signing POC
2 parents 9877bbd + 3f4cf14 commit bb522a4

24 files changed

+4997
-2137
lines changed

ape-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ ethereum:
3333
transaction_acceptance_timeout: 600 # 10 minutes
3434

3535
test:
36+
provider:
37+
chain_id: 131277322940537 # ensure ape doesn't change chain id to 1337
3638
mnemonic: test test test test test test test test test test test junk
3739
number_of_accounts: 40
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
3+
pragma solidity ^0.8.0;
4+
5+
/**
6+
* @title IL1Sender
7+
* @notice Interface for sending data to the L2 receiver contract.
8+
*/
9+
interface IL1Sender {
10+
/**
11+
* @notice Sends data to the L2 receiver contract.
12+
* @param target The address of the target contract on L2.
13+
* @param data The data to be sent to the target contract.
14+
*/
15+
function sendData(address target, bytes calldata data) external;
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
3+
pragma solidity ^0.8.0;
4+
5+
/**
6+
* @title IL2Receiver
7+
* @notice Interface for receiving data from the L1 sender contract.
8+
*/
9+
interface IL2Receiver {
10+
/**
11+
* @notice Receives data from the L1 sender contract.
12+
* @param data The data sent from the L1 sender contract.
13+
*/
14+
function recvData(bytes calldata data) external;
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
3+
pragma solidity ^0.8.0;
4+
5+
/**
6+
* @title ISigningCoordinatorChild
7+
* @notice Interface for x-chain interactions from SigningCoordinator to Child
8+
*/
9+
interface ISigningCoordinatorChild {
10+
event CohortMultisigDeployed(uint32 indexed cohortId, address multisig);
11+
event CohortMultisigUpdated(
12+
uint32 indexed cohortId,
13+
address multisig,
14+
address[] signers,
15+
uint16 threshold,
16+
bool clearSigners
17+
);
18+
19+
function deployCohortMultiSig(
20+
uint32 cohortId,
21+
address[] calldata signers,
22+
uint16 threshold
23+
) external;
24+
25+
function updateMultiSigParameters(
26+
uint32 cohortId,
27+
address[] calldata signers,
28+
uint16 threshold,
29+
bool clearSigners
30+
) external;
31+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
3+
pragma solidity ^0.8.0;
4+
5+
interface IThresholdSigningMultisig {
6+
function initialize(address[] memory, uint16, address) external;
7+
8+
function updateMultiSigParameters(
9+
address[] calldata signers,
10+
uint16 threshold,
11+
bool clearSigners
12+
) external;
13+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
6+
import "./IL1Sender.sol";
7+
import "./IL2Receiver.sol";
8+
9+
interface ICrossDomainMessenger {
10+
function sendMessage(address target, bytes calldata message, uint32 gasLimit) external;
11+
}
12+
13+
/**
14+
* @title OpL1Sender
15+
* @notice Optimism-based contract responsible for sending data
16+
* to the L2 receiver contract via the bridge messenger.
17+
*/
18+
contract OpL1Sender is IL1Sender, Initializable {
19+
ICrossDomainMessenger public immutable messenger;
20+
address public immutable dispatcher;
21+
uint32 public immutable gasLimit;
22+
IL2Receiver public l2Receiver;
23+
24+
/**
25+
* @param _dispatcher The address of the dispatcher contract.
26+
* @param _messenger The address of the CrossDomainMessenger contract.
27+
* @param _gasLimit The gas limit for the message.
28+
*/
29+
constructor(address _dispatcher, ICrossDomainMessenger _messenger, uint32 _gasLimit) {
30+
dispatcher = _dispatcher;
31+
messenger = _messenger;
32+
gasLimit = _gasLimit;
33+
}
34+
35+
function initialize(IL2Receiver _l2Receiver) external initializer {
36+
l2Receiver = _l2Receiver;
37+
}
38+
39+
/**
40+
* @notice Sends data to the L2 receiver contract via the messenger.
41+
* @param target The address of the target contract on L2.
42+
* @param data The data to be sent to the target contract.
43+
*/
44+
function sendData(address target, bytes calldata data) external {
45+
require(dispatcher == msg.sender, "Unauthorized caller");
46+
bytes memory payload = abi.encode(target, data);
47+
bytes memory callData = abi.encodeWithSelector(l2Receiver.recvData.selector, payload);
48+
messenger.sendMessage(address(l2Receiver), callData, gasLimit);
49+
}
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "./IL2Receiver.sol";
6+
7+
interface ICrossDomainMessenger {
8+
function xDomainMessageSender() external view returns (address);
9+
}
10+
11+
/**
12+
* @title OpL2Receiver
13+
* @notice Contract is used to receive data from the L1 sender contract via the bridge messenger.
14+
*/
15+
contract OpL2Receiver is IL2Receiver {
16+
address public immutable messenger;
17+
address public immutable l1Sender;
18+
19+
event Executed(address target, bytes result);
20+
21+
/**
22+
* @param _l1Sender The address of the L1 sender contract.
23+
* @param _messenger The address of the CrossDomainMessenger contract.
24+
*/
25+
constructor(address _l1Sender, address _messenger) {
26+
l1Sender = _l1Sender;
27+
messenger = _messenger;
28+
}
29+
30+
/**
31+
* @notice Receives data from the L1 sender contract via the messenger.
32+
* @param data The data sent from the L1 sender contract.
33+
*/
34+
function recvData(bytes calldata data) external {
35+
require(messenger == msg.sender, "Not from messenger");
36+
require(
37+
l1Sender == ICrossDomainMessenger(messenger).xDomainMessageSender(),
38+
"Invalid sender"
39+
);
40+
(address target, bytes memory callData) = abi.decode(data, (address, bytes));
41+
// solhint-disable-next-line avoid-low-level-calls
42+
(bool success, bytes memory result) = target.call(callData);
43+
require(success, "L2 Receiver Execution failed");
44+
45+
emit Executed(target, result);
46+
}
47+
}

0 commit comments

Comments
 (0)