Commit Graph

49 Commits

Author SHA1 Message Date
Greg Pfeil d72cb63dd0
Remove extra `&` from `SighashCalculator` (#216)
* Remove extra `&` from `SighashCalculator`

* Remove the now-unnecessary lifetimes
2025-05-15 12:16:21 -03:00
Greg Pfeil d3e242b47f
Eliminate `ScriptNum` (#208)
* Move `set_vch` to simplify later diffs

This makes no changes other than swapping the positions of the `set_vch`
and `serialize` operations on `ScriptNum`.

* Extract integer ↔︎ `Vec<u8>` `fn`s from `ScriptNum`

__NB__: I recommend ignoring whitespace when reviewing this commit.

`ScriptNum` was used one of three ways:
1. convert a Rust integer to a stack value
2. load a stack value into Rust
3. do arithmetic on stack values

Combining these into one interface added extra complexity. For example,
`getint()` would clamp the value to `i32` range, but that range could
only be violated if arithmetic was performed on `ScriptNum`s, and
`getint` was never used on the result of arithmetic.

This extracts `parse_num` and `serialize_num` changing the three
patterns as follows:
1. `ScriptNum::from(_).getvch()` is now `serialize_num(_)`, and
2. `ScriptNum::new(_).and_then(getint())` is now `parse_num(_)`,
3. `ScriptNum::new(_)` … `getvch()` remains the same.

* Make `ScriptNum` a process

We never held a `ScriptNum` – we create one from the stack, perform an
operation, and serialize the result. This eliminates the type in favor
of operations that take a closure on `i64`s.

The operations that exist can’t possibly hit the various bounds that
were checked on `ScriptNum` operations, so they were removed.

As part of the above work, this introduces `cast_from_bool`, which is
then used to replace all instances of `VCH_TRUE`/`FALSE`.
2025-04-30 18:12:50 -03:00
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
Greg Pfeil 2afc474338
Addressing post-hoc PR feedback on #174 (#197)
* Add ECC & myself (Greg Pfeil) as authors

* Have the Rust impl correctly report “high s” sigs

There is a bug in the C++ side where the error is not set correctly on a
“high s” signature. The Rust side had mirrored this bug, but this
eliminates the bug in the Rust.

* Remove extra byte from sig before low-s check

This doesn’t seem to have any effect on the semantics, as the DER-formatted signature includes
lengths that ensure it will ignore extra bytes, but the C++ code removes the extra byte, so the Rust
should as well.

* Change some comments

Co-authored-by: Daira-Emma Hopwood <daira@electriccoin.co>

* Appease `rustfmt`

* Have OP_DUP match the C++ impl more closely

* Address the second half of @daira’s #174 review

* Eliminate mutation from `Opcode` parsing

This now splits slices and returns the remaining pieces rather than
modifying the arguments.

* Remove obsolete comment

* Address PR comments

* Address additional comments on #174

---------

Co-authored-by: Daira-Emma Hopwood <daira@electriccoin.co>
2025-02-25 13:49:54 -03:00
Greg Pfeil 228ec8b4f7
Expose `ScriptError` on C++ side (#195)
**This changes the C++ implementation.**

Provides richer errors, which also gives more precision when comparing
against the Rust impl.

This also removes the (now unused) `zcash_script_error_t`. The only case
other than `zcash_script_ERR_OK` that was still in use was
`zcash_script_ERR_VERIFY_SCRIPT`, so that case has been added to
`ScriptError`.

This avoids changing the Rust API, but potentially `Error` and
`ScriptError` on the Rust side could be collapsed into one `enum`. It
would just be a breaking change.
2025-02-11 11:22:52 -03:00
Greg Pfeil 61f3ef3e74
Change type of `lock_time` parameter (#190)
* Change type of `lock_time` parameter

This is a breaking change. Lock times are stored in tx as `u32`, but
this API expected `i64`, forcing conversions on the caller. This change
brings the API into alignment with the tx representation.

* Update the `lock_time` type in the fuzz test
2025-01-30 10:54:32 -03:00
Greg Pfeil 335ae9a2a6
Initial Rust implementation (#174)
* [DRAFT]

* Rearrange Rust impl to match C++ more closely

The only changes here other than moving chunks of code around are
- moving `evaluate` out of `impl Script`, which required changing
 `&self` to `script: &Script`; and
- unifying `ExecutionOptions` with `VerificationFlags`.

* Rename Rust identifiers to match C++

For easier side-by-side comparison.

* Connected the new API, but fails

* Existing unit tests succeed

* The rest of the owl

* Reverting to C++ style, and some other changes

* Appease Clippy

* Replace `ScriptNum` panics with error case

The C++ impl uses exceptions for `ScriptNum`, but catches them.

* Add some shallow property tests

These tests run both the C++ and Rust impls. One uses completely
arbitrary inputs, and the other limits script_sig to data pushes.

* Add shallow fuzz testing

* Preserve richer errors on the Rust side

For now, the underlying errors are discarded when comparing against the
C++ results, but there are corresponding changes on the C++ side in a
separate branch.

* Address @nuttycom’s review comments

- remove `uint256` module
- create a specific type for the C++/Rust comparison implementation
- rename some identifiers
- rephrase some comments

* Some changes to ease zebrad integration

- Switch from `log` to `tracing` for `warn!`,
- Export `SignedOutputs`, which is needed to create a `HashType`, and
- Upgrade zcash_primitives to the same version used by zebrad.

* Appease Clippy

* Remove dependency on zcash_primitives

This was only needed for the `TxVersion` enum. However, the `StrictEnc`
flag is a proxy for the v5 tx requirements, so instead of checking the
`TxVersion` explicitly, we expect callers to include `StrictEnc` for
verification of v5 transactions.

* Moving testing dependencies

libfuzzer-sys is Linux-specific, and it & proptest are only used for tests.

* Normalize Rust errors in comparison interpreter

This was a minor oversight, but this correction should only eliminate
false mismatches.

* Address @nuttycom’s PR feedback

* Eliminate a `panic!`

This `panic!` appears to be unreachable in the current implementation, but there is no need for it.
It doesn’t introduce any new failure cases.

Thanks to @conradoplg for noticing it.

* Use (`Try`)`From` for `ScriptNum` conversions

This also makes the `ScriptNum` field private so that `bn.0` can’t
extract the unconstrained `i64` value.

* Remove some `From` instances that do too much

* Subtract from `OP_RESERVED` instead of `OP_1 - 1`

`OP_RESERVED` is in the ‘0’ offset position of the `OP_n` opcodes. Just
use this even though it isn’t obviously a number to improve readability.

---------

Co-authored-by: Sean Bowe <ewillbefull@gmail.com>
Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
2025-01-29 19:31:52 -03:00
Greg Pfeil a429b3f8d3
Address Str4d’s comments on #171 (#175)
* Address Str4d’s comments on #171

Notably, `HashType` has changed incompatibly, so
ZcashFoundation/zebra#8751 will need to be updated.

* Apply suggestions from code review

Co-authored-by: Jack Grigg <thestr4d@gmail.com>

* Restrict bitflags used for `HashType` in v5 tx

---------

Co-authored-by: Jack Grigg <thestr4d@gmail.com>
2024-10-24 19:24:40 -03:00
Greg Pfeil 9d16e79c72
Provide a Rustier wrapper for zcash_script (#171)
* Move C++ bindings out of lib.rs

Have lib.rs re-export them, but make room for the upcoming Rust implementation.

* Provide a Rustier wrapper for zcash_script

This adds a `Script` trait that exposes slightly Rustier types in order
to have a common interface for the existing C++ implementation as well
as the upcoming Rust implementation (and a third instance that runs both
and checks that the Rust result matches the C++ one).

The module structure (interpreter.rs, zcash_script.rs) and locations of
definitions are intended to mirror the structure of the C++ code, especially as
we get the Rust implementation in place, for easier comparison. That
organization is very likely to change once everything has been checked.

* Address review feedback

Thanks to @nuttycom and @arya2 for getting the closure to work.

* Additional cleanup

* Use `try_from`/`_into` instead of `as`

* Address review feedback

* Widen the `Unknown` error type

This should fix the Windows build.
2024-09-17 16:11:32 -03:00
Conrado Gouvea c9d750743f
update documentation for release 0.2.0 (#161) 2024-06-10 17:17:54 +02:00
Conrado Gouvea 4924030059
Remove dependencies by switching to simplified API with a callback interface (#157)
* created zcash_script_verify_prehashed; compiles

* removed unneded code; callback API

* revert formatting changes to interpreter.cpp/.h

* remove prehashed code

* moving code around

* use #if 0 instead of commenting out to make diff clearer

* tmp

* remove debug prints

* cleanups

* deleted unneeded rust files

* remove unneeded dependencies

* remove more unneeded files

* add new tests and remove old ones

* remove unneded params; add sighashLen to callback

* remove unneeded code

* msvc fixes
2024-06-04 23:52:11 +02:00
Alfredo Garcia ef2a7fdd5d
cargo release execute output for v0.16 (#149)
* chore: Release zcash_script version 0.1.16

* fix the date
2024-04-26 09:45:10 -03:00
Alfredo Garcia 06de015788
Bump v0.1.16 (#147)
* remove zcashd depend

* Squashed 'depend/zcash/' content from commit 1408e23f0

git-subtree-dir: depend/zcash
git-subtree-split: 1408e23f00fa49ca5f86d2c7ebeb5d120603aa4c

* delete cargo, update and apply patch

* update dependencies

* fix compiling issue by updating lib.rs

* update `cc`

* update `cxx-gen`

* add changeloig entry

---------

Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
2024-04-26 11:51:51 +02:00
Alfredo Garcia faed93224e
Bump the release v0.1.15 (#146)
* chore: Release zcash_script version 0.1.15

* update date
2024-04-19 11:48:41 -03:00
Alfredo Garcia 6c2eb13d9f
Create the v0.1.14 release - 2nd attempt (#110)
* update the changelog

* chore: Release zcash_script version 0.1.14

* remove duplicated
2023-10-18 15:39:20 -03:00
Alfredo Garcia 3fdf588c23
v0.1.14 release (#102)
* rm zcash

* Squashed 'depend/zcash/' content from commit e08571476

git-subtree-dir: depend/zcash
git-subtree-split: e08571476d8a59d0a624da7b118ab8d8ad2a6246

* delete zcash/Cargo.toml

* update versions

* update build

* make sapling.rs work by renaming it and copying it to OUT_DIR

* cargo fmt

---------

Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
2023-10-17 16:03:37 -03:00
Alfredo Garcia 36de9309bf
Allow clippy lint (#103)
* allow clippy lint

* Revert "allow clippy lint"

This reverts commit 6744ff1ca4.

* move allow clippy rule to lib.rs

---------

Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
2023-10-17 09:26:34 -03:00
Arya b900ff4261
v0.1.13 release (#91)
* rm depend/zcash

* Squashed 'depend/zcash/' content from commit 00c2a2434

git-subtree-dir: depend/zcash
git-subtree-split: 00c2a2434e655d275c26986c8751793f4c98bb01

* rm depends/zcash/Cargo.toml

* updates Cargo.toml

* Updates Changelog

* add tl_expected.hpp

* Fix build

* add test-dependencies features to ecc deps

* add missing .c files from secp256k1

* chore: Release zcash_script version 0.1.13

---------

Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
2023-07-07 14:06:27 -04:00
teor 258900639b (cargo-release) version 0.1.12 2023-05-08 07:16:28 +10:00
teor 5cfaef7bbd
Upgrade zcash_script to zcashd v5.5.0 (#84)
* Update dependencies to match zcashd v5.5.0

* Update dependencies to match Zebra main branch

* Update release instructions

* Add module docs for the build script to avoid warnings

* Update bridge file list to match the latest zcashd

* Ignore some emacs temporary files

* Standardise directory include paths in Cargo.toml

* Add extra info to cxx_gen errors

* Add additional Rust dependencies needed to compile

* Ignore some expected clippy lints

* Silence a C compiler macro redefinition warning

* Standardise directory paths in build.rs

* fix cxxbridge code generation

* Update Cargo.lock

* Use include!() for bridge.rs

* Add a changelog entry for the next release

* Fix a warning by adding docs for the crate

* Remove previous depend/zcash

* Squashed 'depend/zcash/' content from commit eb80047476

git-subtree-dir: depend/zcash
git-subtree-split: eb80047476e9c0db3524f647d412faf8d4a584ee

* Update depend/zcash to v5.5.0

```sh
git subtree add -P depend/zcash https://github.com/zcash/zcash.git v5.5.0 --squash
git rm depend/zcash/Cargo.toml
```

---------

Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
2023-05-05 09:55:41 -03:00
Arya ed7b95b6da
v0.1.11 release (#69)
* Updates changelog

* chore: Release zcash_script version 0.1.11

* Apply suggestions from code review

Co-authored-by: teor <teor@riseup.net>

---------

Co-authored-by: teor <teor@riseup.net>
2023-02-23 19:24:18 -05:00
Arya 96a9b9026c
chore: Release zcash_script version 0.1.9 (cargo-release) (#62) 2023-02-23 16:08:17 -05:00
Conrado Gouvea 5266ac19b7
v0.1.7 release (#39)
* update changelog for v0.1.7

* (cargo-release) version 0.1.7
2022-08-31 19:16:10 -03:00
Conrado Gouvea bef75ee7bb
Update to zcash 5.2.0 (#37)
* delete previous version

* Squashed 'depend/zcash/' content from commit f98166f7f5

git-subtree-dir: depend/zcash
git-subtree-split: f98166f7f556ee9b9f597d45275c32843a87b0b6

* update to zcash 5.2.0

* remove Windows support for now, see #38
2022-08-23 05:40:55 +10:00
Conrado Gouvea c9fbc441ef
Use subtree again to allow publishing the crate (#34)
* change: update Cargo.toml, lib.rs, CHANGELOG.md for 0.1.6 release.

* Squashed 'depend/zcash/' content from commit 9af3bce26

git-subtree-dir: depend/zcash
git-subtree-split: 9af3bce265ba428382006b0940678418d65f505f

* fix: delete depend/zcash/Cargo.toml to prevent cargo from ignoring it

* ci: add cargo package test

* change(doc): explain the subtree / squash issue in README.md
2022-05-17 19:31:56 -03:00
Conrado Gouvea 98c74180ff
Update zcash to new V5 API; add tests (#30)
* update zcash to new V5 API; add tests

* try using x86_64-pc-windows-gnu on windows

* Expand README

* update zcash

* retrigger build

* update zcash to current nu5-consensus branch

* use Zcash v4.7.0
2022-04-18 15:28:54 -03:00
Conrado Gouvea 8c9bdb3a35 Revert "Add support for zcash_script_transparent_output_address() (#29)"
This reverts commit b7801e4027.
2022-03-03 12:04:47 -05:00
Conrado Gouvea b7801e4027
Add support for zcash_script_transparent_output_address() (#29)
* add support for zcash_script_transparent_output_address()

* try using x86_64-pc-windows-gnu on windows

* update zcash to version which returns address type
2022-03-03 10:52:35 -03:00
Janito Vaqueiro Ferreira Filho 47d5d2c1bc Replace symbolic links with file inclusion
Update `depend/zcash` so that the `orchard_ffi` module has a root
`mod.rs` module file to fix an issue where Cargo can't find any
sub-modules.
2021-10-05 23:21:40 +00:00
Janito Vaqueiro Ferreira Filho 337f5eb182 Add missing FFI modules
New FFI modules required for `libzcash_script`.
2021-10-05 03:38:54 +00:00
Jane Lusby 6b903b1678 (cargo-release) version 0.1.5 2020-12-09 15:47:54 -08:00
Jane Lusby 5534684937 re-export and test new precompute api 2020-12-09 15:22:40 -08:00
Jane Lusby 848eb05d06
bump bindgen back to 0.54 for compatibility with rocksdb (#14)
* bump bindgen back to 0.54 for compatibility with rocksdb

* update changelog for new release

* (cargo-release) version 0.1.4

* (cargo-release) start next development iteration 0.1.5-alpha.0
2020-11-23 19:23:23 -08:00
Jane Lusby 55f1980ba0 New release to enable endomorphism optimization and switch to subtree (#13)
* (cargo-release) version 0.1.3

* (cargo-release) start next development iteration 0.1.4-alpha.0

* update changelog
2020-10-09 17:20:31 -07:00
Jane Lusby 5a5cbe85f6
remove color-eyre from build dependencies (#9)
* remove color-eyre from build dependencies

* looks like we can remove this from the dev deps too

* (cargo-release) version 0.1.2-rc.1

* (cargo-release) version 0.1.2

* (cargo-release) start next development iteration 0.1.3-alpha.0
2020-09-21 16:01:37 -07:00
Jane Lusby 29b6915388 increment version for new release 2020-09-15 17:13:06 -07:00
Jane Lusby 95acf44e83
update bindgen and cc deps (#6)
* update bindgen and cc deps

* try to get ci working

* add back old config and fix remote url

* i guess it actually was the config

* prep for releasing with cargo-release
2020-09-15 17:11:33 -07:00
Jane Lusby dcde9a0b5b
merge zcash_script changes for final release (#3)
* initial working version on cc

* add basic actions automation

* checkout submodules

* don't require bindgen generation

* use newest zcash changes

* pause work on ripping out sodium

* push hacks to some version of the repo

* fix path in build.rs

* add job for testing different OSs

* str4d is the fucking greatest

* cleanup unused code

* remove symlink

* cleanup cruft

* remove old automation files

* Apply suggestions from code review

Co-authored-by: Saleem Rashid <dev@saleemrashid.com>

* add failure case test

* always generate bindings

* install llvm dep on windows

* cleanup unused bindings

* try messing with CI

* use actual branch name

* use correct remote for gitmodules

* Update build.rs

Co-authored-by: Saleem Rashid <dev@saleemrashid.com>

* rename to zcash_script

* cleanup last mentions

* Prepare zcash_script for release (#2)

* cleanup last mentions

* add files that need to be included

Co-authored-by: Saleem Rashid <dev@saleemrashid.com>
2020-08-13 16:47:37 -07:00
Jane Lusby c2252b2a07
initial working version on cc (#1)
* initial working version on cc

* add basic actions automation

* checkout submodules

* don't require bindgen generation

* use newest zcash changes

* pause work on ripping out sodium

* push hacks to some version of the repo

* fix path in build.rs

* add job for testing different OSs

* str4d is the fucking greatest

* cleanup unused code

* remove symlink

* cleanup cruft

* remove old automation files

* Apply suggestions from code review

Co-authored-by: Saleem Rashid <dev@saleemrashid.com>

* add failure case test

* always generate bindings

* install llvm dep on windows

* cleanup unused bindings

* try messing with CI

* use actual branch name

* use correct remote for gitmodules

* Update build.rs

Co-authored-by: Saleem Rashid <dev@saleemrashid.com>

Co-authored-by: Saleem Rashid <dev@saleemrashid.com>
2020-07-22 14:02:44 -07:00
Elichai Turkel 60e17c99da
Compile libsecp256k1 as part of bitcoin, not as a dependency 2020-01-07 16:22:37 +02:00
Tamas Blummer ac28390d13 make bitcoinconsensus::Error cloneable 2018-03-10 14:03:52 +01:00
Tamas Blummer 2fab09f4ea comments 2018-02-25 20:38:00 +01:00
Tamas Blummer 892f159764 added tests and docs 2018-02-25 19:48:00 +01:00
Tamas Blummer 73679aa444 first test and more docs 2018-02-25 11:26:02 +01:00
Tamas Blummer dda24dee99 cleanup compiler flags 2018-02-25 09:33:12 +01:00
Tamas Blummer 9cb24189e8 add VERIFY_ALL 2018-02-25 09:28:15 +01:00
Tamas Blummer d030e549e4 documentation 2018-02-25 09:22:09 +01:00
Tamas Blummer 726da20326 index name corrected 2018-02-25 08:07:55 +01:00
Tamas Blummer 1907aa67a0 connect with Rust 2018-02-25 07:59:58 +01:00