From cb1613dabf65aad6695c05c492ed1016240091e7 Mon Sep 17 00:00:00 2001 From: Illia Kripaka Date: Mon, 12 Oct 2026 11:55:43 +0300 Subject: [PATCH 1/2] bump `smplx-std` dep to 0.1.0 --- Cargo.lock | 269 ++++++++++++++++++++++++++++++++++++++++++----------- Cargo.toml | 2 +- 2 files changed, 217 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86877ca..47d5034 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,7 +133,7 @@ version = "0.1.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "365c0acd5b2e8dd0111a46c4faea83fb3cfb6e39a49a7c73a06e090db7b2eff0" dependencies = [ - "bitcoin_hashes", + "bitcoin_hashes 0.14.101", ] [[package]] @@ -160,13 +160,28 @@ version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90dbd31c98227229239363921e60fcf5e558e43ec69094d46fc4996f08d1d5bc" dependencies = [ - "bitcoin_hashes", - "rand", - "rand_core", + "bitcoin_hashes 0.14.101", + "rand 0.8.8", + "rand_core 0.6.4", "serde", "unicode-normalization", ] +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + [[package]] name = "bitcoin" version = "0.32.102" @@ -176,9 +191,10 @@ dependencies = [ "base58ck", "base64 0.21.7", "bech32", + "bitcoin-consensus-encoding", "bitcoin-io", "bitcoin-units", - "bitcoin_hashes", + "bitcoin_hashes 0.14.101", "hex-conservative 0.2.3", "hex_lit", "secp256k1", @@ -191,11 +207,17 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9daa31138eb443d5751b207f3f64154e2bb09cd59960562ccc7a7112be38147f" dependencies = [ - "bitcoin-internals", + "bitcoin-internals 0.7.0", "hex-conservative 1.3.0", "serde", ] +[[package]] +name = "bitcoin-internals" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d573f4cf32996a8dce612e4348cece65a241f1882ed594047c9ba348e8869fa5" + [[package]] name = "bitcoin-internals" version = "0.7.0" @@ -238,6 +260,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin_hashes" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5304e53726dbe5f93141535e102ed97b5bf4714fbecefdda8f9fb98d7fdaff0e" +dependencies = [ + "bitcoin-consensus-encoding", + "bitcoin-internals 0.6.0", + "hex-conservative 1.3.0", + "serde", +] + [[package]] name = "bitcoincore-rpc" version = "0.19.0" @@ -540,12 +574,16 @@ dependencies = [ [[package]] name = "elements" -version = "0.25.3" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c63a04238f4b7f3564fe9705921452c2900efd00982545e5c634fac9024fe2" +checksum = "34e00f7ddcd826d2f4c9bd72d79a6b6991a0ac4286e7e2b2ff8eecd130549073" dependencies = [ "bech32", "bitcoin", + "bitcoin-consensus-encoding", + "bitcoin-internals 0.6.0", + "bitcoin_hashes 1.2.0", + "hex-conservative 1.3.0", "secp256k1-zkp", "serde", "serde_json", @@ -553,9 +591,9 @@ dependencies = [ [[package]] name = "elements-miniscript" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571fa105690f83c7833df2109eb2e14ca0e62d633d2624ffcb166ff18a3da870" +checksum = "0c18e931c81e6e7e58d63b6fea1c57f5534717f0e6721741c4fce72a6c547e19" dependencies = [ "bitcoin", "elements", @@ -576,7 +614,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -598,11 +636,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ "byteorder", - "rand", + "rand 0.8.8", "rustc-hex", "static_assertions", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foldhash" version = "0.1.5" @@ -668,6 +712,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -676,7 +732,7 @@ checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", "libc", - "r-efi", + "r-efi 6.0.0", ] [[package]] @@ -685,12 +741,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8449d342b1c67f49169e92e71deb7b9b27f30062301a16dbc27a4cc8d2351b7" -[[package]] -name = "glob" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" - [[package]] name = "globset" version = "0.4.20" @@ -1130,6 +1180,25 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proptest" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags 2.13.2", + "num-traits", + "rand 0.9.5", + "rand_chacha 0.9.0", + "rand_xorshift", + "regex-syntax 0.8.11", + "rusty-fork", + "tempfile", + "unarray", +] + [[package]] name = "psm" version = "0.1.32" @@ -1140,6 +1209,12 @@ dependencies = [ "cc", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.47" @@ -1149,6 +1224,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "r-efi" version = "6.0.0" @@ -1168,8 +1249,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", ] [[package]] @@ -1179,7 +1270,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", ] [[package]] @@ -1191,6 +1292,24 @@ dependencies = [ "getrandom 0.2.17", ] +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_xorshift" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +dependencies = [ + "rand_core 0.9.5", +] + [[package]] name = "regex-automata" version = "0.3.9" @@ -1268,7 +1387,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1313,6 +1432,18 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "rusty-fork" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + [[package]] name = "same-file" version = "1.0.6" @@ -1328,8 +1459,8 @@ version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" dependencies = [ - "bitcoin_hashes", - "rand", + "bitcoin_hashes 0.14.101", + "rand 0.8.8", "secp256k1-sys", "serde", ] @@ -1350,7 +1481,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52a44aed3002b5ae975f8624c5df3a949cfbf00479e18778b6058fcd213b76e3" dependencies = [ "bitcoin-private", - "rand", + "rand 0.8.8", "secp256k1", "secp256k1-zkp-sys", "serde", @@ -1443,36 +1574,36 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "simplicity-lang" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13ed081e3046d66c146d7201bcbf3b655ca3436cb83f6efc26d7895bd2b79d06" +checksum = "cff7b10251528d46d9cf60238267911984fedbb0948cccea98dd74fc6bf9f729" dependencies = [ "bitcoin", - "bitcoin_hashes", + "bitcoin_hashes 1.2.0", "byteorder", "elements", "getrandom 0.2.17", "ghost-cell", - "hex-conservative 0.2.3", + "hex-conservative 1.3.0", "miniscript", "simplicity-sys", ] [[package]] name = "simplicity-sys" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d1ec5477c7650b8ef511aa56dccb28f2e8cdb6e87f260ecffdaf0ebfef2d3b" +checksum = "955935733b2735665b4735d9b1361eade6be4c7aea6bca2640345e4c81756f58" dependencies = [ - "bitcoin_hashes", + "bitcoin_hashes 1.2.0", "cc", ] [[package]] name = "simplicityhl" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae77168fa3367d234b11bb3999cbd6e04d7180db0b9e11f83de259528e3b23d1" +checksum = "9e110f12190a4df92970b50d701f7da979638a60c5bf8294d55e4a55aceebf3e" dependencies = [ "ariadne", "base64 0.21.7", @@ -1496,7 +1627,7 @@ dependencies = [ "num-bigint", "num-traits", "primitive-types", - "rand", + "rand 0.8.8", "secp256k1-zkp", "smplx-std", ] @@ -1509,11 +1640,10 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smplx-build" -version = "0.0.12" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e9561b9da1d788d3e777f8a59b085dd13a6fbace5b109f2b0576069f9f36ff" +checksum = "495bb7f7486a93e0568a14dad1ea189810a8dd105664550b3fd65f8605596310" dependencies = [ - "glob", "globwalk", "pathdiff", "prettyplease", @@ -1530,9 +1660,9 @@ dependencies = [ [[package]] name = "smplx-macros" -version = "0.0.12" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f802ff11501371c4c822f0ecdbf7e9e65180ccbbb43b55f252c9a00cb849d24" +checksum = "56c2dfb886f1e285cbffe7da39c83c02adeca708e22a76437ad7576e90a6d959" dependencies = [ "smplx-build", "smplx-test", @@ -1541,9 +1671,9 @@ dependencies = [ [[package]] name = "smplx-regtest" -version = "0.0.12" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881db46f30a472018c26c5f245637a722ccba36a873b845d5e6376e7bd5e1106" +checksum = "821b56c1b840c65f47023eacd733154e14e9cdf2def684eb73d9c3e5e3fb1ef5" dependencies = [ "electrsd", "hex", @@ -1557,12 +1687,11 @@ dependencies = [ [[package]] name = "smplx-sdk" -version = "0.0.12" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98b85112288eccd99ba34bd852681d78c3581a52709eab0ce52a073b9d961d8e" +checksum = "b4cfa47f23c803672ed59418746c21d79c9a715f5b5ea3ac95bb700eaf040550" dependencies = [ "bip39", - "bitcoin_hashes", "bitcoincore-rpc", "dyn-clone", "elements-miniscript", @@ -1577,11 +1706,13 @@ dependencies = [ [[package]] name = "smplx-std" -version = "0.0.12" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05855ac57a1b5f737a4bc244ebf5924453957a2066a0bb0fd8df033498386ba" +checksum = "39425466bf310e59b5cf8bbb6950a2e6f7451aa1e2d210d2361b88bc50e517da" dependencies = [ "either", + "rand 0.9.5", + "rand_core 0.9.5", "serde", "simplicityhl", "smplx-macros", @@ -1591,13 +1722,15 @@ dependencies = [ [[package]] name = "smplx-test" -version = "0.0.12" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a66ea20c2701a90faf10f9a18176058dd7a82222797d5ed6da9c83f0f1ca032" +checksum = "fb31b4595b02a4bee67231dcab35be090684880f4fce0b0770727327520366fb" dependencies = [ "electrsd", "proc-macro2", + "proptest", "quote", + "rand 0.9.5", "serde", "simplicityhl", "smplx-regtest", @@ -1673,10 +1806,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom 0.3.4", "once_cell", "rustix 1.1.5", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1784,6 +1917,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + [[package]] name = "unicode-ident" version = "1.0.26" @@ -1835,6 +1974,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + [[package]] name = "walkdir" version = "2.5.0" @@ -1851,6 +1999,15 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasm-bindgen" version = "0.2.129" @@ -1923,7 +2080,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2038,6 +2195,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 7703add..a74777b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["simplicity", "liquid", "elements", "smart-contracts"] categories = ["cryptography::cryptocurrencies"] [dependencies] -smplx-std = { version = "0.0.12" } +smplx-std = { version = "0.1.0" } [dev-dependencies] anyhow = { version = "1.0.101" } From 6324b2f691365b1aa5650ac81fcdf4496daad569 Mon Sep 17 00:00:00 2001 From: Illia Kripaka Date: Mon, 12 Oct 2026 13:51:21 +0300 Subject: [PATCH 2/2] draft --- Simplex.toml | 11 +- tests/stdlib/common/core.rs | 15 +- tests/stdlib/common/uint.rs | 6 +- tests/stdlib/common/utxo_helper.rs | 2 +- tests/stdlib/secp256k1/operations.rs | 264 ++++++++++++++++++ tests/stdlib/utxo/asserts/asset_id.rs | 10 +- .../utxo/asserts/asset_id_with_amount.rs | 10 +- 7 files changed, 294 insertions(+), 24 deletions(-) diff --git a/Simplex.toml b/Simplex.toml index c522f64..80d4c06 100644 --- a/Simplex.toml +++ b/Simplex.toml @@ -6,10 +6,10 @@ # out_dir = "./src/artifacts" # [dependencies] -# some_dep = { git = "", path = "" } +# some_dep = { git = "", path = "", = "", package = "" } # [regtest] -# mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" +# mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" # bitcoins = 10_000_000 # rpc_port = 18443 # esplora_port = 3000 @@ -17,12 +17,17 @@ # rpc_password = "password" # [test] -# mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" +# mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" # bitcoins = 10_000_000 # verbosity = 0 # [test.esplora] # url = "" +# network = "" + + [test.fuzz] + cases = 10 +# seed = 12345 # network = "" # [test.rpc] diff --git a/tests/stdlib/common/core.rs b/tests/stdlib/common/core.rs index 054768a..f1b7edb 100644 --- a/tests/stdlib/common/core.rs +++ b/tests/stdlib/common/core.rs @@ -3,8 +3,9 @@ #![allow(dead_code)] use secp256k1_zkp::Secp256k1; -use simplex::program::{Program, WitnessTrait}; +use simplex::program::Program; use simplex::signer::Signer; +use simplex::simplicityhl::WitnessValues; use simplex::simplicityhl::elements::{AssetId, Script, Txid}; use simplex::transaction::partial_input::IssuanceInput; use simplex::transaction::{ @@ -110,7 +111,7 @@ pub fn construct_final_tx( txids: Vec, ) -> anyhow::Result where - W: WitnessTrait + 'static, + W: Into + 'static, { let signer = context.get_default_signer(); let script_to_send_to = signer.get_address().script_pubkey(); @@ -140,7 +141,7 @@ where ft.add_program_input( PartialInput::new(program_utxo.clone()), - ProgramInput::new(Box::new(program.as_ref().clone()), Box::new(witness)), + ProgramInput::new(Box::new(program.as_ref().clone()), witness.into()), RequiredSignature::None, ); @@ -232,7 +233,7 @@ pub fn spend( txids: Vec, ) -> anyhow::Result where - W: WitnessTrait + 'static, + W: Into + 'static, { let ft = construct_final_tx(context, program, script, witness, data, txids)?; @@ -267,7 +268,7 @@ pub fn run( expect: Expect, ) -> anyhow::Result<()> where - W: WitnessTrait + 'static, + W: Into + 'static, { let script = fund(context, &program, DEFAULT_SEND_AMOUNT)?; let result = spend(context, &program, &script, witness, None, Vec::new()); @@ -285,7 +286,7 @@ pub fn run_with_op_return( data: &[u8], ) -> anyhow::Result<()> where - W: WitnessTrait + 'static, + W: Into + 'static, { let script = fund(context, &program, DEFAULT_SEND_AMOUNT)?; let result = spend(context, &program, &script, witness, Some(data), Vec::new()); @@ -302,7 +303,7 @@ pub fn run_with_inputs_outputs( txids: Vec, ) -> anyhow::Result<()> where - W: WitnessTrait + 'static, + W: Into + 'static, { let script = program.as_ref().get_script_pubkey(context.get_network()); diff --git a/tests/stdlib/common/uint.rs b/tests/stdlib/common/uint.rs index 1169c33..4aeb13d 100644 --- a/tests/stdlib/common/uint.rs +++ b/tests/stdlib/common/uint.rs @@ -8,8 +8,8 @@ use std::ops::{Add, Div, Mul, Sub}; use rand::Rng; use rand::distributions::uniform::SampleUniform; -use simplex::program::{Program, WitnessTrait}; - +use simplex::program::{Program}; +use simplex::simplicityhl::WitnessValues; use crate::common::u256_wrapper::U256Wrapper; use super::core::{Expect, run}; @@ -47,7 +47,7 @@ pub trait TestUint: + Div { type Program: AsRef; - type Witness: WitnessTrait + 'static; + type Witness: Into + 'static; const ZERO: Self; const ONE: Self; diff --git a/tests/stdlib/common/utxo_helper.rs b/tests/stdlib/common/utxo_helper.rs index 1cf4714..be7ac88 100644 --- a/tests/stdlib/common/utxo_helper.rs +++ b/tests/stdlib/common/utxo_helper.rs @@ -124,7 +124,7 @@ pub fn create_utxos_with_new_asset( } } - Ok((new_asset.unwrap().into_inner().0, txids)) + Ok((new_asset.unwrap().to_byte_array(), txids)) } fn get_asset_id_amount_from_conf_utxo(conf_utxo: UTXO) -> anyhow::Result { diff --git a/tests/stdlib/secp256k1/operations.rs b/tests/stdlib/secp256k1/operations.rs index 673dedf..e5f8891 100644 --- a/tests/stdlib/secp256k1/operations.rs +++ b/tests/stdlib/secp256k1/operations.rs @@ -43,6 +43,7 @@ fn program() -> Secp256k1OperationsTestProgram { } /// One dispatch arm of the contract, plus the witness it reads. +#[derive(Clone, Debug)] struct Case { witness: Secp256k1OperationsTestWitness, } @@ -409,3 +410,266 @@ fn safe_gej_normalize_roundtrip(context: simplex::TestContext) -> anyhow::Result .expect_ge(ge) .run(&context) } + +// mod fuzz { +// use std::fmt::Debug; +// +// use super::*; +// +// use simplex::fuzz::fuzz_check::{Expect, FuzzExecutionCheck}; +// use simplex::fuzz::proptest::prelude::{Just, any}; +// use simplex::fuzz::proptest::strategy::{BoxedStrategy, Strategy}; +// use simplex::simplicityhl::{Arguments, WitnessValues}; +// use simplex::{FuzzMode, TestContext}; +// +// type Ge = ([u8; 32], [u8; 32]); +// type Gej = (Ge, [u8; 32]); +// +// fn arb_fe() -> impl Strategy { +// any::<[u8; 32]>().prop_filter("valid secp256k1 field element", |value| *value < SECP_P) +// } +// +// fn arb_non_zero_fe() -> impl Strategy { +// arb_fe().prop_filter("non-zero secp256k1 field element", |value| { +// *value != [0; 32] +// }) +// } +// +// fn arb_scalar() -> impl Strategy { +// any::<[u8; 32]>().prop_filter("valid secp256k1 scalar", |value| *value < SECP_N) +// } +// +// fn arb_secret_key() -> impl Strategy { +// any::<[u8; 32]>().prop_filter_map("valid secp256k1 secret key", |bytes| { +// SecretKey::from_slice(&bytes).ok() +// }) +// } +// +// fn ge_from_secret_key(secret_key: SecretKey) -> Ge { +// let secp = Secp256k1::new(); +// let public_key = PublicKey::from_secret_key(&secp, &secret_key); +// let serialized = public_key.serialize_uncompressed(); +// +// let mut x = [0; 32]; +// x.copy_from_slice(&serialized[1..33]); +// +// let mut y = [0; 32]; +// y.copy_from_slice(&serialized[33..65]); +// +// (x, y) +// } +// +// fn arb_ge() -> impl Strategy { +// arb_secret_key().prop_map(ge_from_secret_key) +// } +// +// /// Fuzz counterparts for every `#[simplex::test]` case with randomized inputs. +// /// Deterministic cases stay as regular tests. +// struct CaseFuzz { +// cases: BoxedStrategy, +// context: TestContext, +// test_name: &'static str, +// expect: Expect, +// } +// +// fn case_fuzz( +// function: FunctionToTest, +// context: TestContext, +// test_name: &'static str, +// ) -> CaseFuzz { +// CaseFuzz { +// cases: Just(case(function)).boxed(), +// context, +// test_name, +// expect: Expect::Ok, +// } +// } +// +// impl CaseFuzz { +// fn inject( +// mut self, +// values: impl Strategy + 'static, +// inject: impl Fn(Case, T) -> Case + 'static, +// ) -> Self +// where +// T: Debug + 'static, +// { +// self.cases = (self.cases, values) +// .prop_map(move |(case, values)| inject(case, values)) +// .boxed(); +// self +// } +// +// fn expect(mut self, expect: Expect) -> Self { +// self.expect = expect; +// self +// } +// +// fn run(self) -> anyhow::Result<()> { +// let strategy = self.cases.prop_map(|case| { +// let arguments: Arguments = Secp256k1OperationsTestArguments {}.into(); +// let witness: WitnessValues = case.witness.into(); +// +// (arguments, witness) +// }); +// +// self.context +// .engine::< +// Secp256k1OperationsTestProgram, +// Secp256k1OperationsTestArguments, +// Secp256k1OperationsTestWitness, +// >() +// .with_custom_strategy(strategy) +// .with_custom_check(FuzzExecutionCheck::new(self.test_name, self.expect)) +// .run(); +// +// Ok(()) +// } +// } +// +// // 0. ge_to_point +// #[simplex::fuzz] +// fn ge_to_point_matches_parity(context: TestContext) -> anyhow::Result<()> { +// // Sample one on-curve point; whatever parity it has, that's what we expect +// // ge_to_point to produce. +// case_fuzz(GeToPoint, context, "ge_to_point") +// .inject(arb_ge(), |case, ge| { +// let expected_parity = ge.1[31] & 1; // 0 (even y) or 1 (odd y) +// +// case.ge(ge).expect_point((expected_parity, ge.0)) +// }) +// .run() +// } +// +// // 1. point_to_gej +// #[simplex::fuzz] +// fn point_to_gej_roundtrip(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(PointToGej, context, "point_to_gej") +// .inject(arb_ge(), |case, ge| { +// let point = compress(ge); +// case.point(point).expect_point(point) +// }) +// .run() +// } +// +// // 2. fe_sub +// #[simplex::fuzz] +// fn fe_sub_self_is_zero(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(FeSub, context, "fe_sub self is zero") +// .inject(arb_fe(), |case, a| case.uints(a, a).expect_uint([0u8; 32])) +// .run() +// } +// +// #[simplex::fuzz] +// fn fe_sub_matches_reference(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(FeSub, context, "fe_sub") +// .inject((arb_fe(), arb_fe()), |case, (a, b)| { +// let exp = fe_sub_ref(a, b); +// case.uints(a, b).expect_uint(exp) +// }) +// .run() +// } +// +// // 3. scalar_sub +// #[simplex::fuzz] +// fn scalar_sub_matches_reference(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(ScalarSub, context, "scalar_sub") +// .inject((arb_scalar(), arb_scalar()), |case, (a, b)| { +// let exp = scalar_sub_ref(a, b); +// case.uints(a, b).expect_uint(exp) +// }) +// .run() +// } +// +// // 4. gej_sub +// #[simplex::fuzz] +// fn gej_sub_matches_reference(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(GejSub, context, "gej_sub") +// .inject( +// (arb_secret_key(), arb_secret_key()) +// .prop_filter("distinct secp256k1 points", |(p, q)| p != q), +// |case, (p_secret, q_secret)| { +// let secp = Secp256k1::new(); +// let p = PublicKey::from_secret_key(&secp, &p_secret); +// let q = PublicKey::from_secret_key(&secp, &q_secret); +// let diff = p.combine(&q.negate(&secp)).expect("p - q non-infinity"); +// +// case.gejs(pk_to_gej(&p), pk_to_gej(&q)) +// .expect_gej(pk_to_gej(&diff)) +// }, +// ) +// .run() +// } +// +// // 5. fe_eq +// #[simplex::fuzz] +// fn fe_eq_reflexive(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(FeEq, context, "fe_eq_reflexive") +// .inject(arb_fe(), |case, value| case.uints(value, value)) +// .run() +// } +// +// // 6. scalar_eq has only a deterministic case and remains a regular test. +// +// // 7. ge_eq +// #[simplex::fuzz] +// fn ge_eq_rejects_negation(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(GeEq, context, "ge_eq negation") +// .inject(arb_ge(), |case, ge| { +// case.ges(ge, (ge.0, fe_negate_ref(ge.1))) +// }) +// .expect(Expect::AssertFailed) +// .run() +// } +// +// // 8. gej_point_eq +// #[simplex::fuzz] +// fn gej_point_eq_rescaled(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(GejPointEq, context, "gej_point_eq_rescaled") +// .inject((arb_ge(), arb_non_zero_fe()), |case, (ge, lambda)| { +// let lambda_squared = fe_mul_ref(lambda, lambda); +// let lambda_cubed = fe_mul_ref(lambda_squared, lambda); +// let gej: Gej = ( +// ( +// fe_mul_ref(ge.0, lambda_squared), +// fe_mul_ref(ge.1, lambda_cubed), +// ), +// lambda, +// ); +// +// case.gej(gej).point(compress(ge)) +// }) +// .run() +// } +// +// #[simplex::fuzz] +// fn gej_point_eq_rejects_negation(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(GejPointEq, context, "gej_point_eq negation") +// .inject(arb_ge(), |case, ge| { +// let (parity, x) = compress(ge); +// case.gej(ge_to_gej(ge)).point((parity ^ 1, x)) +// }) +// .expect(Expect::AssertFailed) +// .run() +// } +// +// // 9. safe_gej_normalize +// #[simplex::fuzz] +// fn safe_gej_normalize_roundtrip(context: TestContext) -> anyhow::Result<()> { +// case_fuzz(SafeGejNormalize, context, "safe_gej_normalize_roundtrip") +// .inject((arb_ge(), arb_non_zero_fe()), |case, (ge, lambda)| { +// let lambda_squared = fe_mul_ref(lambda, lambda); +// let lambda_cubed = fe_mul_ref(lambda_squared, lambda); +// let gej: Gej = ( +// ( +// fe_mul_ref(ge.0, lambda_squared), +// fe_mul_ref(ge.1, lambda_cubed), +// ), +// lambda, +// ); +// +// case.gej(gej).expect_ge(ge) +// }) +// .run() +// } +// } diff --git a/tests/stdlib/utxo/asserts/asset_id.rs b/tests/stdlib/utxo/asserts/asset_id.rs index 7a4dc6c..7e7c444 100644 --- a/tests/stdlib/utxo/asserts/asset_id.rs +++ b/tests/stdlib/utxo/asserts/asset_id.rs @@ -186,7 +186,7 @@ fn assert_false_explicit_asset_id_for_input(context: simplex::TestContext) -> an case(Explicit) .index(index) .index_type(IndexType::Input) - .expect(context.get_network().policy_asset().into_inner().0) + .expect(context.get_network().policy_asset().to_byte_array()) .expecting(&context, Expect::AssertFailed, txids) } @@ -224,7 +224,7 @@ fn assert_false_explicit_asset_id_for_output(context: simplex::TestContext) -> a case(Explicit) .index(index) .index_type(IndexType::Output) - .expect(context.get_network().policy_asset().into_inner().0) + .expect(context.get_network().policy_asset().to_byte_array()) .expecting(&context, Expect::AssertFailed, txids) } @@ -321,7 +321,7 @@ fn assert_false_explicit_input_asset_id(context: simplex::TestContext) -> anyhow case(ExplicitInput) .index(index) - .expect(context.get_network().policy_asset().into_inner().0) + .expect(context.get_network().policy_asset().to_byte_array()) .expecting(&context, Expect::AssertFailed, txids) } @@ -376,7 +376,7 @@ fn assert_false_explicit_output_asset_id(context: simplex::TestContext) -> anyho case(ExplicitOutput) .index(index) - .expect(context.get_network().policy_asset().into_inner().0) + .expect(context.get_network().policy_asset().to_byte_array()) .expecting(&context, Expect::AssertFailed, txids) } @@ -434,7 +434,7 @@ fn assert_false_explicit_current_asset_id(context: simplex::TestContext) -> anyh case(CurrentExplicit) .index(index) - .expect(context.get_network().policy_asset().into_inner().0) + .expect(context.get_network().policy_asset().to_byte_array()) .expecting(&context, Expect::AssertFailed, txids) } diff --git a/tests/stdlib/utxo/asserts/asset_id_with_amount.rs b/tests/stdlib/utxo/asserts/asset_id_with_amount.rs index d681124..316c42f 100644 --- a/tests/stdlib/utxo/asserts/asset_id_with_amount.rs +++ b/tests/stdlib/utxo/asserts/asset_id_with_amount.rs @@ -210,7 +210,7 @@ fn assert_false_explicit_asset_id_with_amount_for_input( .index(index) .index_type(IndexType::Input) .expect( - context.get_network().policy_asset().into_inner().0, + context.get_network().policy_asset().to_byte_array(), real_amount, ) .expecting(&context, Expect::AssertFailed, txids) @@ -281,7 +281,7 @@ fn assert_false_explicit_asset_id_with_amount_for_output( .index(index) .index_type(IndexType::Output) .expect( - context.get_network().policy_asset().into_inner().0, + context.get_network().policy_asset().to_byte_array(), real_amount, ) .expecting(&context, Expect::AssertFailed, txids) @@ -432,7 +432,7 @@ fn assert_false_explicit_input_asset_id_with_amount( case(ExplicitInput) .index(index) .expect( - context.get_network().policy_asset().into_inner().0, + context.get_network().policy_asset().to_byte_array(), real_amount, ) .expecting(&context, Expect::AssertFailed, txids) @@ -533,7 +533,7 @@ fn assert_false_explicit_output_asset_id_with_amount( case(ExplicitOutput) .index(index) .expect( - context.get_network().policy_asset().into_inner().0, + context.get_network().policy_asset().to_byte_array(), real_amount, ) .expecting(&context, Expect::AssertFailed, txids) @@ -631,7 +631,7 @@ fn assert_false_explicit_current_asset_id_with_amount( case(CurrentExplicit) .index(index) .expect( - context.get_network().policy_asset().into_inner().0, + context.get_network().policy_asset().to_byte_array(), real_amount, ) .expecting(&context, Expect::AssertFailed, txids)