sdk: fixes to types and builds

Change-Id: I10b753450445cc021dbeb9f28ddb0384070e9635
This commit is contained in:
Reisen 2022-01-06 15:08:09 +00:00 committed by Reisen
parent e8ed614e0d
commit e561d6de02
19 changed files with 84 additions and 196 deletions

Binary file not shown.

2
sdk/rust/Cargo.lock generated
View File

@ -1352,7 +1352,6 @@ dependencies = [
"solana-program",
"solitaire",
"wasm-bindgen",
"wormhole-core",
]
[[package]]
@ -1391,6 +1390,7 @@ dependencies = [
name = "wormhole-sdk"
version = "0.1.0"
dependencies = [
"borsh",
"byteorder",
"cosmwasm-std",
"cosmwasm-storage",

View File

@ -64,6 +64,11 @@ pub type Signature = [u8; 66];
/// Ethereum addresses, are left zero padded to 32.
pub type ForeignAddress = [u8; 32];
/// Fields on VAA's are all usually fixed bytestrings, however they often contain UTF-8. When
/// parsed these result in `String` with the additional constraint that they are always equal or
/// less to the underlying byte field.
type ShortUTFString = String;
/// The core VAA itself. This structure is what is received by a contract on the receiving side of
/// a wormhole message passing flow. The payload of the message must be parsed separately to the
/// VAA itself as it is completely user defined.
@ -84,6 +89,13 @@ pub struct VAA {
pub payload: Vec<u8>,
}
/// Contains the hash, secp256k1 payload, and serialized digest of the VAA. These are used in
/// various places in Wormhole codebases.
pub struct VAADigest {
pub digest: Vec<u8>,
pub hash: [u8; 32],
}
impl VAA {
/// Given any argument treatable as a series of bytes, attempt to deserialize into a valid VAA.
pub fn from_bytes<T: AsRef<[u8]>>(input: T) -> Result<Self, WormholeError> {
@ -97,7 +109,7 @@ impl VAA {
/// returns a 256 bit Keccak hash of these components. This hash is utilised in all Wormhole
/// components for identifying unique VAA's, including the bridge, modules, and core guardian
/// software.
pub fn digest(&self) -> Option<[u8; 32]> {
pub fn digest(&self) -> Option<VAADigest> {
use byteorder::{
BigEndian,
WriteBytesExt,
@ -124,13 +136,16 @@ impl VAA {
// We hash the body so that secp256k1 signatures are signing the hash instead of the body
// within our contracts. We do this so we don't have to submit the entire VAA for signature
// verification, only the hash.
let body: [u8; 32] = {
let hash: [u8; 32] = {
let mut h = sha3::Keccak256::default();
let _ = h.write(body.as_slice()).unwrap();
h.finalize().into()
};
Some(body)
Some(VAADigest {
digest: body,
hash,
})
}
}

View File

@ -18,9 +18,10 @@ use crate::vaa::{
parse_fixed,
GovernanceAction,
};
use crate::vaa::ShortUTFString;
use crate::{
parse_fixed_utf8,
Chain,
parse_fixed_utf8,
WormholeError,
};
@ -36,16 +37,16 @@ pub struct Transfer {
pub nft_chain: Chain,
/// Symbol of the token
pub symbol: String,
pub symbol: ShortUTFString,
/// Name of the token
pub name: String,
pub name: ShortUTFString,
/// TokenID of the token (big-endian uint256)
pub token_id: U256,
/// URI of the token metadata
pub uri: String,
pub uri: ShortUTFString,
/// Address of the recipient. Left-zero-padded if shorter than 32 bytes
pub to: [u8; 32],

View File

@ -13,9 +13,10 @@ use nom::{
use primitive_types::U256;
use crate::vaa::{
GovernanceAction,
parse_chain,
parse_fixed,
GovernanceAction,
ShortUTFString,
};
use crate::{
parse_fixed_utf8,
@ -94,11 +95,11 @@ pub struct AssetMeta {
/// Number of decimals the source token has on its origin chain.
pub decimals: u8,
/// Ticker symbol for the token on its origin chain.
pub symbol: String,
/// Ticker Symbol for the token on its origin chain.
pub symbol: ShortUTFString,
/// Full token name for the token on its origin chain.
pub name: String,
/// Full Token name for the token on its origin chain.
pub name: ShortUTFString,
}
impl AssetMeta {

View File

@ -24,19 +24,25 @@ pub fn id() -> Addr {
Addr::unchecked("terra1dq03ugtd40zu9hcgdzrsq6z2z4hwhc9tqk2uy5")
}
/// Export Core Devnet Contract Address
#[cfg(feature = "testnet")]
pub fn id() -> Addr {
Addr::unchecked("terra1pd65m0q9tl3v8znnz5f5ltsfegyzah7g42cx5v")
}
/// Export Core Devnet Contract Address
#[cfg(feature = "devnet")]
pub fn id() -> Addr {
Addr::unchecked("terra1pd65m0q9tl3v8znnz5f5ltsfegyzah7g42cx5v")
}
pub fn post_message<T>(wormhole: Addr, nonce: u32, message: &T) -> StdResult<CosmosMsg>
pub fn post_message<T>(nonce: u32, message: &T) -> StdResult<CosmosMsg>
where
T: Serialize,
T: ?Sized,
{
Ok(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: wormhole.to_string(),
contract_addr: id().to_string(),
funds: vec![],
msg: to_binary(&ExecuteMsg::PostMessage {
message: to_binary(message)?,
@ -47,13 +53,12 @@ where
/// Parse a VAA using the Wormhole contract Query interface.
pub fn parse_vaa(
wormhole: Addr,
deps: DepsMut,
env: Env,
data: &Binary,
) -> StdResult<ParsedVAA> {
let vaa: ParsedVAA = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: wormhole.to_string(),
contract_addr: id().to_string(),
msg: to_binary(&QueryMsg::VerifyVAA {
vaa: data.clone(),
block_time: env.block.time.seconds(),

132
solana/bridge/Cargo.lock generated
View File

@ -69,12 +69,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "arrayvec"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]]
name = "assert_matches"
version = "1.5.0"
@ -153,18 +147,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
version = "0.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848"
dependencies = [
"funty",
"radium",
"tap",
"wyz",
]
[[package]]
name = "blake3"
version = "0.3.8"
@ -172,7 +154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3"
dependencies = [
"arrayref",
"arrayvec 0.5.2",
"arrayvec",
"cc",
"cfg-if 0.1.10",
"constant_time_eq",
@ -304,12 +286,6 @@ dependencies = [
"serde",
]
[[package]]
name = "byte-slice-cast"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d30c751592b77c499e7bce34d99d67c2c11bdc0574e9a488ddade14150a4698"
[[package]]
name = "byte-tools"
version = "0.3.1"
@ -932,9 +908,6 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c"
dependencies = [
"byteorder",
"rand 0.8.4",
"rustc-hex",
"static_assertions",
]
@ -997,12 +970,6 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "funty"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
[[package]]
name = "futures"
version = "0.1.31"
@ -1374,26 +1341,6 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "impl-codec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443"
dependencies = [
"parity-scale-codec",
]
[[package]]
name = "impl-trait-for-tuples"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5dacb10c5b3bb92d46ba347505a9041e676bb20ad220101326bffb0c93031ee"
dependencies = [
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.75",
]
[[package]]
name = "indexmap"
version = "1.7.0"
@ -1636,12 +1583,6 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.4.4"
@ -1757,17 +1698,6 @@ dependencies = [
"libc",
]
[[package]]
name = "nom"
version = "7.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109"
dependencies = [
"memchr",
"minimal-lexical",
"version_check",
]
[[package]]
name = "ntapi"
version = "0.3.6"
@ -1930,32 +1860,6 @@ dependencies = [
"syn 1.0.75",
]
[[package]]
name = "parity-scale-codec"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909"
dependencies = [
"arrayvec 0.7.2",
"bitvec",
"byte-slice-cast",
"impl-trait-for-tuples",
"parity-scale-codec-derive",
"serde",
]
[[package]]
name = "parity-scale-codec-derive"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27"
dependencies = [
"proc-macro-crate 1.0.0",
"proc-macro2 1.0.28",
"quote 1.0.9",
"syn 1.0.75",
]
[[package]]
name = "parking_lot"
version = "0.9.0"
@ -2095,7 +1999,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06345ee39fbccfb06ab45f3a1a5798d9dafa04cb8921a76d227040003a234b0e"
dependencies = [
"fixed-hash",
"impl-codec",
"uint",
]
@ -2175,12 +2078,6 @@ dependencies = [
"proc-macro2 1.0.28",
]
[[package]]
name = "radium"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb"
[[package]]
name = "rand"
version = "0.7.3"
@ -2423,12 +2320,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hex"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -3381,12 +3272,6 @@ dependencies = [
"unicode-xid 0.2.2",
]
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "tar"
version = "0.4.37"
@ -4121,15 +4006,6 @@ dependencies = [
"solitaire",
"solitaire-client",
"wasm-bindgen",
"wormhole-core",
]
[[package]]
name = "wormhole-core"
version = "0.1.0"
dependencies = [
"nom",
"primitive-types",
]
[[package]]
@ -4142,12 +4018,6 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "wyz"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
[[package]]
name = "xattr"
version = "0.2.2"

View File

@ -26,8 +26,6 @@ solana-program = "=1.7.0"
solitaire-client = { path = "../../solitaire/client", optional = true }
solitaire = { path = "../../solitaire/program" }
wasm-bindgen = { version = "0.2.74", features = ["serde-serialize"], optional = true }
serde = { version = "1.0", features = ["derive"] }
wormhole-core = { path = "../../../sdk/rust/core", version="0.1.0" }
[dev-dependencies]
hex = "*"

View File

@ -244,20 +244,6 @@ dependencies = [
"syn 1.0.75",
]
[[package]]
name = "bridge"
version = "0.1.0"
dependencies = [
"borsh",
"byteorder",
"primitive-types",
"serde",
"sha3",
"solana-program",
"solitaire",
"wasm-bindgen",
]
[[package]]
name = "bs58"
version = "0.3.1"
@ -1655,7 +1641,6 @@ name = "nft-bridge"
version = "0.1.0"
dependencies = [
"borsh",
"bridge",
"bstr",
"byteorder",
"hex",
@ -1675,6 +1660,7 @@ dependencies = [
"spl-token",
"spl-token-metadata",
"wasm-bindgen",
"wormhole-bridge-solana",
]
[[package]]
@ -3984,6 +3970,19 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "wormhole-bridge-solana"
version = "0.1.0"
dependencies = [
"borsh",
"byteorder",
"primitive-types",
"serde",
"sha3",
"solana-program",
"solitaire",
]
[[package]]
name = "ws2_32-sys"
version = "0.2.1"

View File

@ -17,7 +17,7 @@ cpi = ["no-entrypoint"]
default = []
[dependencies]
bridge = { path = "../../../bridge/program", features = ["no-entrypoint", "cpi"] }
wormhole-bridge-solana = { path = "../../../bridge/program", features = ["no-entrypoint", "cpi"] }
borsh = "0.8.1"
bstr = "0.2.16"
byteorder = "1.4.3"

View File

@ -244,20 +244,6 @@ dependencies = [
"syn 1.0.75",
]
[[package]]
name = "bridge"
version = "0.1.0"
dependencies = [
"borsh",
"byteorder",
"primitive-types",
"serde",
"sha3",
"solana-program",
"solitaire",
"wasm-bindgen",
]
[[package]]
name = "bs58"
version = "0.3.1"
@ -3402,7 +3388,6 @@ name = "token-bridge"
version = "0.1.0"
dependencies = [
"borsh",
"bridge",
"bstr",
"byteorder",
"hex",
@ -3421,6 +3406,7 @@ dependencies = [
"spl-token",
"spl-token-metadata",
"wasm-bindgen",
"wormhole-bridge-solana",
]
[[package]]
@ -4013,6 +3999,19 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "wormhole-bridge-solana"
version = "0.1.0"
dependencies = [
"borsh",
"byteorder",
"primitive-types",
"serde",
"sha3",
"solana-program",
"solitaire",
]
[[package]]
name = "ws2_32-sys"
version = "0.2.1"

View File

@ -17,7 +17,7 @@ cpi = ["no-entrypoint"]
default = []
[dependencies]
bridge = { path = "../../../bridge/program", features = ["no-entrypoint", "cpi"] }
wormhole-bridge-solana = { path = "../../../bridge/program", features = ["no-entrypoint", "cpi"] }
borsh = "0.8.1"
bstr = "0.2.16"
byteorder = "1.4.3"

View File

@ -6,14 +6,14 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["pyth2wormhole/client", "bridge/client"]
default = ["pyth2wormhole/client", "wormhole-bridge-solana/client"]
[dependencies]
borsh = "0.8.1"
clap = "3.0.0-beta.2" # This beta assimilates structopt into clap
env_logger = "0.8.4"
log = "0.4.14"
bridge = {path = "../../bridge/program"}
wormhole-bridge-solana = {path = "../../bridge/program"}
pyth2wormhole = {path = "../program"}
shellexpand = "2.1.0"
solana-client = "=1.7.0"

View File

@ -9,14 +9,14 @@ crate-type = ["cdylib", "lib"]
name = "pyth2wormhole"
[features]
default = ["bridge/no-entrypoint"]
default = ["wormhole-bridge-solana/no-entrypoint"]
client = ["solitaire/client", "solitaire-client", "no-entrypoint"]
trace = ["solitaire/trace", "bridge/trace"]
trace = ["solitaire/trace", "wormhole-bridge-solana/trace"]
no-entrypoint = []
wasm = ["no-entrypoint", "wasm-bindgen", "serde", "serde_derive", "serde_json"]
[dependencies]
bridge = {path = "../../bridge/program"}
wormhole-bridge-solana = {path = "../../bridge/program"}
solitaire = { path = "../../solitaire/program" }
solitaire-client = { path = "../../solitaire/client", optional = true }
rocksalt = { path = "../../solitaire/rocksalt" }
@ -28,4 +28,4 @@ pyth-client = {git = "https://github.com/pyth-network/pyth-client-rs", branch =
wasm-bindgen = { version = "0.2.74", features = ["serde-serialize"], optional = true}
serde = { version = "1", optional = true}
serde_derive = { version = "1", optional = true}
serde_json = { version = "1", optional = true}
serde_json = { version = "1", optional = true}

8
terra/Cargo.lock generated
View File

@ -1159,7 +1159,7 @@ dependencies = [
"serde",
"serde_json",
"sha3",
"wormhole",
"wormhole-bridge-terra",
]
[[package]]
@ -1332,7 +1332,7 @@ dependencies = [
"solana-program",
"terraswap",
"thiserror",
"wormhole",
"wormhole-bridge-terra",
]
[[package]]
@ -1950,7 +1950,7 @@ dependencies = [
"sha3",
"terraswap",
"thiserror",
"wormhole",
"wormhole-bridge-terra",
]
[[package]]
@ -2299,7 +2299,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "wormhole"
name = "wormhole-bridge-terra"
version = "0.1.0"
dependencies = [
"cosmwasm-std",

View File

@ -20,7 +20,7 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] }
cw721-wrapped = { path = "../cw721-wrapped", features = ["library"] }
cw721-base = { path = "../../contracts/cw721-base", version = "0.10.0", features = ["library"] }
cw721 = { path = "../../packages/cw721" }
wormhole = { path = "../wormhole", features = ["library"] }
wormhole-bridge-terra = { path = "../wormhole", features = ["library"] }
sha3 = { version = "0.9.1", default-features = false }
hex = "0.4.2"
bigint = "4"

View File

@ -23,7 +23,7 @@ cw20 = "0.8.0"
cw20-base = { version = "0.8.0", features = ["library"] }
cw20-wrapped = { path = "../cw20-wrapped", features = ["library"] }
terraswap = "2.4.0"
wormhole = { path = "../wormhole", features = ["library"] }
wormhole-bridge-terra = { path = "../wormhole", features = ["library"] }
thiserror = { version = "1.0.20" }
k256 = { version = "0.9.4", default-features = false, features = ["ecdsa"] }
sha3 = { version = "0.9.1", default-features = false }

View File

@ -22,7 +22,7 @@ cw20 = "0.8.0"
cw20-base = { version = "0.8.0", features = ["library"] }
cw20-wrapped = { path = "../cw20-wrapped", features = ["library"] }
terraswap = "2.4.0"
wormhole = { path = "../wormhole", features = ["library"] }
wormhole-bridge-terra = { path = "../wormhole", features = ["library"] }
thiserror = { version = "1.0.20" }
k256 = { version = "0.9.4", default-features = false, features = ["ecdsa"] }
sha3 = { version = "0.9.1", default-features = false }

View File

@ -6,7 +6,7 @@ edition = "2018"
description = "Wormhole contract"
[lib]
name = "bridge"
name = "wormhole"
crate-type = ["cdylib", "rlib"]
[features]