From 3704faf6bbe5f7c750204c62576327b34bbe0651 Mon Sep 17 00:00:00 2001 From: Ameesha Agrawal Date: Tue, 17 Oct 2023 17:37:05 +0530 Subject: [PATCH 1/3] fix: redeploy socket batcher --- contracts/socket/SocketBatcher.sol | 83 +++-------------- deployments/prod_addresses.json | 20 ++--- deployments/prod_verification.json | 48 ++++++++++ test/socket/SocketBatcher.t.sol | 139 ----------------------------- 4 files changed, 69 insertions(+), 221 deletions(-) diff --git a/contracts/socket/SocketBatcher.sol b/contracts/socket/SocketBatcher.sol index 070fa8a6..ce507a32 100644 --- a/contracts/socket/SocketBatcher.sol +++ b/contracts/socket/SocketBatcher.sol @@ -265,10 +265,10 @@ contract SocketBatcher is AccessControl { * @param socketAddress_ address of socket * @param sealRequests_ the list of requests with packets to be sealed on sourceChain */ - function _sealBatch( + function sealBatch( address socketAddress_, SealRequest[] calldata sealRequests_ - ) internal { + ) external { uint256 sealRequestLength = sealRequests_.length; for (uint256 index = 0; index < sealRequestLength; ) { ISocket(socketAddress_).seal( @@ -282,27 +282,15 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice seal a batch of packets from capacitor on sourceChain mentioned in sealRequests - * @param socketAddress_ address of socket - * @param sealRequests_ the list of requests with packets to be sealed on sourceChain - */ - function sealBatch( - address socketAddress_, - SealRequest[] calldata sealRequests_ - ) external { - _sealBatch(socketAddress_, sealRequests_); - } - /** * @notice propose a batch of packets sequentially by socketDestination * @param socketAddress_ address of socket * @param proposeRequests_ the list of requests with packets to be proposed by socketDestination */ - function _proposeBatch( + function proposeBatch( address socketAddress_, ProposeRequest[] calldata proposeRequests_ - ) internal { + ) external { uint256 proposeRequestLength = proposeRequests_.length; for (uint256 index = 0; index < proposeRequestLength; ) { ISocket(socketAddress_).proposeForSwitchboard( @@ -317,26 +305,17 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice propose a batch of packets sequentially by socketDestination - * @param socketAddress_ address of socket - * @param proposeRequests_ the list of requests with packets to be proposed by socketDestination - */ - function proposeBatch( - address socketAddress_, - ProposeRequest[] calldata proposeRequests_ - ) external { - _proposeBatch(socketAddress_, proposeRequests_); - } - /** * @notice attests a batch of Packets * @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence */ - function _attestBatch(AttestRequest[] calldata attestRequests_) internal { + function attestBatch( + address switchboardAddress_, + AttestRequest[] calldata attestRequests_ + ) external { uint256 attestRequestLength = attestRequests_.length; for (uint256 index = 0; index < attestRequestLength; ) { - FastSwitchboard(attestRequests_[index].switchboard).attest( + FastSwitchboard(switchboardAddress_).attest( attestRequests_[index].packetId, attestRequests_[index].proposalCount, attestRequests_[index].root, @@ -348,34 +327,6 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice attests a batch of Packets - * @param attestRequests_ the list of requests with packets to be attested by switchboard in sequence - */ - function attestBatch(AttestRequest[] calldata attestRequests_) external { - _attestBatch(attestRequests_); - } - - /** - * @notice send a batch of propose, attest and execute transactions - * @param socketAddress_ address of socket - * @param proposeRequests_ the list of requests with packets to be proposed - * @param attestRequests_ the list of requests with packets to be attested by switchboard - * @param executeRequests_ the list of requests with messages to be executed - */ - function sendBatch( - address socketAddress_, - SealRequest[] calldata sealRequests_, - ProposeRequest[] calldata proposeRequests_, - AttestRequest[] calldata attestRequests_, - ExecuteRequest[] calldata executeRequests_ - ) external payable { - _sealBatch(socketAddress_, sealRequests_); - _proposeBatch(socketAddress_, proposeRequests_); - _attestBatch(attestRequests_); - _executeBatch(socketAddress_, executeRequests_); - } - /** * @notice trip a batch of Proposals * @param proposalTripRequests_ the list of requests for tripping proposals @@ -412,10 +363,10 @@ contract SocketBatcher is AccessControl { * @param socketAddress_ address of socket * @param executeRequests_ the list of requests with messages to be executed in sequence */ - function _executeBatch( + function executeBatch( address socketAddress_, ExecuteRequest[] calldata executeRequests_ - ) internal { + ) external payable { uint256 executeRequestLength = executeRequests_.length; uint256 totalMsgValue = msg.value; for (uint256 index = 0; index < executeRequestLength; ) { @@ -443,18 +394,6 @@ contract SocketBatcher is AccessControl { } } - /** - * @notice executes a batch of messages - * @param socketAddress_ address of socket - * @param executeRequests_ the list of requests with messages to be executed in sequence - */ - function executeBatch( - address socketAddress_, - ExecuteRequest[] calldata executeRequests_ - ) external payable { - _executeBatch(socketAddress_, executeRequests_); - } - /** * @notice invoke receive Message on PolygonRootReceiver for a batch of messages in loop * @param polygonRootReceiverAddress_ address of polygonRootReceiver diff --git a/deployments/prod_addresses.json b/deployments/prod_addresses.json index b799d4ef..8decb069 100644 --- a/deployments/prod_addresses.json +++ b/deployments/prod_addresses.json @@ -98,7 +98,7 @@ "FastSwitchboard2": "0x6B5b7402e5bA4732D8A231552144384FC369Ce5e", "OptimisticSwitchboard": "0x3DFDc6DFa41FA64aa3a879254B41517e5ba50c56", "Counter": "0xEA33a8f11A719d728A42Ff5A860eBd7620683433", - "SocketBatcher": "0xB5f289a6Af87A65fddF1a7068F556E7d669c0D4b" + "SocketBatcher": "0x5a23e41c1ff969244eE2A5D563519b170F143AcD" }, "10": { "SignatureVerifier": "0xbb1f202095BE99000038D8d207C7E6f0F85a3925", @@ -448,7 +448,7 @@ "FastSwitchboard2": "0x7bFeb0bf17Da2eCFD3d897f11f87e0b80b3e5303", "OptimisticSwitchboard": "0xDFbf47607FBA3707E69B16576F653154a92d9B96", "Counter": "0x9d10C5D68C0878Ba255E62b3f2051f22E43A9b2f", - "SocketBatcher": "0xb80d97657277e24d70caee6dEF92BFaa7D884A7f" + "SocketBatcher": "0xE0DD154111D407Db671eAeC703CF472d3a2c5333" }, "901": { "SignatureVerifier": "0x19791877C020f7Cd5Ca1c97bdd5D268a52dbB0ff", @@ -534,7 +534,7 @@ "FastSwitchboard2": "0xB39Cb89dfD708115616fdA1a2735613931B14181", "OptimisticSwitchboard": "0x1d6E46fd4DFdfe063f9096Dc2C0862D36A25b1aD", "Counter": "0xfCa282147D5E9b14c208D09dbEbC7Eb5C3814dC5", - "SocketBatcher": "0xb2dA552c9Baa0e15b13302aBBF7B555aBc8eE4E8" + "SocketBatcher": "0xe54f19dCD6f855296F57BC26a899f278E369464e" }, "2999": { "SignatureVerifier": "0x6D290609b3F5F02D52F28d97C75a443ED8564cBf", @@ -796,7 +796,7 @@ "FastSwitchboard2": "0xedAC223C3Fe694A6d4c8407b4f6e95c299d6Eba6", "OptimisticSwitchboard": "0x6977afB0d9F041327D2C7d1E9d412685C1B202ea", "Counter": "0xAf8FcDA8536eBA1dDf2e6F8E405ADAd5C44b8568", - "SocketBatcher": "0x4941AE128a3d0d276d5ABA751B596f1173b2b762" + "SocketBatcher": "0x60dB9641eFee65c437aD8a44D3CEc7fB7934eD9c" }, "421613": { "SignatureVerifier": "0x52e987409522F2abeaD9A66B87B8914Dc5A071D9", @@ -887,7 +887,7 @@ "FastSwitchboard2": "0xB73f329E38265E6a619eeC198A8eC4DB0b9ebe21", "OptimisticSwitchboard": "0xb56e8417755685E6d01A11598f6a1229F11Cc9b5", "Counter": "0x07680Ca88B8Df538A5aB564BBBD3E4F3aBbF97eE", - "SocketBatcher": "0x3F8cdB2F8F61c31855cA6314FFA480F4dEe9574f" + "SocketBatcher": "0x762769E24b61800682B7a66C83835f9C23FB9955" }, "11155111": { "SignatureVerifier": "0x10d9DA6AE85eff6D582A91829f78bde2a3EC2dCC", @@ -899,8 +899,8 @@ "integrations": {}, "FastSwitchboard2": "0x501fCBa3e6F92b2D1d89038FeD56EdacaaF5f7c2", "OptimisticSwitchboard": "0xd84fabe06806270Fb2dDFC2255102206e3B36865", - "SocketBatcher": "0xBc3Ff3923b36F1590C16363b09c4759654d7B6d4", - "Counter": "0xE593288228d17a6D057D9a61a35F32166A6B4191" + "Counter": "0xE593288228d17a6D057D9a61a35F32166A6B4191", + "SocketBatcher": "0x6ba1161bbBC353F4173eB9f785E3A0513264769d" }, "11155112": { "SignatureVerifier": "0x7E3D0FAC82b9d5a67906f7028Aa4a70d582011b2", @@ -986,7 +986,7 @@ "FastSwitchboard2": "0x61438D1E9C9127F4996E2f74bb7BF62CC7f9B32F", "OptimisticSwitchboard": "0xFCd8ebA25c0e0973Fd131b6bF77fd8dAEcCaC75B", "Counter": "0x21abD53f1150b6DFA1111E4F2b7536F6eaA48538", - "SocketBatcher": "0xd17A64B37b432Bc344420D12eD086c5E6BEC1a30" + "SocketBatcher": "0xaE966C37eAb996B2bA55f0b3caD61564EBD691Fa" }, "1399904803": { "SignatureVerifier": "0x03D51955216a7E6F301e0613515fA86A6f3d59A9", @@ -997,7 +997,6 @@ "TransmitManager": "0x0777Ab388f065FC3CdB96008C701751827Ee171B", "FastSwitchboard2": "0x2735d5B15066049a709e680b2D400155aA5A91BE", "OptimisticSwitchboard": "0x59AcE34e5c47aEe3ec8feF2A89DcF14Ac98538C9", - "SocketBatcher": "0x0B35F40f13C3641bDed7654C9a7620cFa312aA7a", "Counter": "0x91C27Cad374246314E756f8Aa2f62F433d6F102C", "integrations": { "5": { @@ -1072,6 +1071,7 @@ "switchboard": "0x59AcE34e5c47aEe3ec8feF2A89DcF14Ac98538C9" } } - } + }, + "SocketBatcher": "0xaa95869960B4f783b17410a7E9e4b91DA3b371C4" } } diff --git a/deployments/prod_verification.json b/deployments/prod_verification.json index 807eda51..5b1a67d0 100644 --- a/deployments/prod_verification.json +++ b/deployments/prod_verification.json @@ -1,5 +1,11 @@ { "5": [ + [ + "0x5a23e41c1ff969244eE2A5D563519b170F143AcD", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xB5f289a6Af87A65fddF1a7068F556E7d669c0D4b", "SocketBatcher", @@ -479,6 +485,12 @@ ] ], "420": [ + [ + "0xE0DD154111D407Db671eAeC703CF472d3a2c5333", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xb80d97657277e24d70caee6dEF92BFaa7D884A7f", "SocketBatcher", @@ -600,6 +612,12 @@ ] ], "901": [ + [ + "0xe54f19dCD6f855296F57BC26a899f278E369464e", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xb2dA552c9Baa0e15b13302aBBF7B555aBc8eE4E8", "SocketBatcher", @@ -923,6 +941,12 @@ ] ], "80001": [ + [ + "0x60dB9641eFee65c437aD8a44D3CEc7fB7934eD9c", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0x4941AE128a3d0d276d5ABA751B596f1173b2b762", "SocketBatcher", @@ -1043,6 +1067,12 @@ ] ], "421613": [ + [ + "0x762769E24b61800682B7a66C83835f9C23FB9955", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0x3F8cdB2F8F61c31855cA6314FFA480F4dEe9574f", "SocketBatcher", @@ -1162,6 +1192,12 @@ ] ], "11155111": [ + [ + "0x6ba1161bbBC353F4173eB9f785E3A0513264769d", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xE593288228d17a6D057D9a61a35F32166A6B4191", "Counter", @@ -1264,6 +1300,12 @@ ] ], "11155112": [ + [ + "0xaE966C37eAb996B2bA55f0b3caD61564EBD691Fa", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0xd17A64B37b432Bc344420D12eD086c5E6BEC1a30", "SocketBatcher", @@ -1372,6 +1414,12 @@ ] ], "1399904803": [ + [ + "0xaa95869960B4f783b17410a7E9e4b91DA3b371C4", + "SocketBatcher", + "contracts/socket/SocketBatcher.sol", + ["0x752B38FA38F53dF7fa60e6113CFd9094b7e040Aa"] + ], [ "0x91C27Cad374246314E756f8Aa2f62F433d6F102C", "Counter", diff --git a/test/socket/SocketBatcher.t.sol b/test/socket/SocketBatcher.t.sol index edd33435..a7851a10 100644 --- a/test/socket/SocketBatcher.t.sol +++ b/test/socket/SocketBatcher.t.sol @@ -38,145 +38,6 @@ contract SocketBatcherTest is Setup { batcher__ = new SocketBatcher(address(this)); } - function testSendBatch() external { - uint256 amount = 100; - bytes memory payload = abi.encode( - keccak256("OP_ADD"), - amount, - _plugOwner - ); - bytes memory proof = abi.encode(0); - - address capacitor = address(_a.configs__[index].capacitor__); - uint256 executionFee; - { - (uint256 switchboardFees, uint256 verificationFee) = _a - .configs__[index] - .switchboard__ - .getMinFees(_b.chainSlug); - - uint256 socketFees; - (executionFee, socketFees) = _a - .executionManager__ - .getExecutionTransmissionMinFees( - _minMsgGasLimit, - 100, - bytes32(0), - _transmissionParams, - _b.chainSlug, - address(_a.transmitManager__) - ); - - uint256 value = switchboardFees + - socketFees + - verificationFee + - executionFee; - - // executionFees to be recomputed which is totalValue - (socketFees + switchboardFees) - // verificationOverheadFees also should go to Executor, hence we do the additional computation below - executionFee = verificationFee + executionFee; - - hoax(_plugOwner); - srcCounter__.remoteAddOperation{value: value}( - _b.chainSlug, - amount, - _minMsgGasLimit, - bytes32(0), - bytes32(0) - ); - } - - bytes32 packetId; - bytes32 root; - { - bytes memory sig_; - (root, packetId, sig_) = _getLatestSignature( - capacitor, - _a.chainSlug, - _b.chainSlug - ); - - _sealOnSrc(_a, capacitor, DEFAULT_BATCH_LENGTH, sig_); - - SocketBatcher.ProposeRequest memory proposeRequest = SocketBatcher - .ProposeRequest({ - packetId: packetId, - root: root, - switchboard: address(_b.configs__[0].switchboard__), - signature: sig_ - }); - SocketBatcher.ProposeRequest[] - memory proposeRequests = new SocketBatcher.ProposeRequest[](1); - proposeRequests[0] = proposeRequest; - - bytes32 digest = keccak256( - abi.encode( - address(_b.configs__[0].switchboard__), - _b.chainSlug, - packetId, - 0, - root - ) - ); - - // generate attest-signature - bytes memory attestSignature = _createSignature( - digest, - _watcherPrivateKey - ); - - SocketBatcher.AttestRequest memory attestRequest = SocketBatcher - .AttestRequest({ - switchboard: address(_b.configs__[0].switchboard__), - packetId: packetId, - proposalCount: 0, - root: root, - signature: attestSignature - }); - - SocketBatcher.AttestRequest[] - memory attestRequests = new SocketBatcher.AttestRequest[](1); - attestRequests[0] = attestRequest; - SocketBatcher.ExecuteRequest[] memory executeRequests; - SocketBatcher.SealRequest[] memory sealRequests; - - batcher__.sendBatch( - address(_b.socket__), - sealRequests, - proposeRequests, - attestRequests, - executeRequests - ); - } - - vm.expectEmit(true, false, false, false); - emit ExecutionSuccess( - _packMessageId(_a.chainSlug, address(dstCounter__), 0) - ); - _executePayloadOnDst( - _b, - ExecutePayloadOnDstParams( - packetId, - 0, - _packMessageId(_a.chainSlug, address(dstCounter__), 0), - _minMsgGasLimit, - bytes32(0), - executionFee, - root, - payload, - proof - ) - ); - - assertEq(dstCounter__.counter(), amount); - assertEq(srcCounter__.counter(), 0); - assertTrue( - _b.socket__.messageExecuted( - _packMessageId(_a.chainSlug, address(dstCounter__), 0) - ) - ); - } - function _deployPlugContracts() internal { vm.startPrank(_plugOwner); From b132629bd638d36a7055c17ae87c75d4fb47338e Mon Sep 17 00:00:00 2001 From: Ameesha Agrawal Date: Tue, 17 Oct 2023 17:38:11 +0530 Subject: [PATCH 2/3] 2.4.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61022a89..6713ab77 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@socket.tech/dl-core", "license": "UNLICENSED", - "version": "2.4.8", + "version": "2.4.9", "description": "Smart contracts for socket data layer.", "main": "./dist/src/index.js", "types": "./dist/src/index.d.ts", From 2c915d20414eee98adf0de9f37d0ef75650fa766 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 17 Oct 2023 23:17:50 +0530 Subject: [PATCH 3/3] fix: counter script --- .gitignore | 4 ++++ scripts/deploy/connect.ts | 5 +---- scripts/deploy/scripts/switchboardData.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5ed9f92f..4693c156 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ scripts/deploy/gasEstimate.ts # coverage lcov.info + +dev_switchboards.json +prod_switchboards.json +switchboards.json \ No newline at end of file diff --git a/scripts/deploy/connect.ts b/scripts/deploy/connect.ts index 24f128af..ffdb0ca5 100644 --- a/scripts/deploy/connect.ts +++ b/scripts/deploy/connect.ts @@ -46,10 +46,7 @@ export const main = async () => { const siblingIntegrationtype: IntegrationTypes[] = siblingSlugs.map( (chainSlug) => { - return getDefaultIntegrationType( - ChainSlugToKey[chain], - ChainSlugToKey[chainSlug] - ); + return getDefaultIntegrationType(chain, chainSlug); } ); diff --git a/scripts/deploy/scripts/switchboardData.ts b/scripts/deploy/scripts/switchboardData.ts index 8e5965d2..38f595c8 100644 --- a/scripts/deploy/scripts/switchboardData.ts +++ b/scripts/deploy/scripts/switchboardData.ts @@ -100,7 +100,7 @@ export const getSwitchboardData = async () => { ); console.log("total switchboards: ", switchboards.length); fs.writeFileSync( - "./switchboards.json", + `./${mode}_switchboards.json`, JSON.stringify(switchboards, null, 2) ); };