From 4eec5bd23cd71ddb94dbd6e97f100f69b133c1b6 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 30 Jul 2024 17:40:08 +0300 Subject: [PATCH 01/15] Rework to use config endpoint. --- contracts/config/networks.json | 5 ++--- .../bridge/001_deploy_bridge.ts | 7 ++++++- .../funding/layer1/001_fund_accounts.ts | 7 ++++++- .../funding/layer1/002_fund_faucet.ts | 10 ++++++++-- .../layer1/001_deploy_cross_chain_messenger.ts | 17 +++++++++++++---- .../layer2/001_deploy_cross_chain_messenger.ts | 7 ++++++- .../tests/helpful/spin_up_local_network_test.go | 4 ++-- integration/simulation/devnetwork/config.go | 17 +++++++++++++++++ integration/simulation/transaction_injector.go | 10 +++++----- tools/walletextension/rpcapi/net_api.go | 9 +++++++++ 10 files changed, 74 insertions(+), 19 deletions(-) diff --git a/contracts/config/networks.json b/contracts/config/networks.json index 889a53d724..6b63a7eade 100644 --- a/contracts/config/networks.json +++ b/contracts/config/networks.json @@ -2,9 +2,7 @@ "localGeth": { "url": "http://127.0.0.1:17000", "deploy": [ - "deployment_scripts/core/layer1/", - "deployment_scripts/testnet/layer1/", - "deployment_scripts/bridge/layer1/" + "deployment_scripts/core" ], "accounts": [ "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb", @@ -19,6 +17,7 @@ "layer1" : "localGeth" }, "deploy": [ + "deployment_scripts/funding/layer1", "deployment_scripts/messenger/layer1", "deployment_scripts/messenger/layer2", "deployment_scripts/bridge/", diff --git a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts index 4445679da3..056bc2a6e4 100644 --- a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts +++ b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts @@ -12,7 +12,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { deployments, getNamedAccounts } = hre; - const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + var mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + if (mgmtContractAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + mgmtContractAddress = networkConfig.ManagementContractAddress; + console.log(`Fallback read of management contract address = ${mgmtContractAddress}`); + } // L2 address of a prefunded deployer account to be used in smart contracts const accountsL2 = await getNamedAccounts(); diff --git a/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts b/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts index 7d6429b620..2b329e10f9 100644 --- a/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts +++ b/contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts @@ -8,7 +8,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const {deployer} = await hre.getNamedAccounts(); const l1Accs = await layer1.getNamedAccounts(); - const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!! + var messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!! + if (messageBusAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + messageBusAddress = networkConfig.MessageBusAddress; + console.log(`Fallback read of message bus address = ${messageBusAddress}`); + } const messageBus = (await hre.ethers.getContractFactory('MessageBus')).attach(messageBusAddress) const prefundAmount = hre.ethers.parseEther("0.5"); diff --git a/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts b/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts index ec4eedab98..3e274e62d6 100644 --- a/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts +++ b/contracts/deployment_scripts/funding/layer1/002_fund_faucet.ts @@ -8,8 +8,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const {deployer} = await hre.getNamedAccounts(); const l1Accs = await layer1.getNamedAccounts(); - const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!!// || "0xFD03804faCA2538F4633B3EBdfEfc38adafa259B" - const prefundAmountStr = process.env.PREFUND_FAUCET_AMOUNT!!// || "1" + var messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!! + if (messageBusAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + messageBusAddress = networkConfig.MessageBusAddress; + console.log(`Fallback read of message bus address = ${messageBusAddress}`); + } + + const prefundAmountStr = process.env.PREFUND_FAUCET_AMOUNT!! || "1" if (prefundAmountStr == "0") { return; diff --git a/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts b/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts index 5a742677e9..9bf9e3aaca 100644 --- a/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts +++ b/contracts/deployment_scripts/messenger/layer1/001_deploy_cross_chain_messenger.ts @@ -14,8 +14,19 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { deployer } = await hre.companionNetworks.layer1.getNamedAccounts(); // Use the contract addresses from the management contract deployment. - const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! - const messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!! + var mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + if (mgmtContractAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + mgmtContractAddress = networkConfig.ManagementContractAddress; + console.log(`Fallback read of management contract address = ${mgmtContractAddress}`); + } + + var messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!! + if (messageBusAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + messageBusAddress = networkConfig.MessageBusAddress; + console.log(`Fallback read of message bus address = ${messageBusAddress}`); + } console.log(`Management Contract address ${mgmtContractAddress}`); console.log(`Message Bus address ${messageBusAddress}`); @@ -34,8 +45,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { } }); - - console.log(`Management Contract address ${mgmtContractAddress}`); // get management contract and write the cross chain messenger address to it const mgmtContract = (await hre.ethers.getContractFactory('ManagementContract')).attach(mgmtContractAddress) const tx = await mgmtContract.getFunction("SetImportantContractAddress").populateTransaction("L1CrossChainMessenger", crossChainDeployment.address); diff --git a/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts b/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts index eba3c0b8b7..91495307e9 100644 --- a/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts +++ b/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts @@ -15,7 +15,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { companionNetworks, } = hre; // Use the contract addresses from the management contract deployment. - const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + var mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!! + if (mgmtContractAddress === undefined) { + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + mgmtContractAddress = networkConfig.ManagementContractAddress; + console.log(`Fallback read of management contract address = ${mgmtContractAddress}`); + } // Get the prefunded L2 deployer account to use for deploying. const {deployer} = await getNamedAccounts(); diff --git a/integration/networktest/tests/helpful/spin_up_local_network_test.go b/integration/networktest/tests/helpful/spin_up_local_network_test.go index 9e96230a50..b962a7371c 100644 --- a/integration/networktest/tests/helpful/spin_up_local_network_test.go +++ b/integration/networktest/tests/helpful/spin_up_local_network_test.go @@ -32,9 +32,9 @@ const ( // Spins up a local network with a gateway, with all processes debuggable. The network will run until the test is stopped. // Note: If you want to access the gateway frontend you need to `npm run build` its frontend with NEXT_PUBLIC_API_GATEWAY_URL=http://localhost:11180 func TestRunLocalNetwork(t *testing.T) { - networktest.TestOnlyRunsInIDE(t) + //networktest.TestOnlyRunsInIDE(t) networktest.EnsureTestLogsSetUp("local-geth-network") - networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway()).Prepare() + networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway(), devnetwork.WithPredictableDeployer()).Prepare() if err != nil { t.Fatal(err) } diff --git a/integration/simulation/devnetwork/config.go b/integration/simulation/devnetwork/config.go index 9ff45f3cb1..70d3fbb2a8 100644 --- a/integration/simulation/devnetwork/config.go +++ b/integration/simulation/devnetwork/config.go @@ -35,6 +35,7 @@ type TenConfig struct { NumNodes int TenGatewayEnabled bool NumSeqEnclaves int + DeployerPK string L1BlockTime time.Duration } @@ -49,6 +50,7 @@ func DefaultTenConfig() *TenConfig { CrossChainInterval: 11 * time.Second, TenGatewayEnabled: false, NumSeqEnclaves: 1, // increase for HA simulation + DeployerPK: "", } } @@ -60,6 +62,15 @@ func LocalDevNetwork(tenConfigOpts ...TenConfigOption) *InMemDevNetwork { // 1 wallet per node nodeOpL1Wallets := params.NewSimWallets(0, tenConfig.NumNodes, integration.EthereumChainID, integration.TenChainID) + + if tenConfig.DeployerPK != "" { + privKey, err := crypto.HexToECDSA(tenConfig.DeployerPK) + if err != nil { + panic("could not initialise deployer private key") + } + nodeOpL1Wallets.MCOwnerWallet = wallet.NewInMemoryWalletFromPK(big.NewInt(integration.EthereumChainID), privKey, testlog.Logger()) + } + l1Config := &L1Config{ PortStart: integration.StartPortNetworkTests, NumNodes: tenConfig.NumNodes, // we'll have 1 L1 node per L2 node @@ -130,3 +141,9 @@ func WithHASequencer() TenConfigOption { tc.NumSeqEnclaves = 2 } } + +func WithPredictableDeployer() TenConfigOption { + return func(tc *TenConfig) { + tc.DeployerPK = "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb" + } +} diff --git a/integration/simulation/transaction_injector.go b/integration/simulation/transaction_injector.go index 0b1a3ce907..a72c54dbe2 100644 --- a/integration/simulation/transaction_injector.go +++ b/integration/simulation/transaction_injector.go @@ -126,7 +126,7 @@ func NewTransactionInjector( func (ti *TransactionInjector) Start() { var wg errgroup.Group wg.Go(func() error { - ti.issueRandomDeposits() + // ti.issueRandomDeposits() return nil }) @@ -139,23 +139,23 @@ func (ti *TransactionInjector) Start() { // to do complex bridge transactions if !ti.params.IsInMem { wg.Go(func() error { - ti.bridgeRandomGasTransfers() + // ti.bridgeRandomGasTransfers() return nil }) } wg.Go(func() error { - ti.issueRandomTransfers() + // ti.issueRandomTransfers() return nil }) wg.Go(func() error { - ti.issueRandomValueTransfers() + // ti.issueRandomValueTransfers() return nil }) wg.Go(func() error { - ti.issueInvalidL2Txs() + // ti.issueInvalidL2Txs() return nil }) diff --git a/tools/walletextension/rpcapi/net_api.go b/tools/walletextension/rpcapi/net_api.go index 855c5b7a42..93a4a3d0af 100644 --- a/tools/walletextension/rpcapi/net_api.go +++ b/tools/walletextension/rpcapi/net_api.go @@ -15,3 +15,12 @@ func NewNetAPI(we *Services) *NetAPI { func (api *NetAPI) Version(ctx context.Context) (*string, error) { return UnauthenticatedTenRPCCall[string](ctx, api.we, &CacheCfg{CacheType: LongLiving}, "net_version") } + +type ConfigResponseJson struct { + ManagementContractAddress string + MessageBusAddress string +} + +func (api *NetAPI) Config(ctx context.Context) (*ConfigResponseJson, error) { + return UnauthenticatedTenRPCCall[ConfigResponseJson](ctx, api.we, &CacheCfg{CacheType: LongLiving}, "obscuro_config") +} From 91f3feec0f9f6c9ffeb9c37e12520360fe5a99dc Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 31 Jul 2024 11:19:11 +0300 Subject: [PATCH 02/15] Returning sim test. --- integration/simulation/transaction_injector.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration/simulation/transaction_injector.go b/integration/simulation/transaction_injector.go index a72c54dbe2..0b1a3ce907 100644 --- a/integration/simulation/transaction_injector.go +++ b/integration/simulation/transaction_injector.go @@ -126,7 +126,7 @@ func NewTransactionInjector( func (ti *TransactionInjector) Start() { var wg errgroup.Group wg.Go(func() error { - // ti.issueRandomDeposits() + ti.issueRandomDeposits() return nil }) @@ -139,23 +139,23 @@ func (ti *TransactionInjector) Start() { // to do complex bridge transactions if !ti.params.IsInMem { wg.Go(func() error { - // ti.bridgeRandomGasTransfers() + ti.bridgeRandomGasTransfers() return nil }) } wg.Go(func() error { - // ti.issueRandomTransfers() + ti.issueRandomTransfers() return nil }) wg.Go(func() error { - // ti.issueRandomValueTransfers() + ti.issueRandomValueTransfers() return nil }) wg.Go(func() error { - // ti.issueInvalidL2Txs() + ti.issueInvalidL2Txs() return nil }) From 6209251a81adb0e0dfea1648f9fb32f949db7b1b Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 31 Jul 2024 13:25:02 +0300 Subject: [PATCH 03/15] Revert IDE flag. --- .../networktest/tests/helpful/spin_up_local_network_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/networktest/tests/helpful/spin_up_local_network_test.go b/integration/networktest/tests/helpful/spin_up_local_network_test.go index b962a7371c..0b357108c9 100644 --- a/integration/networktest/tests/helpful/spin_up_local_network_test.go +++ b/integration/networktest/tests/helpful/spin_up_local_network_test.go @@ -32,7 +32,7 @@ const ( // Spins up a local network with a gateway, with all processes debuggable. The network will run until the test is stopped. // Note: If you want to access the gateway frontend you need to `npm run build` its frontend with NEXT_PUBLIC_API_GATEWAY_URL=http://localhost:11180 func TestRunLocalNetwork(t *testing.T) { - //networktest.TestOnlyRunsInIDE(t) + networktest.TestOnlyRunsInIDE(t) networktest.EnsureTestLogsSetUp("local-geth-network") networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway(), devnetwork.WithPredictableDeployer()).Prepare() if err != nil { From e6f231c575d8d91563a28a5430e243e343760a83 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 31 Jul 2024 13:51:59 +0300 Subject: [PATCH 04/15] Adding l2 message bus. --- .../messenger/layer2/001_deploy_cross_chain_messenger.ts | 7 ++++++- .../testnet/layer2/001_whitelist_tokens.ts | 5 +++++ tools/walletextension/rpcapi/net_api.go | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts b/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts index 91495307e9..43f6e4d869 100644 --- a/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts +++ b/contracts/deployment_scripts/messenger/layer2/001_deploy_cross_chain_messenger.ts @@ -29,7 +29,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { console.log(`Script: 001_deploy_cross_chain_messenger.ts - address used: ${deployer}`); // TODO: Remove hardcoded L2 message bus address when properly exposed. - const messageBusAddress = hre.ethers.getAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b"); + + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + console.log(`L2 MessageBus = ${networkConfig.L2MessageBusAddress}`); + var l2MessageBus = networkConfig.L2MessageBusAddress; + + const messageBusAddress = hre.ethers.getAddress(l2MessageBus); console.log(`Deploying l2 cross chain messenger.`) // Deploy the L2 Cross chain messenger and use the L2 bus for validation const crossChainDeployment = await deployments.deploy('CrossChainMessenger', { diff --git a/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts b/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts index 48950f5cc9..febd838ffd 100644 --- a/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts +++ b/contracts/deployment_scripts/testnet/layer2/001_whitelist_tokens.ts @@ -117,6 +117,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { }); // Perform message relay. This will forward the whitelist command to the L2 subordinate bridge. + // Get the balance of l2Accounts.deployer using provider + const provider = l2Network.ethers.provider; + const balance = await provider.getBalance(l2Accounts.deployer); + console.log(`Balance of l2Accounts.deployer: ${balance}`); + console.log(`Relaying messages using account ${l2Accounts.deployer}`); const relayMsg = async (msg: any) => { return l2Network.deployments.execute("CrossChainMessenger", { diff --git a/tools/walletextension/rpcapi/net_api.go b/tools/walletextension/rpcapi/net_api.go index 93a4a3d0af..208995747a 100644 --- a/tools/walletextension/rpcapi/net_api.go +++ b/tools/walletextension/rpcapi/net_api.go @@ -19,6 +19,7 @@ func (api *NetAPI) Version(ctx context.Context) (*string, error) { type ConfigResponseJson struct { ManagementContractAddress string MessageBusAddress string + L2MessageBusAddress string } func (api *NetAPI) Config(ctx context.Context) (*ConfigResponseJson, error) { From 7f975ed520999e9dbac5fb9f58e0e97976425876 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Fri, 16 Aug 2024 15:25:53 +0300 Subject: [PATCH 05/15] Dumping progress. --- contracts/config/networks.json | 16 +++ .../bridge/001_deploy_bridge.ts | 2 +- .../testing/001_gas_testing_deployment.ts | 2 +- .../testing/002_access_list_test.ts | 36 +++++++ .../testing/003_simple_withdrawal.ts | 98 +++++++++++++++++++ contracts/package.json | 4 +- contracts/src/testing/GasConsumerBalance.sol | 4 + go/common/gethencoding/geth_encoding.go | 3 + go/host/l1/statemachine.go | 2 +- go/host/rpc/clientapi/client_api_eth.go | 28 ++++++ .../helpful/spin_up_local_network_test.go | 2 +- 11 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 contracts/deployment_scripts/testing/002_access_list_test.ts create mode 100644 contracts/deployment_scripts/testing/003_simple_withdrawal.ts diff --git a/contracts/config/networks.json b/contracts/config/networks.json index 889a53d724..1f4e7c0661 100644 --- a/contracts/config/networks.json +++ b/contracts/config/networks.json @@ -31,6 +31,22 @@ "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8" ] }, + "testObscuro": { + "chainId": 443, + "url": "http://127.0.0.1:11180/v1/", + "useGateway": true, + "companionNetworks" : { + "layer1" : "localGeth" + }, + "deploy": [ + "deployment_scripts/testing" + ], + "accounts": [ + "8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b", + "6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682", + "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8" + ] + }, "hardhat": { "deploy": [ "deployment_scripts/core/layer1/", diff --git a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts index 4445679da3..af39193edf 100644 --- a/contracts/deployment_scripts/bridge/001_deploy_bridge.ts +++ b/contracts/deployment_scripts/bridge/001_deploy_bridge.ts @@ -8,7 +8,7 @@ import {DeployFunction} from 'hardhat-deploy/types'; */ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const { + const { deployments, getNamedAccounts } = hre; diff --git a/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts b/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts index d28d409bc2..bb12863e57 100644 --- a/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts +++ b/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts @@ -4,6 +4,7 @@ import { Receipt } from 'hardhat-deploy/dist/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + return; const l2Network = hre; const {deployer} = await hre.getNamedAccounts(); @@ -16,7 +17,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const gasConsumerBalance = await hre.ethers.getContractAt("GasConsumerBalance", gcb.address) const gasEstimation = await gasConsumerBalance.getFunction('get_balance').estimateGas({ from: deployer, - gasPrice: 2, }); await hre.deployments.execute("GasConsumerBalance", { diff --git a/contracts/deployment_scripts/testing/002_access_list_test.ts b/contracts/deployment_scripts/testing/002_access_list_test.ts new file mode 100644 index 0000000000..f2b65fd0e5 --- /dev/null +++ b/contracts/deployment_scripts/testing/002_access_list_test.ts @@ -0,0 +1,36 @@ +import {HardhatRuntimeEnvironment} from 'hardhat/types'; +import {DeployFunction} from 'hardhat-deploy/types'; +import { Receipt } from 'hardhat-deploy/dist/types'; + + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + return; + const l2Network = hre; + const {deployer} = await hre.getNamedAccounts(); + + const gcb = await l2Network.deployments.deploy("GasConsumerBalance", { + from: deployer, + log: true + }) + + const signer = await hre.ethers.getSigner(deployer); + + const gasConsumerBalance = await hre.ethers.getContractAt("GasConsumerBalance", gcb.address) + const gasConsumer = await gasConsumerBalance.connect(signer) + + + const tx = await gasConsumer.getFunction("resetOwner").populateTransaction(deployer); + tx.accessList = [ + { + address: gcb.address, + storageKeys: [] + }, + ]; + const resp = await signer.sendTransaction(tx); + const receipt = await resp.wait(); + console.log(`Receipt.Status=${receipt.status}`); +}; + + +export default func; +func.tags = ['GasDebug']; diff --git a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts new file mode 100644 index 0000000000..a6c24416b4 --- /dev/null +++ b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts @@ -0,0 +1,98 @@ +import {HardhatRuntimeEnvironment} from 'hardhat/types'; +import {DeployFunction} from 'hardhat-deploy/types'; +import { Receipt } from 'hardhat-deploy/dist/types'; +import { StandardMerkleTree } from "@openzeppelin/merkle-tree"; +import { keccak256 } from 'ethers'; + +function process_value_transfer(ethers, value_transfer) { + const abiTypes = ['address', 'address', 'uint256', 'uint64']; + const msg = [ + value_transfer['args'].sender, value_transfer['args'].receiver, + value_transfer['args'].amount.toString(), value_transfer['args'].sequence.toString() + ] + + const abiCoder = ethers.AbiCoder.defaultAbiCoder(); + const encodedMsg = abiCoder.encode(abiTypes, msg); + return [msg, ethers.keccak256(encodedMsg)]; + } + + + function decode_base64(base64String) { + let jsonString = atob(base64String); + return JSON.parse(jsonString); + } + + +async function sleep(ms: number) { + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); +} +async function waitForRootPublished(management, msg, proof, root, interval = 5000, timeout = 90000) { + var gas_estimate = null + const startTime = Date.now(); + while (gas_estimate === null) { + try { + gas_estimate = await management.estimateGas.ExtractNativeValue(msg, proof, root, {} ) + } catch (error) { + console.log(`Estimate gas threw error : ${error.reason}`) + } + if (Date.now() - startTime >= timeout) { + console.log(`Timed out waiting for the estimate gas to return`) + break + } + await sleep(1_000) + } + return gas_estimate +} + + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const l2Network = hre; + const {deployer} = await hre.getNamedAccounts(); + + var mbusBase = await hre.ethers.getContractAt("MessageBus", "0x526c84529b2b8c11f57d93d3f5537aca3aecef9b"); + const mbus = mbusBase.connect(await hre.ethers.provider.getSigner(deployer)); + const tx = await mbus.getFunction("sendValueToL2").send(deployer, 1000, { value: 1000}); + const receipt = await tx.wait() + console.log(`003_simple_withdrawal: Cross Chain send receipt status = ${receipt.status}`); + + const block = await hre.ethers.provider.send('eth_getBlockByHash', [receipt.blockHash, true]); + console.log(`Block received: ${block.number}`) + + + const value_transfer = mbus.interface.parseLog(receipt.logs[0]); + const _processed_value_transfer = process_value_transfer(hre.ethers, value_transfer) + const msg = _processed_value_transfer[0] + const msgHash = _processed_value_transfer[1] + const decoded = decode_base64(block.crossChainTree) + + console.log(` Sender: ${value_transfer['args'].sender}`) + console.log(` Receiver: ${value_transfer['args'].receiver}`) + console.log(` Amount: ${value_transfer['args'].amount}`) + console.log(` Sequence: ${value_transfer['args'].sequence}`) + console.log(` VTrans Hash: ${msgHash}`) + console.log(` XChain tree: ${decoded}`) + + if (decoded[0][1] != msgHash) { + console.error('Value transfer hash is not in the xchain tree!'); + return; + } + + const tree = StandardMerkleTree.of(decoded, ["string", "bytes32"]); + const proof = tree.getProof(['v',msgHash]) + console.log(` Merkle root: ${tree.root}`) + console.log(` Merkle proof: ${JSON.stringify(proof, null,2)}`) + + if (block.crossChainTreeHash != tree.root) { + console.error('Constructed merkle root matches block crossChainTreeHash'); + return + } + + var managementContract = await hre.ethers.getContractAt("ManagementContract", "0x526c84529b2b8c11f57d93d3f5537aca3aecef9b"); + +}; + + +export default func; +func.tags = ['GasDebug']; diff --git a/contracts/package.json b/contracts/package.json index 5ba922d48b..3cf84336d0 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -10,6 +10,7 @@ "author": "", "license": "ISC", "devDependencies": { + "@nomicfoundation/hardhat-ethers": "^3.0.6", "@nomicfoundation/hardhat-toolbox": "^4.0.0", "@openzeppelin/hardhat-upgrades": "^3.0.0", "@solidstate/hardhat-bytecode-exporter": "^1.1.1", @@ -23,11 +24,12 @@ "dependencies": { "@openzeppelin/contracts": "^5.0.1", "@openzeppelin/contracts-upgradeable": "^5.0.1", + "@openzeppelin/merkle-tree": "^1.0.7", "ethers": "^6.6.0", "hardhat-ignore-warnings": "^0.2.6", "ten-hardhat-plugin": "^0.0.9" }, "peerDependencies": { - "@nomicfoundation/hardhat-verify" : "2.0.8" + "@nomicfoundation/hardhat-verify": "2.0.8" } } diff --git a/contracts/src/testing/GasConsumerBalance.sol b/contracts/src/testing/GasConsumerBalance.sol index 3b42c3334e..f1ddc46d88 100644 --- a/contracts/src/testing/GasConsumerBalance.sol +++ b/contracts/src/testing/GasConsumerBalance.sol @@ -15,4 +15,8 @@ contract GasConsumerBalance { require(msg.sender == owner, "You are not the owner"); selfdestruct(payable(address(this))); } + + function resetOwner(address _owner) public { + owner = _owner; + } } \ No newline at end of file diff --git a/go/common/gethencoding/geth_encoding.go b/go/common/gethencoding/geth_encoding.go index 33f819591a..9974b6a97f 100644 --- a/go/common/gethencoding/geth_encoding.go +++ b/go/common/gethencoding/geth_encoding.go @@ -39,6 +39,7 @@ const ( callFieldGasPrice = "gasprice" callFieldMaxFeePerGas = "maxfeepergas" callFieldMaxPriorityFeePerGas = "maxpriorityfeepergas" + callFieldAccessList = "accesslist" ) // EncodingService handles conversion to Geth data structures @@ -235,6 +236,8 @@ func ExtractEthCall(param interface{}) (*gethapi.TransactionArgs, error) { return nil, fmt.Errorf("could not decode value in CallMsg - %w", err) } maxPriorityFeePerGas = (*hexutil.Big)(maxPriorityFeePerGasVal) + case callFieldAccessList: + // ignore access list for now } } diff --git a/go/host/l1/statemachine.go b/go/host/l1/statemachine.go index f3ac218eda..2de3c54da7 100644 --- a/go/host/l1/statemachine.go +++ b/go/host/l1/statemachine.go @@ -160,7 +160,7 @@ func (c *crossChainStateMachine) Synchronize() error { forkUID, _, _, err := c.publisher.GetBundleRangeFromManagementContract(big.NewInt(0).SetUint64(c.latestRollup.Number), c.latestRollup.ForkUID) if err != nil { if errors.Is(err, errutil.ErrNoNextRollup) { - c.logger.Debug("No new rollup or fork found") + c.logger.Info("No new rollup or fork found") return nil } diff --git a/go/host/rpc/clientapi/client_api_eth.go b/go/host/rpc/clientapi/client_api_eth.go index 0435302ea5..bf1231019b 100644 --- a/go/host/rpc/clientapi/client_api_eth.go +++ b/go/host/rpc/clientapi/client_api_eth.go @@ -2,6 +2,7 @@ package clientapi import ( "context" + "encoding/json" "errors" "fmt" "math/big" @@ -48,6 +49,33 @@ func (api *EthereumAPI) BlockNumber() hexutil.Uint64 { return hexutil.Uint64(header.Number.Uint64()) } +/*Access list object with the following fields: + +accessList: A list of objects with the following fields: +address: Addresses to be accessed by the transaction. +storageKeys: Storage keys to be accessed by the transaction. +gasUsed: A hexadecimal string representing the approximate gas cost for the transaction if the access list is included.*/ + +type AccessListObject struct { + Address gethcommon.Address + StorageKeys []gethcommon.Hash + GasUsed hexutil.Uint64 +} + +type AccessListResponse struct { + AccessList []AccessListObject +} + +func (api *EthereumAPI) CreateAccessList(ctx context.Context, encryptedParams common.EncryptedParamsCall) (responses.EnclaveResponse, error) { + emptyResponse := AccessListResponse{AccessList: []AccessListObject{}} + jsonResponse, err := json.Marshal(emptyResponse) + if err != nil { + return *responses.AsEmptyResponse(), err + } + + return *responses.ToEnclaveResponse(jsonResponse), nil +} + // GetBlockByNumber returns the header of the batch with the given height. func (api *EthereumAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, _ bool) (*common.BatchHeader, error) { batchHash, err := api.batchNumberToBatchHash(number) diff --git a/integration/networktest/tests/helpful/spin_up_local_network_test.go b/integration/networktest/tests/helpful/spin_up_local_network_test.go index 9e96230a50..3ddb74f60a 100644 --- a/integration/networktest/tests/helpful/spin_up_local_network_test.go +++ b/integration/networktest/tests/helpful/spin_up_local_network_test.go @@ -32,7 +32,7 @@ const ( // Spins up a local network with a gateway, with all processes debuggable. The network will run until the test is stopped. // Note: If you want to access the gateway frontend you need to `npm run build` its frontend with NEXT_PUBLIC_API_GATEWAY_URL=http://localhost:11180 func TestRunLocalNetwork(t *testing.T) { - networktest.TestOnlyRunsInIDE(t) + //networktest.TestOnlyRunsInIDE(t) networktest.EnsureTestLogsSetUp("local-geth-network") networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway()).Prepare() if err != nil { From a7b3640340a16637c2a0fac88205dee536575d64 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 21 Aug 2024 14:38:26 +0300 Subject: [PATCH 06/15] Dumping debug scripts. --- contracts/config/networks.json | 27 +++++++++++++++- .../testing/003_simple_withdrawal.ts | 31 +++++++++++++++---- integration/eth2network/pos_eth2_network.go | 2 ++ .../simulation/devnetwork/dev_network.go | 1 + 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/contracts/config/networks.json b/contracts/config/networks.json index c43f8f791a..8d1205eb39 100644 --- a/contracts/config/networks.json +++ b/contracts/config/networks.json @@ -1,6 +1,6 @@ { "localGeth": { - "url": "http://127.0.0.1:17000", + "url": "http://127.0.0.1:25400", "deploy": [ "deployment_scripts/core" ], @@ -63,5 +63,30 @@ "balance": "174165200000000000" } ] + }, + "uatGeth": { + "url": "http://dev-testnet-eth2network.uksouth.cloudapp.azure.com:8025", + "deploy": [ + "deployment_scripts/core" + ], + "accounts": [ + "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f1" + ] + }, + "testUatObscuro": { + "chainId": 443, + "url": "https://uat-testnet.ten.xyz/v1/", + "useGateway": true, + "companionNetworks" : { + "layer1" : "uatGeth" + }, + "deploy": [ + "deployment_scripts/testing" + ], + "accounts": [ + "8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b", + "6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682", + "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8" + ] } } \ No newline at end of file diff --git a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts index a6c24416b4..6784571000 100644 --- a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts +++ b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts @@ -1,8 +1,9 @@ -import {HardhatRuntimeEnvironment} from 'hardhat/types'; +import {EthereumProvider, HardhatRuntimeEnvironment} from 'hardhat/types'; import {DeployFunction} from 'hardhat-deploy/types'; import { Receipt } from 'hardhat-deploy/dist/types'; import { StandardMerkleTree } from "@openzeppelin/merkle-tree"; import { keccak256 } from 'ethers'; +import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'; function process_value_transfer(ethers, value_transfer) { const abiTypes = ['address', 'address', 'uint256', 'uint64']; @@ -28,14 +29,18 @@ async function sleep(ms: number) { setTimeout(resolve, ms); }); } -async function waitForRootPublished(management, msg, proof, root, interval = 5000, timeout = 90000) { +async function waitForRootPublished(management, msg, proof, root, provider: EthereumProvider, interval = 5000, timeout = 90000) { var gas_estimate = null + const l1Ethers = new HardhatEthersProvider(provider, "layer1") + const startTime = Date.now(); while (gas_estimate === null) { try { - gas_estimate = await management.estimateGas.ExtractNativeValue(msg, proof, root, {} ) + console.log(`Extracting native value from cross chain message for root ${root}`) + const tx = await management.getFunction('ExtractNativeValue').populateTransaction(msg, proof, root, {} ) + gas_estimate = await l1Ethers.estimateGas(tx) } catch (error) { - console.log(`Estimate gas threw error : ${error.reason}`) + console.log(`Estimate gas threw error : ${error}`) } if (Date.now() - startTime >= timeout) { console.log(`Timed out waiting for the estimate gas to return`) @@ -89,8 +94,22 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { return } - var managementContract = await hre.ethers.getContractAt("ManagementContract", "0x526c84529b2b8c11f57d93d3f5537aca3aecef9b"); - + + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + const mgmtContractAddress = networkConfig.ManagementContractAddress; + const messageBusAddress = networkConfig.MessageBusAddress; + + const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() + const fundTx = await hre.companionNetworks.layer1.deployments.rawTx({ + from: l1Accounts.deployer, + to: messageBusAddress, + value: "1000", + }) + console.log(`Message bus funding status = ${fundTx.status}`) + + var managementContract = await hre.ethers.getContractAt("ManagementContract", mgmtContractAddress); + const estimation = await waitForRootPublished(managementContract, msg, proof, tree.root, hre.companionNetworks.layer1.provider) + console.log(`Estimation for native value extraction = ${estimation}`) }; diff --git a/integration/eth2network/pos_eth2_network.go b/integration/eth2network/pos_eth2_network.go index b2625e905b..e3b811d1d2 100644 --- a/integration/eth2network/pos_eth2_network.go +++ b/integration/eth2network/pos_eth2_network.go @@ -293,6 +293,8 @@ func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPor "--beacondata-dir", beacondataDir, "--validatordata-dir", validatordataDir, ) + fmt.Println(cmd.String()) + var out bytes.Buffer cmd.Stdout = &out cmd.Stderr = &out diff --git a/integration/simulation/devnetwork/dev_network.go b/integration/simulation/devnetwork/dev_network.go index 562235314b..18239760ec 100644 --- a/integration/simulation/devnetwork/dev_network.go +++ b/integration/simulation/devnetwork/dev_network.go @@ -150,6 +150,7 @@ func (s *InMemDevNetwork) Start() { // this is a new network, deploy the contracts to the L1 fmt.Println("Deploying Ten contracts to L1") s.deployTenNetworkContracts() + fmt.Printf("L1 Port - %d\n", integration.StartPortNetworkTests) } fmt.Println("Starting Ten nodes") s.startNodes() From d24d77a6a3735c281c03411bb7e047d7f1d27932 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 21 Aug 2024 14:51:36 +0300 Subject: [PATCH 07/15] UAT version. --- .../testing/003_simple_withdrawal.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts index 6784571000..a2273aa9d8 100644 --- a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts +++ b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts @@ -95,17 +95,17 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { } - const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); - const mgmtContractAddress = networkConfig.ManagementContractAddress; - const messageBusAddress = networkConfig.MessageBusAddress; + // const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + const mgmtContractAddress = "0x946600AF6893Ee818CC7CC2dEC4D0A0bF91C9817"// networkConfig.ManagementContractAddress; + const messageBusAddress = "0x68e95924f22Be35386A8aE0240f8885967d452D6" //networkConfig.MessageBusAddress; - const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() + /* const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() const fundTx = await hre.companionNetworks.layer1.deployments.rawTx({ from: l1Accounts.deployer, to: messageBusAddress, value: "1000", }) - console.log(`Message bus funding status = ${fundTx.status}`) + console.log(`Message bus funding status = ${fundTx.status}`)*/ var managementContract = await hre.ethers.getContractAt("ManagementContract", mgmtContractAddress); const estimation = await waitForRootPublished(managementContract, msg, proof, tree.root, hre.companionNetworks.layer1.provider) From 0bb83add7dc1ce02c1e1b8957101b30f879bfdec Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 28 Aug 2024 13:22:56 +0300 Subject: [PATCH 08/15] Potential fix. --- contracts/config/networks.json | 26 +++++++++++++++++++ .../testing/003_simple_withdrawal.ts | 11 ++++---- contracts/package.json | 3 +-- go/host/l1/statemachine.go | 8 +++++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/contracts/config/networks.json b/contracts/config/networks.json index 8a604af9fd..8d233b64a4 100644 --- a/contracts/config/networks.json +++ b/contracts/config/networks.json @@ -88,5 +88,31 @@ "6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682", "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8" ] + }, + "localTestnetGeth": { + "url": "http://127.0.0.1:8025", + "deploy": [ + "deployment_scripts/core" + ], + "accounts": [ + "f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb", + "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f1" + ] + }, + "localTestnetTen": { + "chainId": 443, + "url": "http://127.0.0.1:3000/v1/", + "useGateway": true, + "companionNetworks" : { + "layer1" : "localTestnetGeth" + }, + "deploy": [ + "deployment_scripts/testing" + ], + "accounts": [ + "8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b", + "6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682", + "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8" + ] } } \ No newline at end of file diff --git a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts index 01b3024d71..f24b3ad564 100644 --- a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts +++ b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts @@ -49,6 +49,7 @@ async function waitForRootPublished(management, msg, proof, root, provider: Ethe } await sleep(1_000) } + console.log(`Estimation took ${Date.now() - startTime} ms`) return gas_estimate } @@ -96,17 +97,17 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { } - // const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); - const mgmtContractAddress = "0x946600AF6893Ee818CC7CC2dEC4D0A0bF91C9817"// networkConfig.ManagementContractAddress; - const messageBusAddress = "0x68e95924f22Be35386A8aE0240f8885967d452D6" //networkConfig.MessageBusAddress; + const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + const mgmtContractAddress = /*"0x946600AF6893Ee818CC7CC2dEC4D0A0bF91C9817"*/ networkConfig.ManagementContractAddress; + const messageBusAddress = /*"0x68e95924f22Be35386A8aE0240f8885967d452D6"*/ networkConfig.MessageBusAddress; - /* const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() + const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() const fundTx = await hre.companionNetworks.layer1.deployments.rawTx({ from: l1Accounts.deployer, to: messageBusAddress, value: "1000", }) - console.log(`Message bus funding status = ${fundTx.status}`)*/ + console.log(`Message bus funding status = ${fundTx.status}`) var managementContract = await hre.ethers.getContractAt("ManagementContract", mgmtContractAddress); const estimation = await waitForRootPublished(managementContract, msg, proof, tree.root, hre.companionNetworks.layer1.provider) diff --git a/contracts/package.json b/contracts/package.json index 40aa221b90..11faaa9eeb 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -10,7 +10,6 @@ "author": "", "license": "ISC", "devDependencies": { - "@nomicfoundation/hardhat-ethers": "^3.0.6", "@nomicfoundation/hardhat-toolbox": "^4.0.0", "@openzeppelin/hardhat-upgrades": "^3.0.0", "@solidstate/hardhat-bytecode-exporter": "^1.1.1", @@ -31,6 +30,6 @@ }, "peerDependencies": { "@nomicfoundation/hardhat-verify" : "2.0.8", - "@nomicfoundation/hardhat-ethers":"3.0.6" + "@nomicfoundation/hardhat-ethers":"3.0.5" } } \ No newline at end of file diff --git a/go/host/l1/statemachine.go b/go/host/l1/statemachine.go index 2de3c54da7..db76f31b85 100644 --- a/go/host/l1/statemachine.go +++ b/go/host/l1/statemachine.go @@ -121,8 +121,13 @@ func (c *crossChainStateMachine) PublishNextBundle() error { } bundle, err := c.enclaveClient.ExportCrossChainData(context.Background(), begin.Uint64(), end.Uint64()) - if err != nil { + if err != nil && !errors.Is(err, errutil.ErrCrossChainBundleNoBatches) { return err + } else if err != nil && errors.Is(err, errutil.ErrCrossChainBundleNoBatches) { + // If there are no cannonical batches for this rollup, move to the next rollup. + // In case a fork happens it will be revisited under different forkID produced from the management contract. + c.currentRollup++ + return nil } alreadyPublished, err := c.IsBundleAlreadyPublished(bundle) @@ -178,6 +183,7 @@ func (c *crossChainStateMachine) Synchronize() error { Number: c.latestRollup.Number + 1, } + c.logger.Info("Synchronized rollup state machine", "latestRollup", c.latestRollup.Number, "forkUID", c.latestRollup.ForkUID.String()) return nil } From 6bee21873258456d97a9ece0739c35e1c0caaa7e Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Wed, 28 Aug 2024 15:00:40 +0300 Subject: [PATCH 09/15] Fix for rpc error. --- go/host/l1/statemachine.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/go/host/l1/statemachine.go b/go/host/l1/statemachine.go index db76f31b85..405bf75468 100644 --- a/go/host/l1/statemachine.go +++ b/go/host/l1/statemachine.go @@ -15,6 +15,7 @@ import ( "github.com/ten-protocol/go-ten/go/common/stopcontrol" "github.com/ten-protocol/go-ten/go/ethadapter" "github.com/ten-protocol/go-ten/go/ethadapter/mgmtcontractlib" + "google.golang.org/grpc/status" ) type ( @@ -121,13 +122,13 @@ func (c *crossChainStateMachine) PublishNextBundle() error { } bundle, err := c.enclaveClient.ExportCrossChainData(context.Background(), begin.Uint64(), end.Uint64()) - if err != nil && !errors.Is(err, errutil.ErrCrossChainBundleNoBatches) { + if err != nil { + s, ok := status.FromError(err) + if ok && errors.Is(s.Err(), errutil.ErrCrossChainBundleNoBatches) { + c.currentRollup++ + return nil + } return err - } else if err != nil && errors.Is(err, errutil.ErrCrossChainBundleNoBatches) { - // If there are no cannonical batches for this rollup, move to the next rollup. - // In case a fork happens it will be revisited under different forkID produced from the management contract. - c.currentRollup++ - return nil } alreadyPublished, err := c.IsBundleAlreadyPublished(bundle) From a4dc14b9310e73ec5ec9dc4ba71d2d0ad01b762c Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Thu, 29 Aug 2024 15:32:52 +0300 Subject: [PATCH 10/15] Committing generated contracts. --- .../GasConsumerBalance/GasConsumerBalance.go | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/contracts/generated/GasConsumerBalance/GasConsumerBalance.go b/contracts/generated/GasConsumerBalance/GasConsumerBalance.go index 2444b2e2fa..724c46f8fe 100644 --- a/contracts/generated/GasConsumerBalance/GasConsumerBalance.go +++ b/contracts/generated/GasConsumerBalance/GasConsumerBalance.go @@ -31,8 +31,8 @@ var ( // GasConsumerBalanceMetaData contains all meta data concerning the GasConsumerBalance contract. var GasConsumerBalanceMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"destroy\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"get_balance\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", - Bin: "0x608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610157806100326000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806383197ef0146100465780638da5cb5b14610050578063c1cfb99a1461004e575b600080fd5b61004e610099565b005b6000546100709073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b60005473ffffffffffffffffffffffffffffffffffffffff16331461011e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f596f7520617265206e6f7420746865206f776e65720000000000000000000000604482015260640160405180910390fd5b30fffea26469706673582212205d989c8df853591d61707dd349944634844c4a7cbbae383852bd046ba70f7ab464736f6c63430008140033", + ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"destroy\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"get_balance\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"resetOwner\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + Bin: "0x608060405234801561001057600080fd5b50600080546001600160a01b031916331790556101b3806100326000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c806373cc802a1461005157806383197ef01461009b5780638da5cb5b146100a3578063c1cfb99a14610099575b600080fd5b61009961005f36600461014d565b600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b005b6100996100d2565b6000546100b6906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6000546001600160a01b0316331461014a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f596f7520617265206e6f7420746865206f776e65720000000000000000000000604482015260640160405180910390fd5b30ff5b60006020828403121561015f57600080fd5b81356001600160a01b038116811461017657600080fd5b939250505056fea264697066735822122028e65924c674b360c7e0fc6c4d9fb70e74b16d18a3a462b15e37d5b51b9b929b64736f6c63430008140033", } // GasConsumerBalanceABI is the input ABI used to generate the binding from. @@ -274,3 +274,24 @@ func (_GasConsumerBalance *GasConsumerBalanceSession) GetBalance() (*types.Trans func (_GasConsumerBalance *GasConsumerBalanceTransactorSession) GetBalance() (*types.Transaction, error) { return _GasConsumerBalance.Contract.GetBalance(&_GasConsumerBalance.TransactOpts) } + +// ResetOwner is a paid mutator transaction binding the contract method 0x73cc802a. +// +// Solidity: function resetOwner(address _owner) returns() +func (_GasConsumerBalance *GasConsumerBalanceTransactor) ResetOwner(opts *bind.TransactOpts, _owner common.Address) (*types.Transaction, error) { + return _GasConsumerBalance.contract.Transact(opts, "resetOwner", _owner) +} + +// ResetOwner is a paid mutator transaction binding the contract method 0x73cc802a. +// +// Solidity: function resetOwner(address _owner) returns() +func (_GasConsumerBalance *GasConsumerBalanceSession) ResetOwner(_owner common.Address) (*types.Transaction, error) { + return _GasConsumerBalance.Contract.ResetOwner(&_GasConsumerBalance.TransactOpts, _owner) +} + +// ResetOwner is a paid mutator transaction binding the contract method 0x73cc802a. +// +// Solidity: function resetOwner(address _owner) returns() +func (_GasConsumerBalance *GasConsumerBalanceTransactorSession) ResetOwner(_owner common.Address) (*types.Transaction, error) { + return _GasConsumerBalance.Contract.ResetOwner(&_GasConsumerBalance.TransactOpts, _owner) +} From 745b11d9bfde17433f04b8af2ee5c3448e9b9b67 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Thu, 29 Aug 2024 15:47:18 +0300 Subject: [PATCH 11/15] UAT changes. --- .../testing/003_simple_withdrawal.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts index f24b3ad564..c7f19ccad6 100644 --- a/contracts/deployment_scripts/testing/003_simple_withdrawal.ts +++ b/contracts/deployment_scripts/testing/003_simple_withdrawal.ts @@ -29,7 +29,7 @@ async function sleep(ms: number) { setTimeout(resolve, ms); }); } -async function waitForRootPublished(management, msg, proof, root, provider: EthereumProvider, interval = 5000, timeout = 90000) { +async function waitForRootPublished(management, msg, proof, root, provider: EthereumProvider, interval = 5000, timeout = 120000) { var gas_estimate = null const l1Ethers = new HardhatEthersProvider(provider, "layer1") @@ -47,7 +47,7 @@ async function waitForRootPublished(management, msg, proof, root, provider: Ethe console.log(`Timed out waiting for the estimate gas to return`) break } - await sleep(1_000) + await sleep(interval) } console.log(`Estimation took ${Date.now() - startTime} ms`) return gas_estimate @@ -97,9 +97,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { } - const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); - const mgmtContractAddress = /*"0x946600AF6893Ee818CC7CC2dEC4D0A0bF91C9817"*/ networkConfig.ManagementContractAddress; - const messageBusAddress = /*"0x68e95924f22Be35386A8aE0240f8885967d452D6"*/ networkConfig.MessageBusAddress; + //const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); + const mgmtContractAddress = "0x946600AF6893Ee818CC7CC2dEC4D0A0bF91C9817" // networkConfig.ManagementContractAddress; + const messageBusAddress = "0x68e95924f22Be35386A8aE0240f8885967d452D6" //networkConfig.MessageBusAddress; const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() const fundTx = await hre.companionNetworks.layer1.deployments.rawTx({ From ec0d7fef7acff0af68645d3ebc669e9ad84203d3 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Fri, 30 Aug 2024 15:40:09 +0300 Subject: [PATCH 12/15] Added dev testnet to the network config. --- contracts/config/networks.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/contracts/config/networks.json b/contracts/config/networks.json index 8d233b64a4..de384dfead 100644 --- a/contracts/config/networks.json +++ b/contracts/config/networks.json @@ -89,6 +89,31 @@ "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8" ] }, + "devGeth": { + "url": "http://dev-testnet-eth2network.uksouth.cloudapp.azure.com:8025", + "deploy": [ + "deployment_scripts/core" + ], + "accounts": [ + "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f1" + ] + }, + "testDevObscuro": { + "chainId": 443, + "url": "https://dev-testnet.ten.xyz/v1/", + "useGateway": true, + "companionNetworks" : { + "layer1" : "uatGeth" + }, + "deploy": [ + "deployment_scripts/testing" + ], + "accounts": [ + "8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b", + "6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682", + "4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8" + ] + }, "localTestnetGeth": { "url": "http://127.0.0.1:8025", "deploy": [ From 7953b04fd76d177737d30d9ca536e8b45f366872 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 3 Sep 2024 11:23:04 +0300 Subject: [PATCH 13/15] Adding back skip flag. --- go/host/l1/publisher.go | 2 ++ .../networktest/tests/helpful/spin_up_local_network_test.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go/host/l1/publisher.go b/go/host/l1/publisher.go index cf52af0d84..3ad66d65a5 100644 --- a/go/host/l1/publisher.go +++ b/go/host/l1/publisher.go @@ -313,6 +313,8 @@ func (p *Publisher) PublishCrossChainBundle(bundle *common.ExtCrossChainBundle, transactor.Nonce = big.NewInt(0).SetUint64(nonce) + p.logger.Debug("Adding cross chain roots to management contract", log.BundleHashKey, bundle.CrossChainRootHashes) + tx, err := managementCtr.AddCrossChainMessagesRoot(transactor, [32]byte(bundle.LastBatchHash.Bytes()), bundle.L1BlockHash, bundle.L1BlockNum, bundle.CrossChainRootHashes, bundle.Signature, rollupNum, forkID) if err != nil { if !errors.Is(err, errutil.ErrCrossChainBundleRepublished) { diff --git a/integration/networktest/tests/helpful/spin_up_local_network_test.go b/integration/networktest/tests/helpful/spin_up_local_network_test.go index b962a7371c..0b357108c9 100644 --- a/integration/networktest/tests/helpful/spin_up_local_network_test.go +++ b/integration/networktest/tests/helpful/spin_up_local_network_test.go @@ -32,7 +32,7 @@ const ( // Spins up a local network with a gateway, with all processes debuggable. The network will run until the test is stopped. // Note: If you want to access the gateway frontend you need to `npm run build` its frontend with NEXT_PUBLIC_API_GATEWAY_URL=http://localhost:11180 func TestRunLocalNetwork(t *testing.T) { - //networktest.TestOnlyRunsInIDE(t) + networktest.TestOnlyRunsInIDE(t) networktest.EnsureTestLogsSetUp("local-geth-network") networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway(), devnetwork.WithPredictableDeployer()).Prepare() if err != nil { From a31b81cd845712144fceec89b2950c8b3db6203b Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 3 Sep 2024 15:39:00 +0300 Subject: [PATCH 14/15] Addressed PR comments. --- .../testing/001_gas_testing_deployment.ts | 1 - go/host/rpc/clientapi/client_api_eth.go | 28 ------------------- 2 files changed, 29 deletions(-) diff --git a/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts b/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts index bb12863e57..d6062a8e60 100644 --- a/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts +++ b/contracts/deployment_scripts/testing/001_gas_testing_deployment.ts @@ -4,7 +4,6 @@ import { Receipt } from 'hardhat-deploy/dist/types'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - return; const l2Network = hre; const {deployer} = await hre.getNamedAccounts(); diff --git a/go/host/rpc/clientapi/client_api_eth.go b/go/host/rpc/clientapi/client_api_eth.go index bf1231019b..0435302ea5 100644 --- a/go/host/rpc/clientapi/client_api_eth.go +++ b/go/host/rpc/clientapi/client_api_eth.go @@ -2,7 +2,6 @@ package clientapi import ( "context" - "encoding/json" "errors" "fmt" "math/big" @@ -49,33 +48,6 @@ func (api *EthereumAPI) BlockNumber() hexutil.Uint64 { return hexutil.Uint64(header.Number.Uint64()) } -/*Access list object with the following fields: - -accessList: A list of objects with the following fields: -address: Addresses to be accessed by the transaction. -storageKeys: Storage keys to be accessed by the transaction. -gasUsed: A hexadecimal string representing the approximate gas cost for the transaction if the access list is included.*/ - -type AccessListObject struct { - Address gethcommon.Address - StorageKeys []gethcommon.Hash - GasUsed hexutil.Uint64 -} - -type AccessListResponse struct { - AccessList []AccessListObject -} - -func (api *EthereumAPI) CreateAccessList(ctx context.Context, encryptedParams common.EncryptedParamsCall) (responses.EnclaveResponse, error) { - emptyResponse := AccessListResponse{AccessList: []AccessListObject{}} - jsonResponse, err := json.Marshal(emptyResponse) - if err != nil { - return *responses.AsEmptyResponse(), err - } - - return *responses.ToEnclaveResponse(jsonResponse), nil -} - // GetBlockByNumber returns the header of the batch with the given height. func (api *EthereumAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, _ bool) (*common.BatchHeader, error) { batchHash, err := api.batchNumberToBatchHash(number) From d393b2bd44183041c5b5b509e0e198c025e9ee55 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 3 Sep 2024 15:39:45 +0300 Subject: [PATCH 15/15] PR comment. --- go/host/l1/statemachine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/host/l1/statemachine.go b/go/host/l1/statemachine.go index 405bf75468..438336a594 100644 --- a/go/host/l1/statemachine.go +++ b/go/host/l1/statemachine.go @@ -166,7 +166,7 @@ func (c *crossChainStateMachine) Synchronize() error { forkUID, _, _, err := c.publisher.GetBundleRangeFromManagementContract(big.NewInt(0).SetUint64(c.latestRollup.Number), c.latestRollup.ForkUID) if err != nil { if errors.Is(err, errutil.ErrNoNextRollup) { - c.logger.Info("No new rollup or fork found") + c.logger.Debug("No new rollup or fork found") return nil }