From a9aa04becfb6818cbb6c8b6f402d5e173972d921 Mon Sep 17 00:00:00 2001 From: RnkSngh Date: Mon, 2 Dec 2024 15:07:44 -0800 Subject: [PATCH 1/3] generate go bindings in one package per contract/library --- Makefile | 13 +++++++++---- .../IAppStateVerifier.go | 2 +- .../IbcEventsEmitter.go | 2 +- .../IbcPacketSender.go | 2 +- .../IClientUpdates.go | 2 +- .../go/{mars => panickingmars}/PanickingMars.go | 2 +- .../go/{channel => protochannel}/ProtoChannel.go | 2 +- .../ProtoCounterparty.go | 2 +- .../RevertingBytesMars.go | 2 +- .../RevertingEmptyMars.go | 2 +- .../RevertingStringCloseChannelMars.go | 2 +- .../RevertingStringMars.go | 2 +- 12 files changed, 20 insertions(+), 15 deletions(-) rename bindings/go/{iproofverifier => iappstateverifier}/IAppStateVerifier.go (99%) rename bindings/go/{ibcdispatcher => ibceventsemitter}/IbcEventsEmitter.go (99%) rename bindings/go/{ibcdispatcher => ibcpacketsender}/IbcPacketSender.go (99%) rename bindings/go/{ilightclient => iclientupdates}/IClientUpdates.go (99%) rename bindings/go/{mars => panickingmars}/PanickingMars.go (99%) rename bindings/go/{channel => protochannel}/ProtoChannel.go (99%) rename bindings/go/{channel => protocounterparty}/ProtoCounterparty.go (99%) rename bindings/go/{mars => revertingbytesmars}/RevertingBytesMars.go (99%) rename bindings/go/{mars => revertingemptymars}/RevertingEmptyMars.go (99%) rename bindings/go/{mars => revertingstringclosechannelmars}/RevertingStringCloseChannelMars.go (99%) rename bindings/go/{mars => revertingstringmars}/RevertingStringMars.go (99%) diff --git a/Makefile b/Makefile index 20f6c446..b5bfe840 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ CONTRACT_JSON_FILES = $(filter-out $(CONTRACT_ABI_FILES),$(CONTRACT_BOTH_FILES)) .PHONY: build-contracts bindings-gen-go bindings-gen-ts build-contracts: + forge --version || exit 1; \ echo "Building contracts"; \ rm -frd ./out; \ forge install; \ @@ -54,7 +55,9 @@ build-contracts: # as they are not publicly exposed, but rather used within the contract itself. # # ABIGen issue ref: https://github.com/ethereum/solidity/issues/9278 -bindings-gen-go: build-contracts +bindings-gen-go: build-contracts + go version || exit 1; \ + abigen --version || exit 1; \ echo "Generating Go vIBC bindings..."; \ rm -rfd ./bindings/go/* ; \ for abi_file in $(CONTRACT_ABI_FILES); do \ @@ -63,14 +66,16 @@ bindings-gen-go: build-contracts continue; \ fi; \ type=$$(basename $$abi_file .abi.json); \ - pkg=$$(basename $$abi_base .sol | tr "[:upper:]" "[:lower:]"); \ + pkg=$$(basename $$type .sol | tr "[:upper:]" "[:lower:]"); \ mkdir -p ./bindings/go/$$pkg; \ abigen --abi $$abi_file --pkg $$pkg --type $$type --out ./bindings/go/$$pkg/$$type.go; \ done; \ - echo "Done." + echo Running sanity check on go bindings ; \ + go build ./... || exit 1; \ + echo "Successfully generated go bindings." bindings-gen-ts: build-contracts echo "Generating TypeScript bindings..."; \ rm -rfd ./src/evm/contracts/*; \ typechain --target ethers-v6 --out-dir ./src/evm/contracts $(CONTRACT_JSON_FILES); \ - echo "Done." + echo "Successfully generated ts bindings." diff --git a/bindings/go/iproofverifier/IAppStateVerifier.go b/bindings/go/iappstateverifier/IAppStateVerifier.go similarity index 99% rename from bindings/go/iproofverifier/IAppStateVerifier.go rename to bindings/go/iappstateverifier/IAppStateVerifier.go index f063b102..47556243 100644 --- a/bindings/go/iproofverifier/IAppStateVerifier.go +++ b/bindings/go/iappstateverifier/IAppStateVerifier.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package iproofverifier +package iappstateverifier import ( "errors" diff --git a/bindings/go/ibcdispatcher/IbcEventsEmitter.go b/bindings/go/ibceventsemitter/IbcEventsEmitter.go similarity index 99% rename from bindings/go/ibcdispatcher/IbcEventsEmitter.go rename to bindings/go/ibceventsemitter/IbcEventsEmitter.go index 55dc9c53..801d2d9e 100644 --- a/bindings/go/ibcdispatcher/IbcEventsEmitter.go +++ b/bindings/go/ibceventsemitter/IbcEventsEmitter.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package ibcdispatcher +package ibceventsemitter import ( "errors" diff --git a/bindings/go/ibcdispatcher/IbcPacketSender.go b/bindings/go/ibcpacketsender/IbcPacketSender.go similarity index 99% rename from bindings/go/ibcdispatcher/IbcPacketSender.go rename to bindings/go/ibcpacketsender/IbcPacketSender.go index ed8d4f25..b4c61ac5 100644 --- a/bindings/go/ibcdispatcher/IbcPacketSender.go +++ b/bindings/go/ibcpacketsender/IbcPacketSender.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package ibcdispatcher +package ibcpacketsender import ( "errors" diff --git a/bindings/go/ilightclient/IClientUpdates.go b/bindings/go/iclientupdates/IClientUpdates.go similarity index 99% rename from bindings/go/ilightclient/IClientUpdates.go rename to bindings/go/iclientupdates/IClientUpdates.go index 6eda62b1..2f61215b 100644 --- a/bindings/go/ilightclient/IClientUpdates.go +++ b/bindings/go/iclientupdates/IClientUpdates.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package ilightclient +package iclientupdates import ( "errors" diff --git a/bindings/go/mars/PanickingMars.go b/bindings/go/panickingmars/PanickingMars.go similarity index 99% rename from bindings/go/mars/PanickingMars.go rename to bindings/go/panickingmars/PanickingMars.go index fdbe7af4..e6ac106d 100644 --- a/bindings/go/mars/PanickingMars.go +++ b/bindings/go/panickingmars/PanickingMars.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package mars +package panickingmars import ( "errors" diff --git a/bindings/go/channel/ProtoChannel.go b/bindings/go/protochannel/ProtoChannel.go similarity index 99% rename from bindings/go/channel/ProtoChannel.go rename to bindings/go/protochannel/ProtoChannel.go index a3833aec..d3d1063b 100644 --- a/bindings/go/channel/ProtoChannel.go +++ b/bindings/go/protochannel/ProtoChannel.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package channel +package protochannel import ( "errors" diff --git a/bindings/go/channel/ProtoCounterparty.go b/bindings/go/protocounterparty/ProtoCounterparty.go similarity index 99% rename from bindings/go/channel/ProtoCounterparty.go rename to bindings/go/protocounterparty/ProtoCounterparty.go index f0026a7f..52352893 100644 --- a/bindings/go/channel/ProtoCounterparty.go +++ b/bindings/go/protocounterparty/ProtoCounterparty.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package channel +package protocounterparty import ( "errors" diff --git a/bindings/go/mars/RevertingBytesMars.go b/bindings/go/revertingbytesmars/RevertingBytesMars.go similarity index 99% rename from bindings/go/mars/RevertingBytesMars.go rename to bindings/go/revertingbytesmars/RevertingBytesMars.go index 3bc96da0..391338d2 100644 --- a/bindings/go/mars/RevertingBytesMars.go +++ b/bindings/go/revertingbytesmars/RevertingBytesMars.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package mars +package revertingbytesmars import ( "errors" diff --git a/bindings/go/mars/RevertingEmptyMars.go b/bindings/go/revertingemptymars/RevertingEmptyMars.go similarity index 99% rename from bindings/go/mars/RevertingEmptyMars.go rename to bindings/go/revertingemptymars/RevertingEmptyMars.go index 3715ea8e..a2847e83 100644 --- a/bindings/go/mars/RevertingEmptyMars.go +++ b/bindings/go/revertingemptymars/RevertingEmptyMars.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package mars +package revertingemptymars import ( "errors" diff --git a/bindings/go/mars/RevertingStringCloseChannelMars.go b/bindings/go/revertingstringclosechannelmars/RevertingStringCloseChannelMars.go similarity index 99% rename from bindings/go/mars/RevertingStringCloseChannelMars.go rename to bindings/go/revertingstringclosechannelmars/RevertingStringCloseChannelMars.go index 99b9e9c5..4cb496a0 100644 --- a/bindings/go/mars/RevertingStringCloseChannelMars.go +++ b/bindings/go/revertingstringclosechannelmars/RevertingStringCloseChannelMars.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package mars +package revertingstringclosechannelmars import ( "errors" diff --git a/bindings/go/mars/RevertingStringMars.go b/bindings/go/revertingstringmars/RevertingStringMars.go similarity index 99% rename from bindings/go/mars/RevertingStringMars.go rename to bindings/go/revertingstringmars/RevertingStringMars.go index da54b1bf..93b622c7 100644 --- a/bindings/go/mars/RevertingStringMars.go +++ b/bindings/go/revertingstringmars/RevertingStringMars.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package mars +package revertingstringmars import ( "errors" From bc2b6dcbf25dae3f7357212783a601c532252299 Mon Sep 17 00:00:00 2001 From: RnkSngh Date: Mon, 2 Dec 2024 15:21:56 -0800 Subject: [PATCH 2/3] default to not running fork tests --- .github/workflows/foundry.yml | 1 + test/Fork/Dispatcher.deploy.t.sol | 119 ++++++++++++++++-------------- 2 files changed, 66 insertions(+), 54 deletions(-) diff --git a/.github/workflows/foundry.yml b/.github/workflows/foundry.yml index d7dd1355..fd381246 100644 --- a/.github/workflows/foundry.yml +++ b/.github/workflows/foundry.yml @@ -41,6 +41,7 @@ jobs: env: MODULE_ROOT_PATH: "./" RPC_URL: ${{ secrets.FORK_RPC_URL }} + RUN_FORK_TEST: true CHAIN_NAME: "fork-test-ci" DUMMY_DEPLOYER_PRIVATE_KEY: ${{ secrets.DUMMY_DEPLOYER_PRIVATE_KEY }} DAPP_PRIVATE_KEY_1: ${{ secrets.DAPP_PRIVATE_KEY_1 }} diff --git a/test/Fork/Dispatcher.deploy.t.sol b/test/Fork/Dispatcher.deploy.t.sol index 4f19a6d2..fb993ca2 100644 --- a/test/Fork/Dispatcher.deploy.t.sol +++ b/test/Fork/Dispatcher.deploy.t.sol @@ -47,65 +47,76 @@ contract DispatcherDeployTest is ChannelHandShakeUpgradeUtil, UpgradeTestUtils { string portPrefix1 = "polyibc.eth1."; string portId1 = "polyibc.eth1.71C95911E9a5D330f4D621842EC243EE1343292e"; string portId2 = "polyibc.eth2.71C95911E9a5D330f4D621842EC243EE1343292e"; + bool skipFork = !vm.envOr("RUN_FORK_TEST", false); // we default to not running tests function setUp() public override { - ChainAddresses memory addresses = ChainAddresses( - IDispatcher(vm.envAddress("DispatcherProxy")), - IUniversalChannelHandler(vm.envAddress("UCProxy")), - ILightClient(vm.envAddress("OptimisticLightClient")), - vm.envAddress("OwnerAddress") - ); - - opLightClient = addresses.optimisticLightClient; // Need to set this so that when we call load_proof, it loads - // the proof to the right address - - mars = Mars(payable(targetMarsAddress)); - - dispatcherProxy = addresses.dispatcherProxy; - vm.prank(addresses.owner); - - // For now, we need to change the portPrefix to that of the one which was used to generate the proof. We also - // have to set that for the connectionHop to light client mapping. - // Ideally, we can move to eventually automatically generating the proof by querying on chain. - dispatcherProxy.setPortPrefix(portPrefix1); - // Use legacy mars implementation to test upgrade compatibility - deployCodeTo("contracts/examples/Mars.sol:Mars", abi.encode(address(dispatcherProxy)), targetMarsAddress); - - // We have to set the connection hops to hard-coded values since these will be checked in the proof - connectionHops0 = ["connection-0", "connection-3"]; - connectionHops1 = ["connection-2", "connection-1"]; - - vm.startPrank(addresses.owner); // Only sender should have permission - dispatcherProxy.setClientForConnection("connection-0", opLightClient); - - dispatcherProxy.setClientForConnection("connection-2", opLightClient); - vm.stopPrank(); - - _local = LocalEnd(IbcChannelReceiver(targetMarsAddress), portId1, "channel-0", connectionHops0, "1.0", "1.0"); - _remote = ChannelEnd(portId2, "channel-1", "1.0"); - - // Do handshake as if Mars was the sending localparty - doSrcProofChannelHandshake(_local, _remote); - - // Do handshake as if Mars was the receiving counterparty - doDestProofChannelHandshake( - _remote, - ChannelEnd(_local.portId, _local.channelId, _local.versionCall), - connectionHops1, - _local.versionExpected, - mars - ); - - // State should be initialized correctly & not impacted after any upgrades; used to check for malformatted state - uint64 nextSequenceRecvValue = - uint64(uint256(vm.load(address(dispatcherProxy), findNextSequenceRecv(address(mars), _local.channelId)))); - uint64 nextSequenceAckValue = - uint64(uint256(vm.load(address(dispatcherProxy), findNextSequenceAck(address(mars), _local.channelId)))); - assertEq(1, nextSequenceRecvValue); - assertEq(1, nextSequenceAckValue); + if (!skipFork) { + ChainAddresses memory addresses = ChainAddresses( + IDispatcher(vm.envAddress("DispatcherProxy")), + IUniversalChannelHandler(vm.envAddress("UCProxy")), + ILightClient(vm.envAddress("OptimisticLightClient")), + vm.envAddress("OwnerAddress") + ); + + opLightClient = addresses.optimisticLightClient; // Need to set this so that when we call load_proof, it + // loads + // the proof to the right address + + mars = Mars(payable(targetMarsAddress)); + + dispatcherProxy = addresses.dispatcherProxy; + vm.prank(addresses.owner); + + // For now, we need to change the portPrefix to that of the one which was used to generate the proof. We + // also + // have to set that for the connectionHop to light client mapping. + // Ideally, we can move to eventually automatically generating the proof by querying on chain. + dispatcherProxy.setPortPrefix(portPrefix1); + // Use legacy mars implementation to test upgrade compatibility + deployCodeTo("contracts/examples/Mars.sol:Mars", abi.encode(address(dispatcherProxy)), targetMarsAddress); + + // We have to set the connection hops to hard-coded values since these will be checked in the proof + connectionHops0 = ["connection-0", "connection-3"]; + connectionHops1 = ["connection-2", "connection-1"]; + + vm.startPrank(addresses.owner); // Only sender should have permission + dispatcherProxy.setClientForConnection("connection-0", opLightClient); + + dispatcherProxy.setClientForConnection("connection-2", opLightClient); + vm.stopPrank(); + + _local = + LocalEnd(IbcChannelReceiver(targetMarsAddress), portId1, "channel-0", connectionHops0, "1.0", "1.0"); + _remote = ChannelEnd(portId2, "channel-1", "1.0"); + + // Do handshake as if Mars was the sending localparty + doSrcProofChannelHandshake(_local, _remote); + + // Do handshake as if Mars was the receiving counterparty + doDestProofChannelHandshake( + _remote, + ChannelEnd(_local.portId, _local.channelId, _local.versionCall), + connectionHops1, + _local.versionExpected, + mars + ); + + // State should be initialized correctly & not impacted after any upgrades; used to check for malformatted + // state + uint64 nextSequenceRecvValue = uint64( + uint256(vm.load(address(dispatcherProxy), findNextSequenceRecv(address(mars), _local.channelId))) + ); + uint64 nextSequenceAckValue = + uint64(uint256(vm.load(address(dispatcherProxy), findNextSequenceAck(address(mars), _local.channelId)))); + assertEq(1, nextSequenceRecvValue); + assertEq(1, nextSequenceAckValue); + } else { + console2.log("skipping fork test since RUN_FORK_TEST was not set to true"); + } } function test_Deployment_SentPacketState_Conserved() public { + vm.skip(skipFork); // Skip if we don't opt-in to running fork tests // Send a few packets as if mars was sending party payload = "packet-1"; // Overwrite these values for inheriting class packet = abi.encodePacked(payload); From 4540d19072bebf968bdb9e33307f16f9215cc6b9 Mon Sep 17 00:00:00 2001 From: RnkSngh Date: Mon, 2 Dec 2024 15:22:35 -0800 Subject: [PATCH 3/3] modify go bindings generation to fail if abi gen isn't found --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b5bfe840..431b5639 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ bindings-gen-go: build-contracts type=$$(basename $$abi_file .abi.json); \ pkg=$$(basename $$type .sol | tr "[:upper:]" "[:lower:]"); \ mkdir -p ./bindings/go/$$pkg; \ - abigen --abi $$abi_file --pkg $$pkg --type $$type --out ./bindings/go/$$pkg/$$type.go; \ + abigen --abi $$abi_file --pkg $$pkg --type $$type --out ./bindings/go/$$pkg/$$type.go || exit 1; \ done; \ echo Running sanity check on go bindings ; \ go build ./... || exit 1; \