Contract Source Validation SEP #1573
Replies: 2 comments 3 replies
-
I have been using your action for my project and it's great 👍 It's very important for the whole supply chain security that we get that part right. Some comments/suggestions:
|
Beta Was this translation helpful? Give feedback.
-
👋🏻 This proposal is really important and it's wonderful to see it starting to get use already. I think the proposal bundles together three super valuable things that need more specification, independently:
Why:
1️⃣ Linking built wasms to source code – The proposal achieves this with GitHub Attestations and Sigstore's Rekor (transparency log) 👏🏻. GitHub Attestations are sufficient for proving the wasm to source code link. We know this because it's now a software engineering best practice adopted by other ecosystems (npm, pypi, homebrew). The rest of the proposal provides other guarantees and benefits that aren't critical for proving a link between a binary (wasm) and code. The less we add to this verification process that is bespoke, the more we lean on the software engineering industries best practices, the more we can benefit from development outside the Stellar ecosystem. For example, using common tools like the For the purposes of defining how to verify code, the proposal would be sufficient to set it's scope on: Currently the proposal doesn't indicate how to do (b) or (c), other than use the
The proposal suggests SDF take ownership of the bespoke workflow, but if we reduce the verification proposal to the above, there will be no need for any trust in any workflow owner, other than GitHub. Assuming the use of Rekor in the verification process, GitHub on its own would only be trusted at build time, not at verification time. It would be awesome if the proposal could discuss the sigstore primitives that are being used. Because really this solution is platform agnostic already. A payload is produced, signed, published to the sigtore transparency log (rekor), and if you trust the signer, you can verify the payload. But being most practical I think it's fine if it relies on GitHub APIs and maybe in the future a compatible SEP is written that describes the process at the sigstore layer. 2️⃣ Linking built wasms to home domains – The proposal includes instructions for how to store This 'home_domain' linking could be an independent SEP and doesn't need to be coupled with source code verification. The wasm file home_domain linking may also not be sufficient for all use cases. Not all deployments of a wasm hash should be associated with the same home domain. Contract deployments/instances also need a way to report their home_domain linkage, and so it may be better to do linking at the instance level instead of the wasm file meta level. 3️⃣ A convenient common build process or common build containers – The proposal as written requires the use of a GitHub build workflow where contracts are built in a specific Ubuntu docker image, and attestation/verification requires releasing:
The workflow is opinionated and makes assumptions about how a developer wants to build and release their contracts. In other ecosystems that use attestation, building is not opinionated or coupled to attestation, for e.g.: The workflow expands the surface area of a contract developers risk, because they must be concerned with a third parties action, and the additional third party components that workflow pull in and may be supply chain exploitable. For example: It shifts control away from the developer and requires developers to use a specific approach to releasing and building their applications. Ideally developers can be in full control of their own build and release processes and still be permitted to participate in verification. I think a standard GitHub Action that builds Rust Stellar contracts would be good for the ecosystem, but it seems unnecessary to couple it with source code verification. A standard Docker image for building could further the goal of reproducible builds as another method for making it possible to verify builds. This proposal would need more than what exists here though, such as a fully and truly reproducible build image, and a way to securely link wasm builds back to their build image. That effort is much more likely to be iterative and require more work because reproducible builds in Rust are hard (something @brson has spent some effort on improving ❤️) and building other peoples Rust code is unsafe (because building Rust code executes it on the host). In an example contract repo I've written a build process that I think should be compatible with the verification proposal, because it uses attestation reasonably to prove linkage between a wasm and code. Currently it doesn't show up as verified on stellar.expert because it doesn't use the stellar-expert workflow: In my own learning I wrote a prototype CLI command that verifies the code links to the binary using only the @orbitlens and folks, wdyt? Are there three proposals here we can separate? @tupui given your experience with pypi I'm interested if separating this proposal makes sense, specifically separately 1️⃣ and 3️⃣, given that ecosystem has as far as I can tell. |
Beta Was this translation helpful? Give feedback.
-
Contract Source Validation SEP
Preamble
Simple Summary
A toolkit for the verification of the trust chain between contract WASM and its source code.
Motivation
Stellar doesn't store the source code of contracts in the blockchain, so it may be quite challenging for users to make sure that a contract they are going to invoke is not malicious and behaves as advertised.
Abstract
This SEP describes an approach of automated source code matching based on GitHub Actions Workflows and GitHub Attestations. It provides the ability to establish a trust chain from a smart contract deployed on Stellar Network to a specific commit in GitHub repository containing source code of this contract. As a side benefit, this standard workflow streamlines the smart contracts compilation and release process for Soroban WASM runtime.
In order to turn on automatic code attestation, smart contract developers create a simple configuration file in a contract Git repository.
When triggered, this workflow:
Upon successful validation, anyone can retrieve the GitHub repo link from the contract binary and verify the authenticity of the build directly on the contract GitHub repository Attestations page or using a blockchain explorer that supports this SEP. The trust chain can be validated up to a particular point-in-time snapshot of the source code at the given commit used to build the contract.
Specification
The verification mechanism relies on the GitHub automation and Attestations build artifacts generated during the automated smart contract compilation. Each attestation contains:
In addition to the source code repository link, the workflow can also store a home domain in the contract to provide a consistent off-chain organization and/or token information resolution using a standard SEP-0001
stellar.toml
file.During the compilation, the pipeline stores a repository address in every compiled contract by adding WASM metadata to the
contractmetav0
custom sections. Metadata is stored in the contract asSCMetaEntry
XDR entry. Downstream systems can retrieve this information directly from the WASM, read repository contents and retrieve corresponding attestation from the GitHub API endpoint:https://api.github.com/repos/<user_name>/<repo_name>/attestations/sha256:<wasm_hash>
, wherewasm_hash
is the SHA256 hash of the contract WASM binary.Metadata entries stored in the contract WASM:
source_repo=github:<user_name>/<repo_name>
- source repository linkexample:
source_repo=github.com:reflector-network/reflector-dao-contract
home_domain=<domain_name>
- domain that hosts organization'sstellar.toml
(domain name only, without schema or relative path)example:
home_domain=reflector.network
Based on this information anyone can verify the authenticity and integrity of the smart contract source code, and perform a reverse lookup of the contract information from the organization's domain.
Workflow Setup and Configuration
Prerequisites
.github/workflows/release.yml
in your repository.Workflow inputs and secrets
Basic compilation workflow path:
stellar-expert/soroban-build-workflow/.github/workflows/release.yml@main
The workflow expects the following inputs in the with section:
release_name
(required) - release name template (should include a release version variable, e.g. ${{ github.ref_name }})package (optional) - package name to build, builds contract in working directory by default
relative_path
(optional) - relative path to the contract source directory, defaults to the repository root directorymake_target
(optional) - make target to invoke, empty by default (useful for contracts with dependencies that must be built before the main contract)Basic workflow for the repository with a single contract
Workflow permissions
In order to create a release, the workflow needs
id-token: write
,contents: write
andattestations: write permissions
. Default workflow permissions for a repository can be found at "Settings" -> "Actions" -> "Workflow permissions". It's important to specify permissions on the top level in the.github/workflows/release.yml
configuration file itself:Building multiple contracts
To build multiple contracts, add a separate job for each contract. The workflow will compile and release each contract independently.
Triggering build process manually
Triggering this workflow manually requires a unique release name prompt. Replace the trigger condition in config and update
release_name
to utilize the value from the prompt.Notes
release_contract
job.Design Rationale
Currently, the pipeline relies on GitHub platform tools and does not provide the toolkit for other platforms, like GitLab or BitBucket. GitHub has the largest market share, so the initial implementation utilized its standard APIs and instruments. In the future, in response to the demand, similar automated workflow can be created for other platforms as well. The
source_repo
metadata record contains a platform prefix (github:
) as an extension point for the smooth integration of other repository hosting providers. In addition, attestations can be also potentially stored on IPFS or other distributed storage to increased the data availability.Likewise, this SEP and workflow can be extended in the future to execute automatic contract deployment to the network on build. However, this process has a huge a list of potential security concerns which need to be evaluated, addressed, and documented before including this functionality in the continuous delivery pipeline.
Security Concerns
This SEP does not create any direct security concerns for the Stellar protocol or ecosystem applications.
Since the verification routine relies on the GitHub build automation and attestations mechanism, this approach implies the trust in GitHub’s security. If GitHub security is compromised, it means that verification data cannot be trusted. The possibility of such an event looks very low considering the track records of GitHub and its enterprise backers.
Unlike other building artifacts, attestations are stored in GitHub forever (or at least until the code repository is removed). Therefore, if developers decide to remove a smart contract repository, the verification chain may be broken. However, downstream systems (like blockchain explorers) may retain the verification information indefinitely, alleviating such risks.
While the build process itself is performed in the virtual Docker environment shielded from any external access, smart contract developers still can potentially use some subtle techniques to inject malicious code into the contract during the compilation phase. Protecting end users from malicious developer actions is out of the scope of this SEP – the primary goal is to provide unfalsifiable evidences that a contract has been compiled automatically using a particular GitHub repository.
The automation workflow that builds smart contracts is currently hosted by StellarExpert. We suggest transferring its repository ownership to SDF in order to minimize trust concerns.
Implementations
Changelog
v0.2.0
- Addedhome_domain
meta, notes on meta XDR and format, design rationale for the GitHub platform lock-inv0.1.1
- Defined metadata storage key format explicitlyv0.1.0
- Initial draftBeta Was this translation helpful? Give feedback.
All reactions