From b44d7b9de4d4db3d57c2b33bb49319e4f19d92bd Mon Sep 17 00:00:00 2001 From: Andrew Kirillov <20803092+akirillo@users.noreply.github.com> Date: Wed, 30 Aug 2023 14:17:24 -0700 Subject: [PATCH] tests: darkpool: test VALID_WALLET_UPDATE statement signatures --- .gitignore | 1 + Cargo.lock | 378 +++++++++++++++++++---------- src/darkpool.cairo | 19 +- src/darkpool/types.cairo | 7 + src/utils/crypto.cairo | 3 +- tests/Cargo.toml | 9 +- tests/src/darkpool/utils.rs | 6 +- tests/src/statement_serde/utils.rs | 5 +- tests/src/utils.rs | 47 +++- tests/tests/darkpool.rs | 68 ++++-- 10 files changed, 368 insertions(+), 175 deletions(-) diff --git a/.gitignore b/.gitignore index 15f417c6..355d0860 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.DS_Store /cairo_project.toml /.vscode +/.gitattributes diff --git a/Cargo.lock b/Cargo.lock index a5ac5cd7..6a8f41fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" dependencies = [ "memchr", ] @@ -98,16 +98,15 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] @@ -137,9 +136,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" dependencies = [ "anstyle", "windows-sys 0.48.0", @@ -373,9 +372,9 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "async-compression" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b74f44609f0f91493e3082d3734d98497e094777144380ea4db9f9905dd5b6" +checksum = "d495b6dc0184693324491a5ac05f559acc97bf937ab31d7a1c33dd0016be6d2b" dependencies = [ "brotli", "flate2", @@ -456,9 +455,15 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "beef" @@ -652,12 +657,12 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.6.0" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" +checksum = "4c2f7349907b712260e64b0afe2f84692af14a454be26187d9df565c7f69266a" dependencies = [ "memchr", - "regex-automata 0.3.6", + "regex-automata 0.3.7", "serde", ] @@ -713,9 +718,9 @@ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "bytesize" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5" +checksum = "a3e368af43e418a04d52505cf3dbc23dda4e3407ae2fa99fd0e4f308ce546acc" [[package]] name = "cairo-felt" @@ -1178,7 +1183,7 @@ dependencies = [ "parity-scale-codec", "schemars", "serde", - "time 0.3.27", + "time 0.3.28", ] [[package]] @@ -1266,9 +1271,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "f56b4c72906975ca04becb8a30e102dfecddd0c06181e3e95ddc444be28881f8" dependencies = [ "android-tzdata", "iana-time-zone", @@ -1277,7 +1282,7 @@ dependencies = [ "serde", "time 0.1.45", "wasm-bindgen", - "winapi", + "windows-targets 0.48.5", ] [[package]] @@ -1293,7 +1298,7 @@ dependencies = [ [[package]] name = "circuit-macros" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "itertools 0.10.5", "mpc-bulletproof", @@ -1305,20 +1310,22 @@ dependencies = [ [[package]] name = "circuit-types" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ + "ark-ec", "ark-ff", "async-trait", "bigdecimal", "circuit-macros", "constants", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "futures", "itertools 0.10.5", "lazy_static", "mpc-bulletproof", "mpc-stark", "num-bigint", + "num-integer", "rand 0.8.5", "renegade-crypto", "serde", @@ -1330,7 +1337,7 @@ dependencies = [ [[package]] name = "circuits" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "ark-crypto-primitives", "ark-ff", @@ -1374,12 +1381,12 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.24" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb690e81c7840c0d7aade59f242ea3b41b9bc27bcd5997890e7702ae4b32e487" +checksum = "7c8d502cbaec4595d2e7d5f61e318f05417bd2b66fdc3809498f0d3fdf0bea27" dependencies = [ "clap_builder", - "clap_derive 4.3.12", + "clap_derive 4.4.0", "once_cell", ] @@ -1389,19 +1396,19 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1eef05769009513df2eb1c3b4613e7fad873a14c600ff025b08f250f59fee7de" dependencies = [ - "clap 4.3.24", + "clap 4.4.1", "log", ] [[package]] name = "clap_builder" -version = "4.3.24" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ed2e96bc16d8d740f6f48d663eddf4b8a0983e79210fd55479b7bcd0a69860e" +checksum = "5891c7bc0edb3e1c2204fc5e94009affabeb1821c9e5fdc3959536c5c0bb984d" dependencies = [ "anstream", "anstyle", - "clap_lex 0.5.0", + "clap_lex 0.5.1", "strsim", ] @@ -1420,9 +1427,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.3.12" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +checksum = "c9fd1a5729c4548118d7d70ff234a44868d00489a4b6597b0b020918a0e91a1a" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -1441,9 +1448,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "clru" @@ -1471,7 +1478,7 @@ dependencies = [ [[package]] name = "common" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "base64 0.13.1", "bimap", @@ -1479,7 +1486,7 @@ dependencies = [ "circuits", "constants", "crossbeam", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "indexmap 1.9.3", "itertools 0.10.5", "lazy_static", @@ -1500,12 +1507,12 @@ dependencies = [ [[package]] name = "config" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "base64 0.13.1", "clap 3.2.25", "common", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "libp2p", "rand_core 0.5.1", "serde", @@ -1532,10 +1539,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" +[[package]] +name = "const-oid" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" + [[package]] name = "constants" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" [[package]] name = "convert_case" @@ -1773,6 +1786,34 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f711ade317dd348950a9910f81c5947e3d8907ebd2b83f76203ff1807e6a2bc2" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.29", +] + [[package]] name = "darling" version = "0.14.4" @@ -1885,6 +1926,16 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.8" @@ -2173,7 +2224,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ "serde", - "signature", + "signature 1.6.4", +] + +[[package]] +name = "ed25519" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" +dependencies = [ + "pkcs8", + "signature 2.1.0", ] [[package]] @@ -2182,8 +2243,8 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek", - "ed25519", + "curve25519-dalek 3.2.0", + "ed25519 1.5.3", "rand 0.7.3", "serde", "serde_bytes", @@ -2191,6 +2252,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ed25519-dalek" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +dependencies = [ + "curve25519-dalek 4.0.0", + "ed25519 2.2.2", + "rand_core 0.6.4", + "serde", + "sha2 0.10.7", + "zeroize", +] + [[package]] name = "either" version = "1.9.0" @@ -2255,9 +2330,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", @@ -2326,7 +2401,7 @@ dependencies = [ [[package]] name = "external-api" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "circuit-types", "common", @@ -2364,6 +2439,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +[[package]] +name = "fiat-crypto" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" + [[package]] name = "filetime" version = "0.2.22" @@ -2822,7 +2903,7 @@ dependencies = [ "bstr", "itoa", "thiserror", - "time 0.3.27", + "time 0.3.28", ] [[package]] @@ -3340,9 +3421,9 @@ dependencies = [ [[package]] name = "good_lp" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4286919dfa7d06a1f3397e04381575043e87dd48e43548396874a5547b9b3913" +checksum = "fa7f3b0e0de4e671b6ffc1274b153a9394cb58bf04ee67505b0cb9915513115f" dependencies = [ "fnv", "minilp", @@ -3351,11 +3432,11 @@ dependencies = [ [[package]] name = "gossip-api" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "circuit-types", "common", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "libp2p", "serde", "serde_json", @@ -3559,7 +3640,7 @@ dependencies = [ "futures-util", "http", "hyper", - "rustls 0.21.6", + "rustls 0.21.7", "tokio", "tokio-rustls", ] @@ -3847,7 +3928,7 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "job-types" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "circuit-types", "circuits", @@ -4080,7 +4161,7 @@ dependencies = [ "petgraph", "pico-args", "regex", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", "string_cache", "term", "tiny-keccak", @@ -4113,9 +4194,9 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libmimalloc-sys" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ac0e912c8ef1b735e92369695618dc5b1819f5a7bf3f167301a3ba1cea515e" +checksum = "25d058a81af0d1c22d7a1c948576bee6d673f7af3c0f35564abd6c81122f513d" dependencies = [ "cc", "libc", @@ -4196,12 +4277,12 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2d584751cecb2aabaa56106be6be91338a60a0f4e420cf2af639204f596fc1" +checksum = "276bb57e7af15d8f100d3c11cbdd32c6752b7eef4ba7a18ecf464972c07abcce" dependencies = [ "bs58", - "ed25519-dalek", + "ed25519-dalek 2.0.0", "log", "multiaddr", "multihash", @@ -4313,9 +4394,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "5486aed0026218e61b8a01d5fbd5a0a134649abb71a0e53b7bc088529dced86e" [[package]] name = "memmap2" @@ -4372,9 +4453,9 @@ dependencies = [ [[package]] name = "mimalloc" -version = "0.1.37" +version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e2894987a3459f3ffb755608bd82188f8ed00d0ae077f1edea29c068d639d98" +checksum = "972e5f23f6716f62665760b0f4cbf592576a80c7b879ba9beaafc0e558894127" dependencies = [ "libmimalloc-sys", ] @@ -4466,9 +4547,9 @@ dependencies = [ [[package]] name = "mpc-stark" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e73ac4d52a6e676d1a27ee72ab463caf87c2b6df28695efc62c6b39dade6855a" +checksum = "f84d6e9643f4e3917c59649b653969e5eee7bf372a80587bfdeead8eec90cb85" dependencies = [ "ark-ec", "ark-ff", @@ -4485,7 +4566,7 @@ dependencies = [ "rand 0.8.5", "rcgen", "rustc-hash", - "rustls 0.20.8", + "rustls 0.20.9", "serde", "serde_json", "sha3 0.10.8", @@ -4764,11 +4845,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.56" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", "foreign-types", "libc", @@ -4796,9 +4877,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.91" +version = "0.9.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" +checksum = "db7e971c2c2bba161b2d2fdf37080177eff520b3bc044787c7f1f5f9e78d869b" dependencies = [ "cc", "libc", @@ -4845,9 +4926,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parity-scale-codec" -version = "3.6.4" +version = "3.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8e946cc0cc711189c0b0249fb8b599cbeeab9784d83c415719368bb8d4ac64" +checksum = "0dec8a8073036902368c2cdc0387e85ff9a37054d7e7c98e592145e0c92cd4fb" dependencies = [ "arrayvec", "bitvec", @@ -4859,9 +4940,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.4" +version = "3.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a296c3079b5fefbc499e1de58dc26c09b1b9a5952d26694ee89f04a43ebbb3e" +checksum = "312270ee71e1cd70289dacf597cab7b207aa107d2f28191c2ae45b2ece18a260" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5080,9 +5161,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -5090,17 +5171,33 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "platforms" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" + [[package]] name = "portable-atomic" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f32154ba0af3a075eefa1eda8bb414ee928f62303a54ea85b8d6638ff1a6ee9e" +checksum = "31114a898e107c51bb1609ffaf55a0e011cf6a4d7f1170d0015a165082c0338b" [[package]] name = "ppv-lite86" @@ -5237,7 +5334,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls 0.20.8", + "rustls 0.20.9", "thiserror", "tokio", "tracing", @@ -5254,7 +5351,7 @@ dependencies = [ "rand 0.8.5", "ring", "rustc-hash", - "rustls 0.20.8", + "rustls 0.20.9", "rustls-native-certs", "slab", "thiserror", @@ -5398,7 +5495,7 @@ checksum = "6413f3de1edee53342e6138e75b56d32e7bc6e332b3bd62d497b1929d4cfbcdd" dependencies = [ "pem", "ring", - "time 0.3.27", + "time 0.3.28", "yasna", ] @@ -5433,14 +5530,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.6", - "regex-syntax 0.7.4", + "regex-automata 0.3.7", + "regex-syntax 0.7.5", ] [[package]] @@ -5454,13 +5551,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] @@ -5483,9 +5580,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "relative-path" @@ -5496,7 +5593,7 @@ checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" [[package]] name = "renegade-crypto" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "ark-crypto-primitives", "ark-ff", @@ -5511,15 +5608,16 @@ dependencies = [ "serde", "serde_json", "starknet", + "tiny-keccak", ] [[package]] name = "reqwest" -version = "0.11.19" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b9b67e2ca7dd9e9f9285b759de30ff538aab981abaaf7bc9bd90b84a0126c3" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "bytes", "encoding_rs", "futures-core", @@ -5538,7 +5636,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.6", + "rustls 0.21.7", "rustls-pemfile", "serde", "serde_json", @@ -5619,9 +5717,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.8" +version = "0.38.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +checksum = "ed6248e1caa625eb708e266e06159f135e8c26f2bb7ceb72dc4b2766d0340964" dependencies = [ "bitflags 2.4.0", "errno", @@ -5632,9 +5730,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" dependencies = [ "log", "ring", @@ -5644,9 +5742,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", @@ -5672,7 +5770,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", ] [[package]] @@ -5794,7 +5892,7 @@ dependencies = [ "cairo-lang-starknet", "cairo-lang-utils", "camino", - "clap 4.3.24", + "clap 4.4.1", "clap-verbosity-flag", "console", "create-output-dir", @@ -5853,7 +5951,7 @@ version = "1.6.0" source = "git+https://github.com/software-mansion/scarb?rev=c07fa61#c07fa61553985f045286166d0235e55492694159" dependencies = [ "camino", - "clap 4.3.24", + "clap 4.4.1", "derive_builder", "semver", "serde", @@ -5872,9 +5970,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.12" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +checksum = "763f8cd0d4c71ed8389c90cb8100cba87e763bd01a8e614d4f0af97bcd50a161" dependencies = [ "dyn-clone", "indexmap 1.9.3", @@ -5885,9 +5983,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.12" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +checksum = "ec0f696e21e10fa546b7ffb1c9672c6de8fbc7a81acf59524386d8639bf12737" dependencies = [ "proc-macro2", "quote", @@ -5957,9 +6055,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.185" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] @@ -5994,9 +6092,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.185" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc59dfdcbad1437773485e0367fea4b090a2e0a16d9ffc46af47764536a298ec" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -6070,7 +6168,7 @@ dependencies = [ "serde", "serde_json", "serde_with_macros", - "time 0.3.27", + "time 0.3.28", ] [[package]] @@ -6196,6 +6294,12 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +[[package]] +name = "signature" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" + [[package]] name = "siphasher" version = "0.3.11" @@ -6274,6 +6378,16 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spki" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "sprs" version = "0.7.1" @@ -6317,7 +6431,7 @@ dependencies = [ [[package]] name = "starknet-client" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "ark-ff", "circuit-types", @@ -6325,6 +6439,7 @@ dependencies = [ "common", "constants", "itertools 0.10.5", + "json", "lazy_static", "mpc-bulletproof", "mpc-stark", @@ -6360,7 +6475,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91f89c79b641618de8aa9668d74c6b6634659ceca311c6318a35c025f9d4d969" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "flate2", "hex", "serde", @@ -6523,7 +6638,7 @@ dependencies = [ name = "starknet_scripts" version = "0.1.0" dependencies = [ - "clap 4.3.24", + "clap 4.4.1", "eyre", "json", "serde_json", @@ -6537,7 +6652,7 @@ dependencies = [ [[package]] name = "state" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "base64 0.13.1", "circuit-types", @@ -6655,7 +6770,7 @@ dependencies = [ [[package]] name = "system-bus" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "bus", "common", @@ -6722,6 +6837,7 @@ dependencies = [ "dojo-test-utils", "eyre", "katana-core", + "lazy_static", "merlin", "mpc-bulletproof", "mpc-stark", @@ -6807,9 +6923,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb39ee79a6d8de55f48f2293a830e040392f1c5f16e336bdd1788cd0aadce07" +checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" dependencies = [ "deranged", "itoa", @@ -6828,9 +6944,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733d258752e9303d392b94b75230d07b0b9c489350c69b851fc6c065fde3e8f9" +checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" dependencies = [ "time-core", ] @@ -6905,7 +7021,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.6", + "rustls 0.21.7", "tokio", ] @@ -7006,7 +7122,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55ae70283aba8d2a8b411c695c437fe25b8b5e44e23e780662002fc72fb47a82" dependencies = [ "async-compression", - "base64 0.21.2", + "base64 0.21.3", "bitflags 2.4.0", "bytes", "futures-core", @@ -7292,9 +7408,9 @@ dependencies = [ [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", @@ -7311,7 +7427,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "util" version = "0.1.0" -source = "git+https://github.com/renegade-fi/renegade.git#c3ee33d4cf859664833c79916c9035dd98539005" +source = "git+https://github.com/renegade-fi/renegade.git?branch=stark-curve-ecdsa#6ac39e780935086746c600b055cd13cc5fddca29" dependencies = [ "chrono", "env_logger 0.9.3", @@ -7694,9 +7810,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.14" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" dependencies = [ "memchr", ] @@ -7747,7 +7863,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" dependencies = [ - "time 0.3.27", + "time 0.3.28", ] [[package]] diff --git a/src/darkpool.cairo b/src/darkpool.cairo index d8a51b7d..630a0781 100644 --- a/src/darkpool.cairo +++ b/src/darkpool.cairo @@ -15,7 +15,7 @@ use renegade_contracts::{ use types::{ ExternalTransfer, MatchPayload, NewWalletCallbackElems, UpdateWalletCallbackElems, - ProcessMatchCallbackElems, Circuit, + ProcessMatchCallbackElems, Circuit, Signature, }; use statements::{ValidWalletCreateStatement, ValidWalletUpdateStatement, ValidSettleStatement}; @@ -71,7 +71,7 @@ trait IDarkpool { ref self: TContractState, wallet_blinder_share: Scalar, statement: ValidWalletUpdateStatement, - statement_signature: (Scalar, Scalar), + statement_signature: Signature, witness_commitments: Array, proof: Proof, verification_job_id: felt252, @@ -128,7 +128,7 @@ mod Darkpool { use super::{ types::{ ExternalTransfer, MatchPayload, NewWalletCallbackElems, UpdateWalletCallbackElems, - ProcessMatchCallbackElems, Circuit, PublicSigningKeyTrait, + ProcessMatchCallbackElems, Circuit, PublicSigningKeyTrait, Signature, }, statements::{ValidWalletCreateStatement, ValidWalletUpdateStatement, ValidSettleStatement} }; @@ -563,7 +563,7 @@ mod Darkpool { ref self: ContractState, wallet_blinder_share: Scalar, statement: ValidWalletUpdateStatement, - statement_signature: (Scalar, Scalar), + statement_signature: Signature, mut witness_commitments: Array, proof: Proof, verification_job_id: felt252, @@ -575,12 +575,17 @@ mod Darkpool { 'invalid statement merkle root' ); - // Assert that statement signature is valid + // Assert that statement signature is valid. + // This check implicitly authorizes a key rotation in the update wallet, + // as the `old_pk_root` in the statement is the root key of the pre-update wallet + // now signing a new wallet with a new root key. let statement_hash = hash_statement(@statement); - let (r, s) = statement_signature; assert( check_ecdsa_signature( - statement_hash.into(), statement.old_pk_root.get_x(), r.into(), s.into() + statement_hash.into(), + statement.old_pk_root.get_x(), + statement_signature.r.into(), + statement_signature.s.into() ), 'invalid statement signature' ); diff --git a/src/darkpool/types.cairo b/src/darkpool/types.cairo index aab083f4..467c6a5b 100644 --- a/src/darkpool/types.cairo +++ b/src/darkpool/types.cairo @@ -86,6 +86,13 @@ impl PublicSigningKeyImpl of PublicSigningKeyTrait { } } +/// Represents an ECDSA signature over the STARK curve +#[derive(Drop, Serde, Copy, PartialEq)] +struct Signature { + r: Scalar, + s: Scalar, +} + // -------------------------- // | CALLBACK ELEMENT TYPES | // -------------------------- diff --git a/src/utils/crypto.cairo b/src/utils/crypto.cairo index 1640c75e..402cd7d3 100644 --- a/src/utils/crypto.cairo +++ b/src/utils/crypto.cairo @@ -79,7 +79,8 @@ fn append_statement_commitments>(statement: @T) -> Scalar { let mut statement_scalars = statement.to_scalars(); diff --git a/tests/Cargo.toml b/tests/Cargo.toml index d0929245..a028da4c 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -8,6 +8,7 @@ starknet_scripts = { path = "../starknet_scripts" } # TODO: Use starknet-client when it's ready once_cell = "1.17.1" +lazy_static = "1.4.0" eyre = "0.6.8" tracing = { version = "0.1", features = ["log"] } @@ -29,7 +30,7 @@ dojo-test-utils = { git = "https://github.com/dojoengine/dojo.git", rev = "954db mpc-stark = { workspace = true } mpc-bulletproof = { git = "https://github.com/renegade-fi/mpc-bulletproof.git", features = ["integration_test"] } merlin = { git = "https://github.com/renegade-fi/merlin.git" } -renegade-crypto = { git = "https://github.com/renegade-fi/renegade.git" } -circuits = { git = "https://github.com/renegade-fi/renegade.git", features = ["test_helpers"] } -circuit-types = { git = "https://github.com/renegade-fi/renegade.git" } -starknet-client = { git = "https://github.com/renegade-fi/renegade.git" } +renegade-crypto = { git = "https://github.com/renegade-fi/renegade.git", branch = "stark-curve-ecdsa" } +circuits = { git = "https://github.com/renegade-fi/renegade.git", branch = "stark-curve-ecdsa", features = ["test_helpers"] } +circuit-types = { git = "https://github.com/renegade-fi/renegade.git", branch = "stark-curve-ecdsa" } +starknet-client = { git = "https://github.com/renegade-fi/renegade.git", branch = "stark-curve-ecdsa" } diff --git a/tests/src/darkpool/utils.rs b/tests/src/darkpool/utils.rs index bcd6a46c..568a39d9 100644 --- a/tests/src/darkpool/utils.rs +++ b/tests/src/darkpool/utils.rs @@ -18,6 +18,7 @@ use eyre::{eyre, Result}; use mpc_stark::algebra::scalar::Scalar; use once_cell::sync::OnceCell; use rand::thread_rng; +use renegade_crypto::ecdsa::sign_scalar_message; use starknet::{ accounts::Account, core::{ @@ -46,7 +47,7 @@ use crate::{ CalldataSerializable, Circuit, DummyValidCommitments, DummyValidMatchMpc, DummyValidReblind, DummyValidSettle, DummyValidWalletCreate, DummyValidWalletUpdate, MatchPayload, NewWalletArgs, ProcessMatchArgs, TestConfig, UpdateWalletArgs, - ARTIFACTS_PATH_ENV_VAR, DUMMY_VALUE, + ARTIFACTS_PATH_ENV_VAR, DUMMY_VALUE, SK_ROOT, }, }; @@ -675,13 +676,14 @@ pub fn get_dummy_update_wallet_args( >(old_wallet, new_wallet, external_transfer); statement.merkle_root = merkle_root; + let statement_signature = sign_scalar_message(&statement.to_scalars(), &SK_ROOT); let (_, proof) = singleprover_prove::((), statement.clone())?; - let verification_job_id = random_felt(); Ok(UpdateWalletArgs { wallet_blinder_share, statement, + statement_signature, proof, witness_commitments: vec![], verification_job_id, diff --git a/tests/src/statement_serde/utils.rs b/tests/src/statement_serde/utils.rs index eb78fb44..4708ed9a 100644 --- a/tests/src/statement_serde/utils.rs +++ b/tests/src/statement_serde/utils.rs @@ -1,5 +1,5 @@ use circuit_types::{ - keychain::{PublicSigningKey, ROOT_KEY_WORDS}, + keychain::{PublicSigningKey, SCALAR_WORDS_PER_FELT}, traits::BaseType, transfers::ExternalTransfer, wallet::WalletShare, @@ -356,6 +356,7 @@ fn dummy_public_wallet_shares() -> WalletShare PublicSigningKey { PublicSigningKey { - key_words: [Scalar::from(DUMMY_VALUE); ROOT_KEY_WORDS], + x: [Scalar::from(DUMMY_VALUE); SCALAR_WORDS_PER_FELT], + y: [Scalar::from(DUMMY_VALUE); SCALAR_WORDS_PER_FELT], } } diff --git a/tests/src/utils.rs b/tests/src/utils.rs index b786ae6e..6e8eb992 100644 --- a/tests/src/utils.rs +++ b/tests/src/utils.rs @@ -1,8 +1,10 @@ use ark_ff::{BigInteger, PrimeField}; use byteorder::{BigEndian, ReadBytesExt}; use circuit_types::{ + keychain::{PublicKeyChain, SecretIdentificationKey, SecretSigningKey}, traits::{BaseType, CircuitBaseType, SingleProverCircuit}, transfers::{ExternalTransfer, ExternalTransferDirection}, + wallet::Wallet, }; use circuits::zk_circuits::{ test_helpers::{SizedWallet, INITIAL_WALLET, MAX_BALANCES, MAX_FEES, MAX_ORDERS}, @@ -37,6 +39,7 @@ use katana_core::{ constants::DEFAULT_INVOKE_MAX_STEPS, db::serde::state::SerializableState, sequencer::SequencerConfig, }; +use lazy_static::lazy_static; use merlin::HashChainTranscript; use mpc_bulletproof::{ r1cs::{ @@ -49,6 +52,7 @@ use mpc_bulletproof::{ use mpc_stark::algebra::{scalar::Scalar, stark_curve::StarkPoint}; use num_bigint::{BigUint, RandBigInt}; use rand::thread_rng; +use renegade_crypto::{ecdsa::Signature, hash::compute_poseidon_hash}; use starknet::{ accounts::{Account, Call, ConnectedAccount}, core::{ @@ -117,6 +121,21 @@ static TRANSCRIPT_STATE_DUMPED: Mutex = Mutex::const_new(false); static POSEIDON_STATE_DUMPED: Mutex = Mutex::const_new(false); static STATEMENT_SERDE_STATE_DUMPED: Mutex = Mutex::const_new(false); +lazy_static! { + pub static ref SK_ROOT: SecretSigningKey = Scalar::from(DUMMY_VALUE); + pub static ref SK_MATCH: SecretIdentificationKey = SecretIdentificationKey { + key: Scalar::from(DUMMY_VALUE) + }; + pub static ref PUBLIC_KEYS: PublicKeyChain = PublicKeyChain { + pk_root: (&(StarkPoint::generator() * *SK_ROOT)).into(), + pk_match: compute_poseidon_hash(&[SK_MATCH.key]).into() + }; + pub static ref DUMMY_WALLET: SizedWallet = Wallet { + keys: PUBLIC_KEYS.clone(), + ..INITIAL_WALLET.clone() + }; +} + /// Label with which to seed the Fiat-Shamir transcript pub const TRANSCRIPT_SEED: &str = "merlin seed"; @@ -505,6 +524,7 @@ pub struct NewWalletArgs { pub struct UpdateWalletArgs { pub wallet_blinder_share: Scalar, pub statement: SizedValidWalletUpdateStatement, + pub statement_signature: Signature, pub proof: R1CSProof, pub witness_commitments: Vec, pub verification_job_id: FieldElement, @@ -547,6 +567,16 @@ impl CalldataSerializable for Vec { } } +impl CalldataSerializable for [T; N] { + fn to_calldata(&self) -> Vec { + self.len() + .to_calldata() + .into_iter() + .chain(self.iter().flat_map(|t| t.to_calldata())) + .collect() + } +} + // `(usize, Scalar)` represents an entry in a `SparseWeightRow` impl CalldataSerializable for (usize, Scalar) { fn to_calldata(&self) -> Vec { @@ -685,7 +715,8 @@ where .chain(self.new_public_shares.to_scalars().to_calldata()) .chain(self.merkle_root.to_calldata()) .chain(self.external_transfer.to_calldata()) - .chain(self.old_pk_root.to_scalars().to_calldata()) + .chain(self.old_pk_root.x.to_calldata()) + .chain(self.old_pk_root.y.to_calldata()) .chain(self.timestamp.to_calldata()) .collect() } @@ -795,6 +826,8 @@ impl CalldataSerializable for UpdateWalletArgs { .to_calldata() .into_iter() .chain(self.statement.to_calldata()) + .chain(self.statement_signature.r.to_calldata()) + .chain(self.statement_signature.s.to_calldata()) .chain(self.witness_commitments.to_calldata()) .chain(self.proof.to_calldata()) .chain(self.verification_job_id.to_calldata()) @@ -910,13 +943,13 @@ pub fn get_dummy_statement_scalars(circuit: Circuit) -> Vec { MAX_FEES, TEST_MERKLE_HEIGHT, >( - INITIAL_WALLET.clone(), - INITIAL_WALLET.clone(), + DUMMY_WALLET.clone(), + DUMMY_WALLET.clone(), ExternalTransfer::default(), ) .1 .to_scalars(), - Circuit::ValidCommitments(_) => create_witness_and_statement(&INITIAL_WALLET.clone()) + Circuit::ValidCommitments(_) => create_witness_and_statement(&DUMMY_WALLET.clone()) .1 .to_scalars(), Circuit::ValidReblind(_) => construct_valid_reblind_witness_statement::< @@ -924,13 +957,13 @@ pub fn get_dummy_statement_scalars(circuit: Circuit) -> Vec { MAX_ORDERS, MAX_FEES, TEST_MERKLE_HEIGHT, - >(&INITIAL_WALLET.clone()) + >(&DUMMY_WALLET.clone()) .1 .to_scalars(), Circuit::ValidMatchMpc(_) => vec![], Circuit::ValidSettle(_) => create_witness_statement( - INITIAL_WALLET.clone(), - INITIAL_WALLET.clone(), + DUMMY_WALLET.clone(), + DUMMY_WALLET.clone(), MATCH_RES.clone(), ) .1 diff --git a/tests/tests/darkpool.rs b/tests/tests/darkpool.rs index 2df3b027..adf705e4 100644 --- a/tests/tests/darkpool.rs +++ b/tests/tests/darkpool.rs @@ -4,10 +4,7 @@ use circuit_types::{ order::Order, transfers::{ExternalTransfer, ExternalTransferDirection}, }; -use circuits::zk_circuits::{ - test_helpers::INITIAL_WALLET, - valid_settle::test_helpers::{MATCH_RES, WALLET1, WALLET2}, -}; +use circuits::zk_circuits::valid_settle::test_helpers::{MATCH_RES, WALLET1, WALLET2}; use eyre::Result; use mpc_stark::algebra::scalar::Scalar; use num_bigint::BigUint; @@ -22,7 +19,10 @@ use tests::{ upgrade, DARKPOOL_ADDRESS, DARKPOOL_CLASS_HASH, ERC20_ADDRESS, INIT_BALANCE, TRANSFER_AMOUNT, UPGRADE_TARGET_CLASS_HASH, }, - utils::{assert_roots_equal, get_root, global_teardown, insert_scalar_to_ark_merkle_tree}, + utils::{ + assert_roots_equal, get_root, global_teardown, insert_scalar_to_ark_merkle_tree, + DUMMY_WALLET, + }, }; // --------------------- @@ -75,8 +75,8 @@ async fn test_update_wallet_root() -> Result<()> { let mut ark_merkle_tree = ark_merkle_tree.unwrap(); let initial_root = get_root(&account, *DARKPOOL_ADDRESS.get().unwrap()).await?; - let old_wallet = INITIAL_WALLET.clone(); - let mut new_wallet = INITIAL_WALLET.clone(); + let old_wallet = DUMMY_WALLET.clone(); + let mut new_wallet = DUMMY_WALLET.clone(); new_wallet.orders[0] = Order::default(); let external_transfer = ExternalTransfer::default(); let args = @@ -101,8 +101,8 @@ async fn test_update_wallet_invalid_statement_root() -> Result<()> { let (sequencer, _) = setup_darkpool_test(false /* init_arkworks_tree */).await?; let account = sequencer.account(); - let old_wallet = INITIAL_WALLET.clone(); - let new_wallet = INITIAL_WALLET.clone(); + let old_wallet = DUMMY_WALLET.clone(); + let new_wallet = DUMMY_WALLET.clone(); let external_transfer = ExternalTransfer::default(); let args = get_dummy_update_wallet_args( old_wallet, @@ -204,8 +204,8 @@ async fn test_update_wallet_last_modified() -> Result<()> { let account = sequencer.account(); let initial_root = get_root(&account, *DARKPOOL_ADDRESS.get().unwrap()).await?; - let old_wallet = INITIAL_WALLET.clone(); - let mut new_wallet = INITIAL_WALLET.clone(); + let old_wallet = DUMMY_WALLET.clone(); + let mut new_wallet = DUMMY_WALLET.clone(); new_wallet.orders[0] = Order::default(); let external_transfer = ExternalTransfer::default(); let args = @@ -261,8 +261,8 @@ async fn test_update_wallet_nullifiers() -> Result<()> { let account = sequencer.account(); let initial_root = get_root(&account, *DARKPOOL_ADDRESS.get().unwrap()).await?; - let old_wallet = INITIAL_WALLET.clone(); - let mut new_wallet = INITIAL_WALLET.clone(); + let old_wallet = DUMMY_WALLET.clone(); + let mut new_wallet = DUMMY_WALLET.clone(); new_wallet.orders[0] = Order::default(); let external_transfer = ExternalTransfer::default(); let args = @@ -343,8 +343,8 @@ async fn test_double_update_wallet() -> Result<()> { let account = sequencer.account(); let initial_root = get_root(&account, *DARKPOOL_ADDRESS.get().unwrap()).await?; - let old_wallet = INITIAL_WALLET.clone(); - let new_wallet = INITIAL_WALLET.clone(); + let old_wallet = DUMMY_WALLET.clone(); + let new_wallet = DUMMY_WALLET.clone(); let external_transfer = ExternalTransfer::default(); let args = get_dummy_update_wallet_args(old_wallet, new_wallet, external_transfer, initial_root)?; @@ -393,8 +393,8 @@ async fn test_update_wallet_deposit() -> Result<()> { // Adapted from `test_external_transfer__valid_deposit_new_balance` in https://github.com/renegade-fi/renegade/blob/main/circuits/src/zk_circuits/valid_wallet_update.rs - let mut old_wallet = INITIAL_WALLET.clone(); - let mut new_wallet = INITIAL_WALLET.clone(); + let mut old_wallet = DUMMY_WALLET.clone(); + let mut new_wallet = DUMMY_WALLET.clone(); // Remove the first balance from the old wallet old_wallet.balances[0] = Balance::default(); @@ -444,8 +444,8 @@ async fn test_update_wallet_withdrawal() -> Result<()> { // Adapted from `test_external_transfer__valid_withdrawal` in https://github.com/renegade-fi/renegade/blob/main/circuits/src/zk_circuits/valid_wallet_update.rs - let mut old_wallet = INITIAL_WALLET.clone(); - let mut new_wallet = INITIAL_WALLET.clone(); + let mut old_wallet = DUMMY_WALLET.clone(); + let mut new_wallet = DUMMY_WALLET.clone(); // Set the first old wallet balance to reflect the initial supply of dummy ERC20 tokens old_wallet.balances[0].mint = @@ -483,14 +483,18 @@ async fn test_update_wallet_withdrawal() -> Result<()> { Ok(()) } +// -------------- +// | MISC TESTS | +// -------------- + #[tokio::test] async fn test_upgrade_darkpool_storage() -> Result<()> { let (sequencer, _) = setup_darkpool_test(false /* init_arkworks_tree */).await?; let account = sequencer.account(); let initial_root = get_root(&account, *DARKPOOL_ADDRESS.get().unwrap()).await?; - let old_wallet = INITIAL_WALLET.clone(); - let mut new_wallet = INITIAL_WALLET.clone(); + let old_wallet = DUMMY_WALLET.clone(); + let mut new_wallet = DUMMY_WALLET.clone(); new_wallet.orders[0] = Order::default(); let external_transfer = ExternalTransfer::default(); let args = @@ -518,3 +522,25 @@ async fn test_upgrade_darkpool_storage() -> Result<()> { Ok(()) } + +#[tokio::test] +async fn test_update_wallet_invalid_signature() -> Result<()> { + let (sequencer, _) = setup_darkpool_test(false /* init_arkworks_tree */).await?; + let account = sequencer.account(); + + let initial_root = get_root(&account, *DARKPOOL_ADDRESS.get().unwrap()).await?; + let old_wallet = DUMMY_WALLET.clone(); + let new_wallet = DUMMY_WALLET.clone(); + let external_transfer = ExternalTransfer::default(); + let mut args = + get_dummy_update_wallet_args(old_wallet, new_wallet, external_transfer, initial_root)?; + + // Corrupt the signature of the statement + args.statement_signature.r += Scalar::one(); + + assert!(update_wallet(&account, &args).await.is_err()); + + global_teardown(sequencer); + + Ok(()) +}