Skip to content

Commit

Permalink
move: versioned toolchain compilation to verify source (MystenLabs#15731
Browse files Browse the repository at this point in the history
)

## Description 

Implements versioned toolchain builds to verify bytecode when publishing
packages. That is, on `publish`, verifies package dependencies and
compiles modules with prior compiler versions if needed.

Guarded by `SUI_RUN_TOOLCHAIN_BUILD`.
discussion.

## Test Plan 

Added a test that requires a dep to compile with the current compiler by
reading from Move.lock. Supporting a prior compiler is TBD. All new
functionality gated for now by `SUI_RUN_TOOLCHAIN_BUILD`.

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
rvantonder authored Jan 23, 2024
1 parent f60db87 commit 169b592
Show file tree
Hide file tree
Showing 13 changed files with 734 additions and 140 deletions.
220 changes: 160 additions & 60 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ enum_dispatch = "^0.3"
expect-test = "1.4.0"
eyre = "0.6.8"
fdlimit = "0.2.1"
flate2 = "1.0.28"
fs_extra = "1.3.0"
futures = "0.3.28"
futures-core = "0.3.21"
Expand Down Expand Up @@ -462,6 +463,7 @@ synstructure = "0.12"
sysinfo = "0.27.5"
tabled = { version = "0.12" }
tap = "1.0.1"
tar = "0.4.40"
tempfile = "3.3.0"
test-fuzz = "3.0.4"
thiserror = "1.0.40"
Expand Down Expand Up @@ -507,6 +509,7 @@ tracing-subscriber = { version = "0.3.15", default-features = false, features =
ttl_cache = "0.5.1"
uint = "0.9.4"
unescape = "0.1.0"
ureq = "2.9.1"
url = "2.3.1"
uuid = { version = "1.1.2", features = ["v4", "fast-rng"] }
webpki = { version = "0.101.0", package = "rustls-webpki", features = [
Expand All @@ -521,6 +524,7 @@ versions = "4.1.0"
# Move dependencies
move-binary-format = { path = "external-crates/move/crates/move-binary-format" }
move-bytecode-utils = { path = "external-crates/move/crates/move-bytecode-utils" }
move-bytecode-source-map = { path = "external-crates/move/crates/move-bytecode-source-map" }
move-cli = { path = "external-crates/move/crates/move-cli" }
move-compiler = { path = "external-crates/move/crates/move-compiler" }
move-core-types = { path = "external-crates/move/crates/move-core-types" }
Expand Down
12 changes: 11 additions & 1 deletion crates/sui-source-validation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sui-source-validation"
version = "0.1.0"
version.workspace = true
authors = ["Mysten Labs <[email protected]>"]
license = "Apache-2.0"
publish = false
Expand All @@ -11,7 +11,9 @@ path = "src/lib.rs"

[dependencies]
anyhow.workspace = true
colored.workspace = true
thiserror.workspace = true
tracing.workspace = true
futures.workspace = true

sui-json-rpc-types.workspace = true
Expand All @@ -20,12 +22,20 @@ sui-sdk.workspace = true
sui-move-build.workspace = true

move-binary-format.workspace = true
move-bytecode-source-map.workspace = true
move-command-line-common.workspace = true
move-compiler.workspace = true
move-core-types.workspace = true
move-package.workspace = true
move-symbol-pool.workspace = true

tar.workspace = true
tempfile.workspace = true
flate2.workspace = true
ureq.workspace = true
workspace-hack.workspace = true


[dev-dependencies]

expect-test.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "a"
version = "0.0.1"
published-at = "$STORAGE_ID"

[dependencies]
b = { local = "../versioned-b" }

[addresses]
a = "$RUNTIME_ID"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module a::a {
use b::b::b;
use b::b::c;

public fun a() : u64 {
b() + c()
}
}
11 changes: 11 additions & 0 deletions crates/sui-source-validation/fixture/versioned-b/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 0
manifest_digest = "C70E0438875A0C3B10FA5995F317F701134E629D1B2E5F3DCA3621E50034F809"
deps_digest = "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"

[move.toolchain-version]
compiler-version = "$COMPILER_VERSION"
edition = "legacy"
flavor = "sui"
7 changes: 7 additions & 0 deletions crates/sui-source-validation/fixture/versioned-b/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "b"
version = "0.0.2"
published-at = "$STORAGE_ID"

[addresses]
b = "$RUNTIME_ID"
12 changes: 12 additions & 0 deletions crates/sui-source-validation/fixture/versioned-b/sources/b.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module b::b {
public fun b(): u64 {
42
}

public fun c(): u64 {
b() + 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module b::c {
public fun c(): u64 {
43
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module b::d {
public fun d(): u64 {
44
}
}
Loading

0 comments on commit 169b592

Please sign in to comment.