Skip to content

Commit 51c05cd

Browse files
authored
chore(target_chains/sui): vendor Wormhole dependency into the repo (#1618)
* chore(target_chains/sui): vendor wh dependency for movement in * chore(target_chains/sui): add changes and readme
1 parent 6695289 commit 51c05cd

File tree

136 files changed

+27766
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+27766
-1
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ repos:
33
rev: v3.2.0
44
hooks:
55
- id: trailing-whitespace
6+
exclude: target_chains/sui/vendor/
67
- id: end-of-file-fixer
8+
exclude: target_chains/sui/vendor/
79
- id: check-added-large-files
8-
exclude: package-lock.json
10+
exclude: package-lock.json,target_chains/sui/vendor/
911
# Hook to format many type of files in the repo
1012
# including solidity contracts.
1113
- repo: https://github.com/pre-commit/mirrors-prettier
@@ -15,6 +17,7 @@ repos:
1517
additional_dependencies:
1618
1719
20+
exclude: target_chains/sui/vendor/
1821
- repo: local
1922
hooks:
2023
# Hooks for the remote executor

target_chains/sui/vendor/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Vendored dependencies for SUI contract
2+
3+
This directory contains the wormhole dependencies used for deploying Pyth contracts on the chains
4+
that Wormhole is not officially deployed on. For each network, a slightly different variant of the
5+
code should be used that has the `CHAIN_ID` and `Move.toml` modified. Therefore, we are storing
6+
each of them in a separate directory.
7+
8+
The Wormhole contract is taken out of commit
9+
[`e94c8ef4a810cae63d4e54811aa6a843b5fd9e65`](https://github.com/wormhole-foundation/wormhole/tree/e94c8ef4a810cae63d4e54811aa6a843b5fd9e65)
10+
from the Wormhole repository. To update it, pull the latest version and copy it here and update the
11+
README.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
deploy.out
2+
sui.log.*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# first build the image
2+
3+
cd ..; DOCKER_BUILDKIT=1 docker build --no-cache --progress plain -f sui/Dockerfile.base -t sui .
4+
5+
# tag the image with the appropriate version
6+
7+
docker tag sui:latest ghcr.io/wormhole-foundation/sui:1.19.1-mainnet
8+
9+
# push to ghcr
10+
11+
docker push ghcr.io/wormhole-foundation/sui:1.19.1-mainnet
12+
13+
echo remember to update both Dockerfile and Dockerfile.export
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM cli-gen AS cli-export
2+
FROM const-gen AS const-export
3+
FROM ghcr.io/wormhole-foundation/sui:1.19.1-mainnet@sha256:544a1b2aa5701fae25a19aed3c5e8c24e0caf7d1c9f511b6844d339a8f0b2a00 as sui
4+
5+
# initial run
6+
# COPY sui/devnet/genesis_config genesis_config
7+
# RUN sui genesis -f --from-config genesis_config
8+
9+
# subsequent runs after committing files from /root/.sui/sui_config/
10+
COPY sui/devnet/ /root/.sui/sui_config/
11+
12+
WORKDIR /tmp
13+
14+
COPY sui/scripts/ scripts
15+
COPY sui/wormhole/ wormhole
16+
COPY sui/token_bridge/ token_bridge
17+
COPY sui/examples/ examples
18+
COPY sui/Makefile Makefile
19+
20+
# Copy .env and CLI
21+
COPY --from=const-export .env .env
22+
COPY --from=cli-export clients/js /cli
23+
24+
# Link `worm`
25+
WORKDIR /cli
26+
27+
RUN npm link
28+
29+
FROM sui AS tests
30+
31+
WORKDIR /tmp
32+
33+
RUN --mount=type=cache,target=/root/.move,id=move_cache make test
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM rust:1.62@sha256:5777f201f507075309c4d2d1c1e8d8219e654ae1de154c844341050016a64a0c as sui-node
2+
3+
WORKDIR /tmp
4+
5+
RUN curl -L https://github.com/MystenLabs/sui/releases/download/mainnet-v1.19.1/sui-mainnet-v1.19.1-ubuntu-x86_64.tgz > sui-mainnet-v1.19.1-ubuntu-x86_64.tgz
6+
RUN echo "6a8cc96759760293143a00fe7031a5fea70d2dff5b98d18c0470c09555da63e0 sui-mainnet-v1.19.1-ubuntu-x86_64.tgz" | sha256sum -c --status
7+
8+
RUN tar -xvf sui-mainnet-v1.19.1-ubuntu-x86_64.tgz
9+
RUN mv target/release/sui-ubuntu-x86_64 /bin/sui
10+
RUN mv target/release/sui-faucet-ubuntu-x86_64 /bin/sui-faucet
11+
RUN mv target/release/sui-node-ubuntu-x86_64 /bin/sui-node
12+
13+
RUN rm sui-mainnet-v1.19.1-ubuntu-x86_64.tgz
14+
15+
RUN apt-get update
16+
RUN apt-get install -y ca-certificates curl gnupg
17+
RUN mkdir -p /etc/apt/keyrings
18+
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
19+
20+
ARG NODE_MAJOR=18
21+
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
22+
23+
RUN apt-get update
24+
RUN apt-get install nodejs -y
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
TEST_CONTRACT_DIRS := wormhole token_bridge examples/coins examples/core_messages
2+
CLEAN_CONTRACT_DIRS := wormhole token_bridge examples/coins examples/core_messages
3+
4+
.PHONY: clean
5+
clean:
6+
$(foreach dir,$(TEST_CONTRACT_DIRS), make -C $(dir) $@ &&) true
7+
8+
.PHONY: test
9+
test:
10+
$(foreach dir,$(TEST_CONTRACT_DIRS), make -C $(dir) $@ &&) true
11+
12+
test-docker:
13+
DOCKER_BUILDKIT=1 docker build --progress plain -f ../Dockerfile.cli -t cli-gen ..
14+
DOCKER_BUILDKIT=1 docker build --build-arg num_guardians=1 --progress plain -f ../Dockerfile.const -t const-gen ..
15+
DOCKER_BUILDKIT=1 docker build -f Dockerfile ..
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
brew install cmake
2+
3+
rustup install stable-x86_64-apple-darwin
4+
#rustup target add stable-x86_64-apple-darwin
5+
rustup target add x86_64-apple-darwin
6+
7+
=== Building
8+
9+
% ./node_builder.sh
10+
11+
=== Running
12+
13+
% ./start_node.sh
14+
15+
# If you don't remember your newly generated address
16+
17+
% sui client addresses
18+
Showing 1 results.
19+
0x13b3cb89cf3226d3b860294fc75dc6c91f0c5ecf
20+
21+
# Give yourself some money
22+
23+
% scripts/faucet.sh `sui client addresses | tail -1`
24+
25+
# Looking at the prefunded address
26+
27+
% sui client objects --address 0x13b3cb89cf3226d3b860294fc75dc6c91f0c5ecf
28+
29+
=== Boot tilt
30+
31+
# fund our standard account
32+
33+
We don't run a faucet since it doesn't always unlock the client LOCK files. So, instead we just steal a chunk of coins
34+
from the default accounts created when the node was initialized. Once sui is showing as live...
35+
36+
``` sh
37+
% kubectl exec -it sui-0 -c sui-node -- /tmp/funder.sh
38+
```
39+
40+
# getting into the sui k8s node (if you need to crawl around)
41+
42+
kubectl exec -it sui-0 -c sui-node -- /bin/bash
43+
kubectl exec -it guardian-0 -c guardiand -- /bin/bash
44+
45+
# setup the client.yaml
46+
47+
``` sh
48+
% rm -rf $HOME/.sui
49+
% sui keytool import "daughter exclude wheat pudding police weapon giggle taste space whip satoshi occur" ed25519
50+
% sui client
51+
```
52+
point it at http://localhost:9000. The key you create doesn't matter.
53+
54+
# edit $HOME/.sui/sui_config/client.yaml
55+
56+
``` sh
57+
sed -i -e 's/active_address.*/active_address: "0x13b3cb89cf3226d3b860294fc75dc6c91f0c5ecf"/' ~/.sui/sui_config/client.yaml
58+
```
59+
60+
61+
# deploy the contract
62+
63+
``` sh
64+
% scripts/deploy.sh
65+
```
66+
67+
# start the watcher
68+
69+
``` sh
70+
% . env.sh
71+
% python3 tests/ws.py
72+
```
73+
74+
# publish a message (different window)
75+
76+
``` sh
77+
% . env.sh
78+
% scripts/publish_message.sh
79+
```
80+
81+
==
82+
83+
docker run -it -v `pwd`:`pwd` -w `pwd` --net=host ghcr.io/wormhole-foundation/sui:0.16.0 bash
84+
dnf -y install git make
85+
86+
``` sh
87+
% rm -rf $HOME/.sui
88+
% sui keytool import "daughter exclude wheat pudding police weapon giggle taste space whip satoshi occur" secp256k1
89+
% sui client
90+
```
91+
92+
to get a new emitter
93+
94+
kubectl exec -it sui-0 -c sui-node -- /tmp/funder.sh
95+
scripts/deploy.sh
96+
. env.sh
97+
sui client call --function get_new_emitter --module wormhole --package $WORM_PACKAGE --gas-budget 20000 --args \"$WORM_STATE\"
98+
99+
sui client objects
100+
scripts/publish_message.sh 0x165ef7366c4267c6506bcf63d2419556f34f48d6
101+
102+
103+
curl -s -X POST -d '{"jsonrpc":"2.0", "id": 1, "method": "sui_getEvents", "params": [{"MoveEvent": "0xf4179152ab02e4212d7e7b20f37a9a86ab6d50fb::state::WormholeMessage"}, null, 10, true]}' -H 'Content-Type: application/json' http://127.0.0.1:9002 | jq
104+
105+
curl -s -X POST -d '{"jsonrpc":"2.0", "id": 1, "method": "sui_getEvents", "params": [{"Transaction": "cL+uWFEVcQrkAiOxOJmaK7JmlOJdE3/8X5JFbJwBxCQ="}, null, 10, true]}' -H 'Content-Type: application/json' http://127.0.0.1:9002 | jq
106+
107+
"txhash": "0x70bfae585115710ae40223b138999a2bb26694e25d137ffc5f92456c9c01c424", "txhash_b58": "8b8Bn8MUqAWeVz2BE5hMicC9KaRkV6UM4v1JLWGUjxcT", "
108+
Digest: cL+uWFEVcQrkAiOxOJmaK7JmlOJdE3/8X5JFbJwBxCQ=
109+
110+
kubectl exec -it guardian-0 -- /guardiand admin send-observation-request --socket /tmp/admin.sock 21 70bfae585115710ae40223b138999a2bb26694e25d137ffc5f92456c9c01c424
111+
112+
// curl -s -X POST -d '{"jsonrpc":"2.0", "id": 1, "method": "sui_getCommitteeInfo", "params": []}' -H 'Content-Type: application/json' http://127.0.0.1:9002 | jq
113+
114+
// curl -s -X POST -d '{"jsonrpc":"2.0", "id": 1, "method": "sui_getLatestCheckpointSequenceNumber", "params": []}' -H 'Content-Type: application/json' http://127.0.0.1:9000
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Wormhole on Sui
2+
3+
This folder contains the reference implementation of the Wormhole cross-chain
4+
messaging protocol smart contracts on the [Sui](https://mystenlabs.com/)
5+
blockchain, implemented in the [Move](https://move-book.com/) programming
6+
language.
7+
8+
# Project structure
9+
10+
The project is laid out as follows:
11+
12+
- [wormhole](./wormhole) the core messaging layer
13+
- [token_bridge](./token_bridge) the asset transfer layer
14+
- [coin](./coin) a template for creating Wormhole wrapped coins
15+
16+
# Installation
17+
18+
Make sure your Cargo version is at least 1.65.0 and then follow the steps below:
19+
20+
- https://docs.sui.io/build/install
21+
22+
#https://docs.sui.io/guides/developer/getting-started/sui-install# Prerequisites
23+
24+
Install the `Sui` CLI. This tool is used to compile the contracts and run the tests.
25+
26+
```sh
27+
cargo install --locked --git https://github.com/MystenLabs/sui.git --rev 041c5f2bae2fe52079e44b70514333532d69f4e6 sui
28+
```
29+
30+
Some useful Sui CLI commands are
31+
32+
- `sui start` to spin up a local network
33+
- `rpc-server` to start a server for handling rpc calls
34+
35+
Next, install the [worm](../clients/js/README.md) CLI tool by running
36+
37+
```sh
38+
wormhole/clients/js $ make install
39+
```
40+
41+
`worm` is the swiss army knife for interacting with wormhole contracts on all
42+
supported chains, and generating signed messages (VAAs) for testing.
43+
44+
As an optional, but recommended step, install the
45+
[move-analyzer](https://github.com/move-language/move/tree/main/language/move-analyzer)
46+
Language Server (LSP):
47+
48+
```sh
49+
cargo install --git https://github.com/move-language/move.git move-analyzer --branch main --features "address32"
50+
```
51+
52+
This installs the LSP backend which is then supported by most popular editors such as [emacs](https://github.com/emacs-lsp/lsp-mode), [vim](https://github.com/neoclide/coc.nvim), and even [vscode](https://marketplace.visualstudio.com/items?itemName=move.move-analyzer).
53+
54+
<details>
55+
<summary>For emacs, you may need to add the following to your config file:</summary>
56+
57+
```lisp
58+
;; Move
59+
(define-derived-mode move-mode rust-mode "Move"
60+
:group 'move-mode)
61+
62+
(add-to-list 'auto-mode-alist '("\\.move\\'" . move-mode))
63+
64+
(with-eval-after-load 'lsp-mode
65+
(add-to-list 'lsp-language-id-configuration
66+
'(move-mode . "move"))
67+
68+
(lsp-register-client
69+
(make-lsp-client :new-connection (lsp-stdio-connection "move-analyzer")
70+
:activation-fn (lsp-activate-on "move")
71+
:server-id 'move-analyzer)))
72+
```
73+
74+
</details>
75+
76+
## Building & running tests
77+
78+
The project uses a simple `make`-based build system for building and running
79+
tests. Running `make test` in this directory will run the tests for each
80+
contract. If you only want to run the tests for, say, the token bridge contract,
81+
then you can run `make test` in the `token_bridge` directory, or run `make -C
82+
token_bridge test` from this directory.
83+
84+
Additionally, `make test-docker` runs the tests in a docker container which is
85+
set up with all the necessary dependencies. This is the command that runs in CI.
86+
87+
## Running a local validator and deploying the contracts to it
88+
89+
Simply run
90+
91+
```sh
92+
worm start-validator sui
93+
```
94+
95+
which will start a local sui validator with an RPC endpoint at `0.0.0.0:9000`.
96+
97+
Once the validator is running, the contracts are ready to deploy. In the
98+
[scripts](./scripts) directory, run
99+
100+
```sh
101+
scripts $ ./deploy.sh devnet
102+
```
103+
104+
This will deploy the core contract and the token bridge.
105+
106+
When you make a change to the contract, you can simply restart the validator and
107+
run the deploy script again.
108+
109+
<!-- However, a better way is to run one of the following scripts:
110+
111+
``` sh
112+
scripts $ ./upgrade devnet Core # for upgrading the wormhole contract
113+
scripts $ ./upgrade devnet TokenBridge # for upgrading the token bridge contract
114+
scripts $ ./upgrade devnet NFTBridge # for upgrading the NFT bridge contract
115+
```
116+
117+
Behind the scenes, these scripts exercise the whole contract upgrade code path
118+
(see below), including generating and verifying a signed governance action, and
119+
the Move bytecode verifier checking ABI compatibility. If an upgrade here fails
120+
due to incompatibility, it will likely on mainnet too. (TODO: add CI action to
121+
simulate upgrades against main when there's a stable version) -->
122+
123+
# Implementation notes / coding practices
124+
125+
In this section, we describe some of the implementation design decisions and
126+
coding practices we converged on along the way. Note that the coding guidelines
127+
are prescriptive rather than descriptive, and the goal is for the contracts to
128+
ultimately follow these, but they might not during earlier development phases.
129+
130+
### TODO

0 commit comments

Comments
 (0)