Skip to content

Commit 0ec7b69

Browse files
authored
[Sui 15/x] - Pyth upgrade script + bug fix (#936)
* upgrade script for Pyth, so far getting the dependencies and digest works * upgrade_pyth * made progress: works up until verify_vaa * delete some comments * upgrade almost works, on last step now * comments * edit * upgrade process pretty much works (we got an IncompatibleUpgrade error) * fix bug in pyth migrate process (handle_migrate threw error because take_digest was destroying non-empty cursor and not removing prefix bytes) * comments and toml file * revert change to Move.lock file * remove migrate__v__0_1_1 * prettier
1 parent 2c334b6 commit 0ec7b69

File tree

7 files changed

+330
-18
lines changed

7 files changed

+330
-18
lines changed

target_chains/sui/contracts/Move.testnet.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local = "../../../../wormhole/sui/wormhole"
1212

1313
[addresses]
1414
pyth = "0x0"
15-
wormhole = "0x80c60bff35fe5026e319cf3d66ae671f2b4e12923c92c45df75eaf4de79e3ce7"
15+
wormhole = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94"
1616

1717
[dev-addresses]
1818
pyth = "0x100"

target_chains/sui/contracts/sources/governance/contract_upgrade.move

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module pyth::contract_upgrade {
1212
use sui::object::{ID};
1313
use sui::package::{UpgradeReceipt, UpgradeTicket};
1414
use wormhole::bytes32::{Self, Bytes32};
15+
use wormhole::bytes::{Self};
1516
use wormhole::cursor::{Self};
1617
use wormhole::governance_message::{Self, DecreeTicket, DecreeReceipt};
1718

@@ -123,13 +124,17 @@ module pyth::contract_upgrade {
123124

124125
fun deserialize(payload: vector<u8>): UpgradeContract {
125126
let cur = cursor::new(payload);
127+
// Pyth upgrade governance message payloads are 40 bytes long. The breakdown looks like
128+
// 4 (magic) + 1 (module name) + 1 (action) + 2 (target chain) + 32 (digest)
126129

130+
bytes::take_bytes(&mut cur, 8); // ignore the first 8 bytes here (they were used for verification in a different code path)
127131
// This amount cannot be greater than max u64.
128132
let digest = bytes32::take_bytes(&mut cur);
129133
assert!(bytes32::is_nonzero(&digest), E_DIGEST_ZERO_BYTES);
130134

131-
cursor::destroy_empty(cur);
132-
135+
// there might be additional appended to payload in the future,
136+
// which is why we don't cursor::destroy_empty(&mut cur)
137+
cursor::take_rest(cur);
133138
UpgradeContract { digest }
134139
}
135140

target_chains/sui/contracts/sources/migrate.move

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ module pyth::migrate {
2626
pyth_state: &mut State,
2727
receipt: DecreeReceipt<GovernanceWitness>
2828
) {
29-
// This should be removed in an upgrade from 0.1.1.
30-
state::migrate__v__0_1_1(pyth_state);
3129

3230
// Perform standard migrate.
3331
handle_migrate(pyth_state, receipt);
@@ -55,8 +53,6 @@ module pyth::migrate {
5553
pyth_state: &mut State,
5654
receipt: DecreeReceipt<GovernanceWitness>
5755
) {
58-
// Update the version first.
59-
//
6056
// See `version_control` module for hard-coded configuration.
6157
state::migrate_version(pyth_state);
6258

target_chains/sui/scripts/pyth/pyth_deploy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { REGISTRY, NETWORK } from "../registry";
1818
dotenv.config({ path: "~/.env" });
1919

2020
// Network dependent settings.
21-
let network = NETWORK.MAINNET; // <= NOTE: Update this when changing network
22-
const walletPrivateKey = process.env.SUI_MAINNET; // <= NOTE: Update this when changing network
21+
let network = NETWORK.TESTNET; // <= NOTE: Update this when changing network
22+
const walletPrivateKey = process.env.SUI_TESTNET_ALT_KEY; // <= NOTE: Update this when changing network
2323

2424
const registry = REGISTRY[network];
2525
const provider = new JsonRpcProvider(
@@ -47,7 +47,7 @@ async function publishPackage(signer: RawSigner, packagePath: string) {
4747
dependencies: string[];
4848
} = JSON.parse(
4949
execSync(
50-
`sui move build --dump-bytecode-as-base64 --path ${packagePath} 2> /dev/null`,
50+
`sui move build --dump-bytecode-as-base64 --path ${__dirname}/${packagePath} 2> /dev/null`,
5151
{
5252
encoding: "utf-8",
5353
}

target_chains/sui/scripts/pyth/pyth_init_state.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { REGISTRY, NETWORK, INITIAL_DATA_SOURCES } from "../registry";
1212
dotenv.config({ path: "~/.env" });
1313

1414
// Network dependent settings.
15-
let network = NETWORK.MAINNET; // <= NOTE: Update this when changing network
16-
let walletPrivateKey = process.env.SUI_MAINNET; // <= NOTE: Update this when changing network
15+
let network = NETWORK.TESTNET; // <= NOTE: Update this when changing network
16+
let walletPrivateKey = process.env.SUI_TESTNET_ALT_KEY; // <= NOTE: Update this when changing network
1717

1818
const registry = REGISTRY[network];
1919
const initial_data_sources = INITIAL_DATA_SOURCES[network];
@@ -35,9 +35,9 @@ async function main() {
3535

3636
// NOTE: Set these before calling init_pyth
3737
const upgradeCap =
38-
"0x92d51150b762fd694877b23ecaba79a3fc1032bc24914d145a393b62e1e61894";
38+
"0x3009604c845875def6c08d6bba8769f13e8fd4c600210063cdb5bf3b3c650eca";
3939
const deployerCap =
40-
"0x645ba70c9087d54a3e5e6abed0d506516dddb71d987b0ee503593de2677caefe";
40+
"0x6655c230a23dc642d97fa9f8ab2a23a92813f23930e33f3fe20e63acfe3b60e9";
4141

4242
init_pyth(wallet, PYTH_PACKAGE, deployerCap, upgradeCap);
4343
}

0 commit comments

Comments
 (0)