Skip to content

Commit 2a5be25

Browse files
[MVR]prepare Talus token for MVR (#26)
* Prepare Talus token for MVR * Clarify token overview * Improve token README flow
1 parent f31428c commit 2a5be25

12 files changed

Lines changed: 416 additions & 136 deletions

File tree

‎.github/actions/fetch-sui-cli/action.yml‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,34 @@ inputs:
77
runs:
88
using: "composite"
99
steps:
10-
- run: mkdir -p /home/runner/.local/bin
10+
- name: Install Sui CLI
1111
shell: bash
12-
- run: wget "https://github.com/MystenLabs/sui/releases/download/${{ inputs.sui_ref }}/sui-${{ inputs.sui_ref }}-ubuntu-x86_64.tgz"
13-
shell: bash
14-
- run: tar -xvzf "sui-${{ inputs.sui_ref }}-ubuntu-x86_64.tgz" -C /home/runner/.local/bin
15-
shell: bash
16-
- run: sudo chmod +x /home/runner/.local/bin/sui
17-
shell: bash
18-
- run: sui --version
19-
shell: bash
12+
env:
13+
SUI_REF: ${{ inputs.sui_ref }}
14+
run: |
15+
set -euo pipefail
16+
archive="$RUNNER_TEMP/sui-$SUI_REF.tgz"
17+
bin_dir="$RUNNER_TEMP/sui-$SUI_REF/bin"
18+
mkdir -p "$bin_dir"
19+
curl --fail --location --retry 3 \
20+
"https://github.com/MystenLabs/sui/releases/download/$SUI_REF/sui-$SUI_REF-ubuntu-x86_64.tgz" \
21+
--output "$archive"
22+
python3 - "$archive" "$bin_dir/sui" <<'PY'
23+
import pathlib
24+
import shutil
25+
import sys
26+
import tarfile
27+
28+
with tarfile.open(sys.argv[1], "r:gz") as archive:
29+
binaries = [
30+
member for member in archive.getmembers()
31+
if member.isfile() and pathlib.PurePosixPath(member.name).name == "sui"
32+
]
33+
if len(binaries) != 1:
34+
raise SystemExit("Expected exactly one Sui binary in the release archive")
35+
with archive.extractfile(binaries[0]) as source, open(sys.argv[2], "wb") as target:
36+
shutil.copyfileobj(source, target)
37+
PY
38+
chmod +x "$bin_dir/sui"
39+
echo "$bin_dir" >> "$GITHUB_PATH"
40+
"$bin_dir/sui" --version

‎.github/workflows/sui-move-ci.yml‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ main, master ]
88

99
env:
10-
SUI_REF: mainnet-v1.45.3
10+
SUI_REF: testnet-v1.80.0
1111

1212
jobs:
1313
build-and-test:
@@ -27,3 +27,23 @@ jobs:
2727

2828
- name: Build and Test
2929
run: just build-test
30+
31+
- name: Check consumer deployments
32+
run: |
33+
just test-dependency mainnet
34+
just test-dependency testnet
35+
36+
verify-token-bytecode:
37+
name: Verify published token bytecode
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Check out repository code
41+
uses: actions/checkout@v6
42+
43+
- name: Fetch release compiler
44+
uses: ./.github/actions/fetch-sui-cli
45+
with:
46+
sui_ref: mainnet-v1.59.1
47+
48+
- name: Reproduce published module
49+
run: python3 Tests/dependency/verify.py bytecode

‎.gitignore‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ build/
4545

4646
#Move Lock
4747
*.lock
48+
!Tests/dependency/Move.lock
49+
50+
# Temporary publication records
51+
Pub.*.toml
4852

4953
# Move coverage and tracing information
5054
.trace
@@ -55,4 +59,4 @@ target-out-docker
5559
**/Dockerfile.tmp
5660

5761
# Doc generation output
58-
*.md.old
62+
*.md.old

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ talus-token/
2323
## Contracts
2424

2525
### Talus Contract
26-
A custom coin implementation on the Sui blockchain.
26+
The US coin on Sui. See the [token documentation](talus/README.md) for deployment addresses, MVR usage, supply behavior, and the public interface.
2727

2828
### Loyalty Token Contract
2929
A custom token implementation on the Sui blockchain. Repeated used for every deposit pool instance.

‎Tests/dependency/Move.lock‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Generated by move; do not edit
2+
# This file should be checked in.
3+
4+
[move]
5+
version = 4
6+
7+
[pinned.mainnet.MoveStdlib]
8+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/move-stdlib", rev = "2a0becb2fcc6989e492981104af67f62f2c9511a" }
9+
use_environment = "mainnet"
10+
manifest_digest = "C4FE4C91DE74CBF223B2E380AE40F592177D21870DC2D7EB6227D2D694E05363"
11+
deps = {}
12+
13+
[pinned.mainnet.Sui]
14+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "2a0becb2fcc6989e492981104af67f62f2c9511a" }
15+
use_environment = "mainnet"
16+
manifest_digest = "CD547CB1ACCE0880C835DAED2D8FFCB91D56C833AE5240D3AA5B918398263195"
17+
deps = { MoveStdlib = "MoveStdlib" }
18+
19+
[pinned.mainnet.Talus]
20+
source = { local = "../../talus" }
21+
use_environment = "mainnet"
22+
manifest_digest = "E41BBD67BE8940D26C79D78B028477EF5B33BA217A1282C78ACB344CF8A5ECF6"
23+
deps = { std = "MoveStdlib", sui = "Sui" }
24+
25+
[pinned.mainnet.dependency]
26+
source = { root = true }
27+
use_environment = "mainnet"
28+
manifest_digest = "A42B746C9FB93599E742B4E7377BECD32082274B642F763C3D768D49A16046B4"
29+
deps = { std = "MoveStdlib", sui = "Sui", talus = "Talus" }
30+
31+
[pinned.testnet.MoveStdlib]
32+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/move-stdlib", rev = "2a0becb2fcc6989e492981104af67f62f2c9511a" }
33+
use_environment = "testnet"
34+
manifest_digest = "C4FE4C91DE74CBF223B2E380AE40F592177D21870DC2D7EB6227D2D694E05363"
35+
deps = {}
36+
37+
[pinned.testnet.Sui]
38+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "2a0becb2fcc6989e492981104af67f62f2c9511a" }
39+
use_environment = "testnet"
40+
manifest_digest = "7AFB66695545775FBFBB2D3078ADFD084244D5002392E837FDE21D9EA1C6D01C"
41+
deps = { MoveStdlib = "MoveStdlib" }
42+
43+
[pinned.testnet.Talus]
44+
source = { local = "../../talus" }
45+
use_environment = "testnet"
46+
manifest_digest = "5745706258F61D6CE210904B3E6AE87A73CE9D31A6F93BE4718C442529332A87"
47+
deps = { std = "MoveStdlib", sui = "Sui" }
48+
49+
[pinned.testnet.dependency]
50+
source = { root = true }
51+
use_environment = "testnet"
52+
manifest_digest = "9AB99AED189CB308A136DAAAED75415DD6747E00541BEAEA08B4A2B7960F209F"
53+
deps = { std = "MoveStdlib", sui = "Sui", talus = "Talus" }

‎Tests/dependency/Move.toml‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
[package]
22
name = "dependency"
3-
edition = "2024.beta"
4-
[dependencies]
5-
6-
Talus = {local = "../../talus"}
7-
[addresses]
8-
dependency = "0x0"
9-
3+
edition = "2024"
104

5+
[dependencies]
6+
talus = { local = "../../talus" }

‎Tests/dependency/readme.md‎

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,31 @@
1-
## Dependency Test Contract
2-
This package contains a test contract designed to verify dependencies between the talus package and this package.
1+
# Token consumer checks
32

4-
### Test Procedure
5-
1. Configure Client Environment
6-
Set up your Sui client for the desired network.
3+
This package imports `talus::us::US` and uses `Coin<US>`. It depends on the
4+
local token package so CI can check the source in the current pull request.
75

8-
Devnet Configuration:
6+
From the repository root, use Sui 1.80.0 and Python 3.11 or newer:
97

10-
RPC: `https://rpc.ssfn.devnet.production.taluslabs.dev`
11-
12-
Faucet: `https://faucet.devnet.production.taluslabs.dev/gas`
13-
14-
Explorer: `https://explorer.devnet.taluslabs.dev/`
15-
16-
2. Fund Wallet
17-
Acquire at least two native SUI gas objects (coins) using the faucet link provided above or the Discord faucet.
18-
19-
3. Mint US Tokens
20-
Retrieve the required Object IDs (Faucet ID, Token IDs) from the registry files below:
21-
22-
Devnet: [objects.devnet.json](https://storage.googleapis.com/production-talus-tge-objects/v1.1.2/objects.devnet.json)
23-
24-
Testnet: [objects.testnet.json](https://storage.googleapis.com/production-talus-tge-objects/v1.1.2/objects.testnet.json)
25-
26-
Mainnet: [objects.mainnet.json](https://storage.googleapis.com/production-talus-tge-objects/v1.1.2/objects.mainnet.json)
27-
28-
Mint Command: Replace variables (starting with $) with the actual IDs found in the JSON files above.
29-
30-
```Bash
31-
sui client call --package <faucet package id> --module faucet --function mint \
32-
--type-args <token package id>::us::US \
33-
--type-args 0x2::sui::SUI \
34-
--args <faucet object id> \
35-
--args <sui coin id> \
36-
--dry-run
8+
```sh
9+
just test-dependency mainnet
10+
just test-dependency testnet
3711
```
3812

39-
Important: After minting, record your US Token Object ID. Ensure the `<token package id>` used matches the address defined in ../../talus/Move.lock under the corresponding environment and the faucet is under the same deployment sequence.
13+
Each check builds the consumer, verifies its dependency address and token type,
14+
and rejects a token address from the other network. The expected deployments
15+
are checked against `talus/Published.toml`. The checks compile without submitting
16+
transactions or requiring a funded wallet.
4017

41-
4. Publish and Test
42-
Publish the package and execute the dependency test function.
18+
To reproduce the deployed token module, use the Sui 1.59.1 binary:
4319

44-
```Bash
45-
# 1. Publish the package
46-
sui client publish . --dry-run
20+
```sh
21+
python3 Tests/dependency/verify.py --sui /path/to/sui bytecode
22+
```
4723

48-
# 2. Call the test function
49-
# Replace <dependency package id> with the ID generated from the publish step
50-
# Replace <US token id> with the ID obtained in Step 3
51-
sui client call --package <dependency package id> --module test --function half --arg
24+
This compiles the current token sources in a temporary directory and compares
25+
the module SHA256 with the bytes from the Mainnet and Testnet publications.
26+
The compiler uses its pinned framework dependencies. The repository's current
27+
lockfile remains intact. The expected hash and publication transaction digests
28+
are recorded in `verify.py`.
5229

53-
```
30+
These checks use a local dependency. See the [token README](../../talus/README.md)
31+
for the MVR dependency used by applications.

‎Tests/dependency/verify.py‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""Check token publication records, consumer linkage, and deployed module bytes."""
2+
3+
import argparse
4+
import base64
5+
import hashlib
6+
import json
7+
from pathlib import Path
8+
import shutil
9+
import subprocess
10+
import sys
11+
import tempfile
12+
import tomllib
13+
14+
15+
ROOT = Path(__file__).resolve().parents[2]
16+
TOKEN = ROOT / "talus"
17+
CONSUMER = ROOT / "Tests" / "dependency"
18+
DEPLOYMENTS = {
19+
"mainnet": (
20+
"35834a8a",
21+
"0xee962a61432231c2ede6946515beb02290cb516ad087bb06a731e922b2a5f57a",
22+
),
23+
"testnet": (
24+
"4c78adac",
25+
"0x5f1861ac8198fae5dc6ec79e435d653d08167187ad8c0522c34f34c372853c5a",
26+
),
27+
}
28+
# SHA256 of the single module submitted in both successful publications:
29+
# Mainnet: EwmnFH7uYr9uDALhSNqdkQQzEqBn3ryS6vE2iYWm1agg
30+
# Testnet: 9VH4oB8Xi6uA69nqTTNbaxwooZgRCJC3s95CEDxkETqE
31+
# Publication bytes have the module's own address set to zero.
32+
MODULE_SHA256 = "fd276ffb8e5c75685315b7a931a2a453015aeb1b0faa245c0a2c491aaa6b5e0f"
33+
34+
35+
def run_sui(binary, *args):
36+
result = subprocess.run(
37+
[binary, *args], check=True, capture_output=True, text=True,
38+
)
39+
if result.stderr:
40+
print(result.stderr, file=sys.stderr, end="")
41+
return result.stdout
42+
43+
44+
def check_publications():
45+
with (TOKEN / "Published.toml").open("rb") as source:
46+
records = tomllib.load(source)["published"]
47+
if set(records) != set(DEPLOYMENTS):
48+
raise ValueError("Publication records must contain Mainnet and Testnet")
49+
for network, (chain, package) in DEPLOYMENTS.items():
50+
expected = {
51+
"chain-id": chain,
52+
"published-at": package,
53+
"original-id": package,
54+
"version": 1,
55+
"toolchain-version": "1.59.1",
56+
}
57+
for key, value in expected.items():
58+
if records[network].get(key) != value:
59+
raise ValueError(f"Unexpected {network} publication field: {key}")
60+
61+
62+
def module_bytes(build):
63+
if len(build["modules"]) != 1:
64+
raise ValueError("Expected exactly one module")
65+
return base64.b64decode(build["modules"][0], validate=True)
66+
67+
68+
def check_bytecode(binary):
69+
version = run_sui(binary, "--version").split()[1].split("-")[0]
70+
if version != "1.59.1":
71+
raise ValueError("Bytecode reproduction requires Sui 1.59.1")
72+
# The release compiler supplies its pinned framework. Compile in isolation
73+
# so the current package manager's lockfile stays intact.
74+
with tempfile.TemporaryDirectory(prefix="talus_verify_") as directory:
75+
package = Path(directory)
76+
shutil.copyfile(TOKEN / "Move.toml", package / "Move.toml")
77+
shutil.copytree(TOKEN / "sources", package / "sources")
78+
build = json.loads(run_sui(
79+
binary, "move", "build", "--path", str(package),
80+
"--dump-bytecode-as-base64", "--ignore-chain",
81+
))
82+
digest = hashlib.sha256(module_bytes(build)).hexdigest()
83+
if digest != MODULE_SHA256:
84+
raise ValueError(f"Token module differs from the deployed bytecode: {digest}")
85+
print("Token bytecode matches the published Mainnet and Testnet module")
86+
87+
88+
def check_dependency(binary, network):
89+
build = json.loads(run_sui(
90+
binary, "move", "build", "--path", str(CONSUMER), "-e", network,
91+
"--dump-bytecode-as-base64", "--no-tree-shaking",
92+
))
93+
package = DEPLOYMENTS[network][1]
94+
dependencies = {int(address, 16) for address in build["dependencies"]}
95+
if int(package, 16) not in dependencies:
96+
raise ValueError(f"Consumer does not link the {network} token package")
97+
for other_network, (_, other_package) in DEPLOYMENTS.items():
98+
if other_network != network and int(other_package, 16) in dependencies:
99+
raise ValueError(f"Consumer unexpectedly links the {other_network} token")
100+
if bytes.fromhex(package[2:]) not in module_bytes(build):
101+
raise ValueError("Consumer bytecode does not reference the expected token type")
102+
print(f"Consumer uses the correct {network} token: {package}")
103+
104+
105+
def main():
106+
parser = argparse.ArgumentParser(description=__doc__)
107+
parser.add_argument("--sui", default="sui", help="Path to the Sui binary")
108+
commands = parser.add_subparsers(dest="command", required=True)
109+
commands.add_parser("bytecode", help="Reproduce the token with Sui 1.59.1")
110+
dependency = commands.add_parser("dependency", help="Check consumer linkage")
111+
dependency.add_argument("network", choices=DEPLOYMENTS)
112+
args = parser.parse_args()
113+
check_publications()
114+
if args.command == "bytecode":
115+
check_bytecode(args.sui)
116+
else:
117+
check_dependency(args.sui, args.network)
118+
119+
120+
if __name__ == "__main__":
121+
try:
122+
main()
123+
except subprocess.CalledProcessError as error:
124+
print(error.stdout or "", file=sys.stderr, end="")
125+
print(error.stderr or "", file=sys.stderr, end="")
126+
sys.exit(error.returncode)
127+
except (OSError, ValueError, KeyError) as error:
128+
sys.exit(str(error))

0 commit comments

Comments
 (0)