Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major Changes to Reproducible Builds #53

Merged
merged 13 commits into from
Jul 16, 2024
Merged

Conversation

rauljordan
Copy link
Contributor

@rauljordan rauljordan commented Jul 12, 2024

Description

Add Project Hash as Custom WASM Section
Currently, program verification involves injecting a hash of the contents of all Rust sources of a project in the contract deployment calldata. However, this project hash should actually be part of the WASM file itself. We include it as a custom wasm section, which will cause different project hashes to require unique program activations and make them part of consensus. This also extends the docker.rs of reproducible builds to support nightly.

Tested to show that changing a single comment in a project leads to a different activation, and that hashes match with verification:

contract size: 4.5 KB
wasm size: 13.2 KB
File used for deployment hash: ./Cargo.lock
File used for deployment hash: ./Cargo.toml
File used for deployment hash: ./examples/counter.rs
File used for deployment hash: ./src/lib.rs
File used for deployment hash: ./src/main.rs
Project hash computed on deployment: "8af697e3893b7d8e45ccb01f6f310ae846d66f67afd75dc2ae2e12437801ea06"
Verified - program matches local project's file hashes

We also add more details in case verification fails, such as what part of the verification mismatches: either the EVM prelude or the contract code itself.

Require Toolchain File for Reproducible Stylus Programs
Our next major change is requiring a rust-toolchain.toml file, which is a convention for reproducible Rust programs in the directory of the project being deployed. This allows specifying the exact toolchain channel, such as a specific nightly Rust version, to ensure builds are always made with the expected channel.

@rauljordan rauljordan requested a review from rory-ocl July 12, 2024 15:48
check/src/deploy.rs Outdated Show resolved Hide resolved
@rauljordan rauljordan changed the title Fix Up Reproducible Builds to Include Project Hash as WASM Custom Section Major Changes to Reproducible Builds Jul 16, 2024
@rauljordan rauljordan marked this pull request as draft July 16, 2024 15:30
@rauljordan rauljordan marked this pull request as ready for review July 16, 2024 15:30
@rauljordan rauljordan requested a review from rory-ocl July 16, 2024 15:34
@rauljordan
Copy link
Contributor Author

Thanks @rory-ocl ! This is ready again

RUN cargo install cargo-stylus
RUN cargo install --force cargo-stylus-check
RUN cargo install --force cargo-stylus-replay
RUN cargo install --force cargo-stylus-cgen
",
version
version,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that this version variable has also been cleaned to prevent injection attacks? @rauljordan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Fixed

// Next, parse the Rust version from the toolchain project, only allowing alphanumeric chars and dashes.
let channel = channel
.chars()
.filter(|c| c.is_alphanumeric() || *c == '-')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like . should also be a valid character according to the docs. <channel> = stable|beta|nightly|<major.minor.patch>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming ! will add

@@ -76,10 +86,14 @@ fn run_in_docker_container(version: &str, command_line: &[&str]) -> Result<()> {
}

pub fn run_reproducible(version: &str, command_line: &[String]) -> Result<()> {
let version: String = version
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added here @rory-ocl

@rauljordan rauljordan merged commit be51b58 into main Jul 16, 2024
7 checks passed
@rauljordan rauljordan deleted the proper-program-verification branch July 16, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants