|
| 1 | +/** |
| 2 | + * TronBox Migration: Upgrade consensus contracts |
| 3 | + * |
| 4 | + * Deploys new BeefyV1, BeefyV1FiatShamir, and ConsensusRouter, |
| 5 | + * then updates the TronHost's hostParams to use the new router. |
| 6 | + * |
| 7 | + * Required: ParachainProof was changed from `Parachain parachain` (singular) |
| 8 | + * to `Parachain[] parachains` (array) — the on-chain contracts still use the |
| 9 | + * old layout, so we must redeploy to match the current Rust prover encoding. |
| 10 | + */ |
| 11 | + |
| 12 | +const HeaderImpl = artifacts.require("HeaderImpl"); |
| 13 | +const Codec = artifacts.require("Codec"); |
| 14 | +const Transcript = artifacts.require("Transcript"); |
| 15 | +const BeefyV1 = artifacts.require("BeefyV1"); |
| 16 | +const BeefyV1FiatShamir = artifacts.require("BeefyV1FiatShamir"); |
| 17 | +const ConsensusRouter = artifacts.require("ConsensusRouter"); |
| 18 | +const TronHost = artifacts.require("TronHost"); |
| 19 | + |
| 20 | +const ZERO_ADDRESS_HEX = "0x0000000000000000000000000000000000000000"; |
| 21 | + |
| 22 | +const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); |
| 23 | +const BLOCK_TIME = 6000; |
| 24 | + |
| 25 | +module.exports = async function (deployer, network, accounts) { |
| 26 | + const hostAddress = process.env.TRON_HOST; |
| 27 | + if (!hostAddress) { |
| 28 | + console.error("ERROR: Set TRON_HOST env var to the existing TronHost address"); |
| 29 | + process.exit(1); |
| 30 | + } |
| 31 | + |
| 32 | + const tronHost = await TronHost.at(hostAddress); |
| 33 | + |
| 34 | + console.log("\n╔═══════════════════════════════════════════╗"); |
| 35 | + console.log("║ Upgrade Consensus Contracts ║"); |
| 36 | + console.log("╠═══════════════════════════════════════════╣"); |
| 37 | + console.log(`║ Network : ${network.padEnd(28)}║`); |
| 38 | + console.log(`║ TronHost : ${hostAddress.slice(0, 28).padEnd(28)}║`); |
| 39 | + console.log("╚═══════════════════════════════════════════╝\n"); |
| 40 | + |
| 41 | + // ─── 1. Deploy shared libraries ────────────────────────────────── |
| 42 | + console.log("→ Deploying HeaderImpl library ..."); |
| 43 | + await deployer.deploy(HeaderImpl); |
| 44 | + console.log(" ✓ HeaderImpl:", HeaderImpl.address); |
| 45 | + |
| 46 | + console.log("→ Deploying Codec library ..."); |
| 47 | + await deployer.deploy(Codec); |
| 48 | + console.log(" ✓ Codec:", Codec.address); |
| 49 | + |
| 50 | + console.log("→ Deploying Transcript library ..."); |
| 51 | + await deployer.deploy(Transcript); |
| 52 | + console.log(" ✓ Transcript:", Transcript.address); |
| 53 | + |
| 54 | + // ─── 2. Deploy BeefyV1 (naive proof verifier) ──────────────────── |
| 55 | + console.log("→ Linking libraries → BeefyV1 ..."); |
| 56 | + await deployer.link(HeaderImpl, BeefyV1); |
| 57 | + await deployer.link(Codec, BeefyV1); |
| 58 | + |
| 59 | + console.log("→ Deploying BeefyV1 ..."); |
| 60 | + await deployer.deploy(BeefyV1); |
| 61 | + const beefyV1 = await BeefyV1.deployed(); |
| 62 | + console.log(" ✓ BeefyV1:", beefyV1.address); |
| 63 | + |
| 64 | + // ─── 3. Deploy BeefyV1FiatShamir ───────────────────────────────── |
| 65 | + console.log("→ Linking libraries → BeefyV1FiatShamir ..."); |
| 66 | + await deployer.link(HeaderImpl, BeefyV1FiatShamir); |
| 67 | + await deployer.link(Codec, BeefyV1FiatShamir); |
| 68 | + await deployer.link(Transcript, BeefyV1FiatShamir); |
| 69 | + |
| 70 | + console.log("→ Deploying BeefyV1FiatShamir ..."); |
| 71 | + await deployer.deploy(BeefyV1FiatShamir); |
| 72 | + const beefyV1FiatShamir = await BeefyV1FiatShamir.deployed(); |
| 73 | + console.log(" ✓ BeefyV1FiatShamir:", beefyV1FiatShamir.address); |
| 74 | + |
| 75 | + // ─── 4. Deploy ConsensusRouter ─────────────────────────────────── |
| 76 | + // SP1Beefy set to zero — not available on TRON (depends on sp1-contracts) |
| 77 | + console.log("→ Deploying ConsensusRouter ..."); |
| 78 | + await deployer.deploy( |
| 79 | + ConsensusRouter, |
| 80 | + ZERO_ADDRESS_HEX, // sp1Beefy — not available on TRON |
| 81 | + beefyV1.address, // beefyV1 (naive) |
| 82 | + beefyV1FiatShamir.address, // beefyV1FiatShamir |
| 83 | + ); |
| 84 | + const newRouter = await ConsensusRouter.deployed(); |
| 85 | + console.log(" ✓ ConsensusRouter:", newRouter.address); |
| 86 | + |
| 87 | + // ─── 5. Update TronHost to use new ConsensusRouter ─────────────── |
| 88 | + console.log("→ Waiting for block confirmation ..."); |
| 89 | + await sleep(BLOCK_TIME); |
| 90 | + |
| 91 | + console.log("→ Reading current host params ..."); |
| 92 | + const currentParams = await tronHost.hostParams(); |
| 93 | + |
| 94 | + const updatedParams = [ |
| 95 | + currentParams.defaultTimeout.toString(), |
| 96 | + currentParams.defaultPerByteFee.toString(), |
| 97 | + currentParams.stateCommitmentFee.toString(), |
| 98 | + currentParams.feeToken, |
| 99 | + currentParams.admin, |
| 100 | + currentParams.handler, |
| 101 | + currentParams.hostManager, |
| 102 | + currentParams.uniswapV2, |
| 103 | + currentParams.unStakingPeriod.toString(), |
| 104 | + currentParams.challengePeriod.toString(), |
| 105 | + newRouter.address, // ← new consensusClient |
| 106 | + currentParams.stateMachines.map(sm => sm.toString()), |
| 107 | + currentParams.perByteFees.map(f => f.toString()), |
| 108 | + currentParams.hyperbridge, |
| 109 | + ]; |
| 110 | + |
| 111 | + console.log("→ Updating host params with new consensus client ..."); |
| 112 | + await tronHost.updateHostParams(updatedParams); |
| 113 | + console.log(" ✓ Host params updated"); |
| 114 | + |
| 115 | + // ─── Summary ───────────────────────────────────────────────────── |
| 116 | + console.log("\n╔═══════════════════════════════════════════════════════════╗"); |
| 117 | + console.log("║ Upgrade Summary ║"); |
| 118 | + console.log("╠═══════════════════════════════════════════════════════════╣"); |
| 119 | + console.log(`║ BeefyV1 : ${beefyV1.address}`); |
| 120 | + console.log(`║ BeefyV1FiatShamir : ${beefyV1FiatShamir.address}`); |
| 121 | + console.log(`║ SP1Beefy : (not deployed — zero address)`); |
| 122 | + console.log(`║ ConsensusRouter : ${newRouter.address}`); |
| 123 | + console.log(`║ TronHost (updated) : ${hostAddress}`); |
| 124 | + console.log("╚═══════════════════════════════════════════════════════════╝\n"); |
| 125 | +}; |
0 commit comments