Skip to content

Commit cf9a978

Browse files
authored
svm/wormhole-core-shims: support non-solana SVM deployments (wormhole-foundation#4527)
* svm/definitions: use const computation to derive static PDAs This allows us to only have to specify the program id * svm/definitions: add feature flag to pick up addresses from env * svm/definitions: fix path in test * svm/definitions: error when 'solana' and 'from-env' are both passed * svm/definitions: small formatting * svm/definitions: fix *correct* spelling to make spellcheck happy * svm/definitions: remove bs58 validation https://docs.rs/const-crypto/latest/src/const_crypto/bs58.rs.html#8-15 already handles this * svm/definitions: std-finality -> standard-finality * svm/definitions: mention commitment level in docs
1 parent 6a765a5 commit cf9a978

File tree

9 files changed

+333
-114
lines changed

9 files changed

+333
-114
lines changed

svm/wormhole-core-shims/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svm/wormhole-core-shims/anchor/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svm/wormhole-core-shims/crates/definitions/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@ version.workspace = true
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[features]
15-
default = []
15+
default = [ "standard-finality" ]
1616
borsh = ["dep:borsh"]
1717

1818
### Network types
1919
testnet = []
2020
localnet = []
21+
from-env = []
22+
23+
### Standard finality definition
24+
standard-finality = []
2125

2226
### Specific networks
23-
solana = []
27+
solana = [ "standard-finality" ]
2428

2529
[dependencies]
30+
const-crypto = "0.3.0"
2631
borsh = { optional = true, workspace = true }
2732
cfg-if.workspace = true
2833
sha2-const-stable.workspace = true
2934
solana-program.workspace = true
3035

3136
[dev-dependencies]
32-
base64.workspace = true
37+
base64.workspace = true

svm/wormhole-core-shims/crates/definitions/README.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,36 @@ Definitions relating to Wormhole SVM programs. These definitions include finding
44
PDA addresses (and corresponding bump seeds), various consts (like program IDs),
55
and other things that define these program accounts and data.
66

7-
## Cargo Features
8-
9-
There are features that define network types and specific SVM networks.
10-
11-
### Network Types
12-
13-
The default network type is mainnet. There is no feature that defines mainnet.
14-
But if one of the following features are defined, program IDs and account
15-
addresses will not use the ones defined for mainnet.
16-
17-
- `localnet`: Wormhole's Tilt devnet. Programs like the Wormhole Core Bridge and
18-
its associated PDAs have addresses specific to this local development network.
19-
- `testnet`: Public devnet or testnet depending on the specific SVM network. For
20-
Solana specifically, this feature corresponds to the public Solana devnet.
21-
22-
### Specific Networks
23-
24-
There are no default network features. These feature labels also exist as
25-
submodules in this crate. By defining a particular SVM network feature, the
26-
definitions found in this submodule are simply exported into the crate root.
27-
28-
- `solana`
7+
The crate is parameterized over a set of program IDs (the Wormhole program, the
8+
post-vaa shim program, and the verify-vaa shim program). Since this crate may be
9+
used in many different scenarios, and many different SVM networks, we expose
10+
feature flags to control which program IDs are used to derive the other constants.
11+
12+
For Solana, we have a hardcoded set of addresses for `mainnet`, `devnet` and a
13+
local testing environment. If the `solana` feature is specified, it will default
14+
to the mainnet addresses. Otherwise, the `testnet` flag provides the addresses
15+
for Solana Devnet, and the `localnet` flag provides the addresses for the local
16+
testing environment.
17+
18+
Alternatively, when using on another SVM chain (or on Solana, but against an
19+
independent Wormhole deployment) just specify the `from-env` feature flag (and
20+
don't specify Solana, even if the chain is Solana). In this case, the following
21+
4 environment variables are needed:
22+
- `CHAIN_ID`: the Wormhole ID of the chain deployed on. e.g. Solana is 1, Fogo is 51.
23+
- `BRIDGE_ADDRESS`: program ID of the Wormhole program
24+
- `POST_MESSAGE_SHIM_PROGRAM_ID`: program ID of the [../../programs/post-message/](post-message shim).
25+
- `VERIFY_VAA_SHIM_PROGRAM_ID`: program ID of the [../../programs/verify-vaa](verify-vaa shim).
26+
27+
The definitions crate can be compiled without either the `solana` or the
28+
`from-env` feature flags. In this case, it will not expose any addresses in the top-level crate, for example `crate::CORE_BRIDGE_FEE_COLLECTOR` won't be available. However, the predefined Solana addresses are still available via their qualified paths:
29+
e.g. `crate::solana::devnet::CORE_BRIDGE_FEE_COLLECTOR`.
30+
31+
A crate wishing to build on top of this crate should pass through the
32+
`from-env`, `solana`, `testnet`, and `devnet` flags, but may wish to specify
33+
`from-env` as the default.
2934

3035
### Other Features
3136

3237
- `borsh`: Accounts and events relating to Wormhole SVM programs that follow
3338
Borsh serialization. This feature also supports deserializing data with
34-
discriminators.
39+
discriminators.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_export]
2+
macro_rules! env_pubkey {
3+
($name: literal) => {
4+
const_crypto::bs58::decode_pubkey(env!($name))
5+
};
6+
}

0 commit comments

Comments
 (0)