Go to file
Greg Pfeil cc157ffdce
Add various stepwise functionality (#204)
* Move some constants in preparation

This makes some minor changes to constants to facilitate splitting out a
stepwise interpreter.

* Extract a step function from the interpreter

This is generally useful for testing, but specifically, we want to be
able to run this side-by-side with the C++ interpreter, and check that
every bit of our state matches along the way.

This change is as minimal as possible, to avoid divergence until after
it can be compared against C++. E.g., the massive `match opcode {…}`
block that has been moved should only change the dereferencing of
`op_count`.

* Add a `State` struct to make stepping easier

* Expose step interpreter

* Add a stepwise comparison interpreter

The C++ changes aren’t in place yet, so this is currently just an A/A test.

This changes our closures into structs containing a function, because
that’s how we can pass around functions with universally-quantified
lifetimes.

* Make interpreters more flexible

Previously the `ZcashScript` impls didn’t use `self`, so the types were
just tags. However, with the new `StepwiseInterpreter`, they need
`self`.

This also removes `RustInterpreter` in favor of a `rust_interpreter`
function that instantiates an appropriate `StepwiseInterpreter`.

* Add a function for C++/Rust comparison interpreter

* Fix fuzzer

* Clean up `use` in lib.rs

* Fix weird indentation

* Make various fields non-`pub`

* Add a `new` constructor for `Stack`

* Remove incorrect comment

* Appease Clippy

Adds `Default` impls for `Stack` and `State`.

* Rename `State::manual` to `State::from_parts`
2025-04-10 18:03:29 -03:00
.github Initial Rust implementation (#174) 2025-01-29 19:31:52 -03:00
depend Expose `ScriptError` on C++ side (#195) 2025-02-11 11:22:52 -03:00
fuzz Add various stepwise functionality (#204) 2025-04-10 18:03:29 -03:00
src Add various stepwise functionality (#204) 2025-04-10 18:03:29 -03:00
.gitignore Add Cargo.lock to the project (#96) 2023-09-18 10:51:36 +10:00
CHANGELOG.md update documentation for release 0.2.0 (#161) 2024-06-10 17:17:54 +02:00
Cargo.lock Bump cc from 1.2.10 to 1.2.11 (#196) 2025-02-04 11:11:42 -03:00
Cargo.toml Addressing post-hoc PR feedback on #174 (#197) 2025-02-25 13:49:54 -03:00
LICENSE Initial commit 2018-02-25 06:26:24 +01:00
README.md update documentation for release 0.2.0 (#161) 2024-06-10 17:17:54 +02:00
build.rs Bump cc 1.1.10 (#186) 2025-01-23 19:11:03 -03:00
rust-toolchain.toml Add a basic rust-toolchain.toml (#176) 2024-12-16 10:47:41 +01:00

README.md

zcash_script

Build Status Latest Version Rust Documentation

Rust bindings to the ECC's zcash_script C++ library.

Developing

This crate works by manually including the zcash_script .h and .cpp files, using bindgen to generate Rust bindings, and compiling everything together into a single library.

Updating this crate

  1. Create a new branch batch so all the release commits can be made into a PR
  2. Update depend/zcash with the latest tagged version of zcashd, using the instructions below
  3. Test if everything works by running cargo test. If you get any compiling errors, see the troubleshooting section below.
  4. Check all open PRs to see if they can be merged before the release
  5. Do the release, following the instructions below
  6. Check the release tag was pushed to https://github.com/ZcashFoundation/zcash_script/tags

Updating depend/zcash

We keep a copy of the zcash source in depend/zcash, but it has diverged in 0.2.0 release (based on zcashd 5.9.0) with the following changes:

  • The root Cargo.toml was be deleted, since otherwise cargo will ignore the entire folder when publishing the crate (see https://github.com/rust-lang/cargo/issues/8597).
  • New classes were introduced in interpreter.h/.cpp to support the callback API.
  • Some #if guards were added to remove code that is not needed for script verification.

The simplified API now mostly require files that are truly required for script verification. These are unlikely to change so this crate no longers need to keep the zcashd source in sync, unless there was some bug fix in script verification.

If updating zcashd source is required, you will need to manually update the depend/zcash source tree and reapply changes that have been made to it. If you do that, please document the process in detail in this file.

Publishing New Releases

Releases for zcash-script are made with the help of cargo release.

  1. Update CHANGELOG.md to document any major changes since the last release
  2. Run cargo release <level> to commit the release version bump (but not actually publish), <level> can be patch, minor or major
  3. Open a zcash_script PR with the changes, get it reviewed, and wait for CI to pass
  4. Publish a new release using cargo release --execute <level>

NOTE: It's important to specify the level when using cargo release because of the way it implements the substitutions. We specify a number of automatic substitutions in Cargo.toml but they will only be applied if cargo release also handles incrementing the version itself, do not increment the version by hand and then run cargo release or cargo release -- release, or it will not correctly update all version references in the codebase.

Troubleshooting

"undefined reference to name"

This likely means that a .c file is not being included in build.rs. Search for name in the zcashd source tree to find which file contains it, and add it to a file() call inside build.rs.

"fatal error: file: No such file or directory"

This likely means that a .h file is not being found. Seach for a file with the given name and add its folder to a .include() call in build.rs. If the file does not exist there it's likely from a 3rd-party dependency that is downloaded at build time. Search for the file name on some search engine to attempt to find what project it belongs to, cross-referencing the depends/packages folder in zcashd. Then you may need to copy those files to a folder inside zcash_script like we did in depend/expected.