From 24aa9327375b94e7e0f63a1fed01fe34e00db5ab Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Fri, 28 Feb 2025 11:06:33 +0000 Subject: [PATCH 01/26] Update script to allow for untracked files --- script/update-socket-protocol-commit.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script/update-socket-protocol-commit.sh b/script/update-socket-protocol-commit.sh index ee25f6a..e8b21b9 100644 --- a/script/update-socket-protocol-commit.sh +++ b/script/update-socket-protocol-commit.sh @@ -1,8 +1,8 @@ #!/bin/bash -# Check if there are modified or staged files -if [[ -n $(git status --porcelain) ]]; then - echo "Error: You have uncommitted changes. Commit or stash them before running this script." +# Check for modified or staged files, but ignore untracked files +if [[ -n $(git status --porcelain | grep '^[ MRAUCD]') ]]; then + echo "Error: You have modified or staged files. Commit or stash them before running this script." exit 1 fi From 584e1362876f62384f3a26a7185e7bcea26c2db4 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Fri, 28 Feb 2025 11:06:48 +0000 Subject: [PATCH 02/26] Update socket-protocol submodule --- .gitmodules | 2 +- lib/socket-protocol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 38f7d81..5847cbd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,5 +3,5 @@ url = https://github.com/foundry-rs/forge-std [submodule "lib/socket-protocol"] path = lib/socket-protocol - url = https://github.com/SocketDotTech/socket-protocol + url = https://github.com/SocketDotTech/socket-protocol.git branch = staging diff --git a/lib/socket-protocol b/lib/socket-protocol index 4f163cd..92aaa4e 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit 4f163cd0c10d2b09b4c49d5956aea8c01687f42a +Subproject commit 92aaa4e2c1631495b51a6036a02a61803711b3d6 From a9d6ff1ba792ed26dd2709f895683759655c3a4e Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Fri, 28 Feb 2025 14:03:09 +0000 Subject: [PATCH 03/26] Update devnet addresses --- .env.sample | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.env.sample b/.env.sample index a5db2d9..8aa9c77 100644 --- a/.env.sample +++ b/.env.sample @@ -7,9 +7,9 @@ BASE_SEPOLIA_RPC="https://rpc.ankr.com/base_sepolia" # EVMx key addresses # Find the most up to date addresses in deployments/dev_addresses.json -ADDRESS_RESOLVER="0xc4AC8186Dac133Cf132bb9FC7e2675e482670047" -AUCTION_MANAGER="0x6e156147B6fe75310D001d0eb0598173FBFB98E4" -FEES_MANAGER="0x9C92cC886Fe92f7700d045580d85A4D2BF3Ebf01" +ADDRESS_RESOLVER="0xf3046B22F98C25305E8040286fB1b33378BA10a1" +AUCTION_MANAGER="0x5d6d4DCb0F719F01441377F633F3EdD186e19360" +FEES_MANAGER="0x603723100172D30171B7Fd9870ba80F8baf6FaD4" ARBITRUM_FEES_PLUG="0x89324F93d852cB4fcDC4Ee202456be466ce096bb" # Add your deployer private key here From ad49ecf3c482e8863bd993ddba91acde21bf569b Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 12:52:47 +0000 Subject: [PATCH 04/26] Fix formatting --- .../DeploymentMistakesDeployer.sol | 61 +++++-------------- src/inbox/Inbox.sol | 10 +-- src/inbox/InboxAppGateway.sol | 31 ++++------ src/robustness/IRobustnessMultichain.sol | 6 +- src/robustness/RobustnessAppGateway.sol | 8 +-- src/robustness/RobustnessDeployer.sol | 6 +- src/robustness/RobustnessMultichain.sol | 6 +- 7 files changed, 37 insertions(+), 91 deletions(-) diff --git a/src/deployment-mistakes/DeploymentMistakesDeployer.sol b/src/deployment-mistakes/DeploymentMistakesDeployer.sol index 5476d75..7ecbc88 100644 --- a/src/deployment-mistakes/DeploymentMistakesDeployer.sol +++ b/src/deployment-mistakes/DeploymentMistakesDeployer.sol @@ -5,58 +5,32 @@ import "./DeployOnchainMistakes.sol"; import "socket-protocol/contracts/base/AppDeployerBase.sol"; contract DeploymentMistakesDeployer is AppDeployerBase { - bytes32 public noPlugNoInititialize = - _createContractId("noPlugNoInititialize"); + bytes32 public noPlugNoInititialize = _createContractId("noPlugNoInititialize"); bytes32 public noPlugInitialize = _createContractId("noPlugInitialize"); bytes32 public plugNoInitialize = _createContractId("plugNoInitialize"); bytes32 public plugInitialize = _createContractId("plugInitialize"); - bytes32 public plugInitializeTwice = - _createContractId("plugInitializeTwice"); - bytes32 public plugNoInitInitialize = - _createContractId("plugNoInitInitialize"); + bytes32 public plugInitializeTwice = _createContractId("plugInitializeTwice"); + bytes32 public plugNoInitInitialize = _createContractId("plugNoInitInitialize"); - constructor( - address addressResolver_, - address auctionManager_, - bytes32 sbType_, - Fees memory fees_ - ) AppDeployerBase(addressResolver_, auctionManager_, sbType_) { - creationCodeWithArgs[noPlugNoInititialize] = abi.encodePacked( - type(NoPlugNoInititialize).creationCode - ); - creationCodeWithArgs[noPlugInitialize] = abi.encodePacked( - type(NoPlugInitialize).creationCode - ); - creationCodeWithArgs[plugNoInitialize] = abi.encodePacked( - type(PlugNoInitialize).creationCode - ); - creationCodeWithArgs[plugInitialize] = abi.encodePacked( - type(PlugInitialize).creationCode - ); - creationCodeWithArgs[plugInitializeTwice] = abi.encodePacked( - type(PlugInitializeTwice).creationCode - ); - creationCodeWithArgs[plugNoInitInitialize] = abi.encodePacked( - type(PlugNoInitInitialize).creationCode - ); + constructor(address addressResolver_, address auctionManager_, bytes32 sbType_, Fees memory fees_) + AppDeployerBase(addressResolver_, auctionManager_, sbType_) + { + creationCodeWithArgs[noPlugNoInititialize] = abi.encodePacked(type(NoPlugNoInititialize).creationCode); + creationCodeWithArgs[noPlugInitialize] = abi.encodePacked(type(NoPlugInitialize).creationCode); + creationCodeWithArgs[plugNoInitialize] = abi.encodePacked(type(PlugNoInitialize).creationCode); + creationCodeWithArgs[plugInitialize] = abi.encodePacked(type(PlugInitialize).creationCode); + creationCodeWithArgs[plugInitializeTwice] = abi.encodePacked(type(PlugInitializeTwice).creationCode); + creationCodeWithArgs[plugNoInitInitialize] = abi.encodePacked(type(PlugNoInitInitialize).creationCode); _setOverrides(fees_); } function deployContracts(uint32 chainSlug_) external async { _deploy(noPlugNoInititialize, chainSlug_, IsPlug.NO); _deploy( - noPlugInitialize, - chainSlug_, - IsPlug.NO, - abi.encodeWithSelector(NoPlugInitialize.initialise.selector, 10) + noPlugInitialize, chainSlug_, IsPlug.NO, abi.encodeWithSelector(NoPlugInitialize.initialise.selector, 10) ); _deploy(plugNoInitialize, chainSlug_, IsPlug.YES); - _deploy( - plugInitialize, - chainSlug_, - IsPlug.YES, - abi.encodeWithSelector(PlugInitialize.initialise.selector, 10) - ); + _deploy(plugInitialize, chainSlug_, IsPlug.YES, abi.encodeWithSelector(PlugInitialize.initialise.selector, 10)); _deploy( plugInitializeTwice, chainSlug_, @@ -67,11 +41,8 @@ contract DeploymentMistakesDeployer is AppDeployerBase { } function initialize(uint32 chainSlug_) public override async { - PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]) - .initialise(10); - PlugNoInitInitialize( - forwarderAddresses[plugNoInitInitialize][chainSlug_] - ).initialise(10); + PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]).initialise(10); + PlugNoInitInitialize(forwarderAddresses[plugNoInitInitialize][chainSlug_]).initialise(10); } function setFees(Fees memory fees_) public { diff --git a/src/inbox/Inbox.sol b/src/inbox/Inbox.sol index 0daf05a..47da32d 100644 --- a/src/inbox/Inbox.sol +++ b/src/inbox/Inbox.sol @@ -12,17 +12,11 @@ contract Inbox is Ownable, PlugBase { uint32 public constant PROPAGATE_TO_ANOTHER = 2; function increaseOnGateway(uint256 value_) external returns (bytes32) { - return _callAppGateway( - abi.encode(INCREASE_ON_GATEWAY, abi.encode(value_)), - bytes32(0) - ); + return _callAppGateway(abi.encode(INCREASE_ON_GATEWAY, abi.encode(value_)), bytes32(0)); } function propagateToAnother(uint32 targetChain) external returns (bytes32) { - return _callAppGateway( - abi.encode(PROPAGATE_TO_ANOTHER, abi.encode(value, targetChain)), - bytes32(0) - ); + return _callAppGateway(abi.encode(PROPAGATE_TO_ANOTHER, abi.encode(value, targetChain)), bytes32(0)); } function updateFromGateway(uint256 value_) external onlySocket { diff --git a/src/inbox/InboxAppGateway.sol b/src/inbox/InboxAppGateway.sol index 55e3caa..6ecc009 100644 --- a/src/inbox/InboxAppGateway.sol +++ b/src/inbox/InboxAppGateway.sol @@ -1,14 +1,15 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; + import "socket-protocol/contracts/base/AppGatewayBase.sol"; interface IInboxDeployer { function inbox() external pure returns (bytes32 bytecode); - function forwarderAddresses( - bytes32 contractId_, - uint32 chainSlug_ - ) external view returns (address forwarderAddress); + function forwarderAddresses(bytes32 contractId_, uint32 chainSlug_) + external + view + returns (address forwarderAddress); } interface IInbox { @@ -26,35 +27,29 @@ contract InboxAppGateway is AppGatewayBase { uint32 public constant INCREASE_ON_GATEWAY = 1; uint32 public constant PROPAGATE_TO_ANOTHER = 2; - constructor( - address addressResolver_, - address deployerContract_, - address auctionManager_, - Fees memory fees_ - ) AppGatewayBase(addressResolver_, auctionManager_) { + constructor(address addressResolver_, address deployerContract_, address auctionManager_, Fees memory fees_) + AppGatewayBase(addressResolver_, auctionManager_) + { addressResolver__.setContractsToGateways(deployerContract_); deployerAddress = deployerContract_; _setOverrides(fees_); } function updateOnchain(uint32 targetChain) public { - address inboxForwarderAddress = IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); + address inboxForwarderAddress = + IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); IInbox(inboxForwarderAddress).updateFromGateway(valueOnGateway); } - function callFromInbox( - uint32, - address, - bytes calldata payload_, - bytes32 - ) external override onlyWatcherPrecompile { + function callFromInbox(uint32, address, bytes calldata payload_, bytes32) external override onlyWatcherPrecompile { (uint32 msgType, bytes memory payload) = abi.decode(payload_, (uint32, bytes)); if (msgType == INCREASE_ON_GATEWAY) { uint256 valueOnchain = abi.decode(payload, (uint256)); valueOnGateway += valueOnchain; } else if (msgType == PROPAGATE_TO_ANOTHER) { (uint256 valueOnchain, uint32 targetChain) = abi.decode(payload, (uint256, uint32)); - address inboxForwarderAddress = IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); + address inboxForwarderAddress = + IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); IInbox(inboxForwarderAddress).updateFromGateway(valueOnchain); } else { revert("InboxGateway: invalid message type"); diff --git a/src/robustness/IRobustnessMultichain.sol b/src/robustness/IRobustnessMultichain.sol index eadbf8b..504a23f 100644 --- a/src/robustness/IRobustnessMultichain.sol +++ b/src/robustness/IRobustnessMultichain.sol @@ -12,9 +12,5 @@ interface IRobustnessMultichain { function getValue(uint256 index_) external; - function connectSocket( - address appGateway_, - address socket_, - address switchboard_ - ) external; + function connectSocket(address appGateway_, address socket_, address switchboard_) external; } diff --git a/src/robustness/RobustnessAppGateway.sol b/src/robustness/RobustnessAppGateway.sol index b385fcb..ebc7a5c 100644 --- a/src/robustness/RobustnessAppGateway.sol +++ b/src/robustness/RobustnessAppGateway.sol @@ -5,7 +5,6 @@ import "socket-protocol/contracts/base/AppGatewayBase.sol"; import "./IRobustnessMultichain.sol"; contract RobustnessAppGateway is AppGatewayBase { - uint256[] public values; uint256[] public resolveTimes = new uint256[](10); @@ -86,12 +85,7 @@ contract RobustnessAppGateway is AppGatewayBase { function triggerTimeouts() public { for (uint256 i = 0; i < timeoutDurations.length; i++) { watcherPrecompile__().setTimeout( - address(this), - abi.encodeWithSelector( - this.resolveTimeout.selector, - i - ), - timeoutDurations[i] + address(this), abi.encodeWithSelector(this.resolveTimeout.selector, i), timeoutDurations[i] ); } } diff --git a/src/robustness/RobustnessDeployer.sol b/src/robustness/RobustnessDeployer.sol index 01d9250..0d69e0b 100644 --- a/src/robustness/RobustnessDeployer.sol +++ b/src/robustness/RobustnessDeployer.sol @@ -18,9 +18,9 @@ contract RobustnessDeployer is AppDeployerBase { _deploy(multichain, chainSlug_, IsPlug.YES); } - function initialize(uint32) public pure override { - return; - } + function initialize(uint32) public pure override { + return; + } function setFees(Fees memory fees_) public { fees = fees_; diff --git a/src/robustness/RobustnessMultichain.sol b/src/robustness/RobustnessMultichain.sol index 1f657df..669a2e5 100644 --- a/src/robustness/RobustnessMultichain.sol +++ b/src/robustness/RobustnessMultichain.sol @@ -30,11 +30,7 @@ contract RobustnessMultichain is PlugBase { return values[index_]; } - function connectSocket( - address appGateway_, - address socket_, - address switchboard_ - ) external { + function connectSocket(address appGateway_, address socket_, address switchboard_) external { _connectSocket(appGateway_, socket_, switchboard_); } } From a6510b98ff8a77f607321880afd4cd1546813fcf Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 12:53:35 +0000 Subject: [PATCH 05/26] Fix remappings --- remappings.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/remappings.txt b/remappings.txt index 9b23047..4c31fa1 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,5 +1,3 @@ -ds-test/=lib/socket-protocol/lib/forge-std/lib/ds-test/src/ -forge-std/=lib/forge-std/src/ +forge-std/=lib/socket-protocol/lib/forge-std/src/ socket-protocol/=lib/socket-protocol/ solady/=lib/socket-protocol/lib/solady/src/ -solmate/=lib/socket-protocol/lib/solmate/src/ From 223e65d23094f9f93db4a8a295e013160b4893b6 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 12:55:16 +0000 Subject: [PATCH 06/26] Remove Auction manager from .env.sample --- .env.sample | 1 - 1 file changed, 1 deletion(-) diff --git a/.env.sample b/.env.sample index 8aa9c77..7baff03 100644 --- a/.env.sample +++ b/.env.sample @@ -8,7 +8,6 @@ BASE_SEPOLIA_RPC="https://rpc.ankr.com/base_sepolia" # EVMx key addresses # Find the most up to date addresses in deployments/dev_addresses.json ADDRESS_RESOLVER="0xf3046B22F98C25305E8040286fB1b33378BA10a1" -AUCTION_MANAGER="0x5d6d4DCb0F719F01441377F633F3EdD186e19360" FEES_MANAGER="0x603723100172D30171B7Fd9870ba80F8baf6FaD4" ARBITRUM_FEES_PLUG="0x89324F93d852cB4fcDC4Ee202456be466ce096bb" From a302f09f3301e506babc706e1d141dff819f8d47 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:24:04 +0000 Subject: [PATCH 07/26] Update socket-protocol lib --- lib/socket-protocol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/socket-protocol b/lib/socket-protocol index 92aaa4e..f80efc9 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit 92aaa4e2c1631495b51a6036a02a61803711b3d6 +Subproject commit f80efc9db00288d91a83c33e761d02f522303f37 From 54e0637bc945b1d65e3494aa74a5ea56cfb836ca Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:25:09 +0000 Subject: [PATCH 08/26] Merge Deployer to AppGateway --- script/SetupScript.sol | 12 ++--- .../DeployEVMxDeploymentMistakesApp.s.sol | 23 +-------- .../RunEVMxDeploymentMistakes.s.sol | 20 +++----- script/inbox/DeployEVMxInbox.s.sol | 7 +-- script/inbox/RunEVMxInbox.s.sol | 15 ++---- script/robust/DeployEVMxRobustnessTests.sol | 8 +-- script/robust/RunEVMxRobustness.s.sol | 11 +--- .../DeploymentMistakesAppGateway.sol | 39 ++++++++++++-- .../DeploymentMistakesDeployer.sol | 51 ------------------- src/inbox/InboxAppGateway.sol | 19 ++++--- src/inbox/InboxDeployer.sol | 28 ---------- src/robustness/RobustnessAppGateway.sol | 16 ++++-- src/robustness/RobustnessDeployer.sol | 28 ---------- 13 files changed, 80 insertions(+), 197 deletions(-) delete mode 100644 src/deployment-mistakes/DeploymentMistakesDeployer.sol delete mode 100644 src/inbox/InboxDeployer.sol delete mode 100644 src/robustness/RobustnessDeployer.sol diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 192fc36..3d1ceff 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -3,18 +3,15 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {DepositFees} from "socket-protocol/script/PayFeesInArbitrumETH.s.sol"; +import {DepositFees} from "socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol"; import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; import {FeesPlug} from "socket-protocol/contracts/protocol/payload-delivery/FeesPlug.sol"; import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; -import {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/app-gateway/FeesManager.sol"; +import {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/FeesManager.sol"; interface IAppGateway { - function withdrawFeeTokens(uint32 chainId, address token, uint256 amount, address recipient) external; -} - -interface IDeployer { function deployContracts(uint32 chainId) external; + function withdrawFeeTokens(uint32 chainId, address token, uint256 amount, address recipient) external; } abstract contract SetupScript is Script { @@ -96,7 +93,7 @@ abstract contract SetupScript is Script { vm.startBroadcast(privateKey); for (uint256 i = 0; i < chainIds.length; i++) { - IDeployer(deployer()).deployContracts(chainIds[i]); + IAppGateway(appGateway()).deployContracts(chainIds[i]); } vm.stopBroadcast(); @@ -105,7 +102,6 @@ abstract contract SetupScript is Script { // Abstract functions to be implemented by child contracts function appGateway() internal view virtual returns (address); - function deployer() internal view virtual returns (address); // Standard flow // Each implementation script will call these functions diff --git a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol index d7cba33..451deb3 100644 --- a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol +++ b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol @@ -7,12 +7,10 @@ import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol" import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol"; -import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.sol"; contract DeployEVMxContracts is Script { function run() external { address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - address auctionManager = vm.envAddress("AUCTION_MANAGER"); string memory rpc = vm.envString("EVMX_RPC"); vm.createSelectFork(rpc); @@ -21,28 +19,9 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - DeploymentMistakesDeployer deployer = - new DeploymentMistakesDeployer(addressResolver, auctionManager, FAST, fees); - - DeploymentMistakesAppGateway gateway = - new DeploymentMistakesAppGateway(addressResolver, address(deployer), auctionManager, fees); + DeploymentMistakesAppGateway gateway = new DeploymentMistakesAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("DeploymentMistakesDeployer:", address(deployer)); console.log("DeploymentMistakesAppGateway:", address(gateway)); - - console.log("DeploymentMistakesDeployer contract ids:"); - console.log("noPlugNoInititialize"); - console.logBytes32(deployer.noPlugNoInititialize()); - console.log("noPlugInitialize"); - console.logBytes32(deployer.noPlugInitialize()); - console.log("plugNoInitialize"); - console.logBytes32(deployer.plugNoInitialize()); - console.log("plugInitialize"); - console.logBytes32(deployer.plugInitialize()); - console.log("plugInitializeTwice"); - console.logBytes32(deployer.plugInitializeTwice()); - console.log("plugNoInitInitialize"); - console.logBytes32(deployer.plugNoInitInitialize()); } } diff --git a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol index 7e9d680..67ebcc1 100644 --- a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol +++ b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.0; import {console} from "forge-std/console.sol"; import {SetupScript} from "../SetupScript.sol"; import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol"; -import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.sol"; import { NoPlugNoInititialize, NoPlugInitialize, @@ -15,7 +14,6 @@ import { } from "../../src/deployment-mistakes/DeployOnchainMistakes.sol"; contract RunEVMxDeploymentMistakes is SetupScript { - DeploymentMistakesDeployer mistakesDeployer; DeploymentMistakesAppGateway mistakesAppGateway; address noPlugNoInititializeForwarder; address noPlugInitializeForwarder; @@ -28,34 +26,31 @@ contract RunEVMxDeploymentMistakes is SetupScript { return address(mistakesAppGateway); } - function deployer() internal view override returns (address) { - return address(mistakesDeployer); - } - function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); noPlugNoInititializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.noPlugNoInititialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.noPlugNoInititialize(), arbSepChainId); console.log("No Plug No Init Forwarder:", noPlugNoInititializeForwarder); noPlugInitializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.noPlugInitialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.noPlugInitialize(), arbSepChainId); console.log("No Plug Init Forwarder:", noPlugInitializeForwarder); plugNoInitializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.plugNoInitialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugNoInitialize(), arbSepChainId); console.log("Plug No Init Forwarder:", plugNoInitializeForwarder); - plugInitializeForwarder = mistakesDeployer.forwarderAddresses(mistakesDeployer.plugInitialize(), arbSepChainId); + plugInitializeForwarder = + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugInitialize(), arbSepChainId); console.log("Plug Init Forwarder:", plugInitializeForwarder); plugInitializeTwiceForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.plugInitializeTwice(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugInitializeTwice(), arbSepChainId); console.log("Plug Init Init Forwarder:", plugInitializeTwiceForwarder); plugNoInitInitializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.plugNoInitInitialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugNoInitInitialize(), arbSepChainId); console.log("Plug No Init Init Forwarder:", plugNoInitInitializeForwarder); } @@ -107,7 +102,6 @@ contract RunEVMxDeploymentMistakes is SetupScript { function executeScriptSpecificLogic() internal override { // Initialize contract references - mistakesDeployer = DeploymentMistakesDeployer(deployerAddress); mistakesAppGateway = DeploymentMistakesAppGateway(appGatewayAddress); // Deploy only to Arbitrum Sepolia diff --git a/script/inbox/DeployEVMxInbox.s.sol b/script/inbox/DeployEVMxInbox.s.sol index 68da615..a1b104f 100644 --- a/script/inbox/DeployEVMxInbox.s.sol +++ b/script/inbox/DeployEVMxInbox.s.sol @@ -7,12 +7,10 @@ import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol" import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {InboxAppGateway} from "../../src/inbox/InboxAppGateway.sol"; -import {InboxDeployer} from "../../src/inbox/InboxDeployer.sol"; contract DeployEVMxContracts is Script { function run() external { address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - address auctionManager = vm.envAddress("AUCTION_MANAGER"); string memory rpc = vm.envString("EVMX_RPC"); vm.createSelectFork(rpc); @@ -21,12 +19,9 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - InboxDeployer deployer = new InboxDeployer(addressResolver, auctionManager, FAST, fees); - - InboxAppGateway gateway = new InboxAppGateway(addressResolver, address(deployer), auctionManager, fees); + InboxAppGateway gateway = new InboxAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("Deployer:", address(deployer)); console.log("AppGateway:", address(gateway)); } } diff --git a/script/inbox/RunEVMxInbox.s.sol b/script/inbox/RunEVMxInbox.s.sol index 8535c55..119a9e1 100644 --- a/script/inbox/RunEVMxInbox.s.sol +++ b/script/inbox/RunEVMxInbox.s.sol @@ -3,11 +3,9 @@ pragma solidity ^0.8.0; import {console} from "forge-std/console.sol"; import {SetupScript} from "../SetupScript.sol"; -import {InboxDeployer} from "../../src/inbox/InboxDeployer.sol"; import {InboxAppGateway, IInbox} from "../../src/inbox/InboxAppGateway.sol"; contract RunEVMxInbox is SetupScript { - InboxDeployer inboxDeployer; InboxAppGateway inboxAppGateway; address opSepForwarder; address arbSepForwarder; @@ -16,22 +14,18 @@ contract RunEVMxInbox is SetupScript { return address(inboxAppGateway); } - function deployer() internal view override returns (address) { - return address(inboxDeployer); - } - function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); - opSepForwarder = inboxDeployer.forwarderAddresses(inboxDeployer.inbox(), opSepChainId); - arbSepForwarder = inboxDeployer.forwarderAddresses(inboxDeployer.inbox(), arbSepChainId); + opSepForwarder = inboxAppGateway.forwarderAddresses(inboxAppGateway.inbox(), opSepChainId); + arbSepForwarder = inboxAppGateway.forwarderAddresses(inboxAppGateway.inbox(), arbSepChainId); console.log("Optimism Sepolia Forwarder:", opSepForwarder); console.log("Arbitrum Sepolia Forwarder:", arbSepForwarder); } function inboxTransactions() internal { - address opSepInboxAddress = inboxDeployer.getOnChainAddress(inboxDeployer.inbox(), opSepChainId); - address arbSepInboxAddress = inboxDeployer.getOnChainAddress(inboxDeployer.inbox(), arbSepChainId); + address opSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), opSepChainId); + address arbSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), arbSepChainId); vm.createSelectFork(rpcEVMx); vm.startBroadcast(privateKey); @@ -49,7 +43,6 @@ contract RunEVMxInbox is SetupScript { function executeScriptSpecificLogic() internal override { // Initialize contract references - inboxDeployer = InboxDeployer(deployerAddress); inboxAppGateway = InboxAppGateway(appGatewayAddress); // Deploy to both test chains diff --git a/script/robust/DeployEVMxRobustnessTests.sol b/script/robust/DeployEVMxRobustnessTests.sol index 4e57518..b0383fe 100644 --- a/script/robust/DeployEVMxRobustnessTests.sol +++ b/script/robust/DeployEVMxRobustnessTests.sol @@ -6,13 +6,11 @@ import {console} from "forge-std/console.sol"; import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; -import {RobustnessDeployer} from "../../src/robustness/RobustnessDeployer.sol"; import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol"; contract DeployEVMxContracts is Script { function run() external { address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - address auctionManager = vm.envAddress("AUCTION_MANAGER"); string memory rpc = vm.envString("EVMX_RPC"); vm.createSelectFork(rpc); @@ -21,13 +19,9 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - RobustnessDeployer deployer = new RobustnessDeployer(addressResolver, auctionManager, FAST, fees); - - RobustnessAppGateway gateway = - new RobustnessAppGateway(addressResolver, address(deployer), auctionManager, fees); + RobustnessAppGateway gateway = new RobustnessAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("Deployer:", address(deployer)); console.log("AppGateway:", address(gateway)); } } diff --git a/script/robust/RunEVMxRobustness.s.sol b/script/robust/RunEVMxRobustness.s.sol index e819cb7..f2d6325 100644 --- a/script/robust/RunEVMxRobustness.s.sol +++ b/script/robust/RunEVMxRobustness.s.sol @@ -3,11 +3,9 @@ pragma solidity ^0.8.0; import {console} from "forge-std/console.sol"; import {SetupScript} from "../SetupScript.sol"; -import {RobustnessDeployer} from "../../src/robustness/RobustnessDeployer.sol"; import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol"; contract RunEVMxRobustness is SetupScript { - RobustnessDeployer robustnessDeployer; RobustnessAppGateway robustnessAppGateway; address opSepForwarder; address arbSepForwarder; @@ -16,14 +14,10 @@ contract RunEVMxRobustness is SetupScript { return address(robustnessAppGateway); } - function deployer() internal view override returns (address) { - return address(robustnessDeployer); - } - function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); - opSepForwarder = robustnessDeployer.forwarderAddresses(robustnessDeployer.multichain(), opSepChainId); - arbSepForwarder = robustnessDeployer.forwarderAddresses(robustnessDeployer.multichain(), arbSepChainId); + opSepForwarder = robustnessAppGateway.forwarderAddresses(robustnessAppGateway.multichain(), opSepChainId); + arbSepForwarder = robustnessAppGateway.forwarderAddresses(robustnessAppGateway.multichain(), arbSepChainId); console.log("Optimism Sepolia Forwarder:", opSepForwarder); console.log("Arbitrum Sepolia Forwarder:", arbSepForwarder); @@ -98,7 +92,6 @@ contract RunEVMxRobustness is SetupScript { function executeScriptSpecificLogic() internal override { // Initialize contract references - robustnessDeployer = RobustnessDeployer(deployerAddress); robustnessAppGateway = RobustnessAppGateway(appGatewayAddress); // Deploy to both test chains diff --git a/src/deployment-mistakes/DeploymentMistakesAppGateway.sol b/src/deployment-mistakes/DeploymentMistakesAppGateway.sol index 98b1b47..fa350dc 100644 --- a/src/deployment-mistakes/DeploymentMistakesAppGateway.sol +++ b/src/deployment-mistakes/DeploymentMistakesAppGateway.sol @@ -5,13 +5,44 @@ import "socket-protocol/contracts/base/AppGatewayBase.sol"; import "./DeployOnchainMistakes.sol"; contract DeploymentMistakesAppGateway is AppGatewayBase { - constructor(address addressResolver_, address deployerContract_, address auctionManager_, Fees memory fees_) - AppGatewayBase(addressResolver_, auctionManager_) - { - addressResolver__.setContractsToGateways(deployerContract_); + bytes32 public noPlugNoInititialize = _createContractId("noPlugNoInititialize"); + bytes32 public noPlugInitialize = _createContractId("noPlugInitialize"); + bytes32 public plugNoInitialize = _createContractId("plugNoInitialize"); + bytes32 public plugInitialize = _createContractId("plugInitialize"); + bytes32 public plugInitializeTwice = _createContractId("plugInitializeTwice"); + bytes32 public plugNoInitInitialize = _createContractId("plugNoInitInitialize"); + + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[noPlugNoInititialize] = abi.encodePacked(type(NoPlugNoInititialize).creationCode); + creationCodeWithArgs[noPlugInitialize] = abi.encodePacked(type(NoPlugInitialize).creationCode); + creationCodeWithArgs[plugNoInitialize] = abi.encodePacked(type(PlugNoInitialize).creationCode); + creationCodeWithArgs[plugInitialize] = abi.encodePacked(type(PlugInitialize).creationCode); + creationCodeWithArgs[plugInitializeTwice] = abi.encodePacked(type(PlugInitializeTwice).creationCode); + creationCodeWithArgs[plugNoInitInitialize] = abi.encodePacked(type(PlugNoInitInitialize).creationCode); _setOverrides(fees_); } + function deployContracts(uint32 chainSlug_) external async { + _deploy(noPlugNoInititialize, chainSlug_, IsPlug.NO); + _deploy( + noPlugInitialize, chainSlug_, IsPlug.NO, abi.encodeWithSelector(NoPlugInitialize.initialise.selector, 10) + ); + _deploy(plugNoInitialize, chainSlug_, IsPlug.YES); + _deploy(plugInitialize, chainSlug_, IsPlug.YES, abi.encodeWithSelector(PlugInitialize.initialise.selector, 10)); + _deploy( + plugInitializeTwice, + chainSlug_, + IsPlug.YES, + abi.encodeWithSelector(PlugInitializeTwice.initialise.selector, 10) + ); + _deploy(plugNoInitInitialize, chainSlug_, IsPlug.YES); + } + + function initialize(uint32 chainSlug_) public override async { + PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]).initialise(10); + PlugNoInitInitialize(forwarderAddresses[plugNoInitInitialize][chainSlug_]).initialise(10); + } + function setFees(Fees memory fees_) public { fees = fees_; } diff --git a/src/deployment-mistakes/DeploymentMistakesDeployer.sol b/src/deployment-mistakes/DeploymentMistakesDeployer.sol deleted file mode 100644 index 7ecbc88..0000000 --- a/src/deployment-mistakes/DeploymentMistakesDeployer.sol +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -import "./DeployOnchainMistakes.sol"; -import "socket-protocol/contracts/base/AppDeployerBase.sol"; - -contract DeploymentMistakesDeployer is AppDeployerBase { - bytes32 public noPlugNoInititialize = _createContractId("noPlugNoInititialize"); - bytes32 public noPlugInitialize = _createContractId("noPlugInitialize"); - bytes32 public plugNoInitialize = _createContractId("plugNoInitialize"); - bytes32 public plugInitialize = _createContractId("plugInitialize"); - bytes32 public plugInitializeTwice = _createContractId("plugInitializeTwice"); - bytes32 public plugNoInitInitialize = _createContractId("plugNoInitInitialize"); - - constructor(address addressResolver_, address auctionManager_, bytes32 sbType_, Fees memory fees_) - AppDeployerBase(addressResolver_, auctionManager_, sbType_) - { - creationCodeWithArgs[noPlugNoInititialize] = abi.encodePacked(type(NoPlugNoInititialize).creationCode); - creationCodeWithArgs[noPlugInitialize] = abi.encodePacked(type(NoPlugInitialize).creationCode); - creationCodeWithArgs[plugNoInitialize] = abi.encodePacked(type(PlugNoInitialize).creationCode); - creationCodeWithArgs[plugInitialize] = abi.encodePacked(type(PlugInitialize).creationCode); - creationCodeWithArgs[plugInitializeTwice] = abi.encodePacked(type(PlugInitializeTwice).creationCode); - creationCodeWithArgs[plugNoInitInitialize] = abi.encodePacked(type(PlugNoInitInitialize).creationCode); - _setOverrides(fees_); - } - - function deployContracts(uint32 chainSlug_) external async { - _deploy(noPlugNoInititialize, chainSlug_, IsPlug.NO); - _deploy( - noPlugInitialize, chainSlug_, IsPlug.NO, abi.encodeWithSelector(NoPlugInitialize.initialise.selector, 10) - ); - _deploy(plugNoInitialize, chainSlug_, IsPlug.YES); - _deploy(plugInitialize, chainSlug_, IsPlug.YES, abi.encodeWithSelector(PlugInitialize.initialise.selector, 10)); - _deploy( - plugInitializeTwice, - chainSlug_, - IsPlug.YES, - abi.encodeWithSelector(PlugInitializeTwice.initialise.selector, 10) - ); - _deploy(plugNoInitInitialize, chainSlug_, IsPlug.YES); - } - - function initialize(uint32 chainSlug_) public override async { - PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]).initialise(10); - PlugNoInitInitialize(forwarderAddresses[plugNoInitInitialize][chainSlug_]).initialise(10); - } - - function setFees(Fees memory fees_) public { - fees = fees_; - } -} diff --git a/src/inbox/InboxAppGateway.sol b/src/inbox/InboxAppGateway.sol index 6ecc009..62c5627 100644 --- a/src/inbox/InboxAppGateway.sol +++ b/src/inbox/InboxAppGateway.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.0; import "socket-protocol/contracts/base/AppGatewayBase.sol"; +import "./Inbox.sol"; interface IInboxDeployer { function inbox() external pure returns (bytes32 bytecode); @@ -20,6 +21,7 @@ interface IInbox { } contract InboxAppGateway is AppGatewayBase { + bytes32 public inbox = _createContractId("inbox"); uint256 public valueOnGateway; address deployerAddress; @@ -27,21 +29,26 @@ contract InboxAppGateway is AppGatewayBase { uint32 public constant INCREASE_ON_GATEWAY = 1; uint32 public constant PROPAGATE_TO_ANOTHER = 2; - constructor(address addressResolver_, address deployerContract_, address auctionManager_, Fees memory fees_) - AppGatewayBase(addressResolver_, auctionManager_) - { - addressResolver__.setContractsToGateways(deployerContract_); - deployerAddress = deployerContract_; + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[inbox] = abi.encodePacked(type(Inbox).creationCode); _setOverrides(fees_); } + function deployContracts(uint32 chainSlug_) external async { + _deploy(inbox, chainSlug_, IsPlug.YES); + } + + function initialize(uint32) public pure override { + return; + } + function updateOnchain(uint32 targetChain) public { address inboxForwarderAddress = IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); IInbox(inboxForwarderAddress).updateFromGateway(valueOnGateway); } - function callFromInbox(uint32, address, bytes calldata payload_, bytes32) external override onlyWatcherPrecompile { + function callFromChain(uint32, address, bytes calldata payload_, bytes32) external override onlyWatcherPrecompile { (uint32 msgType, bytes memory payload) = abi.decode(payload_, (uint32, bytes)); if (msgType == INCREASE_ON_GATEWAY) { uint256 valueOnchain = abi.decode(payload, (uint256)); diff --git a/src/inbox/InboxDeployer.sol b/src/inbox/InboxDeployer.sol deleted file mode 100644 index f1dca30..0000000 --- a/src/inbox/InboxDeployer.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity ^0.8.0; - -import "socket-protocol/contracts/base/AppDeployerBase.sol"; -import "./Inbox.sol"; - -contract InboxDeployer is AppDeployerBase { - bytes32 public inbox = _createContractId("inbox"); - - constructor(address addressResolver_, address auctionManager_, bytes32 sbType_, Fees memory fees_) - AppDeployerBase(addressResolver_, auctionManager_, sbType_) - { - creationCodeWithArgs[inbox] = abi.encodePacked(type(Inbox).creationCode); - _setOverrides(fees_); - } - - function deployContracts(uint32 chainSlug_) external async { - _deploy(inbox, chainSlug_, IsPlug.YES); - } - - function initialize(uint32) public pure override { - return; - } - - function setFees(Fees memory fees_) public { - fees = fees_; - } -} diff --git a/src/robustness/RobustnessAppGateway.sol b/src/robustness/RobustnessAppGateway.sol index ebc7a5c..8c2fc11 100644 --- a/src/robustness/RobustnessAppGateway.sol +++ b/src/robustness/RobustnessAppGateway.sol @@ -3,20 +3,28 @@ pragma solidity >=0.7.0 <0.9.0; import "socket-protocol/contracts/base/AppGatewayBase.sol"; import "./IRobustnessMultichain.sol"; +import "./RobustnessMultichain.sol"; contract RobustnessAppGateway is AppGatewayBase { + bytes32 public multichain = _createContractId("RobustnessMultichain"); uint256[] public values; uint256[] public resolveTimes = new uint256[](10); uint256[] public timeoutDurations = [1, 10, 20, 30, 40, 50, 100, 500, 1000, 10000]; - constructor(address addressResolver_, address deployerContract_, address auctionManager_, Fees memory fees_) - AppGatewayBase(addressResolver_, auctionManager_) - { - addressResolver__.setContractsToGateways(deployerContract_); + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[multichain] = abi.encodePacked(type(RobustnessMultichain).creationCode); _setOverrides(fees_); } + function deployContracts(uint32 chainSlug_) external async { + _deploy(multichain, chainSlug_, IsPlug.YES); + } + + function initialize(uint32) public pure override { + return; + } + function triggerSequentialWrite(address instance_) public async { _setOverrides(Read.OFF, Parallel.OFF); for (uint256 i = 0; i < 10; i++) { diff --git a/src/robustness/RobustnessDeployer.sol b/src/robustness/RobustnessDeployer.sol deleted file mode 100644 index 0d69e0b..0000000 --- a/src/robustness/RobustnessDeployer.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -import "./RobustnessMultichain.sol"; -import "socket-protocol/contracts/base/AppDeployerBase.sol"; - -contract RobustnessDeployer is AppDeployerBase { - bytes32 public multichain = _createContractId("RobustnessMultichain"); - - constructor(address addressResolver_, address auctionManager_, bytes32 sbType_, Fees memory fees_) - AppDeployerBase(addressResolver_, auctionManager_, sbType_) - { - creationCodeWithArgs[multichain] = abi.encodePacked(type(RobustnessMultichain).creationCode); - _setOverrides(fees_); - } - - function deployContracts(uint32 chainSlug_) external async { - _deploy(multichain, chainSlug_, IsPlug.YES); - } - - function initialize(uint32) public pure override { - return; - } - - function setFees(Fees memory fees_) public { - fees = fees_; - } -} From e7c9fb0628f41bc45cd5278d12c1e2cc32ce3597 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:25:50 +0000 Subject: [PATCH 09/26] Add Read contracts --- script/read/DeployEVMxReadTests.sol | 27 ++++++++++ script/read/RunEVMxRead.s.sol | 79 +++++++++++++++++++++++++++++ src/read/IReadMultichain.sol | 16 ++++++ src/read/ReadAppGateway.sol | 64 +++++++++++++++++++++++ src/read/ReadMultichain.sol | 27 ++++++++++ 5 files changed, 213 insertions(+) create mode 100644 script/read/DeployEVMxReadTests.sol create mode 100644 script/read/RunEVMxRead.s.sol create mode 100644 src/read/IReadMultichain.sol create mode 100644 src/read/ReadAppGateway.sol create mode 100644 src/read/ReadMultichain.sol diff --git a/script/read/DeployEVMxReadTests.sol b/script/read/DeployEVMxReadTests.sol new file mode 100644 index 0000000..5e5bca6 --- /dev/null +++ b/script/read/DeployEVMxReadTests.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {Script} from "forge-std/Script.sol"; +import {console} from "forge-std/console.sol"; +import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; +import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; + +import {ReadAppGateway} from "../../src/read/ReadAppGateway.sol"; + +contract DeployEVMxContracts is Script { + function run() external { + address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); + string memory rpc = vm.envString("EVMX_RPC"); + vm.createSelectFork(rpc); + + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); + + ReadAppGateway gateway = new ReadAppGateway(addressResolver, fees); + + console.log("Contracts deployed:"); + console.log("AppGateway:", address(gateway)); + } +} diff --git a/script/read/RunEVMxRead.s.sol b/script/read/RunEVMxRead.s.sol new file mode 100644 index 0000000..48e1445 --- /dev/null +++ b/script/read/RunEVMxRead.s.sol @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {console} from "forge-std/console.sol"; +import {SetupScript} from "../SetupScript.sol"; +import {ReadAppGateway} from "../../src/read/ReadAppGateway.sol"; + +contract RunEVMxRead is SetupScript { + ReadAppGateway readAppGateway; + address opSepForwarder; + address arbSepForwarder; + + function appGateway() internal view override returns (address) { + return address(readAppGateway); + } + + function getForwarderAddresses() internal { + vm.createSelectFork(rpcEVMx); + opSepForwarder = readAppGateway.forwarderAddresses(readAppGateway.multichain(), opSepChainId); + arbSepForwarder = readAppGateway.forwarderAddresses(readAppGateway.multichain(), arbSepChainId); + + console.log("Optimism Sepolia Forwarder:", opSepForwarder); + console.log("Arbitrum Sepolia Forwarder:", arbSepForwarder); + } + + function runAllTriggers() internal { + vm.createSelectFork(rpcEVMx); + vm.startBroadcast(privateKey); + + console.log("Running all trigger functions..."); + + // 1. Trigger Parallel Read + console.log("triggerParallelRead..."); + readAppGateway.triggerParallelRead(opSepForwarder); + + // 2. Trigger Alternating Read between chains + console.log("triggerAltRead..."); + readAppGateway.triggerAltRead(opSepForwarder, arbSepForwarder); + + vm.stopBroadcast(); + console.log("All triggers executed successfully"); + } + + function checkResults() internal { + vm.createSelectFork(rpcEVMx); + + console.log("\n----- RESULTS -----"); + + // Check values array + console.log("Values array:"); + for (uint256 i = 0; i < 10; i++) { + try readAppGateway.values(i) returns (uint256 value) { + console.log("values[%s]: %s", i, value); + } catch { + console.log("values[%s]: not set", i); + break; + } + } + } + + function executeScriptSpecificLogic() internal override { + // Initialize contract references + readAppGateway = ReadAppGateway(appGatewayAddress); + + // Deploy to both test chains + uint32[] memory chainIds = new uint32[](2); + chainIds[0] = opSepChainId; + chainIds[1] = arbSepChainId; + deployOnchainContracts(chainIds); + + getForwarderAddresses(); + runAllTriggers(); + checkResults(); + } + + function run() external { + _run(arbSepChainId); + } +} diff --git a/src/read/IReadMultichain.sol b/src/read/IReadMultichain.sol new file mode 100644 index 0000000..729d81c --- /dev/null +++ b/src/read/IReadMultichain.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +interface IReadMultichain { + function counter() external; + + function values() external; + + function increase() external; + + function setValues(uint256[] memory values_) external; + + function getValue(uint256 index_) external; + + function connectSocket(address appGateway_, address socket_, address switchboard_) external; +} diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol new file mode 100644 index 0000000..a9e0c1a --- /dev/null +++ b/src/read/ReadAppGateway.sol @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +import "socket-protocol/contracts/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/interfaces/IForwarder.sol"; +import "socket-protocol/contracts/interfaces/IPromise.sol"; +import "./IReadMultichain.sol"; +import "./ReadMultichain.sol"; + +contract ReadAppGateway is AppGatewayBase { + bytes32 public multichain = _createContractId("ReadMultichain"); + uint256[] public values; + + event ValueRead(address instance, uint256 index, uint256 value); + + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); + _setOverrides(fees_); + } + + function deployContracts(uint32 chainSlug_) external async { + _deploy(multichain, chainSlug_, IsPlug.YES); + } + + function initialize(uint32) public pure override { + return; + } + + function triggerParallelRead(address instance_) public async { + _setOverrides(Read.ON, Parallel.ON); + for (uint256 i = 0; i < 10; i++) { + IReadMultichain(instance_).getValue(i); + IPromise(instance_).then(this.handleValue.selector, abi.encode(i)); + } + } + + function triggerAltRead(address instance1_, address instance2_) public async { + _setOverrides(Read.ON, Parallel.ON); + for (uint256 i = 0; i < 10; i++) { + if (i % 2 == 0) { + IReadMultichain(instance1_).getValue(i); + IPromise(instance1_).then(this.handleValue.selector, abi.encode(i)); + } else { + IReadMultichain(instance2_).getValue(i); + IPromise(instance2_).then(this.handleValue.selector, abi.encode(i)); + } + } + } + + function handleValue(bytes memory data, bytes memory returnData) public onlyPromises { + uint256 index_ = abi.decode(data, (uint256)); + uint256 value_ = abi.decode(returnData, (uint256)); + values[index_] = value_; + emit ValueRead(msg.sender, index_, value_); + } + + function setFees(Fees memory fees_) public { + fees = fees_; + } + + function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + } +} diff --git a/src/read/ReadMultichain.sol b/src/read/ReadMultichain.sol new file mode 100644 index 0000000..017dfd5 --- /dev/null +++ b/src/read/ReadMultichain.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +import "socket-protocol/contracts/base/PlugBase.sol"; + +contract ReadMultichain is PlugBase { + uint256[] public values; + + event ValuesInitialized(uint256[] values); + + constructor() { + values = new uint256[](10); + uint256 seed = (block.number % 10) + 1; + for (uint256 i = 0; i < 10; i++) { + values[i] = seed + i; + } + emit ValuesInitialized(values); + } + + function getValue(uint256 index_) external view returns (uint256) { + return values[index_]; + } + + function connectSocket(address appGateway_, address socket_, address switchboard_) external { + _connectSocket(appGateway_, socket_, switchboard_); + } +} From 4c06e434fa06e1d09ae761c1bd63bf7ee1566005 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:31:11 +0000 Subject: [PATCH 10/26] Update with starter-kit .env.sample --- .env.sample | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.env.sample b/.env.sample index 7baff03..64b474a 100644 --- a/.env.sample +++ b/.env.sample @@ -6,7 +6,8 @@ OPTIMISM_SEPOLIA_RPC="https://rpc.ankr.com/optimism_sepolia" BASE_SEPOLIA_RPC="https://rpc.ankr.com/base_sepolia" # EVMx key addresses -# Find the most up to date addresses in deployments/dev_addresses.json +# Find the most up to date addresses at: +# https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json ADDRESS_RESOLVER="0xf3046B22F98C25305E8040286fB1b33378BA10a1" FEES_MANAGER="0x603723100172D30171B7Fd9870ba80F8baf6FaD4" ARBITRUM_FEES_PLUG="0x89324F93d852cB4fcDC4Ee202456be466ce096bb" @@ -17,7 +18,3 @@ PRIVATE_KEY="0x" # Set app related values after deployment on EVMx APP_GATEWAY="0x" - -# FOR INFRASTRUCTURE DEPLOYMENT ONLY -# Removes hardhat issues related to linting and syntax checking -SOCKET_SIGNER_KEY="0000dead0000dead0000dead0000dead0000dead0000dead0000dead0000dead" From 0d1090c79bcc246019c4fd4bed7104a3149541cd Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:36:53 +0000 Subject: [PATCH 11/26] Standardize deploy to EVMx scripts --- .../DeployEVMxDeploymentMistakesApp.s.sol | 7 ++++--- script/inbox/DeployEVMxInbox.s.sol | 7 ++++--- script/read/DeployEVMxReadTests.sol | 5 +++-- script/robust/DeployEVMxRobustnessTests.sol | 7 ++++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol index 451deb3..8067d35 100644 --- a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol +++ b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; +import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol"; @@ -19,9 +19,10 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - DeploymentMistakesAppGateway gateway = new DeploymentMistakesAppGateway(addressResolver, fees); + DeploymentMistakesAppGateway appGateway = new DeploymentMistakesAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("DeploymentMistakesAppGateway:", address(gateway)); + console.log("DeploymentMistakesAppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); } } diff --git a/script/inbox/DeployEVMxInbox.s.sol b/script/inbox/DeployEVMxInbox.s.sol index a1b104f..d4eac6d 100644 --- a/script/inbox/DeployEVMxInbox.s.sol +++ b/script/inbox/DeployEVMxInbox.s.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; +import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {InboxAppGateway} from "../../src/inbox/InboxAppGateway.sol"; @@ -19,9 +19,10 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - InboxAppGateway gateway = new InboxAppGateway(addressResolver, fees); + InboxAppGateway appGateway = new InboxAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("AppGateway:", address(gateway)); + console.log("AppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); } } diff --git a/script/read/DeployEVMxReadTests.sol b/script/read/DeployEVMxReadTests.sol index 5e5bca6..d2e1c3f 100644 --- a/script/read/DeployEVMxReadTests.sol +++ b/script/read/DeployEVMxReadTests.sol @@ -19,9 +19,10 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - ReadAppGateway gateway = new ReadAppGateway(addressResolver, fees); + ReadAppGateway appGateway = new ReadAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("AppGateway:", address(gateway)); + console.log("AppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); } } diff --git a/script/robust/DeployEVMxRobustnessTests.sol b/script/robust/DeployEVMxRobustnessTests.sol index b0383fe..870aa1d 100644 --- a/script/robust/DeployEVMxRobustnessTests.sol +++ b/script/robust/DeployEVMxRobustnessTests.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; +import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol"; @@ -19,9 +19,10 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - RobustnessAppGateway gateway = new RobustnessAppGateway(addressResolver, fees); + RobustnessAppGateway appGateway = new RobustnessAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("AppGateway:", address(gateway)); + console.log("AppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); } } From 109e660f47b25f657afde4591c11170a8577c4e2 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:03:01 +0000 Subject: [PATCH 12/26] Remove auction manager from setup script --- script/SetupScript.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 3d1ceff..11fb1f7 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -19,7 +19,6 @@ abstract contract SetupScript is Script { string rpcEVMx = vm.envString("EVMX_RPC"); string rpcArbSepolia = vm.envString("ARBITRUM_SEPOLIA_RPC"); address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - address auctionManager = vm.envAddress("AUCTION_MANAGER"); address feesPlugArbSepolia = vm.envAddress("ARBITRUM_FEES_PLUG"); address feesManagerAddress = vm.envAddress("FEES_MANAGER"); uint256 privateKey = vm.envUint("PRIVATE_KEY"); From 4700aeee946fecae1a631edeb89cd91bbadd53e0 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:03:51 +0000 Subject: [PATCH 13/26] Remove deployer address from setup script --- script/SetupScript.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 11fb1f7..8fa6eb2 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -22,7 +22,6 @@ abstract contract SetupScript is Script { address feesPlugArbSepolia = vm.envAddress("ARBITRUM_FEES_PLUG"); address feesManagerAddress = vm.envAddress("FEES_MANAGER"); uint256 privateKey = vm.envUint("PRIVATE_KEY"); - address deployerAddress = vm.envAddress("DEPLOYER"); address appGatewayAddress = vm.envAddress("APP_GATEWAY"); // ----- SCRIPT VARIABLES ----- From 77766608714c97af63460d0f5d01ff025eb0c7c3 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:08:24 +0000 Subject: [PATCH 14/26] Fix wrong chain id --- script/SetupScript.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 8fa6eb2..255d363 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -25,7 +25,7 @@ abstract contract SetupScript is Script { address appGatewayAddress = vm.envAddress("APP_GATEWAY"); // ----- SCRIPT VARIABLES ----- - uint32 arbSepChainId = 411614; + uint32 arbSepChainId = 421614; uint32 opSepChainId = 11155420; Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); From a123dd1e837b3e79dd25ef7b8bf8f4564e1c3c39 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:45:52 +0000 Subject: [PATCH 15/26] Reduce minimum fees --- .../deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol | 2 +- script/inbox/DeployEVMxInbox.s.sol | 2 +- script/read/DeployEVMxReadTests.sol | 2 +- script/robust/DeployEVMxRobustnessTests.sol | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol index 8067d35..309abed 100644 --- a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol +++ b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol @@ -17,7 +17,7 @@ contract DeployEVMxContracts is Script { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(deployerPrivateKey); - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); + Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); DeploymentMistakesAppGateway appGateway = new DeploymentMistakesAppGateway(addressResolver, fees); diff --git a/script/inbox/DeployEVMxInbox.s.sol b/script/inbox/DeployEVMxInbox.s.sol index d4eac6d..88c7a4b 100644 --- a/script/inbox/DeployEVMxInbox.s.sol +++ b/script/inbox/DeployEVMxInbox.s.sol @@ -17,7 +17,7 @@ contract DeployEVMxContracts is Script { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(deployerPrivateKey); - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); + Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); InboxAppGateway appGateway = new InboxAppGateway(addressResolver, fees); diff --git a/script/read/DeployEVMxReadTests.sol b/script/read/DeployEVMxReadTests.sol index d2e1c3f..763c6be 100644 --- a/script/read/DeployEVMxReadTests.sol +++ b/script/read/DeployEVMxReadTests.sol @@ -17,7 +17,7 @@ contract DeployEVMxContracts is Script { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(deployerPrivateKey); - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); + Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); ReadAppGateway appGateway = new ReadAppGateway(addressResolver, fees); diff --git a/script/robust/DeployEVMxRobustnessTests.sol b/script/robust/DeployEVMxRobustnessTests.sol index 870aa1d..491da5c 100644 --- a/script/robust/DeployEVMxRobustnessTests.sol +++ b/script/robust/DeployEVMxRobustnessTests.sol @@ -17,7 +17,7 @@ contract DeployEVMxContracts is Script { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(deployerPrivateKey); - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); + Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); RobustnessAppGateway appGateway = new RobustnessAppGateway(addressResolver, fees); From 825969da738f167a339193442515be756fe605e6 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 16:13:14 +0000 Subject: [PATCH 16/26] Split onchain deployment from test run --- script/SetupScript.sol | 3 ++- .../RunEVMxDeploymentMistakes.s.sol | 17 ++++++++++------- script/inbox/RunEVMxInbox.s.sol | 18 ++++++++++-------- script/read/RunEVMxRead.s.sol | 18 ++++++++++-------- script/robust/RunEVMxRobustness.s.sol | 18 ++++++++++-------- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 255d363..656705e 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -27,6 +27,7 @@ abstract contract SetupScript is Script { // ----- SCRIPT VARIABLES ----- uint32 arbSepChainId = 421614; uint32 opSepChainId = 11155420; + uint32[2] chainIds = [opSepChainId, arbSepChainId]; Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); FeesManager feesManager = FeesManager(payable(feesManagerAddress)); @@ -86,7 +87,7 @@ abstract contract SetupScript is Script { } } - function deployOnchainContracts(uint32[] memory chainIds) internal { + function _deployOnchainContracts() internal { vm.createSelectFork(rpcEVMx); vm.startBroadcast(privateKey); diff --git a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol index 67ebcc1..12e8584 100644 --- a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol +++ b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol @@ -100,15 +100,13 @@ contract RunEVMxDeploymentMistakes is SetupScript { vm.stopBroadcast(); } - function executeScriptSpecificLogic() internal override { - // Initialize contract references + // Initialize contract references + function init() internal { mistakesAppGateway = DeploymentMistakesAppGateway(appGatewayAddress); + } - // Deploy only to Arbitrum Sepolia - uint32[] memory chainIds = new uint32[](1); - chainIds[0] = arbSepChainId; - deployOnchainContracts(chainIds); - + function executeScriptSpecificLogic() internal override { + init(); getForwarderAddresses(); validateMistakes(); } @@ -116,4 +114,9 @@ contract RunEVMxDeploymentMistakes is SetupScript { function run() external { _run(arbSepChainId); } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } } diff --git a/script/inbox/RunEVMxInbox.s.sol b/script/inbox/RunEVMxInbox.s.sol index 119a9e1..c86c94a 100644 --- a/script/inbox/RunEVMxInbox.s.sol +++ b/script/inbox/RunEVMxInbox.s.sol @@ -41,16 +41,13 @@ contract RunEVMxInbox is SetupScript { console.log("All inbox transactions executed successfully"); } - function executeScriptSpecificLogic() internal override { - // Initialize contract references + // Initialize contract references + function init() internal { inboxAppGateway = InboxAppGateway(appGatewayAddress); + } - // Deploy to both test chains - uint32[] memory chainIds = new uint32[](2); - chainIds[0] = opSepChainId; - chainIds[1] = arbSepChainId; - deployOnchainContracts(chainIds); - + function executeScriptSpecificLogic() internal override { + init(); getForwarderAddresses(); inboxTransactions(); } @@ -58,4 +55,9 @@ contract RunEVMxInbox is SetupScript { function run() external { _run(arbSepChainId); } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } } diff --git a/script/read/RunEVMxRead.s.sol b/script/read/RunEVMxRead.s.sol index 48e1445..7f0ef43 100644 --- a/script/read/RunEVMxRead.s.sol +++ b/script/read/RunEVMxRead.s.sol @@ -58,16 +58,13 @@ contract RunEVMxRead is SetupScript { } } - function executeScriptSpecificLogic() internal override { - // Initialize contract references + // Initialize contract references + function init() internal { readAppGateway = ReadAppGateway(appGatewayAddress); + } - // Deploy to both test chains - uint32[] memory chainIds = new uint32[](2); - chainIds[0] = opSepChainId; - chainIds[1] = arbSepChainId; - deployOnchainContracts(chainIds); - + function executeScriptSpecificLogic() internal override { + init(); getForwarderAddresses(); runAllTriggers(); checkResults(); @@ -76,4 +73,9 @@ contract RunEVMxRead is SetupScript { function run() external { _run(arbSepChainId); } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } } diff --git a/script/robust/RunEVMxRobustness.s.sol b/script/robust/RunEVMxRobustness.s.sol index f2d6325..c265992 100644 --- a/script/robust/RunEVMxRobustness.s.sol +++ b/script/robust/RunEVMxRobustness.s.sol @@ -90,16 +90,13 @@ contract RunEVMxRobustness is SetupScript { } } - function executeScriptSpecificLogic() internal override { - // Initialize contract references + // Initialize contract references + function init() internal { robustnessAppGateway = RobustnessAppGateway(appGatewayAddress); + } - // Deploy to both test chains - uint32[] memory chainIds = new uint32[](2); - chainIds[0] = opSepChainId; - chainIds[1] = arbSepChainId; - deployOnchainContracts(chainIds); - + function executeScriptSpecificLogic() internal override { + init(); getForwarderAddresses(); runAllTriggers(); checkResults(); @@ -108,4 +105,9 @@ contract RunEVMxRobustness is SetupScript { function run() external { _run(arbSepChainId); } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } } From 8a58bbe9395b71f66948597b7036882215d659db Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 16:13:35 +0000 Subject: [PATCH 17/26] Update README --- README.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a149af..174aa98 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ -This repository is to get you started with development on SOCKET protocol. -Follow the accompanying [guide](https://docs.socket.tech/getting-started). +# Deployment Steps for EVMx Read Tests + +Follow these steps to deploy and run the EVMx Read tests. + +### 1. **Deploy the EVMx Read Tests Script** +Run the following command to deploy the EVMx Read tests script: +```bash +forge script script/read/DeployEVMxReadTests.sol --broadcast --legacy --with-gas-price 0 +``` + +### 2. **Verify the Contract** +Verify the `ReadAppGateway` contract on Blockscout: +```bash +forge verify-contract --rpc-url https://rpc-evmx-devnet.socket.tech/ --verifier blockscout --verifier-url https://evmx.cloud.blockscout.com/api src/read/ReadAppGateway.sol:ReadAppGateway +``` + +### 3. **Update the `APP_GATEWAY` in `.env`** +Make sure to update the `APP_GATEWAY` address in your `.env` file. + +### 4. **Pay Fees in Arbitrum ETH** +Run the script to pay fees in Arbitrum ETH: +```bash +forge script lib/socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation +``` + +### 5. **Deploy Onchain Contracts** +Deploy the onchain contracts using the following script: +```bash +forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployOnchainContracts()" +``` + +### 6. **Run EVMx Read Script** +Finally, run the EVMx Read script: +```bash +forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy +``` From 6f656e2cc78c42ffedc531d0b710f8da44be1f37 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 17:45:34 +0000 Subject: [PATCH 18/26] Update README --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 174aa98..0a1ecaa 100644 --- a/README.md +++ b/README.md @@ -8,28 +8,34 @@ Run the following command to deploy the EVMx Read tests script: forge script script/read/DeployEVMxReadTests.sol --broadcast --legacy --with-gas-price 0 ``` -### 2. **Verify the Contract** +### 1a. **Verify the Contract** Verify the `ReadAppGateway` contract on Blockscout: ```bash forge verify-contract --rpc-url https://rpc-evmx-devnet.socket.tech/ --verifier blockscout --verifier-url https://evmx.cloud.blockscout.com/api src/read/ReadAppGateway.sol:ReadAppGateway ``` -### 3. **Update the `APP_GATEWAY` in `.env`** +### 2. **Update the `APP_GATEWAY` in `.env`** Make sure to update the `APP_GATEWAY` address in your `.env` file. -### 4. **Pay Fees in Arbitrum ETH** +### 3. **Pay Fees in Arbitrum ETH** Run the script to pay fees in Arbitrum ETH: ```bash forge script lib/socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation ``` -### 5. **Deploy Onchain Contracts** +### 4. **Deploy Onchain Contracts** Deploy the onchain contracts using the following script: ```bash forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployOnchainContracts()" ``` -### 6. **Run EVMx Read Script** +### 4a. **Verify the Contract** +Verify the `ReadMultichain` contract on Arbitrum Sepolia Blockscout: +```bash +forge verify-contract --rpc-url https://rpc.ankr.com/arbitrum_sepolia --verifier-url https://arbitrum-sepolia.blockscout.com/api --verifier blockscout src/read/ReadMultichain.sol:ReadMultichain +``` + +### 5. **Run EVMx Read Script** Finally, run the EVMx Read script: ```bash forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy From 2a3e8d487c6dda5d08b81063429b6774b7caa19e Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 6 Mar 2025 17:46:10 +0000 Subject: [PATCH 19/26] Update read example --- src/read/IReadMultichain.sol | 8 +------- src/read/ReadAppGateway.sol | 16 ++++++++-------- src/read/ReadMultichain.sol | 11 +++++------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/read/IReadMultichain.sol b/src/read/IReadMultichain.sol index 729d81c..93c966d 100644 --- a/src/read/IReadMultichain.sol +++ b/src/read/IReadMultichain.sol @@ -2,15 +2,9 @@ pragma solidity >=0.7.0 <0.9.0; interface IReadMultichain { - function counter() external; - - function values() external; + function values(uint256) external; function increase() external; - function setValues(uint256[] memory values_) external; - - function getValue(uint256 index_) external; - function connectSocket(address appGateway_, address socket_, address switchboard_) external; } diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index a9e0c1a..2622112 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -29,8 +29,8 @@ contract ReadAppGateway is AppGatewayBase { function triggerParallelRead(address instance_) public async { _setOverrides(Read.ON, Parallel.ON); for (uint256 i = 0; i < 10; i++) { - IReadMultichain(instance_).getValue(i); - IPromise(instance_).then(this.handleValue.selector, abi.encode(i)); + IReadMultichain(instance_).values(i); + IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); } } @@ -38,20 +38,20 @@ contract ReadAppGateway is AppGatewayBase { _setOverrides(Read.ON, Parallel.ON); for (uint256 i = 0; i < 10; i++) { if (i % 2 == 0) { - IReadMultichain(instance1_).getValue(i); - IPromise(instance1_).then(this.handleValue.selector, abi.encode(i)); + IReadMultichain(instance1_).values(i); + IPromise(instance1_).then(this.handleValue.selector, abi.encode(i, instance1_)); } else { - IReadMultichain(instance2_).getValue(i); - IPromise(instance2_).then(this.handleValue.selector, abi.encode(i)); + IReadMultichain(instance2_).values(i); + IPromise(instance2_).then(this.handleValue.selector, abi.encode(i, instance2_)); } } } function handleValue(bytes memory data, bytes memory returnData) public onlyPromises { - uint256 index_ = abi.decode(data, (uint256)); + (uint256 index_, address instance) = abi.decode(data, (uint256, address)); uint256 value_ = abi.decode(returnData, (uint256)); values[index_] = value_; - emit ValueRead(msg.sender, index_, value_); + emit ValueRead(instance, index_, value_); } function setFees(Fees memory fees_) public { diff --git a/src/read/ReadMultichain.sol b/src/read/ReadMultichain.sol index 017dfd5..3c2acea 100644 --- a/src/read/ReadMultichain.sol +++ b/src/read/ReadMultichain.sol @@ -10,15 +10,14 @@ contract ReadMultichain is PlugBase { constructor() { values = new uint256[](10); - uint256 seed = (block.number % 10) + 1; + uint256 baseSeed = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender))); + for (uint256 i = 0; i < 10; i++) { - values[i] = seed + i; + uint256 uniqueSeed = uint256(keccak256(abi.encodePacked(baseSeed, i))); + values[i] = (uniqueSeed % 10) + 1; } - emit ValuesInitialized(values); - } - function getValue(uint256 index_) external view returns (uint256) { - return values[index_]; + emit ValuesInitialized(values); } function connectSocket(address appGateway_, address socket_, address switchboard_) external { From 5183f19ea52810b7a89663ead3e5d9458b2113d9 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Fri, 7 Mar 2025 15:53:42 +0000 Subject: [PATCH 20/26] Ensure the array has enough elements --- src/read/ReadAppGateway.sol | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 2622112..351ffb4 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -50,6 +50,11 @@ contract ReadAppGateway is AppGatewayBase { function handleValue(bytes memory data, bytes memory returnData) public onlyPromises { (uint256 index_, address instance) = abi.decode(data, (uint256, address)); uint256 value_ = abi.decode(returnData, (uint256)); + + while (values.length <= index_) { + values.push(0); + } + values[index_] = value_; emit ValueRead(instance, index_, value_); } From 67cbecd4be16bbded383b11d18d4eafcff71aa8b Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:40:37 +0400 Subject: [PATCH 21/26] Initialize AppGateway array --- src/read/ReadAppGateway.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 351ffb4..759cb81 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -11,11 +11,14 @@ contract ReadAppGateway is AppGatewayBase { bytes32 public multichain = _createContractId("ReadMultichain"); uint256[] public values; + error OutOfBounds(); + event ValueRead(address instance, uint256 index, uint256 value); constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); _setOverrides(fees_); + values = new uint256[](10); } function deployContracts(uint32 chainSlug_) external async { @@ -51,10 +54,7 @@ contract ReadAppGateway is AppGatewayBase { (uint256 index_, address instance) = abi.decode(data, (uint256, address)); uint256 value_ = abi.decode(returnData, (uint256)); - while (values.length <= index_) { - values.push(0); - } - + if (index_ >= 10) revert OutOfBounds(); values[index_] = value_; emit ValueRead(instance, index_, value_); } From fbccb93d6d61ce41b8073ffdb8ee8c30a1105bb5 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 10 Mar 2025 16:36:10 +0400 Subject: [PATCH 22/26] Check results after each read call --- script/read/RunEVMxRead.s.sol | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/script/read/RunEVMxRead.s.sol b/script/read/RunEVMxRead.s.sol index 7f0ef43..f32ab53 100644 --- a/script/read/RunEVMxRead.s.sol +++ b/script/read/RunEVMxRead.s.sol @@ -26,24 +26,22 @@ contract RunEVMxRead is SetupScript { function runAllTriggers() internal { vm.createSelectFork(rpcEVMx); vm.startBroadcast(privateKey); - console.log("Running all trigger functions..."); // 1. Trigger Parallel Read console.log("triggerParallelRead..."); readAppGateway.triggerParallelRead(opSepForwarder); + checkResults(); // 2. Trigger Alternating Read between chains console.log("triggerAltRead..."); readAppGateway.triggerAltRead(opSepForwarder, arbSepForwarder); - + checkResults(); vm.stopBroadcast(); console.log("All triggers executed successfully"); } - function checkResults() internal { - vm.createSelectFork(rpcEVMx); - + function checkResults() internal view { console.log("\n----- RESULTS -----"); // Check values array @@ -67,7 +65,6 @@ contract RunEVMxRead is SetupScript { init(); getForwarderAddresses(); runAllTriggers(); - checkResults(); } function run() external { From b5cb47285beb7c6757540e5110b3e6bc309a6599 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 10 Mar 2025 16:40:16 +0400 Subject: [PATCH 23/26] Rename Robustness to Write --- script/robust/DeployEVMxRobustnessTests.sol | 4 +- script/robust/RunEVMxRobustness.s.sol | 8 ++-- .../IWriteMultichain.sol} | 2 +- .../WriteAppGateway.sol} | 40 +++++++++---------- .../WriteMultichain.sol} | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) rename src/{robustness/IRobustnessMultichain.sol => write/IWriteMultichain.sol} (91%) rename src/{robustness/RobustnessAppGateway.sol => write/WriteAppGateway.sol} (75%) rename src/{robustness/RobustnessMultichain.sol => write/WriteMultichain.sol} (95%) diff --git a/script/robust/DeployEVMxRobustnessTests.sol b/script/robust/DeployEVMxRobustnessTests.sol index 491da5c..1b8267f 100644 --- a/script/robust/DeployEVMxRobustnessTests.sol +++ b/script/robust/DeployEVMxRobustnessTests.sol @@ -6,7 +6,7 @@ import {console} from "forge-std/console.sol"; import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; -import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol"; +import {WriteAppGateway} from "../../src/robustness/WriteAppGateway.sol"; contract DeployEVMxContracts is Script { function run() external { @@ -19,7 +19,7 @@ contract DeployEVMxContracts is Script { Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); - RobustnessAppGateway appGateway = new RobustnessAppGateway(addressResolver, fees); + WriteAppGateway appGateway = new WriteAppGateway(addressResolver, fees); console.log("Contracts deployed:"); console.log("AppGateway:", address(appGateway)); diff --git a/script/robust/RunEVMxRobustness.s.sol b/script/robust/RunEVMxRobustness.s.sol index c265992..4987828 100644 --- a/script/robust/RunEVMxRobustness.s.sol +++ b/script/robust/RunEVMxRobustness.s.sol @@ -3,10 +3,10 @@ pragma solidity ^0.8.0; import {console} from "forge-std/console.sol"; import {SetupScript} from "../SetupScript.sol"; -import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol"; +import {WriteAppGateway} from "../../src/robustness/WriteAppGateway.sol"; -contract RunEVMxRobustness is SetupScript { - RobustnessAppGateway robustnessAppGateway; +contract RunEVMxWrite is SetupScript { + WriteAppGateway robustnessAppGateway; address opSepForwarder; address arbSepForwarder; @@ -92,7 +92,7 @@ contract RunEVMxRobustness is SetupScript { // Initialize contract references function init() internal { - robustnessAppGateway = RobustnessAppGateway(appGatewayAddress); + robustnessAppGateway = WriteAppGateway(appGatewayAddress); } function executeScriptSpecificLogic() internal override { diff --git a/src/robustness/IRobustnessMultichain.sol b/src/write/IWriteMultichain.sol similarity index 91% rename from src/robustness/IRobustnessMultichain.sol rename to src/write/IWriteMultichain.sol index 504a23f..4d1d4cf 100644 --- a/src/robustness/IRobustnessMultichain.sol +++ b/src/write/IWriteMultichain.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; -interface IRobustnessMultichain { +interface IWriteMultichain { function counter() external; function values() external; diff --git a/src/robustness/RobustnessAppGateway.sol b/src/write/WriteAppGateway.sol similarity index 75% rename from src/robustness/RobustnessAppGateway.sol rename to src/write/WriteAppGateway.sol index 8c2fc11..ecb3caf 100644 --- a/src/robustness/RobustnessAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -2,18 +2,18 @@ pragma solidity >=0.7.0 <0.9.0; import "socket-protocol/contracts/base/AppGatewayBase.sol"; -import "./IRobustnessMultichain.sol"; -import "./RobustnessMultichain.sol"; +import "./IWriteMultichain.sol"; +import "./WriteMultichain.sol"; -contract RobustnessAppGateway is AppGatewayBase { - bytes32 public multichain = _createContractId("RobustnessMultichain"); +contract WriteAppGateway is AppGatewayBase { + bytes32 public multichain = _createContractId("WriteMultichain"); uint256[] public values; uint256[] public resolveTimes = new uint256[](10); uint256[] public timeoutDurations = [1, 10, 20, 30, 40, 50, 100, 500, 1000, 10000]; constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { - creationCodeWithArgs[multichain] = abi.encodePacked(type(RobustnessMultichain).creationCode); + creationCodeWithArgs[multichain] = abi.encodePacked(type(WriteMultichain).creationCode); _setOverrides(fees_); } @@ -28,29 +28,29 @@ contract RobustnessAppGateway is AppGatewayBase { function triggerSequentialWrite(address instance_) public async { _setOverrides(Read.OFF, Parallel.OFF); for (uint256 i = 0; i < 10; i++) { - IRobustnessMultichain(instance_).increase(); + IWriteMultichain(instance_).increase(); } } function triggerParallelWrite(address instance_) public async { _setOverrides(Read.OFF, Parallel.ON); for (uint256 i = 0; i < 10; i++) { - IRobustnessMultichain(instance_).increase(); + IWriteMultichain(instance_).increase(); } } function triggerAltWrite(address instance1_, address instance2_) public async { _setOverrides(Read.OFF, Parallel.OFF); for (uint256 i = 0; i < 5; i++) { - IRobustnessMultichain(instance1_).increase(); - IRobustnessMultichain(instance2_).increase(); + IWriteMultichain(instance1_).increase(); + IWriteMultichain(instance2_).increase(); } } function triggerParallelRead(address instance_) public async { _setOverrides(Read.ON, Parallel.ON); for (uint256 i = 0; i < 10; i++) { - IRobustnessMultichain(instance_).getValue(i); + IWriteMultichain(instance_).getValue(i); IPromise(instance_).then(this.setValue.selector, abi.encode(i)); } } @@ -59,10 +59,10 @@ contract RobustnessAppGateway is AppGatewayBase { _setOverrides(Read.ON, Parallel.ON); for (uint256 i = 0; i < 10; i++) { if (i % 2 == 0) { - IRobustnessMultichain(instance1_).getValue(i); + IWriteMultichain(instance1_).getValue(i); IPromise(instance1_).then(this.setValue.selector, abi.encode(i)); } else { - IRobustnessMultichain(instance2_).getValue(i); + IWriteMultichain(instance2_).getValue(i); IPromise(instance2_).then(this.setValue.selector, abi.encode(i)); } } @@ -70,24 +70,24 @@ contract RobustnessAppGateway is AppGatewayBase { function triggerReadAndWrite(address instance_) public async { _setOverrides(Read.ON, Parallel.OFF); - IRobustnessMultichain(instance_).getValue(0); + IWriteMultichain(instance_).getValue(0); IPromise(instance_).then(this.setValue.selector, abi.encode(0)); - IRobustnessMultichain(instance_).getValue(1); + IWriteMultichain(instance_).getValue(1); IPromise(instance_).then(this.setValue.selector, abi.encode(1)); _setOverrides(Read.OFF); - IRobustnessMultichain(instance_).increase(); - IRobustnessMultichain(instance_).increase(); + IWriteMultichain(instance_).increase(); + IWriteMultichain(instance_).increase(); _setOverrides(Read.ON); - IRobustnessMultichain(instance_).getValue(2); + IWriteMultichain(instance_).getValue(2); IPromise(instance_).then(this.setValue.selector, abi.encode(2)); - IRobustnessMultichain(instance_).getValue(3); + IWriteMultichain(instance_).getValue(3); IPromise(instance_).then(this.setValue.selector, abi.encode(3)); _setOverrides(Read.OFF); - IRobustnessMultichain(instance_).increase(); - IRobustnessMultichain(instance_).increase(); + IWriteMultichain(instance_).increase(); + IWriteMultichain(instance_).increase(); } function triggerTimeouts() public { diff --git a/src/robustness/RobustnessMultichain.sol b/src/write/WriteMultichain.sol similarity index 95% rename from src/robustness/RobustnessMultichain.sol rename to src/write/WriteMultichain.sol index 669a2e5..30426f9 100644 --- a/src/robustness/RobustnessMultichain.sol +++ b/src/write/WriteMultichain.sol @@ -3,7 +3,7 @@ pragma solidity >=0.7.0 <0.9.0; import "socket-protocol/contracts/base/PlugBase.sol"; -contract RobustnessMultichain is PlugBase { +contract WriteMultichain is PlugBase { uint256 public counter; uint256[] public values; From ac395f6630716f97af0e7dc595e11c924c3b8fd5 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 10 Mar 2025 18:05:40 +0400 Subject: [PATCH 24/26] Rework Robustness into Write tests --- README.md | 47 +++++++- script/robust/RunEVMxRobustness.s.sol | 113 ------------------ .../DeployEVMxRobustnessTests.sol | 2 +- script/write/RunEVMxWrite.s.sol | 73 +++++++++++ src/write/IWriteMultichain.sol | 6 - src/write/WriteAppGateway.sol | 65 ---------- src/write/WriteMultichain.sol | 21 +--- 7 files changed, 121 insertions(+), 206 deletions(-) delete mode 100644 script/robust/RunEVMxRobustness.s.sol rename script/{robust => write}/DeployEVMxRobustnessTests.sol (93%) create mode 100644 script/write/RunEVMxWrite.s.sol diff --git a/README.md b/README.md index 0a1ecaa..460aef7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Run the following command to deploy the EVMx Read tests script: forge script script/read/DeployEVMxReadTests.sol --broadcast --legacy --with-gas-price 0 ``` -### 1a. **Verify the Contract** +### 1a. **Verify the EVMx Contract** Verify the `ReadAppGateway` contract on Blockscout: ```bash forge verify-contract --rpc-url https://rpc-evmx-devnet.socket.tech/ --verifier blockscout --verifier-url https://evmx.cloud.blockscout.com/api src/read/ReadAppGateway.sol:ReadAppGateway @@ -29,7 +29,7 @@ Deploy the onchain contracts using the following script: forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployOnchainContracts()" ``` -### 4a. **Verify the Contract** +### 4a. **Verify the Onchain Contract** Verify the `ReadMultichain` contract on Arbitrum Sepolia Blockscout: ```bash forge verify-contract --rpc-url https://rpc.ankr.com/arbitrum_sepolia --verifier-url https://arbitrum-sepolia.blockscout.com/api --verifier blockscout src/read/ReadMultichain.sol:ReadMultichain @@ -40,3 +40,46 @@ Finally, run the EVMx Read script: ```bash forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy ``` + +# Deployment Steps for EVMx Write Tests + +Follow these steps to deploy and run the EVMx Write tests. + +### 1. **Deploy the EVMx Write Tests Script** +Run the following command to deploy the EVMx Write tests script: +```bash +forge script script/write/DeployEVMxWriteTests.sol --broadcast --legacy --with-gas-price 0 +``` + +### 1a. **Verify the Contract** +Verify the `WriteAppGateway` contract on Blockscout: +```bash +forge verify-contract --rpc-url https://rpc-evmx-devnet.socket.tech/ --verifier blockscout --verifier-url https://evmx.cloud.blockscout.com/api src/write/WriteAppGateway.sol:WriteAppGateway +``` + +### 2. **Update the `APP_GATEWAY` in `.env`** +Make sure to update the `APP_GATEWAY` address in your `.env` file. + +### 3. **Pay Fees in Arbitrum ETH** +Run the script to pay fees in Arbitrum ETH: +```bash +forge script lib/socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation +``` + +### 4. **Deploy Onchain Contracts** +Deploy the onchain contracts using the following script: +```bash +forge script script/write/RunEVMxWrite.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployOnchainContracts()" +``` + +### 4a. **Verify the Contract** +Verify the `WriteMultichain` contract on Arbitrum Sepolia Blockscout: +```bash +forge verify-contract --rpc-url https://rpc.ankr.com/arbitrum_sepolia --verifier-url https://arbitrum-sepolia.blockscout.com/api --verifier blockscout src/write/WriteMultichain.sol:WriteMultichain +``` + +### 5. **Run EVMx Write Script** +Finally, run the EVMx Write script: +```bash +forge script script/write/RunEVMxWrite.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy +``` diff --git a/script/robust/RunEVMxRobustness.s.sol b/script/robust/RunEVMxRobustness.s.sol deleted file mode 100644 index 4987828..0000000 --- a/script/robust/RunEVMxRobustness.s.sol +++ /dev/null @@ -1,113 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {console} from "forge-std/console.sol"; -import {SetupScript} from "../SetupScript.sol"; -import {WriteAppGateway} from "../../src/robustness/WriteAppGateway.sol"; - -contract RunEVMxWrite is SetupScript { - WriteAppGateway robustnessAppGateway; - address opSepForwarder; - address arbSepForwarder; - - function appGateway() internal view override returns (address) { - return address(robustnessAppGateway); - } - - function getForwarderAddresses() internal { - vm.createSelectFork(rpcEVMx); - opSepForwarder = robustnessAppGateway.forwarderAddresses(robustnessAppGateway.multichain(), opSepChainId); - arbSepForwarder = robustnessAppGateway.forwarderAddresses(robustnessAppGateway.multichain(), arbSepChainId); - - console.log("Optimism Sepolia Forwarder:", opSepForwarder); - console.log("Arbitrum Sepolia Forwarder:", arbSepForwarder); - } - - function runAllTriggers() internal { - vm.createSelectFork(rpcEVMx); - vm.startBroadcast(privateKey); - - console.log("Running all trigger functions..."); - - // 1. Trigger Sequential Write - console.log("triggerSequentialWrite..."); - robustnessAppGateway.triggerSequentialWrite(opSepForwarder); - - // 2. Trigger Parallel Write - console.log("triggerParallelWrite..."); - robustnessAppGateway.triggerParallelWrite(arbSepForwarder); - - // 3. Trigger Alternating Write between chains - console.log("triggerAltWrite..."); - robustnessAppGateway.triggerAltWrite(opSepForwarder, arbSepForwarder); - - // 4. Trigger Parallel Read - console.log("triggerParallelRead..."); - robustnessAppGateway.triggerParallelRead(opSepForwarder); - - // 5. Trigger Alternating Read between chains - console.log("triggerAltRead..."); - robustnessAppGateway.triggerAltRead(opSepForwarder, arbSepForwarder); - - // 6. Trigger Read and Write - console.log("triggerReadAndWrite..."); - robustnessAppGateway.triggerReadAndWrite(arbSepForwarder); - - // 7. Trigger Timeouts - console.log("triggerTimeouts..."); - robustnessAppGateway.triggerTimeouts(); - - vm.stopBroadcast(); - console.log("All triggers executed successfully"); - } - - function checkResults() internal { - vm.createSelectFork(rpcEVMx); - - console.log("\n----- RESULTS -----"); - - // Check values array - console.log("Values array:"); - for (uint256 i = 0; i < 10; i++) { - try robustnessAppGateway.values(i) returns (uint256 value) { - console.log("values[%s]: %s", i, value); - } catch { - console.log("values[%s]: not set", i); - break; - } - } - - // Check resolve times for timeouts - console.log("\nTimeout resolve times:"); - for (uint256 i = 0; i < 10; i++) { - uint256 resolveTime = robustnessAppGateway.resolveTimes(i); - uint256 duration = robustnessAppGateway.timeoutDurations(i); - if (resolveTime > 0) { - console.log("Timeout %s (duration %s): resolved at timestamp %s", i, duration, resolveTime); - } else { - console.log("Timeout %s (duration %s): not yet resolved", i, duration); - } - } - } - - // Initialize contract references - function init() internal { - robustnessAppGateway = WriteAppGateway(appGatewayAddress); - } - - function executeScriptSpecificLogic() internal override { - init(); - getForwarderAddresses(); - runAllTriggers(); - checkResults(); - } - - function run() external { - _run(arbSepChainId); - } - - function deployOnchainContracts() external { - init(); - _deployOnchainContracts(); - } -} diff --git a/script/robust/DeployEVMxRobustnessTests.sol b/script/write/DeployEVMxRobustnessTests.sol similarity index 93% rename from script/robust/DeployEVMxRobustnessTests.sol rename to script/write/DeployEVMxRobustnessTests.sol index 1b8267f..44f65fe 100644 --- a/script/robust/DeployEVMxRobustnessTests.sol +++ b/script/write/DeployEVMxRobustnessTests.sol @@ -6,7 +6,7 @@ import {console} from "forge-std/console.sol"; import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; -import {WriteAppGateway} from "../../src/robustness/WriteAppGateway.sol"; +import {WriteAppGateway} from "../../src/write/WriteAppGateway.sol"; contract DeployEVMxContracts is Script { function run() external { diff --git a/script/write/RunEVMxWrite.s.sol b/script/write/RunEVMxWrite.s.sol new file mode 100644 index 0000000..2824d7d --- /dev/null +++ b/script/write/RunEVMxWrite.s.sol @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {console} from "forge-std/console.sol"; +import {SetupScript} from "../SetupScript.sol"; +import {WriteAppGateway} from "../../src/write/WriteAppGateway.sol"; + +contract RunEVMxWrite is SetupScript { + WriteAppGateway writeAppGateway; + address opSepForwarder; + address arbSepForwarder; + + function appGateway() internal view override returns (address) { + return address(writeAppGateway); + } + + function getForwarderAddresses() internal { + vm.createSelectFork(rpcEVMx); + opSepForwarder = writeAppGateway.forwarderAddresses(writeAppGateway.multichain(), opSepChainId); + arbSepForwarder = writeAppGateway.forwarderAddresses(writeAppGateway.multichain(), arbSepChainId); + + console.log("Optimism Sepolia Forwarder:", opSepForwarder); + console.log("Arbitrum Sepolia Forwarder:", arbSepForwarder); + } + + function runAllTriggers() internal { + vm.createSelectFork(rpcEVMx); + vm.startBroadcast(privateKey); + console.log("Running all trigger functions..."); + + // 1. Trigger Sequential Write + console.log("triggerSequentialWrite..."); + writeAppGateway.triggerSequentialWrite(opSepForwarder); + + // 2. Trigger Parallel Write + console.log("triggerParallelWrite..."); + writeAppGateway.triggerParallelWrite(arbSepForwarder); + + // 3. Trigger Alternating Write between chains + console.log("triggerAltWrite..."); + writeAppGateway.triggerAltWrite(opSepForwarder, arbSepForwarder); + + vm.stopBroadcast(); + console.log("All triggers executed successfully"); + } + + function checkResults() internal { + vm.createSelectFork(rpcEVMx); + console.log("\n----- RESULTS -----"); + // TODO: Add check for Counter value + } + + // Initialize contract references + function init() internal { + writeAppGateway = WriteAppGateway(appGatewayAddress); + } + + function executeScriptSpecificLogic() internal override { + init(); + getForwarderAddresses(); + runAllTriggers(); + checkResults(); + } + + function run() external { + _run(arbSepChainId); + } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } +} diff --git a/src/write/IWriteMultichain.sol b/src/write/IWriteMultichain.sol index 4d1d4cf..99f5d60 100644 --- a/src/write/IWriteMultichain.sol +++ b/src/write/IWriteMultichain.sol @@ -4,13 +4,7 @@ pragma solidity >=0.7.0 <0.9.0; interface IWriteMultichain { function counter() external; - function values() external; - function increase() external; - function setValues(uint256[] memory values_) external; - - function getValue(uint256 index_) external; - function connectSocket(address appGateway_, address socket_, address switchboard_) external; } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index ecb3caf..da4b0c3 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -7,10 +7,6 @@ import "./WriteMultichain.sol"; contract WriteAppGateway is AppGatewayBase { bytes32 public multichain = _createContractId("WriteMultichain"); - uint256[] public values; - uint256[] public resolveTimes = new uint256[](10); - - uint256[] public timeoutDurations = [1, 10, 20, 30, 40, 50, 100, 500, 1000, 10000]; constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(WriteMultichain).creationCode); @@ -47,67 +43,6 @@ contract WriteAppGateway is AppGatewayBase { } } - function triggerParallelRead(address instance_) public async { - _setOverrides(Read.ON, Parallel.ON); - for (uint256 i = 0; i < 10; i++) { - IWriteMultichain(instance_).getValue(i); - IPromise(instance_).then(this.setValue.selector, abi.encode(i)); - } - } - - function triggerAltRead(address instance1_, address instance2_) public async { - _setOverrides(Read.ON, Parallel.ON); - for (uint256 i = 0; i < 10; i++) { - if (i % 2 == 0) { - IWriteMultichain(instance1_).getValue(i); - IPromise(instance1_).then(this.setValue.selector, abi.encode(i)); - } else { - IWriteMultichain(instance2_).getValue(i); - IPromise(instance2_).then(this.setValue.selector, abi.encode(i)); - } - } - } - - function triggerReadAndWrite(address instance_) public async { - _setOverrides(Read.ON, Parallel.OFF); - IWriteMultichain(instance_).getValue(0); - IPromise(instance_).then(this.setValue.selector, abi.encode(0)); - IWriteMultichain(instance_).getValue(1); - IPromise(instance_).then(this.setValue.selector, abi.encode(1)); - - _setOverrides(Read.OFF); - IWriteMultichain(instance_).increase(); - IWriteMultichain(instance_).increase(); - - _setOverrides(Read.ON); - IWriteMultichain(instance_).getValue(2); - IPromise(instance_).then(this.setValue.selector, abi.encode(2)); - IWriteMultichain(instance_).getValue(3); - IPromise(instance_).then(this.setValue.selector, abi.encode(3)); - - _setOverrides(Read.OFF); - IWriteMultichain(instance_).increase(); - IWriteMultichain(instance_).increase(); - } - - function triggerTimeouts() public { - for (uint256 i = 0; i < timeoutDurations.length; i++) { - watcherPrecompile__().setTimeout( - address(this), abi.encodeWithSelector(this.resolveTimeout.selector, i), timeoutDurations[i] - ); - } - } - - function resolveTimeout(uint256 index_) public { - resolveTimes[index_] = block.timestamp; - } - - function setValue(bytes memory data, bytes memory returnData) public onlyPromises { - uint256 index_ = abi.decode(data, (uint256)); - uint256 value_ = abi.decode(returnData, (uint256)); - values[index_] = value_; - } - function setFees(Fees memory fees_) public { fees = fees_; } diff --git a/src/write/WriteMultichain.sol b/src/write/WriteMultichain.sol index 30426f9..9ff5c63 100644 --- a/src/write/WriteMultichain.sol +++ b/src/write/WriteMultichain.sol @@ -6,28 +6,11 @@ import "socket-protocol/contracts/base/PlugBase.sol"; contract WriteMultichain is PlugBase { uint256 public counter; - uint256[] public values; + event CounterIncreasedTo(uint256); function increase() external onlySocket { counter++; - } - - function setValues(uint256[] memory values_) external { - values = new uint256[](10); - values[0] = values_[0]; - values[1] = values_[1]; - values[2] = values_[2]; - values[3] = values_[3]; - values[4] = values_[4]; - values[5] = values_[5]; - values[6] = values_[6]; - values[7] = values_[7]; - values[8] = values_[8]; - values[9] = values_[9]; - } - - function getValue(uint256 index_) external view returns (uint256) { - return values[index_]; + emit CounterIncreasedTo(counter); } function connectSocket(address appGateway_, address socket_, address switchboard_) external { From ddf758f04b94272e183168ea31e33b31e7d17a6d Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 10 Mar 2025 18:19:06 +0400 Subject: [PATCH 25/26] Update script name --- .../{DeployEVMxRobustnessTests.sol => DeployEVMxWriteTests.sol} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename script/write/{DeployEVMxRobustnessTests.sol => DeployEVMxWriteTests.sol} (100%) diff --git a/script/write/DeployEVMxRobustnessTests.sol b/script/write/DeployEVMxWriteTests.sol similarity index 100% rename from script/write/DeployEVMxRobustnessTests.sol rename to script/write/DeployEVMxWriteTests.sol From a228692d998db873a742bf657c46ba578eb0b43d Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 10 Mar 2025 19:02:10 +0400 Subject: [PATCH 26/26] Update TODO --- script/read/RunEVMxRead.s.sol | 1 + script/write/RunEVMxWrite.s.sol | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/script/read/RunEVMxRead.s.sol b/script/read/RunEVMxRead.s.sol index f32ab53..b5aa387 100644 --- a/script/read/RunEVMxRead.s.sol +++ b/script/read/RunEVMxRead.s.sol @@ -43,6 +43,7 @@ contract RunEVMxRead is SetupScript { function checkResults() internal view { console.log("\n----- RESULTS -----"); + // TODO: monitor events as Foundry reads are not reliable // Check values array console.log("Values array:"); diff --git a/script/write/RunEVMxWrite.s.sol b/script/write/RunEVMxWrite.s.sol index 2824d7d..5bc82fd 100644 --- a/script/write/RunEVMxWrite.s.sol +++ b/script/write/RunEVMxWrite.s.sol @@ -47,7 +47,7 @@ contract RunEVMxWrite is SetupScript { function checkResults() internal { vm.createSelectFork(rpcEVMx); console.log("\n----- RESULTS -----"); - // TODO: Add check for Counter value + // TODO: Add check for Counter value and/or onchain event } // Initialize contract references