-
Notifications
You must be signed in to change notification settings - Fork 120
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
Add information for reproducible builds to metadata #525
Comments
cargo-contract
version to Wasm blob
We should also check for Rust compiler env variables that can influence the build process and persist them in the custom section. |
Don't we control the build through |
I updated the issue so that it says that we want to emit this data into the metadata. Reasoning is that this makes the life of everyone much easier without really preventing any use case: We always want to validate metadata and wasm anyways. Having a validated wasm with wrong metadata is just as dangerous as invalidated. Additionally, the information included are partly specific to ink! and should not leak to The |
I haven't been able to create reproducible build artifacts while working through #696 At the moment I'm building contracts manually using #!/bin/bash
set -eux
# Our default profile from https://github.com/paritytech/cargo-contract/blob/master/src/workspace/profile.rs#L30-L39
echo '[profile.release]
opt-level = "z"
lto = "fat"
codegen-units = 1
overflow-checks = true
panic = "abort"' >> Cargo.toml
# Our flags from https://github.com/paritytech/cargo-contract/blob/master/src/cmd/build.rs#L277-L302
export RUSTC_BOOTSTRAP=1
export RUSTFLAGS="-C link-arg=-zstack-size=65536 -C link-arg=--import-memory -Clinker-plugin-lto"
# Try removing user/system specific paths from the build artifacts, hasn't helped
# though.
#
# From here: https://github.com/cbeuw/lotus/blob/master/cargo-build.sh
export CARGO_HOME=$HOME/.cargo
RUSTFLAGS="$RUSTFLAGS -Z remap-cwd-prefix=. --remap-path-prefix $CARGO_HOME=cargo_home"
cargo build --no-default-features --release --target=wasm32-unknown-unknown \
-Zbuild-std -Zbuild-std-features=panic_immediate_abort
# Quick way to compare the build artifacts
sha256sum target/wasm32-unknown-unknown/release/erc20.wasm I've got three Linux boxes that I've been using for testing (I also have some Macs, but I've been able to get matching build artifacts on Machines A and B, but not on C. They all have the same I've found differences in the versions of
(Happy to check others libraries which you think may affect the build) The Wat files between Machine {A, B} and Machine C are pretty similar. From what I can I think we can get reproducible builds on similar-ish setups (e.g Linux x86 vs. Linux However, I'm not entirely sure what compiler settings or system libraries need to match BreadcrumbsHere's a list of resources I've used so that somebody can follow the breadcrumbs in the
|
I guess docker is the way then. But let's only use it for what it is really necessary: Making sure the same operating system environment is used. So we still emit toolchain version etc. into the metadata. But additionally we also emit which version of the docker file is used (or One problem that arises is that people will not be aware that they need to build their contract within docker to have any chance of having it verified. They then build it on whatever machine and deploy it to chain. Then it is too late. So should we maybe have a warning somewhere while building to inform people to build in docker to have a chance to verify? Alternatively, we just ignore this problem and don't do docker: It is the block explorers job to cover the main architectures and build it on the appropriate one. |
I think the approach we should take here is to provide a "reference" environment with a
I would say that's similar to the
I'd tie this in with the first thing I mentioned, of just providing the reference image and people |
I am just arguing to keep this "reference environment" as slim as possible. Only operating system. Cause it will eventually get stale and people will get angry that they need to use old compilers and stuff. So don't just emit "ref env v3" into the metadata. Cause then you force people to use its compiler version. |
Argh. All solutions are really not ideal. @HCastano Thanks for the detailed writeup, that's very helpful for following along. Did you find a difference in |
Thinking out loud here: What if we work around mismatching Wasm bytecode hashes by hashing some other representation of the contract that can be deterministically built? Specifically: check if the LLVM IR is deterministic for builds ‒ so an earlier representation of the contract. The LLVM IR can be emitted via
This solution would also not be ideal, due to the increased blob size. But we would gain the ability for everyone to upload contract source code + metadata to a block explorer, no matter if the contract was build in the reference environment. My concern is that only few users will go through the additional hoop of setting up the reference environment. |
Apart from the fact that this is a moonshot anyways (I don't think this byte code will keep matching) this won't work: A malicious contract author can freely choose this hash to be anything they want and can henceforth make you believe any source code will match. The only way is to verify the wasm that is actually executing. |
Please note that no only the environment, but also the crates dependencies can also affect the final contract. Just fixing the |
Related #1148 |
Needed to enable reproducible builds for use-ink/ink#1226.
We need:
ToDo
cargo contract build
cargo contract verify [TARGET.contract]
which reads the information from the metadata, builds the current workspace according to it and compares the resultingoutput.contract
file against theTARGET
The text was updated successfully, but these errors were encountered: