diff --git a/packages/bridge-ui/src/constants/abi/Bridge.ts b/packages/bridge-ui/src/constants/abi/Bridge.ts index 444f5fbcfc2..478f8ef10cf 100644 --- a/packages/bridge-ui/src/constants/abi/Bridge.ts +++ b/packages/bridge-ui/src/constants/abi/Bridge.ts @@ -128,7 +128,7 @@ export default [ }, { indexed: false, - internalType: "enum LibBridgeData.MessageStatus", + internalType: "enum LibBridgeStatus.MessageStatus", name: "status", type: "uint8", }, @@ -217,24 +217,6 @@ export default [ stateMutability: "view", type: "function", }, - { - inputs: [ - { - internalType: "uint256", - name: "_chainId", - type: "uint256", - }, - { - internalType: "bool", - name: "enabled", - type: "bool", - }, - ], - name: "enableDestChain", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, { inputs: [ { @@ -246,7 +228,7 @@ export default [ name: "getMessageStatus", outputs: [ { - internalType: "enum LibBridgeData.MessageStatus", + internalType: "enum LibBridgeStatus.MessageStatus", name: "", type: "uint8", }, @@ -616,7 +598,7 @@ export default [ }, { internalType: "bool", - name: "lastAttempt", + name: "isLastAttempt", type: "bool", }, ], diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index 215f257f272..e42e0251f78 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -99,17 +99,6 @@ contract Bridge is EssentialContract, IBridge { }); } - function enableDestChain( - uint256 _chainId, - bool enabled - ) external nonReentrant { - LibBridgeSend.enableDestChain({ - state: state, - chainId: _chainId, - enabled: enabled - }); - } - /********************* * Public Functions * *********************/ @@ -169,6 +158,7 @@ contract Bridge is EssentialContract, IBridge { } function isDestChainEnabled(uint256 _chainId) public view returns (bool) { - return state.destChains[_chainId]; + return + LibBridgeSend.isDestChainEnabled(AddressResolver(this), _chainId); } } diff --git a/packages/protocol/contracts/bridge/libs/LibBridgeData.sol b/packages/protocol/contracts/bridge/libs/LibBridgeData.sol index 8252528c53b..b4b99b4421f 100644 --- a/packages/protocol/contracts/bridge/libs/LibBridgeData.sol +++ b/packages/protocol/contracts/bridge/libs/LibBridgeData.sol @@ -20,11 +20,9 @@ import "../IBridge.sol"; */ library LibBridgeData { struct State { - // chainId => isEnabled - mapping(uint256 => bool) destChains; uint256 nextMessageId; IBridge.Context ctx; // 3 slots - uint256[45] __gap; + uint256[46] __gap; } bytes32 internal constant SIGNAL_PLACEHOLDER = bytes32(uint256(1)); diff --git a/packages/protocol/contracts/bridge/libs/LibBridgeSend.sol b/packages/protocol/contracts/bridge/libs/LibBridgeSend.sol index 07f7bb5a9f5..fd4de05d276 100644 --- a/packages/protocol/contracts/bridge/libs/LibBridgeSend.sol +++ b/packages/protocol/contracts/bridge/libs/LibBridgeSend.sol @@ -26,7 +26,7 @@ library LibBridgeSend { * * @param message Specifies the `depositValue`, `callValue`, * and `processingFee`. These must sum to `msg.value`. It also specifies the - * `destChainId` which must be first enabled via `enableDestChain`, + * `destChainId` which must have a `bridge` address set on the AddressResolver * and differ from the current chain ID. * * @return signal The message is hashed, stored, and emitted as a signal. @@ -42,7 +42,7 @@ library LibBridgeSend { require(message.owner != address(0), "B:owner"); require( message.destChainId != block.chainid && - state.destChains[message.destChainId], + isDestChainEnabled(resolver, message.destChainId), "B:destChainId" ); @@ -69,16 +69,10 @@ library LibBridgeSend { emit LibBridgeData.MessageSent(signal, message); } - /** - * Enable a destination chain ID for bridge transactions. - */ - function enableDestChain( - LibBridgeData.State storage state, - uint256 chainId, - bool enabled - ) internal { - require(chainId > 0 && chainId != block.chainid, "B:chainId"); - state.destChains[chainId] = enabled; - emit LibBridgeData.DestChainEnabled(chainId, enabled); + function isDestChainEnabled( + AddressResolver resolver, + uint256 chainId + ) internal view returns (bool) { + return resolver.resolve(chainId, "bridge") != address(0); } } diff --git a/packages/protocol/contracts/test/bridge/libs/TestLibBridgeSend.sol b/packages/protocol/contracts/test/bridge/libs/TestLibBridgeSend.sol index 9a8d3533c43..a9b21c2b83f 100644 --- a/packages/protocol/contracts/test/bridge/libs/TestLibBridgeSend.sol +++ b/packages/protocol/contracts/test/bridge/libs/TestLibBridgeSend.sol @@ -23,12 +23,4 @@ contract TestLibBridgeSend is EssentialContract { ) public payable returns (bytes32 signal) { return LibBridgeSend.sendMessage(state, AddressResolver(this), message); } - - function enableDestChain(uint256 chainId, bool enabled) public { - LibBridgeSend.enableDestChain(state, chainId, enabled); - } - - function getDestChainStatus(uint256 chainId) public view returns (bool) { - return state.destChains[chainId]; - } } diff --git a/packages/protocol/docs/bridge/Bridge.md b/packages/protocol/docs/bridge/Bridge.md index 812951db4a2..9efb367bccf 100644 --- a/packages/protocol/docs/bridge/Bridge.md +++ b/packages/protocol/docs/bridge/Bridge.md @@ -75,12 +75,6 @@ function processMessage(struct IBridge.Message message, bytes proof) external function retryMessage(struct IBridge.Message message, bool isLastAttempt) external ``` -### enableDestChain - -```solidity -function enableDestChain(uint256 _chainId, bool enabled) external -``` - ### isMessageSent ```solidity diff --git a/packages/protocol/test/bridge/Bridge.test.ts b/packages/protocol/test/bridge/Bridge.test.ts index 10a127a6430..633262a0d7f 100644 --- a/packages/protocol/test/bridge/Bridge.test.ts +++ b/packages/protocol/test/bridge/Bridge.test.ts @@ -57,8 +57,6 @@ async function deployBridge( await bridge.connect(signer).init(addressManager.address); - await bridge.connect(signer).enableDestChain(destChain, true); - const etherVault: EtherVault = await ( await ethers.getContractFactory("EtherVault") ) @@ -107,6 +105,11 @@ describe("Bridge", function () { srcChainId ); + await addressManager.setAddress( + `${enabledDestChainId}.bridge`, + "0x0000000000000000000000000000000000000001" // dummy address so chain is "enabled" + ); + // deploy protocol contract return { owner, diff --git a/packages/protocol/test/bridge/libs/LibBridgeSend.test.ts b/packages/protocol/test/bridge/libs/LibBridgeSend.test.ts index ffc897beb57..f40c61b6406 100644 --- a/packages/protocol/test/bridge/libs/LibBridgeSend.test.ts +++ b/packages/protocol/test/bridge/libs/LibBridgeSend.test.ts @@ -27,6 +27,11 @@ describe("LibBridgeSend", function () { ).deploy(); await addressManager.init(); + await addressManager.setAddress( + `${enabledDestChainId}.bridge`, + "0x0000000000000000000000000000000000000001" // dummy address so chain is "enabled" + ); + const etherVault: EtherVault = await ( await ethers.getContractFactory("EtherVault") ) @@ -51,26 +56,6 @@ describe("LibBridgeSend", function () { .authorize(libSend.address, true); }); - describe("enableDestChain()", async function () { - it("should throw when chainId <= 0", async function () { - await expect(libSend.enableDestChain(0, true)).to.be.revertedWith( - "B:chainId" - ); - }); - - it("should throw when chainId == block.chainId", async function () { - await expect( - libSend.enableDestChain(blockChainId, true) - ).to.be.revertedWith("B:chainId"); - }); - - it("should emit DestChainEnabled() event", async function () { - expect( - await libSend.enableDestChain(enabledDestChainId, true) - ).to.emit(libSend, "DestChainEnabled"); - }); - }); - describe("sendMessage()", async function () { it("should throw when message.owner == address(0)", async function () { const nonEnabledDestChain = 2; @@ -143,8 +128,6 @@ describe("LibBridgeSend", function () { }); it("should throw when expectedAmount != msg.value", async function () { - await libSend.enableDestChain(enabledDestChainId, true); - const message: Message = { id: 1, sender: owner.address, @@ -167,8 +150,6 @@ describe("LibBridgeSend", function () { }); it("should emit MessageSent() event and signal should be hashed correctly", async function () { - await libSend.enableDestChain(enabledDestChainId, true); - const message: Message = { id: 1, sender: owner.address, diff --git a/packages/protocol/test/genesis/generate_genesis.test.ts b/packages/protocol/test/genesis/generate_genesis.test.ts index 3e8593a966b..60ab623950e 100644 --- a/packages/protocol/test/genesis/generate_genesis.test.ts +++ b/packages/protocol/test/genesis/generate_genesis.test.ts @@ -97,7 +97,7 @@ action("Generate Genesis", function () { const addressManager = new hre.ethers.Contract( addressManagerAlloc.address, require("../../artifacts/contracts/thirdparty/AddressManager.sol/AddressManager.json").abi, - provider + signer ); const owner = await addressManager.owner(); @@ -110,11 +110,11 @@ action("Generate Genesis", function () { expect(bridge).to.be.equal(getContractAlloc("Bridge").address); - const tokenValut = await addressManager.getAddress( + const tokenVault = await addressManager.getAddress( `${testConfig.chainId}.token_vault` ); - expect(tokenValut).to.be.equal( + expect(tokenVault).to.be.equal( getContractAlloc("TokenVault").address ); @@ -237,8 +237,6 @@ action("Generate Genesis", function () { expect(owner).to.be.equal(testConfig.contractOwner); - await expect(Bridge.enableDestChain(1, true)).not.to.reverted; - await expect( Bridge.processMessage( { @@ -273,6 +271,19 @@ action("Generate Genesis", function () { expect(owner).to.be.equal(testConfig.contractOwner); + const addressManager = new hre.ethers.Contract( + getContractAlloc("AddressManager").address, + require("../../artifacts/contracts/thirdparty/AddressManager.sol/AddressManager.json").abi, + signer + ); + + await expect( + addressManager.setAddress( + "1.bridge", + getContractAlloc("Bridge").address + ) + ).not.to.be.reverted; + await expect( TokenVault.sendEther( 1, diff --git a/packages/protocol/test/libs/LibTrieProof.test.ts b/packages/protocol/test/libs/LibTrieProof.test.ts index 89b5e7f1b7c..4d8829900c1 100644 --- a/packages/protocol/test/libs/LibTrieProof.test.ts +++ b/packages/protocol/test/libs/LibTrieProof.test.ts @@ -26,11 +26,18 @@ describe("integration:LibTrieProof", function () { const { chainId } = await ethers.provider.getNetwork(); + const enabledDestChainId = chainId + 1; + await addressManager.setAddress( `${chainId}.ether_vault`, "0xEA3dD11036f668F08940E13e3bcB097C93b09E07" ); + await addressManager.setAddress( + `${enabledDestChainId}.bridge`, + "0x0000000000000000000000000000000000000001" // dummy address so chain is "enabled" + ); + const libBridgeRetry = await ( await ethers.getContractFactory("LibBridgeRetry") ).deploy(); @@ -57,23 +64,21 @@ describe("integration:LibTrieProof", function () { const [owner] = await ethers.getSigners(); - return { owner, testLibTreProof, bridge }; + return { owner, testLibTreProof, bridge, enabledDestChainId }; } describe("verify()", function () { it("verifies", async function () { - const { owner, testLibTreProof, bridge } = + const { owner, testLibTreProof, bridge, enabledDestChainId } = await deployLibTrieProofFixture(); const { chainId } = await ethers.provider.getNetwork(); const srcChainId = chainId; - const destChainId = srcChainId + 1; - await (await bridge.enableDestChain(destChainId, true)).wait(); const message: Message = { id: 1, sender: owner.address, srcChainId: srcChainId, - destChainId: destChainId, + destChainId: enabledDestChainId, owner: owner.address, to: owner.address, refundAddress: owner.address, diff --git a/packages/relayer/TaikoL1.json b/packages/relayer/TaikoL1.json index 912fabe60c6..9af8ad47467 100644 --- a/packages/relayer/TaikoL1.json +++ b/packages/relayer/TaikoL1.json @@ -232,25 +232,6 @@ "name": "OwnershipTransferred", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "prover", - "type": "address" - }, - { - "indexed": false, - "internalType": "bool", - "name": "whitelisted", - "type": "bool" - } - ], - "name": "ProverWhitelisted", - "type": "event" - }, { "inputs": [], "name": "addressManager", @@ -282,6 +263,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "getBlockFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -308,77 +302,144 @@ }, { "inputs": [], - "name": "getConstants", + "name": "getConfig", "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "bytes4", - "name": "", - "type": "bytes4" - }, - { - "internalType": "bytes32", + "components": [ + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxNumBlocks", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockHashHistory", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "zkProofsPerBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxVerificationsPerTx", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "commitConfirmations", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxProofsPerForkChoice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockMaxGasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxTransactionsPerBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBytesPerTxList", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minTxGasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "anchorTxGasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "feePremiumLamda", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "rewardBurnBips", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "proposerDepositPctg", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "feeBaseMAF", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockTimeMAF", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "proofTimeMAF", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "rewardMultiplierPctg", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "feeGracePeriodPctg", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "feeMaxPeriodPctg", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "blockTimeCap", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "proofTimeCap", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "boostrapDiscountHalvingPeriod", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "initialUncleDelay", + "type": "uint64" + }, + { + "internalType": "bool", + "name": "enableTokenomics", + "type": "bool" + } + ], + "internalType": "struct TaikoData.Config", "name": "", - "type": "bytes32" + "type": "tuple" } ], "stateMutability": "pure", @@ -397,6 +458,30 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "provenAt", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "proposedAt", + "type": "uint64" + } + ], + "name": "getProofReward", + "outputs": [ + { + "internalType": "uint256", + "name": "reward", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -413,6 +498,21 @@ "internalType": "bytes32", "name": "metaHash", "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "deposit", + "type": "uint256" + }, + { + "internalType": "address", + "name": "proposer", + "type": "address" + }, + { + "internalType": "uint64", + "name": "proposedAt", + "type": "uint64" } ], "internalType": "struct TaikoData.ProposedBlock", @@ -427,6 +527,36 @@ "inputs": [], "name": "getStateVariables", "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "", + "type": "uint64" + }, { "internalType": "uint64", "name": "", @@ -463,13 +593,32 @@ "outputs": [ { "internalType": "bytes32", - "name": "", + "name": "header", "type": "bytes32" } ], "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "blockId", + "type": "uint256" + } + ], + "name": "getUncleProofDelay", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -494,6 +643,11 @@ "internalType": "bytes32", "name": "_genesisBlockHash", "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_feeBase", + "type": "uint256" } ], "name": "init", @@ -543,25 +697,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [ - { - "internalType": "address", - "name": "prover", - "type": "address" - } - ], - "name": "isProverWhitelisted", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "owner", @@ -592,7 +727,7 @@ "inputs": [ { "internalType": "uint256", - "name": "blockIndex", + "name": "blockId", "type": "uint256" }, { @@ -610,7 +745,7 @@ "inputs": [ { "internalType": "uint256", - "name": "blockIndex", + "name": "blockId", "type": "uint256" }, { @@ -712,14 +847,49 @@ "inputs": [], "name": "state", "outputs": [ + { + "internalType": "uint64", + "name": "genesisHeight", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "genesisTimestamp", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "__reservedA1", + "type": "uint64" + }, { "internalType": "uint64", "name": "statusBits", "type": "uint64" }, + { + "internalType": "uint256", + "name": "feeBase", + "type": "uint256" + }, { "internalType": "uint64", - "name": "genesisHeight", + "name": "nextBlockId", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "lastProposedAt", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "avgBlockTime", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "__avgGasLimit", "type": "uint64" }, { @@ -734,7 +904,12 @@ }, { "internalType": "uint64", - "name": "nextBlockId", + "name": "avgProofTime", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "__reservedC1", "type": "uint64" } ], @@ -766,23 +941,5 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "prover", - "type": "address" - }, - { - "internalType": "bool", - "name": "whitelisted", - "type": "bool" - } - ], - "name": "whitelistProver", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" } ] diff --git a/packages/status-page/src/constants/abi/Bridge.ts b/packages/status-page/src/constants/abi/Bridge.ts index 444f5fbcfc2..34525018b52 100644 --- a/packages/status-page/src/constants/abi/Bridge.ts +++ b/packages/status-page/src/constants/abi/Bridge.ts @@ -217,24 +217,6 @@ export default [ stateMutability: "view", type: "function", }, - { - inputs: [ - { - internalType: "uint256", - name: "_chainId", - type: "uint256", - }, - { - internalType: "bool", - name: "enabled", - type: "bool", - }, - ], - name: "enableDestChain", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, { inputs: [ { diff --git a/packages/website/docs/smart-contracts/bridge/Bridge.md b/packages/website/docs/smart-contracts/bridge/Bridge.md index 448f41941f8..a17a27816f1 100644 --- a/packages/website/docs/smart-contracts/bridge/Bridge.md +++ b/packages/website/docs/smart-contracts/bridge/Bridge.md @@ -63,12 +63,6 @@ function processMessage(struct IBridge.Message message, bytes proof) external function retryMessage(struct IBridge.Message message, bool isLastAttempt) external ``` -### enableDestChain - -```solidity -function enableDestChain(uint256 _chainId, bool enabled) external -``` - ### isMessageSent ```solidity