Skip to content

Commit 7bc6606

Browse files
authored
[tron]: update consensus client (#762)
1 parent 6f655bb commit 7bc6606

File tree

6 files changed

+139
-1
lines changed

6 files changed

+139
-1
lines changed

evm/test/TokenGatewayForkTest.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ contract TeleportForkTest is MainnetForkBaseTest {
3838
// mainnet address holding eth and dai
3939
address whaleAccount = address(0x47ac0Fb4F2D84898e4D9E7b4DaB3C24507a6D503);
4040

41+
// Fund the whale account
42+
vm.deal(whaleAccount, 100 ether);
43+
deal(address(dai), whaleAccount, 1_000_000 * 1e6);
44+
4145
// relayer fee + per-byte fee
4246
uint256 messagingFee = (9 * 1e17) + (BODY_BYTES_SIZE * host.perByteFee(StateMachine.evm(97)));
4347

@@ -77,6 +81,9 @@ contract TeleportForkTest is MainnetForkBaseTest {
7781
// mainnet address holding eth and dai
7882
address whaleAccount = address(0x47ac0Fb4F2D84898e4D9E7b4DaB3C24507a6D503);
7983

84+
// Fund the whale account
85+
vm.deal(whaleAccount, 100 ether);
86+
8087
// relayer fee + per-byte fee
8188
uint256 messagingFee = (9 * 1e17) + (BODY_BYTES_SIZE * host.perByteFee(StateMachine.evm(97)));
8289

evm/test/UniV3UniswapV2WrapperTest.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ contract UniV3UniswapV2WrapperTest is MainnetForkBaseTest {
5151
uint256 amountOut = 485147;
5252
uint256 amountsIn = 2000000000000000000;
5353

54+
vm.deal(WHALE, 100 ether);
5455
uint256 initialDaiBalance = IERC20(DAI).balanceOf(WHALE);
5556
uint256 initialEthBalance = WHALE.balance;
5657

@@ -78,6 +79,7 @@ contract UniV3UniswapV2WrapperTest is MainnetForkBaseTest {
7879

7980
uint256 amountOutMin = 0;
8081

82+
vm.deal(WHALE, 100 ether);
8183
uint256 initialDaiBalance = IERC20(DAI).balanceOf(WHALE);
8284
uint256 initialEthBalance = WHALE.balance;
8385

evm/test/UniV4UniswapV2WrapperTest.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ contract UniV4UniswapV2WrapperTest is MainnetForkBaseTest {
5858
uint256[] memory expectedAmounts = wrapper.getAmountsOut(exactEthAmount, path);
5959
uint256 amountOutMin = expectedAmounts[1];
6060

61+
vm.deal(WHALE, 100 ether);
6162
uint256 initialDaiBalance = IERC20(DAI).balanceOf(WHALE);
6263
uint256 initialEthBalance = WHALE.balance;
6364

@@ -89,6 +90,7 @@ contract UniV4UniswapV2WrapperTest is MainnetForkBaseTest {
8990
uint256 amountOut = 1000 * 1e18;
9091
uint256 maxEthIn = 2 ether;
9192

93+
vm.deal(WHALE, 100 ether);
9294
uint256 initialEthBalance = WHALE.balance;
9395
uint256 initialDeployerBalance = DEPLOYER.balance;
9496

evm/tron/contracts/TronImports.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import {HostManager, HostManagerParams} from "../../src/core/HostManager.sol";
1919

2020
// ── Consensus ───────────────────────────────────────────────────────────────
2121

22+
import {BeefyV1} from "../../src/consensus/BeefyV1.sol";
2223
import {BeefyV1FiatShamir} from "../../src/consensus/BeefyV1FiatShamir.sol";
24+
// SP1Beefy excluded — depends on @sp1-contracts not available in TronBox
2325
import {ConsensusRouter} from "../../src/consensus/ConsensusRouter.sol";
2426
import {HeaderImpl} from "../../src/consensus/Header.sol";
2527
import {Codec} from "../../src/consensus/Codec.sol";
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
};

tesseract/consensus/beefy/src/prover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ where
213213
.collect::<Vec<_>>()
214214
.try_into()
215215
.expect("bitmap should have exactly 4 words");
216-
let encoded = (message.relay, message.parachain, bitmap_words).abi_encode();
216+
let encoded = (message.relay, message.parachain, bitmap_words).abi_encode_params();
217217
[&[PROOF_TYPE_FIAT_SHAMIR], encoded.as_slice()].concat()
218218
},
219219
};

0 commit comments

Comments
 (0)