From 89d76688d794990c725eed34dbfb1c7c350cc7d6 Mon Sep 17 00:00:00 2001 From: collin Date: Tue, 11 Aug 2020 23:51:56 -0700 Subject: [PATCH 01/30] add leo-state module --- Cargo.lock | 1442 ++++++++++++++++- Cargo.toml | 3 +- state/Cargo.toml | 25 + state/src/errors/error.rs | 5 + state/src/errors/mod.rs | 5 + state/src/errors/record_verification_error.rs | 30 + state/src/lib.rs | 11 + state/src/local_data_commitment/mod.rs | 1 + .../verify_local_data_commitment.rs | 0 .../record_commitment/dpc_record_values.rs | 123 ++ state/src/record_commitment/mod.rs | 5 + .../verify_record_commitment.rs | 35 + state/tests/mod.rs | 1 + state/tests/test.rs | 316 ++++ 14 files changed, 1938 insertions(+), 64 deletions(-) create mode 100644 state/Cargo.toml create mode 100644 state/src/errors/error.rs create mode 100644 state/src/errors/mod.rs create mode 100644 state/src/errors/record_verification_error.rs create mode 100644 state/src/lib.rs create mode 100644 state/src/local_data_commitment/mod.rs create mode 100644 state/src/local_data_commitment/verify_local_data_commitment.rs create mode 100644 state/src/record_commitment/dpc_record_values.rs create mode 100644 state/src/record_commitment/mod.rs create mode 100644 state/src/record_commitment/verify_record_commitment.rs create mode 100644 state/tests/mod.rs create mode 100644 state/tests/test.rs diff --git a/Cargo.lock b/Cargo.lock index 81b84faa32..daabbf1b46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,15 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi", + "winapi 0.3.9", ] +[[package]] +name = "arc-swap" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" + [[package]] name = "atty" version = "0.2.14" @@ -41,7 +47,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -70,6 +76,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + [[package]] name = "bech32" version = "0.6.0" @@ -86,6 +98,30 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c72a978d268b1d70b0e963217e60fdabd9523a941457a6c42a7315d15c7e89e5" +dependencies = [ + "bitflags", + "cexpr", + "cfg-if", + "clang-sys", + "clap", + "env_logger", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2 1.0.19", + "quote 1.0.7", + "regex", + "rustc-hash", + "shlex", + "which", +] + [[package]] name = "bitflags" version = "1.2.1" @@ -164,6 +200,12 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + [[package]] name = "bzip2" version = "0.3.3" @@ -199,6 +241,18 @@ name = "cc" version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom", +] [[package]] name = "cfg-if" @@ -227,6 +281,17 @@ dependencies = [ "envmnt", ] +[[package]] +name = "clang-sys" +version = "0.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6837df1d5cba2397b835c8530f51723267e16abbf83892e9e5af4f0e5dd10a" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "2.33.1" @@ -242,6 +307,15 @@ dependencies = [ "vec_map", ] +[[package]] +name = "cloudabi" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467" +dependencies = [ + "bitflags", +] + [[package]] name = "colored" version = "2.0.0" @@ -250,9 +324,25 @@ checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" dependencies = [ "atty", "lazy_static", - "winapi", + "winapi 0.3.9", ] +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + [[package]] name = "cpuid-bool" version = "0.1.2" @@ -384,6 +474,36 @@ dependencies = [ "memchr", ] +[[package]] +name = "curl" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9447ad28eee2a5cfb031c329d46bef77487244fff6a724b378885b8691a35f78" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi 0.3.9", +] + +[[package]] +name = "curl-sys" +version = "0.4.34+curl-7.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4eff0be6985b7e709f64b5a541f700e9ad1407190a29f4884319eb663ed1d6" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi 0.3.9", +] + [[package]] name = "derivative" version = "2.1.1" @@ -413,12 +533,27 @@ dependencies = [ "generic-array 0.14.3", ] +[[package]] +name = "dtoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" + [[package]] name = "either" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +[[package]] +name = "encoding_rs" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171" +dependencies = [ + "cfg-if", +] + [[package]] name = "env_logger" version = "0.7.1" @@ -482,6 +617,27 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "from-pest" version = "0.3.1" @@ -498,12 +654,79 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1fd087255f739f4f1aeea69f11b72f8080e9c2e7645cd06955dad4a178a49e3" +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + [[package]] name = "futures" version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" +[[package]] +name = "futures-channel" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" + +[[package]] +name = "futures-io" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" + +[[package]] +name = "futures-sink" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" + +[[package]] +name = "futures-task" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" +dependencies = [ + "once_cell", +] + +[[package]] +name = "futures-util" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.12.3" @@ -549,6 +772,31 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "h2" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "1.6.0" @@ -579,6 +827,33 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +[[package]] +name = "http" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "httparse" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" + [[package]] name = "humantime" version = "1.3.0" @@ -588,6 +863,54 @@ dependencies = [ "quick-error", ] +[[package]] +name = "hyper" +version = "0.13.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project", + "socket2", + "time", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-tls", +] + +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.5.0" @@ -598,6 +921,27 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485" + +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + [[package]] name = "itertools" version = "0.7.11" @@ -622,6 +966,15 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +[[package]] +name = "jobserver" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.44" @@ -644,12 +997,28 @@ dependencies = [ "serde_json", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" + [[package]] name = "leo" version = "0.1.0" @@ -658,22 +1027,25 @@ dependencies = [ "colored", "env_logger", "from-pest", + "lazy_static", "leo-compiler", "leo-gadgets", "leo-input", "leo-package", + "leo-state", "log", "rand", "rand_core", + "reqwest", "rusty-hook", "serde", "serde_json", - "snarkos-algorithms", - "snarkos-curves", - "snarkos-errors", - "snarkos-gadgets", - "snarkos-models", - "snarkos-utilities", + "snarkos-algorithms 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-curves 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-gadgets 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", "thiserror", "toml", ] @@ -711,13 +1083,13 @@ dependencies = [ "rand_xorshift", "serde", "sha2", - "snarkos-curves", - "snarkos-dpc", - "snarkos-errors", - "snarkos-gadgets", - "snarkos-models", - "snarkos-objects", - "snarkos-utilities", + "snarkos-curves 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-dpc 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-gadgets 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-objects 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", "thiserror", ] @@ -727,9 +1099,9 @@ version = "0.1.0" dependencies = [ "rand", "rand_xorshift", - "snarkos-errors", - "snarkos-models", - "snarkos-utilities", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", "thiserror", ] @@ -741,11 +1113,11 @@ dependencies = [ "pest", "pest-ast", "pest_derive", - "snarkos-algorithms", - "snarkos-curves", - "snarkos-errors", - "snarkos-gadgets", - "snarkos-models", + "snarkos-algorithms 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-curves 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-gadgets 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", "thiserror", ] @@ -766,6 +1138,25 @@ dependencies = [ "zip", ] +[[package]] +name = "leo-state" +version = "0.1.0" +dependencies = [ + "leo-input", + "leo-typed", + "rand", + "rand_xorshift", + "snarkos-algorithms 0.8.0", + "snarkos-curves 0.8.0", + "snarkos-dpc 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-objects 0.8.0", + "snarkos-testing", + "snarkos-utilities 0.8.0", + "thiserror", +] + [[package]] name = "leo-typed" version = "0.1.0" @@ -776,8 +1167,8 @@ dependencies = [ "pest", "serde", "serde_json", - "snarkos-errors", - "snarkos-models", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", ] [[package]] @@ -786,6 +1177,49 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" +[[package]] +name = "libloading" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +dependencies = [ + "cc", + "winapi 0.3.9", +] + +[[package]] +name = "librocksdb-sys" +version = "6.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883213ae3d09bfc3d104aefe94b25ebb183b6f4d3a515b23b14817e1f4854005" +dependencies = [ + "bindgen", + "cc", + "glob", + "libc", +] + +[[package]] +name = "libz-sys" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "lock_api" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.11" @@ -801,6 +1235,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + [[package]] name = "maybe-uninit" version = "2.0.0" @@ -822,6 +1262,22 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "miniz_oxide" version = "0.4.0" @@ -831,12 +1287,115 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.6.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +dependencies = [ + "cfg-if", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow 0.2.1", + "net2", + "slab", + "winapi 0.2.8", +] + +[[package]] +name = "mio-named-pipes" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" +dependencies = [ + "log", + "mio", + "miow 0.3.5", + "winapi 0.3.9", +] + +[[package]] +name = "mio-uds" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" +dependencies = [ + "iovec", + "libc", + "mio", +] + +[[package]] +name = "miow" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + +[[package]] +name = "miow" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" +dependencies = [ + "socket2", + "winapi 0.3.9", +] + +[[package]] +name = "native-tls" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "net2" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" +dependencies = [ + "cfg-if", + "libc", + "winapi 0.3.9", +] + [[package]] name = "nias" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab250442c86f1850815b5d268639dff018c0627022bc1940eb2d642ca1ce12f0" +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + [[package]] name = "num-bigint" version = "0.3.0" @@ -907,6 +1466,77 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openssl" +version = "0.10.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" + +[[package]] +name = "openssl-sys" +version = "0.9.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" +dependencies = [ + "cfg-if", + "cloudabi", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi 0.3.9", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + [[package]] name = "pest" version = "2.1.3" @@ -963,6 +1593,38 @@ dependencies = [ "sha-1", ] +[[package]] +name = "pin-project" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" +dependencies = [ + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.36", +] + +[[package]] +name = "pin-project-lite" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.18" @@ -1110,6 +1772,12 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + [[package]] name = "regex" version = "1.3.9" @@ -1137,12 +1805,73 @@ version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "reqwest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12427a5577082c24419c9c417db35cfeb65962efc7675bb6b0d5f1f9d315bfe6" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "rocksdb" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12069b106981c6103d3eab7dd1c86751482d0779a520b7c14954c8b586c1e643" +dependencies = [ + "libc", + "librocksdb-sys", +] + [[package]] name = "rustc-demangle" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.2.3" @@ -1179,12 +1908,45 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi 0.3.9", +] + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "security-framework" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -1241,6 +2003,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" +dependencies = [ + "dtoa", + "itoa", + "serde", + "url", +] + [[package]] name = "sha-1" version = "0.8.2" @@ -1266,6 +2040,22 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "signal-hook-registry" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" +dependencies = [ + "arc-swap", + "libc", +] + [[package]] name = "single" version = "1.0.0" @@ -1275,6 +2065,12 @@ dependencies = [ "failure", ] +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" + [[package]] name = "smallvec" version = "1.4.1" @@ -1295,10 +2091,52 @@ dependencies = [ "rayon", "sha2", "smallvec", - "snarkos-errors", - "snarkos-models", - "snarkos-profiler", - "snarkos-utilities", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-profiler 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-algorithms" +version = "0.8.0" +dependencies = [ + "blake2", + "derivative", + "digest 0.8.1", + "itertools 0.9.0", + "rand", + "rand_chacha", + "rayon", + "sha2", + "smallvec", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-profiler 0.8.0", + "snarkos-utilities 0.8.0", +] + +[[package]] +name = "snarkos-consensus" +version = "0.8.0" +dependencies = [ + "bincode", + "chrono", + "hex", + "log", + "rand", + "serde", + "snarkos-algorithms 0.8.0", + "snarkos-curves 0.8.0", + "snarkos-dpc 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-objects 0.8.0", + "snarkos-posw", + "snarkos-profiler 0.8.0", + "snarkos-storage", + "snarkos-utilities 0.8.0", + "tokio", ] [[package]] @@ -1311,9 +2149,23 @@ dependencies = [ "rand_xorshift", "rustc_version", "serde", - "snarkos-errors", - "snarkos-models", - "snarkos-utilities", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-curves" +version = "0.8.0" +dependencies = [ + "derivative", + "rand", + "rand_xorshift", + "rustc_version", + "serde", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-utilities 0.8.0", ] [[package]] @@ -1326,6 +2178,15 @@ dependencies = [ "syn 1.0.36", ] +[[package]] +name = "snarkos-derives" +version = "0.1.0" +dependencies = [ + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.36", +] + [[package]] name = "snarkos-dpc" version = "0.8.0" @@ -1336,15 +2197,35 @@ dependencies = [ "hex", "itertools 0.9.0", "rand", - "snarkos-algorithms", - "snarkos-curves", - "snarkos-errors", - "snarkos-gadgets", - "snarkos-models", - "snarkos-objects", - "snarkos-parameters", - "snarkos-profiler", - "snarkos-utilities", + "snarkos-algorithms 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-curves 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-gadgets 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-objects 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-parameters 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-profiler 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-dpc" +version = "0.8.0" +dependencies = [ + "blake2", + "derivative", + "hex", + "itertools 0.9.0", + "rand", + "snarkos-algorithms 0.8.0", + "snarkos-curves 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-gadgets 0.8.0", + "snarkos-models 0.8.0", + "snarkos-objects 0.8.0", + "snarkos-parameters 0.8.0", + "snarkos-profiler 0.8.0", + "snarkos-utilities 0.8.0", ] [[package]] @@ -1360,6 +2241,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "snarkos-errors" +version = "0.8.0" +dependencies = [ + "base58", + "bech32", + "bincode", + "curl", + "hex", + "jsonrpc-core", + "rocksdb", + "thiserror", +] + [[package]] name = "snarkos-gadgets" version = "0.8.0" @@ -1368,11 +2263,44 @@ dependencies = [ "derivative", "digest 0.8.1", "itertools 0.9.0", - "snarkos-algorithms", - "snarkos-curves", - "snarkos-errors", - "snarkos-models", - "snarkos-utilities", + "snarkos-algorithms 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-curves 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-gadgets" +version = "0.8.0" +dependencies = [ + "derivative", + "digest 0.8.1", + "itertools 0.9.0", + "snarkos-algorithms 0.8.0", + "snarkos-curves 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-utilities 0.8.0", +] + +[[package]] +name = "snarkos-marlin" +version = "0.1.0" +dependencies = [ + "blake2", + "derivative", + "digest 0.8.1", + "rand_chacha", + "rand_core", + "rayon", + "snarkos-algorithms 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-gadgets 0.8.0", + "snarkos-models 0.8.0", + "snarkos-polycommit", + "snarkos-profiler 0.8.0", + "snarkos-utilities 0.8.0", ] [[package]] @@ -1387,8 +2315,45 @@ dependencies = [ "rand_xorshift", "serde", "smallvec", - "snarkos-errors", - "snarkos-utilities", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-models" +version = "0.8.0" +dependencies = [ + "bincode", + "derivative", + "itertools 0.9.0", + "rand", + "rand_xorshift", + "serde", + "smallvec", + "snarkos-errors 0.8.0", + "snarkos-utilities 0.8.0", +] + +[[package]] +name = "snarkos-network" +version = "0.8.0" +dependencies = [ + "bincode", + "byteorder", + "chrono", + "hex", + "log", + "rand", + "serde", + "snarkos-algorithms 0.8.0", + "snarkos-consensus", + "snarkos-dpc 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-objects 0.8.0", + "snarkos-storage", + "snarkos-utilities 0.8.0", + "tokio", ] [[package]] @@ -1405,11 +2370,31 @@ dependencies = [ "rand", "serde", "sha2", - "snarkos-algorithms", - "snarkos-curves", - "snarkos-errors", - "snarkos-models", - "snarkos-utilities", + "snarkos-algorithms 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-curves 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-objects" +version = "0.8.0" +dependencies = [ + "base58", + "bech32", + "chrono", + "derivative", + "hex", + "once_cell", + "rand", + "serde", + "sha2", + "snarkos-algorithms 0.8.0", + "snarkos-curves 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-utilities 0.8.0", ] [[package]] @@ -1418,10 +2403,56 @@ version = "0.8.0" source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#8d84d89f6b6c3b4693d3c08758cce28139910807" dependencies = [ "hex", - "snarkos-algorithms", - "snarkos-errors", - "snarkos-models", - "snarkos-utilities", + "snarkos-algorithms 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-parameters" +version = "0.8.0" +dependencies = [ + "curl", + "hex", + "snarkos-algorithms 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-utilities 0.8.0", +] + +[[package]] +name = "snarkos-polycommit" +version = "0.1.0" +dependencies = [ + "derivative", + "digest 0.8.1", + "rand_core", + "snarkos-algorithms 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-profiler 0.8.0", + "snarkos-utilities 0.8.0", +] + +[[package]] +name = "snarkos-posw" +version = "0.8.0" +dependencies = [ + "blake2", + "rand", + "snarkos-algorithms 0.8.0", + "snarkos-curves 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-gadgets 0.8.0", + "snarkos-marlin", + "snarkos-models 0.8.0", + "snarkos-objects 0.8.0", + "snarkos-parameters 0.8.0", + "snarkos-polycommit", + "snarkos-profiler 0.8.0", + "snarkos-utilities 0.8.0", + "thiserror", ] [[package]] @@ -1429,6 +2460,50 @@ name = "snarkos-profiler" version = "0.8.0" source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#8d84d89f6b6c3b4693d3c08758cce28139910807" +[[package]] +name = "snarkos-profiler" +version = "0.8.0" + +[[package]] +name = "snarkos-storage" +version = "0.8.0" +dependencies = [ + "bincode", + "hex", + "parking_lot", + "rand", + "rocksdb", + "serde", + "snarkos-algorithms 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-objects 0.8.0", + "snarkos-parameters 0.8.0", + "snarkos-utilities 0.8.0", +] + +[[package]] +name = "snarkos-testing" +version = "0.8.0" +dependencies = [ + "once_cell", + "rand", + "rand_xorshift", + "snarkos-algorithms 0.8.0", + "snarkos-consensus", + "snarkos-curves 0.8.0", + "snarkos-dpc 0.8.0", + "snarkos-errors 0.8.0", + "snarkos-models 0.8.0", + "snarkos-network", + "snarkos-objects 0.8.0", + "snarkos-parameters 0.8.0", + "snarkos-posw", + "snarkos-storage", + "snarkos-utilities 0.8.0", + "tokio", +] + [[package]] name = "snarkos-utilities" version = "0.8.0" @@ -1436,8 +2511,30 @@ source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#8d84d89f6b6c3b4693d3c08758 dependencies = [ "bincode", "rand", - "snarkos-derives", - "snarkos-errors", + "snarkos-derives 0.1.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", +] + +[[package]] +name = "snarkos-utilities" +version = "0.8.0" +dependencies = [ + "bincode", + "rand", + "snarkos-derives 0.1.0", + "snarkos-errors 0.8.0", +] + +[[package]] +name = "socket2" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi 0.3.9", ] [[package]] @@ -1486,6 +2583,20 @@ dependencies = [ "unicode-xid 0.2.1", ] +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi 0.3.9", +] + [[package]] name = "termcolor" version = "1.1.0" @@ -1540,7 +2651,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1553,6 +2664,71 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" + +[[package]] +name = "tokio" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "iovec", + "lazy_static", + "libc", + "memchr", + "mio", + "mio-named-pipes", + "mio-uds", + "num_cpus", + "pin-project-lite", + "signal-hook-registry", + "slab", + "tokio-macros", + "winapi 0.3.9", +] + +[[package]] +name = "tokio-macros" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +dependencies = [ + "proc-macro2 1.0.19", + "quote 1.0.7", + "syn 1.0.36", +] + +[[package]] +name = "tokio-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.5.6" @@ -1562,6 +2738,38 @@ dependencies = [ "serde", ] +[[package]] +name = "tower-service" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" + +[[package]] +name = "tracing" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" +dependencies = [ + "cfg-if", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db63662723c316b43ca36d833707cc93dff82a02ba3d7e354f342682cc8b3545" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + [[package]] name = "typenum" version = "1.12.0" @@ -1574,6 +2782,33 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.8" @@ -1592,6 +2827,23 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "url" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +dependencies = [ + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" + [[package]] name = "vec_map" version = "0.8.2" @@ -1617,10 +2869,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" dependencies = [ "same-file", - "winapi", + "winapi 0.3.9", "winapi-util", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -1634,6 +2896,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" dependencies = [ "cfg-if", + "serde", + "serde_json", "wasm-bindgen-macro", ] @@ -1652,6 +2916,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95f8d235a77f880bcef268d379810ea6c0af2eacfa90b1ad5af731776e0c4699" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.67" @@ -1691,6 +2967,21 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "which" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +dependencies = [ + "libc", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -1701,6 +2992,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1713,7 +3010,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1722,6 +3019,25 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "zip" version = "0.5.6" diff --git a/Cargo.toml b/Cargo.toml index fa922b9269..b3e2efe251 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,13 +13,14 @@ name = "leo" path = "leo/main.rs" [workspace] -members = [ "ast", "compiler", "gadgets", "input", "linter", "package", "typed" ] +members = [ "ast", "compiler", "gadgets", "input", "linter", "package", "typed", "state"] [dependencies] leo-compiler = { path = "compiler", version = "0.1.0" } leo-gadgets = { path = "gadgets", version = "0.1.0" } leo-input = { path = "input", version = "0.1.0" } leo-package = { path = "package", version = "0.1.0" } +leo-state = { path = "state", version = "0.1.0" } snarkos-algorithms = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-algorithms", default-features = false } snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false } diff --git a/state/Cargo.toml b/state/Cargo.toml new file mode 100644 index 0000000000..3099b9d9ac --- /dev/null +++ b/state/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "leo-state" +version = "0.1.0" +authors = ["The Aleo Team "] +edition = "2018" + +[dependencies] +leo-input = { path = "../input", version = "0.1.0" } +leo-typed = { path = "../typed", version = "0.1.0" } + +snarkos-algorithms = { path = "../../snarkOS/algorithms" } +snarkos-curves = { path = "../../snarkOS/curves" } +snarkos-dpc = { path = "../../snarkOS/dpc" } +snarkos-errors = { path = "../../snarkOS/errors" } +snarkos-models = { path = "../../snarkOS/models" } +snarkos-objects = { path = "../../snarkOS/objects" } +snarkos-utilities = { path = "../../snarkOS/utilities" } + +rand = { version = "0.7" } +rand_xorshift = { version = "0.2" } +thiserror = { version = "1.0" } + + +[dev-dependencies] +snarkos-testing = { path = "../../snarkOS/testing" } diff --git a/state/src/errors/error.rs b/state/src/errors/error.rs new file mode 100644 index 0000000000..064d1486d3 --- /dev/null +++ b/state/src/errors/error.rs @@ -0,0 +1,5 @@ +// +// #[derive(Debug, Error)] +// pub enum VerifyError { +// +// } diff --git a/state/src/errors/mod.rs b/state/src/errors/mod.rs new file mode 100644 index 0000000000..1521dadc27 --- /dev/null +++ b/state/src/errors/mod.rs @@ -0,0 +1,5 @@ +pub mod error; +pub use self::error::*; + +pub mod record_verification_error; +pub use self::record_verification_error::*; diff --git a/state/src/errors/record_verification_error.rs b/state/src/errors/record_verification_error.rs new file mode 100644 index 0000000000..7a64cb5442 --- /dev/null +++ b/state/src/errors/record_verification_error.rs @@ -0,0 +1,30 @@ +use snarkos_errors::{algorithms::CommitmentError, objects::account::AccountError}; + +use std::{io::Error as IOError, num::ParseIntError, str::ParseBoolError}; + +#[derive(Debug, Error)] +pub enum RecordVerificationError { + #[error("{}", _0)] + AccountError(#[from] AccountError), + + #[error("{}", _0)] + CommitmentError(#[from] CommitmentError), + + #[error("expected parameter array of u8 bytes, found `{}`", _0)] + ExpectedBytes(String), + + #[error("expected integer parameter, found `{}`", _0)] + ExpectedInteger(String), + + #[error("{}", _0)] + IOError(#[from] IOError), + + #[error("record parameter `{}` not found in state file", _0)] + MissingParameter(String), + + #[error("{}", _0)] + ParseBoolError(#[from] ParseBoolError), + + #[error("{}", _0)] + ParseIntError(#[from] ParseIntError), +} diff --git a/state/src/lib.rs b/state/src/lib.rs new file mode 100644 index 0000000000..ff055bd082 --- /dev/null +++ b/state/src/lib.rs @@ -0,0 +1,11 @@ +#[macro_use] +extern crate thiserror; + +pub mod errors; +pub use self::errors::*; + +pub mod local_data_commitment; +pub use self::local_data_commitment::*; + +pub mod record_commitment; +pub use self::record_commitment::*; diff --git a/state/src/local_data_commitment/mod.rs b/state/src/local_data_commitment/mod.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/state/src/local_data_commitment/mod.rs @@ -0,0 +1 @@ + diff --git a/state/src/local_data_commitment/verify_local_data_commitment.rs b/state/src/local_data_commitment/verify_local_data_commitment.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs new file mode 100644 index 0000000000..d077f1ed3b --- /dev/null +++ b/state/src/record_commitment/dpc_record_values.rs @@ -0,0 +1,123 @@ +use crate::RecordVerificationError; +use leo_typed::{InputValue, Record as TypedRecord}; + +use snarkos_dpc::base_dpc::instantiated::Components; +use snarkos_objects::AccountAddress; +use std::{convert::TryFrom, str::FromStr}; + +static OWNER_PARAMETER_STRING: &str = "owner"; +static IS_DUMMY_PARAMETER_STRING: &str = "is_dummy"; +static VALUE_PARAMETER_STRING: &str = "value"; +static PAYLOAD_PARAMETER_STRING: &str = "parameter"; +static BIRTH_PROGRAM_ID_PARAMETER_STRING: &str = "birth_program_id"; +static DEATH_PROGRAM_ID_PARAMETER_STRING: &str = "death_program_id"; +static SERIAL_NUMBER_NONCE_PARAMETER_STRING: &str = "serial_number_nonce"; +static COMMITMENT_PARAMETER_STRING: &str = "commitment"; +static COMMITMENT_RANDOMNESS_PARAMETER_STRING: &str = "commitment_randomness"; + +pub struct DPCRecordValues { + pub owner: AccountAddress, + pub is_dummy: bool, + pub value: u64, + pub payload: Vec, + pub birth_program_id: Vec, + pub death_program_id: Vec, + pub serial_number_nonce: Vec, + pub commitment: Vec, + pub commitment_randomness: Vec, +} + +impl TryFrom for DPCRecordValues { + type Error = RecordVerificationError; + + fn try_from(record: TypedRecord) -> Result { + // Lookup record owner + let owner_value = get_parameter_value(OWNER_PARAMETER_STRING.to_owned(), &record)?; + let owner = AccountAddress::::from_str(&format!("{}", owner_value))?; + + // Lookup record is_dummy + let is_dummy_value = get_parameter_value(IS_DUMMY_PARAMETER_STRING.to_owned(), &record)?; + let is_dummy = is_dummy_value.to_string().parse::()?; + + // Lookup record value + let value_value = get_parameter_value(VALUE_PARAMETER_STRING.to_owned(), &record)?; + let value = input_to_integer_string(value_value)?.parse::()?; + + // Lookup record payload + let payload_value = get_parameter_value(PAYLOAD_PARAMETER_STRING.to_owned(), &record)?; + let payload = input_to_u8_vec(payload_value)?; + + // Lookup record birth program id + let birth_program_id_value = get_parameter_value(BIRTH_PROGRAM_ID_PARAMETER_STRING.to_owned(), &record)?; + let birth_program_id = input_to_u8_vec(birth_program_id_value)?; + + // Lookup record death program id + let death_program_id_value = get_parameter_value(DEATH_PROGRAM_ID_PARAMETER_STRING.to_owned(), &record)?; + let death_program_id = input_to_u8_vec(death_program_id_value)?; + + // Lookup record serial number nonce + let serial_number_nonce_value = get_parameter_value(SERIAL_NUMBER_NONCE_PARAMETER_STRING.to_owned(), &record)?; + let serial_number_nonce = input_to_u8_vec(serial_number_nonce_value)?; + + // Lookup record commitment + let commitment_value = get_parameter_value(COMMITMENT_PARAMETER_STRING.to_owned(), &record)?; + let commitment = input_to_u8_vec(commitment_value)?; + + // Lookup record commitment randomness + let commitment_randomness_value = + get_parameter_value(COMMITMENT_RANDOMNESS_PARAMETER_STRING.to_owned(), &record)?; + let commitment_randomness = input_to_u8_vec(commitment_randomness_value)?; + + Ok(Self { + owner, + is_dummy, + value, + payload, + birth_program_id, + death_program_id, + serial_number_nonce, + commitment, + commitment_randomness, + }) + } +} + +fn get_parameter_value(name: String, record: &TypedRecord) -> Result { + let parameters = record.values(); + let matched_parameter = parameters + .iter() + .find(|(parameter, _value)| parameter.variable.name == name); + + match matched_parameter { + Some((_parameter, value_option)) => match value_option { + Some(value) => Ok(value.clone()), + None => Err(RecordVerificationError::MissingParameter(name)), + }, + None => Err(RecordVerificationError::MissingParameter(name)), + } +} + +fn input_to_integer_string(input: InputValue) -> Result { + match input { + InputValue::Integer(_type, string) => Ok(string), + value => Err(RecordVerificationError::ExpectedInteger(value.to_string())), + } +} + +fn input_to_u8_vec(input: InputValue) -> Result, RecordVerificationError> { + let input_array = match input { + InputValue::Array(values) => values, + value => return Err(RecordVerificationError::ExpectedBytes(value.to_string())), + }; + + let mut result_vec = vec![]; + + for input in input_array { + let integer_string = input_to_integer_string(input)?; + let byte = integer_string.parse::()?; + + result_vec.push(byte); + } + + Ok(result_vec) +} diff --git a/state/src/record_commitment/mod.rs b/state/src/record_commitment/mod.rs new file mode 100644 index 0000000000..9f92e4a742 --- /dev/null +++ b/state/src/record_commitment/mod.rs @@ -0,0 +1,5 @@ +pub mod dpc_record_values; +pub use self::dpc_record_values::*; + +pub mod verify_record_commitment; +pub use self::verify_record_commitment::*; diff --git a/state/src/record_commitment/verify_record_commitment.rs b/state/src/record_commitment/verify_record_commitment.rs new file mode 100644 index 0000000000..13e1cd1b13 --- /dev/null +++ b/state/src/record_commitment/verify_record_commitment.rs @@ -0,0 +1,35 @@ +use crate::{DPCRecordValues, RecordVerificationError}; +use leo_typed::Record as TypedRecord; + +use snarkos_dpc::base_dpc::instantiated::RecordCommitment; +use snarkos_models::{algorithms::CommitmentScheme, curves::Fp256}; +use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; +use std::convert::TryFrom; + +pub fn verify_record_commitment( + typed_record: TypedRecord, + record_commitment: RecordCommitment, +) -> Result { + // generate a dpc record from the typed record + let record = DPCRecordValues::try_from(typed_record)?; + + let record_commitment_input = to_bytes![ + record.owner, + record.is_dummy, + record.value, + record.payload, + record.birth_program_id, + record.death_program_id, + record.serial_number_nonce + ]?; + + let commitment = Fp256::read(&record.commitment[..])?; + let commitment_randomness = Fp256::read(&record.commitment_randomness[..])?; + + let record_commitment = + RecordCommitment::commit(&record_commitment, &record_commitment_input, &commitment_randomness)?; + + let result = record_commitment == commitment; + + Ok(result) +} diff --git a/state/tests/mod.rs b/state/tests/mod.rs new file mode 100644 index 0000000000..981d4655af --- /dev/null +++ b/state/tests/mod.rs @@ -0,0 +1 @@ +// mod test; diff --git a/state/tests/test.rs b/state/tests/test.rs new file mode 100644 index 0000000000..9666a7e12f --- /dev/null +++ b/state/tests/test.rs @@ -0,0 +1,316 @@ +use snarkos_curves::edwards_bls12::{EdwardsParameters, EdwardsProjective as EdwardsBls}; +use snarkos_dpc::base_dpc::{ + instantiated::*, + record_encryption::*, + record_payload::RecordPayload, + record_serializer::*, + BaseDPCComponents, + ExecuteContext, + DPC, +}; +use snarkos_models::{ + algorithms::{CommitmentScheme, CRH}, + dpc::{Record, RecordSerializerScheme}, + objects::AccountScheme, +}; +use snarkos_objects::{ + Account, + AccountViewKey, + Block, + BlockHeader, + BlockHeaderHash, + DPCTransactions, + MerkleRootHash, + PedersenMerkleRootHash, + ProofOfSuccinctWork, +}; +use snarkos_utilities::{bytes::ToBytes, rand::UniformRand, to_bytes}; + +use rand::{Rng, SeedableRng}; +use rand_xorshift::XorShiftRng; +use snarkos_algorithms::commitment_tree::CommitmentMerklePath; +use snarkos_dpc::{DummyProgram, NoopProgram}; +use snarkos_models::{ + algorithms::MerkleParameters, + dpc::{DPCScheme, Program}, + objects::LedgerScheme, +}; + +#[test] +fn test_integrate_with_dpc() { + use snarkos_testing::storage::*; + type L = Ledger; + + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); + + // Specify network_id + let network_id: u8 = 0; + + // Generate parameters for the ledger, commitment schemes, CRH, and the + // "always-accept" program. + let ledger_parameters = CommitmentMerkleParameters::setup(&mut rng); + let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); + let noop_program_snark_pp = + InstantiatedDPC::generate_noop_program_snark_parameters(&system_parameters, &mut rng).unwrap(); + let dummy_program_snark_pp = + InstantiatedDPC::generate_dummy_program_snark_parameters(&system_parameters, &mut rng).unwrap(); + + let noop_program_id = to_bytes![ + ProgramVerificationKeyHash::hash( + &system_parameters.program_verification_key_hash, + &to_bytes![noop_program_snark_pp.verification_key].unwrap() + ) + .unwrap() + ] + .unwrap(); + + let dummy_program_id = to_bytes![ + ProgramVerificationKeyHash::hash( + &system_parameters.program_verification_key_hash, + &to_bytes![dummy_program_snark_pp.verification_key].unwrap() + ) + .unwrap() + ] + .unwrap(); + + let signature_parameters = &system_parameters.account_signature; + let commitment_parameters = &system_parameters.account_commitment; + let encryption_parameters = &system_parameters.account_encryption; + + // Generate metadata and an account for a dummy initial record. + let dummy_account = Account::new( + signature_parameters, + commitment_parameters, + encryption_parameters, + &mut rng, + ) + .unwrap(); + + let genesis_block = Block { + header: BlockHeader { + previous_block_hash: BlockHeaderHash([0u8; 32]), + merkle_root_hash: MerkleRootHash([0u8; 32]), + time: 0, + difficulty_target: 0x07FF_FFFF_FFFF_FFFF_u64, + nonce: 0, + pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]), + proof: ProofOfSuccinctWork::default(), + }, + transactions: DPCTransactions::new(), + }; + + // Use genesis record, serial number, and memo to initialize the ledger. + let ledger = initialize_test_blockchain::(ledger_parameters, genesis_block); + + let sn_nonce = SerialNumberNonce::hash(&system_parameters.serial_number_nonce, &[0u8; 1]).unwrap(); + // let old_record = DPC::generate_record( + // &system_parameters, + // &sn_nonce, + // &dummy_account.address, + // true, + // 0, + // &RecordPayload::default(), + // &dummy_program_id, + // &dummy_program_id, + // &mut rng, + // ) + // .unwrap(); + + let value = rng.gen(); + let payload: [u8; 32] = rng.gen(); + let old_record = DPC::generate_record( + &system_parameters, + &sn_nonce, + &dummy_account.address, + false, + value, + &RecordPayload::from_bytes(&payload), + &noop_program_id, + &noop_program_id, + &mut rng, + ) + .unwrap(); + + // Set the input records for our transaction to be the initial dummy records. + let old_records = vec![old_record.clone(); NUM_INPUT_RECORDS]; + let old_account_private_keys = vec![dummy_account.private_key.clone(); NUM_INPUT_RECORDS]; + + // Construct new records. + + // Create an account for an actual new record. + + let new_account = Account::new( + signature_parameters, + commitment_parameters, + encryption_parameters, + &mut rng, + ) + .unwrap(); + + // Set the new record's program to be the "always-accept" program. + + let new_record_owners = vec![new_account.address.clone(); NUM_OUTPUT_RECORDS]; + let new_is_dummy_flags = vec![false; NUM_OUTPUT_RECORDS]; + let new_values = vec![10; NUM_OUTPUT_RECORDS]; + let new_payloads = vec![RecordPayload::default(); NUM_OUTPUT_RECORDS]; + let new_birth_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; + let new_death_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; + let memo = [0u8; 32]; + + let context = >::execute_offline( + &system_parameters, + &old_records, + &old_account_private_keys, + &new_record_owners, + &new_is_dummy_flags, + &new_values, + &new_payloads, + &new_birth_program_ids, + &new_death_program_ids, + &memo, + network_id, + &mut rng, + ) + .unwrap(); + + let local_data = context.into_local_data(); + + for (i, record) in local_data.old_records.iter().enumerate() { + println!("{} : {}", i, record.is_dummy()); + } + + ////////////////////////////////////////////////////////////// + // Todo: parse state from file instead of DPC::generate_record + // compare commitments + /* + let commitment = Commit( + record.owner, + record.value, + record.payload, + record.is_dummy, + record.birth_program_id, + record.death_program_id, + record.serial_number_nonce, + record.commitment_randomness, + ); + + record.commitment == commitment + */ + + let record_commitment_input = to_bytes![ + old_record.owner(), + old_record.is_dummy(), + old_record.value(), + old_record.payload(), + old_record.birth_program_id(), + old_record.death_program_id(), + old_record.serial_number_nonce() + ] + .unwrap(); + + let record_commitment = RecordCommitment::commit( + &system_parameters.record_commitment, + &record_commitment_input, + &old_record.commitment_randomness(), + ) + .unwrap(); + + assert_eq!(record_commitment, old_record.commitment()); + + ////////////////////////////////////////////////////////////// + + // Verify local data commitment + + // let leaf_index = 0; + // let root = local_data.local_data_merkle_tree.root(); + // + // let path = ledger.prove_cm(&old_record.commitment()).unwrap(); + // let memo = local_data.memorandum; + // let network_id = local_data.network_id; + // let leaf_randomness = local_data.local_data_commitment_randomizers[0].clone(); + + // Verify that the local data commitment leaf is valid for the root + + // let path = ledger.prove_cm(&record.commitment()).unwrap(); + // let digest = ledger.digest().unwrap(); + // let verified = path.verify(&digest, &record.commitment()).unwrap(); + + ///////////////////////////////////////////////// + + // Generate the program proofs + + // let noop_program = NoopProgram::<_, ::NoopProgramSNARK>::new(noop_program_id); + // let dummy_program = DummyProgram::<_, ::DummyProgramSNARK>::new(dummy_program_id); + // + // let mut old_proof_and_vk = vec![]; + // for i in 0..NUM_INPUT_RECORDS { + // let private_input = dummy_program + // .execute( + // &dummy_program_snark_pp.proving_key, + // &dummy_program_snark_pp.verification_key, + // &local_data, + // i as u8, + // &mut rng, + // ) + // .unwrap(); + // + // old_proof_and_vk.push(private_input); + // } + // + // let mut new_proof_and_vk = vec![]; + // for j in 0..NUM_OUTPUT_RECORDS { + // let private_input = noop_program + // .execute( + // &noop_program_snark_pp.proving_key, + // &noop_program_snark_pp.verification_key, + // &local_data, + // (NUM_INPUT_RECORDS + j) as u8, + // &mut rng, + // ) + // .unwrap(); + // + // new_proof_and_vk.push(private_input); + // } + // + // let ExecuteContext { + // system_parameters: _, + // + // old_records, + // old_account_private_keys, + // old_serial_numbers, + // old_randomizers: _, + // + // new_records, + // new_sn_nonce_randomness, + // new_commitments, + // + // new_records_encryption_randomness, + // new_encrypted_records: _, + // new_encrypted_record_hashes, + // + // program_commitment, + // program_randomness, + // local_data_merkle_tree, + // local_data_commitment_randomizers, + // value_balance, + // memorandum, + // network_id, + // } = context; + // + // let local_data_root = local_data_merkle_tree.root(); + + // Verify that the local data commitment leaf is valid for the root + + // let local_data_commitment = LocalDataCommitment::commit( + // &system_parameters.local_data_commitment, + // + // ) + + // let merkle = CommitmentMerklePath::verify( + // system_parameters.local_data_commitment + // state.root + // state.path + // ) + + // system_parameters.local_data_commitment +} From 36b0d6a50808d9c79ecd8f8d1beb675ef2aa666d Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 11:59:35 -0700 Subject: [PATCH 02/30] add initial local data commitment check --- state/src/errors/error.rs | 5 -- .../errors/local_data_verification_error.rs | 2 + state/src/errors/mod.rs | 4 +- state/src/errors/record_verification_error.rs | 3 + state/src/local_data_commitment/mod.rs | 7 ++ .../state_leaf_values.rs | 6 ++ .../src/local_data_commitment/state_values.rs | 4 + .../verify_local_data_commitment.rs | 80 +++++++++++++++++++ .../record_commitment/dpc_record_values.rs | 29 ++++--- .../verify_record_commitment.rs | 21 +++-- 10 files changed, 135 insertions(+), 26 deletions(-) delete mode 100644 state/src/errors/error.rs create mode 100644 state/src/errors/local_data_verification_error.rs create mode 100644 state/src/local_data_commitment/state_leaf_values.rs create mode 100644 state/src/local_data_commitment/state_values.rs diff --git a/state/src/errors/error.rs b/state/src/errors/error.rs deleted file mode 100644 index 064d1486d3..0000000000 --- a/state/src/errors/error.rs +++ /dev/null @@ -1,5 +0,0 @@ -// -// #[derive(Debug, Error)] -// pub enum VerifyError { -// -// } diff --git a/state/src/errors/local_data_verification_error.rs b/state/src/errors/local_data_verification_error.rs new file mode 100644 index 0000000000..e3e116eb9b --- /dev/null +++ b/state/src/errors/local_data_verification_error.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Error)] +pub enum LocalDataVerificationError {} diff --git a/state/src/errors/mod.rs b/state/src/errors/mod.rs index 1521dadc27..f76e23cf06 100644 --- a/state/src/errors/mod.rs +++ b/state/src/errors/mod.rs @@ -1,5 +1,5 @@ -pub mod error; -pub use self::error::*; +pub mod local_data_verification_error; +pub use self::local_data_verification_error::*; pub mod record_verification_error; pub use self::record_verification_error::*; diff --git a/state/src/errors/record_verification_error.rs b/state/src/errors/record_verification_error.rs index 7a64cb5442..d44e4737f4 100644 --- a/state/src/errors/record_verification_error.rs +++ b/state/src/errors/record_verification_error.rs @@ -7,6 +7,9 @@ pub enum RecordVerificationError { #[error("{}", _0)] AccountError(#[from] AccountError), + #[error("record commitment does not match record data")] + CommitmentsDoNotMatch, + #[error("{}", _0)] CommitmentError(#[from] CommitmentError), diff --git a/state/src/local_data_commitment/mod.rs b/state/src/local_data_commitment/mod.rs index 8b13789179..2f13f6333c 100644 --- a/state/src/local_data_commitment/mod.rs +++ b/state/src/local_data_commitment/mod.rs @@ -1 +1,8 @@ +pub mod state_values; +pub use self::state_values::*; +pub mod state_leaf_values; +pub use self::state_leaf_values::*; + +pub mod verify_local_data_commitment; +pub use self::verify_local_data_commitment::*; diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs new file mode 100644 index 0000000000..a77e041571 --- /dev/null +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -0,0 +1,6 @@ +pub struct StateLeafValues { + pub path: Vec>, + pub memo: Vec, + pub network_id: u8, + pub leaf_randomness: Vec, +} diff --git a/state/src/local_data_commitment/state_values.rs b/state/src/local_data_commitment/state_values.rs new file mode 100644 index 0000000000..a15d0cffc4 --- /dev/null +++ b/state/src/local_data_commitment/state_values.rs @@ -0,0 +1,4 @@ +pub struct StateValues { + pub leaf_index: u32, + pub root: Vec, +} diff --git a/state/src/local_data_commitment/verify_local_data_commitment.rs b/state/src/local_data_commitment/verify_local_data_commitment.rs index e69de29bb2..71a3870179 100644 --- a/state/src/local_data_commitment/verify_local_data_commitment.rs +++ b/state/src/local_data_commitment/verify_local_data_commitment.rs @@ -0,0 +1,80 @@ +use crate::{verify_record_commitment::verify_record_commitment, LocalDataVerificationError}; +use leo_typed::Input as TypedInput; + +use snarkos_algorithms::commitment_tree::CommitmentMerklePath; +use snarkos_dpc::base_dpc::instantiated::{Components, LocalDataCRH, LocalDataCommitment, RecordCommitment}; +use snarkos_models::{ + algorithms::{CommitmentScheme, CRH}, + curves::Fp256, + dpc::DPCComponents, +}; +use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; + +pub fn verify_local_data_commitment( + typed_input: &TypedInput, + record_commitment_params: RecordCommitment, + local_data_commitment_params: LocalDataCommitment, + local_data_crh_params: LocalDataCRH, +) -> Result { + // verify record commitment + let typed_record = typed_input.get_record(); + let dpc_record_values = verify_record_commitment(typed_record, record_commitment_params).unwrap(); + + let record_commitment: Vec = dpc_record_values.commitment; + let record_serial_number: Vec = dpc_record_values.serial_number; + + // parse typed state values + let leaf_index: u32 = 0; + let root: Vec = vec![]; + + // parse typed state leaf values + let _path: Vec> = vec![]; + let memo: Vec = vec![]; + let network_id: Vec = vec![]; + let leaf_randomness: Vec = vec![]; + + // Select local data commitment input bytes + let is_death = leaf_index < (Components::NUM_INPUT_RECORDS as u32); + + let input_bytes = if is_death { + to_bytes![record_serial_number, record_commitment, memo, network_id].unwrap() + } else { + to_bytes![record_commitment, memo, network_id].unwrap() + }; + + // Construct local data commitment leaf + let leaf_randomness = Fp256::read(&leaf_randomness[..]).unwrap(); + + let local_data_commitment_leaf = + LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &leaf_randomness).unwrap(); + + // Construct record commitment merkle path + + // let local_data_merkle_path = CommitmentMerklePath::from(path); // Ideally we want something like this + + // Initialize failing blank values for now + let leaves = ( + ::Output::default(), + ::Output::default(), + ); + + let inner_hashes = ( + ::Output::default(), + ::Output::default(), + ); + + let local_data_merkle_path = CommitmentMerklePath:: { + leaves, + inner_hashes, + parameters: local_data_crh_params, + }; + + // Check record commitment merkle path is valid for the given local data commitment root + let local_data_commitment_root = Fp256::read(&root[..]).unwrap(); + + let result = local_data_merkle_path + .verify(&local_data_commitment_root, &local_data_commitment_leaf) + .unwrap(); + + Ok(result) +} diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index d077f1ed3b..10b6d14eec 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -5,6 +5,7 @@ use snarkos_dpc::base_dpc::instantiated::Components; use snarkos_objects::AccountAddress; use std::{convert::TryFrom, str::FromStr}; +static SERIAL_NUMBER_PARAMETER_STRING: &str = "serial_number"; static OWNER_PARAMETER_STRING: &str = "owner"; static IS_DUMMY_PARAMETER_STRING: &str = "is_dummy"; static VALUE_PARAMETER_STRING: &str = "value"; @@ -16,6 +17,7 @@ static COMMITMENT_PARAMETER_STRING: &str = "commitment"; static COMMITMENT_RANDOMNESS_PARAMETER_STRING: &str = "commitment_randomness"; pub struct DPCRecordValues { + pub serial_number: Vec, pub owner: AccountAddress, pub is_dummy: bool, pub value: u64, @@ -27,48 +29,53 @@ pub struct DPCRecordValues { pub commitment_randomness: Vec, } -impl TryFrom for DPCRecordValues { +impl TryFrom<&TypedRecord> for DPCRecordValues { type Error = RecordVerificationError; - fn try_from(record: TypedRecord) -> Result { + fn try_from(record: &TypedRecord) -> Result { + // Lookup serial number + let serial_number_value = get_parameter_value(SERIAL_NUMBER_PARAMETER_STRING.to_owned(), record)?; + let serial_number = input_to_u8_vec(serial_number_value)?; + // Lookup record owner - let owner_value = get_parameter_value(OWNER_PARAMETER_STRING.to_owned(), &record)?; + let owner_value = get_parameter_value(OWNER_PARAMETER_STRING.to_owned(), record)?; let owner = AccountAddress::::from_str(&format!("{}", owner_value))?; // Lookup record is_dummy - let is_dummy_value = get_parameter_value(IS_DUMMY_PARAMETER_STRING.to_owned(), &record)?; + let is_dummy_value = get_parameter_value(IS_DUMMY_PARAMETER_STRING.to_owned(), record)?; let is_dummy = is_dummy_value.to_string().parse::()?; // Lookup record value - let value_value = get_parameter_value(VALUE_PARAMETER_STRING.to_owned(), &record)?; + let value_value = get_parameter_value(VALUE_PARAMETER_STRING.to_owned(), record)?; let value = input_to_integer_string(value_value)?.parse::()?; // Lookup record payload - let payload_value = get_parameter_value(PAYLOAD_PARAMETER_STRING.to_owned(), &record)?; + let payload_value = get_parameter_value(PAYLOAD_PARAMETER_STRING.to_owned(), record)?; let payload = input_to_u8_vec(payload_value)?; // Lookup record birth program id - let birth_program_id_value = get_parameter_value(BIRTH_PROGRAM_ID_PARAMETER_STRING.to_owned(), &record)?; + let birth_program_id_value = get_parameter_value(BIRTH_PROGRAM_ID_PARAMETER_STRING.to_owned(), record)?; let birth_program_id = input_to_u8_vec(birth_program_id_value)?; // Lookup record death program id - let death_program_id_value = get_parameter_value(DEATH_PROGRAM_ID_PARAMETER_STRING.to_owned(), &record)?; + let death_program_id_value = get_parameter_value(DEATH_PROGRAM_ID_PARAMETER_STRING.to_owned(), record)?; let death_program_id = input_to_u8_vec(death_program_id_value)?; // Lookup record serial number nonce - let serial_number_nonce_value = get_parameter_value(SERIAL_NUMBER_NONCE_PARAMETER_STRING.to_owned(), &record)?; + let serial_number_nonce_value = get_parameter_value(SERIAL_NUMBER_NONCE_PARAMETER_STRING.to_owned(), record)?; let serial_number_nonce = input_to_u8_vec(serial_number_nonce_value)?; // Lookup record commitment - let commitment_value = get_parameter_value(COMMITMENT_PARAMETER_STRING.to_owned(), &record)?; + let commitment_value = get_parameter_value(COMMITMENT_PARAMETER_STRING.to_owned(), record)?; let commitment = input_to_u8_vec(commitment_value)?; // Lookup record commitment randomness let commitment_randomness_value = - get_parameter_value(COMMITMENT_RANDOMNESS_PARAMETER_STRING.to_owned(), &record)?; + get_parameter_value(COMMITMENT_RANDOMNESS_PARAMETER_STRING.to_owned(), record)?; let commitment_randomness = input_to_u8_vec(commitment_randomness_value)?; Ok(Self { + serial_number, owner, is_dummy, value, diff --git a/state/src/record_commitment/verify_record_commitment.rs b/state/src/record_commitment/verify_record_commitment.rs index 13e1cd1b13..52ead66821 100644 --- a/state/src/record_commitment/verify_record_commitment.rs +++ b/state/src/record_commitment/verify_record_commitment.rs @@ -7,9 +7,9 @@ use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; pub fn verify_record_commitment( - typed_record: TypedRecord, - record_commitment: RecordCommitment, -) -> Result { + typed_record: &TypedRecord, + record_commitment_params: RecordCommitment, +) -> Result { // generate a dpc record from the typed record let record = DPCRecordValues::try_from(typed_record)?; @@ -26,10 +26,15 @@ pub fn verify_record_commitment( let commitment = Fp256::read(&record.commitment[..])?; let commitment_randomness = Fp256::read(&record.commitment_randomness[..])?; - let record_commitment = - RecordCommitment::commit(&record_commitment, &record_commitment_input, &commitment_randomness)?; + let record_commitment = RecordCommitment::commit( + &record_commitment_params, + &record_commitment_input, + &commitment_randomness, + )?; - let result = record_commitment == commitment; - - Ok(result) + if record_commitment == commitment { + Ok(record) + } else { + Err(RecordVerificationError::CommitmentsDoNotMatch) + } } From 83ea7c18b90da95ad0df679e86535b6a85e7d5fd Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 12:30:30 -0700 Subject: [PATCH 03/30] add typed state values parsing --- state/src/errors/input_value.rs | 13 ++++++ state/src/errors/mod.rs | 14 +++++-- state/src/errors/state_values.rs | 5 +++ ...ror.rs => verify_local_data_commitment.rs} | 0 ...n_error.rs => verify_record_commitment.rs} | 9 ++-- state/src/lib.rs | 3 ++ .../src/local_data_commitment/state_values.rs | 42 +++++++++++++++++++ .../verify_local_data_commitment.rs | 10 +++-- .../record_commitment/dpc_record_values.rs | 27 +----------- state/src/utilities/input_value.rs | 27 ++++++++++++ state/src/utilities/mod.rs | 2 + 11 files changed, 113 insertions(+), 39 deletions(-) create mode 100644 state/src/errors/input_value.rs create mode 100644 state/src/errors/state_values.rs rename state/src/errors/{local_data_verification_error.rs => verify_local_data_commitment.rs} (100%) rename state/src/errors/{record_verification_error.rs => verify_record_commitment.rs} (79%) create mode 100644 state/src/utilities/input_value.rs create mode 100644 state/src/utilities/mod.rs diff --git a/state/src/errors/input_value.rs b/state/src/errors/input_value.rs new file mode 100644 index 0000000000..0af7057d5d --- /dev/null +++ b/state/src/errors/input_value.rs @@ -0,0 +1,13 @@ +use std::num::ParseIntError; + +#[derive(Debug, Error)] +pub enum InputValueError { + #[error("expected parameter array of u8 bytes, found `{}`", _0)] + ExpectedBytes(String), + + #[error("expected integer parameter, found `{}`", _0)] + ExpectedInteger(String), + + #[error("{}", _0)] + ParseIntError(#[from] ParseIntError), +} diff --git a/state/src/errors/mod.rs b/state/src/errors/mod.rs index f76e23cf06..1add734877 100644 --- a/state/src/errors/mod.rs +++ b/state/src/errors/mod.rs @@ -1,5 +1,11 @@ -pub mod local_data_verification_error; -pub use self::local_data_verification_error::*; +pub mod input_value; +pub use self::input_value::*; -pub mod record_verification_error; -pub use self::record_verification_error::*; +pub mod state_values; +pub use self::state_values::*; + +pub mod verify_local_data_commitment; +pub use self::verify_local_data_commitment::*; + +pub mod verify_record_commitment; +pub use self::verify_record_commitment::*; diff --git a/state/src/errors/state_values.rs b/state/src/errors/state_values.rs new file mode 100644 index 0000000000..c4ae7e45c6 --- /dev/null +++ b/state/src/errors/state_values.rs @@ -0,0 +1,5 @@ +#[derive(Debug, Error)] +pub enum StateValuesError { + #[error("state parameter `{}` not found in state file", _0)] + MissingParameter(String), +} diff --git a/state/src/errors/local_data_verification_error.rs b/state/src/errors/verify_local_data_commitment.rs similarity index 100% rename from state/src/errors/local_data_verification_error.rs rename to state/src/errors/verify_local_data_commitment.rs diff --git a/state/src/errors/record_verification_error.rs b/state/src/errors/verify_record_commitment.rs similarity index 79% rename from state/src/errors/record_verification_error.rs rename to state/src/errors/verify_record_commitment.rs index d44e4737f4..441eb25f1f 100644 --- a/state/src/errors/record_verification_error.rs +++ b/state/src/errors/verify_record_commitment.rs @@ -1,3 +1,5 @@ +use crate::InputValueError; + use snarkos_errors::{algorithms::CommitmentError, objects::account::AccountError}; use std::{io::Error as IOError, num::ParseIntError, str::ParseBoolError}; @@ -13,11 +15,8 @@ pub enum RecordVerificationError { #[error("{}", _0)] CommitmentError(#[from] CommitmentError), - #[error("expected parameter array of u8 bytes, found `{}`", _0)] - ExpectedBytes(String), - - #[error("expected integer parameter, found `{}`", _0)] - ExpectedInteger(String), + #[error("{}", _0)] + InputValueError(#[from] InputValueError), #[error("{}", _0)] IOError(#[from] IOError), diff --git a/state/src/lib.rs b/state/src/lib.rs index ff055bd082..40cfd206e8 100644 --- a/state/src/lib.rs +++ b/state/src/lib.rs @@ -9,3 +9,6 @@ pub use self::local_data_commitment::*; pub mod record_commitment; pub use self::record_commitment::*; + +pub mod utilities; +pub use self::utilities::*; diff --git a/state/src/local_data_commitment/state_values.rs b/state/src/local_data_commitment/state_values.rs index a15d0cffc4..d8dc715457 100644 --- a/state/src/local_data_commitment/state_values.rs +++ b/state/src/local_data_commitment/state_values.rs @@ -1,4 +1,46 @@ +use crate::{input_to_integer_string, input_to_u8_vec, StateValuesError}; + +use leo_typed::{InputValue, State as TypedState}; +use std::convert::TryFrom; + +static LEAF_INDEX_PARAMETER_STRING: &str = "leaf_index"; +static ROOT_PARAMETER_STRING: &str = "root"; + pub struct StateValues { pub leaf_index: u32, pub root: Vec, } + +impl TryFrom<&TypedState> for StateValues { + type Error = StateValuesError; + + fn try_from(state: &TypedState) -> Result { + // Lookup leaf index + let leaf_index_value = get_parameter_value(LEAF_INDEX_PARAMETER_STRING.to_owned(), state).unwrap(); + let leaf_index = input_to_integer_string(leaf_index_value) + .unwrap() + .parse::() + .unwrap(); + + // Lookup root + let root_value = get_parameter_value(ROOT_PARAMETER_STRING.to_owned(), state).unwrap(); + let root = input_to_u8_vec(root_value).unwrap(); + + Ok(Self { leaf_index, root }) + } +} + +fn get_parameter_value(name: String, state: &TypedState) -> Result { + let parameters = state.values(); + let matched_parameter = parameters + .iter() + .find(|(parameter, _value)| parameter.variable.name == name); + + match matched_parameter { + Some((_parameter, value_option)) => match value_option { + Some(value) => Ok(value.clone()), + None => Err(StateValuesError::MissingParameter(name)), + }, + None => Err(StateValuesError::MissingParameter(name)), + } +} diff --git a/state/src/local_data_commitment/verify_local_data_commitment.rs b/state/src/local_data_commitment/verify_local_data_commitment.rs index 71a3870179..51e52a415a 100644 --- a/state/src/local_data_commitment/verify_local_data_commitment.rs +++ b/state/src/local_data_commitment/verify_local_data_commitment.rs @@ -1,4 +1,4 @@ -use crate::{verify_record_commitment::verify_record_commitment, LocalDataVerificationError}; +use crate::{record_commitment::verify_record_commitment, LocalDataVerificationError, StateValues}; use leo_typed::Input as TypedInput; use snarkos_algorithms::commitment_tree::CommitmentMerklePath; @@ -9,6 +9,7 @@ use snarkos_models::{ dpc::DPCComponents, }; use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; +use std::convert::TryFrom; pub fn verify_local_data_commitment( typed_input: &TypedInput, @@ -19,13 +20,14 @@ pub fn verify_local_data_commitment( // verify record commitment let typed_record = typed_input.get_record(); let dpc_record_values = verify_record_commitment(typed_record, record_commitment_params).unwrap(); - let record_commitment: Vec = dpc_record_values.commitment; let record_serial_number: Vec = dpc_record_values.serial_number; // parse typed state values - let leaf_index: u32 = 0; - let root: Vec = vec![]; + let typed_state = typed_input.get_state(); + let state_values = StateValues::try_from(typed_state).unwrap(); + let leaf_index: u32 = state_values.leaf_index; + let root: Vec = state_values.root; // parse typed state leaf values let _path: Vec> = vec![]; diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index 10b6d14eec..443934b049 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -1,4 +1,4 @@ -use crate::RecordVerificationError; +use crate::{utilities::*, RecordVerificationError}; use leo_typed::{InputValue, Record as TypedRecord}; use snarkos_dpc::base_dpc::instantiated::Components; @@ -103,28 +103,3 @@ fn get_parameter_value(name: String, record: &TypedRecord) -> Result Err(RecordVerificationError::MissingParameter(name)), } } - -fn input_to_integer_string(input: InputValue) -> Result { - match input { - InputValue::Integer(_type, string) => Ok(string), - value => Err(RecordVerificationError::ExpectedInteger(value.to_string())), - } -} - -fn input_to_u8_vec(input: InputValue) -> Result, RecordVerificationError> { - let input_array = match input { - InputValue::Array(values) => values, - value => return Err(RecordVerificationError::ExpectedBytes(value.to_string())), - }; - - let mut result_vec = vec![]; - - for input in input_array { - let integer_string = input_to_integer_string(input)?; - let byte = integer_string.parse::()?; - - result_vec.push(byte); - } - - Ok(result_vec) -} diff --git a/state/src/utilities/input_value.rs b/state/src/utilities/input_value.rs new file mode 100644 index 0000000000..99299f7d58 --- /dev/null +++ b/state/src/utilities/input_value.rs @@ -0,0 +1,27 @@ +use crate::InputValueError; +use leo_typed::InputValue; + +pub fn input_to_integer_string(input: InputValue) -> Result { + match input { + InputValue::Integer(_type, string) => Ok(string), + value => Err(InputValueError::ExpectedInteger(value.to_string())), + } +} + +pub fn input_to_u8_vec(input: InputValue) -> Result, InputValueError> { + let input_array = match input { + InputValue::Array(values) => values, + value => return Err(InputValueError::ExpectedBytes(value.to_string())), + }; + + let mut result_vec = vec![]; + + for input in input_array { + let integer_string = input_to_integer_string(input)?; + let byte = integer_string.parse::()?; + + result_vec.push(byte); + } + + Ok(result_vec) +} diff --git a/state/src/utilities/mod.rs b/state/src/utilities/mod.rs new file mode 100644 index 0000000000..5166631852 --- /dev/null +++ b/state/src/utilities/mod.rs @@ -0,0 +1,2 @@ +pub mod input_value; +pub use self::input_value::*; From f986b21b1f8298f06b3c08be2060e3a68d63dd43 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 12:50:23 -0700 Subject: [PATCH 04/30] add typed state leaf values to parsing --- state/src/errors/mod.rs | 3 + state/src/errors/state_leaf_values.rs | 5 ++ .../state_leaf_values.rs | 58 +++++++++++++++++++ .../verify_local_data_commitment.rs | 16 ++--- state/src/utilities/input_value.rs | 17 ++++++ 5 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 state/src/errors/state_leaf_values.rs diff --git a/state/src/errors/mod.rs b/state/src/errors/mod.rs index 1add734877..cfa49d974c 100644 --- a/state/src/errors/mod.rs +++ b/state/src/errors/mod.rs @@ -1,6 +1,9 @@ pub mod input_value; pub use self::input_value::*; +pub mod state_leaf_values; +pub use self::state_leaf_values::*; + pub mod state_values; pub use self::state_values::*; diff --git a/state/src/errors/state_leaf_values.rs b/state/src/errors/state_leaf_values.rs new file mode 100644 index 0000000000..e8f49411b3 --- /dev/null +++ b/state/src/errors/state_leaf_values.rs @@ -0,0 +1,5 @@ +#[derive(Debug, Error)] +pub enum StateLeafValuesError { + #[error("state parameter `{}` not found in state file", _0)] + MissingParameter(String), +} diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs index a77e041571..29803450f3 100644 --- a/state/src/local_data_commitment/state_leaf_values.rs +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -1,6 +1,64 @@ +use crate::{input_to_integer_string, input_to_nested_u8_vec, input_to_u8_vec, StateLeafValuesError}; + +use leo_typed::{InputValue, StateLeaf as TypedStateLeaf}; +use std::convert::TryFrom; + +static PATH_PARAMETER_STRING: &str = "path"; +static MEMO_PARAMETER_STRING: &str = "memo"; +static NETWORK_ID_PARAMETER_STRING: &str = "network_id"; +static LEAF_RANDOMNESS_PARAMETER_STRING: &str = "leaf_randomness"; + pub struct StateLeafValues { pub path: Vec>, pub memo: Vec, pub network_id: u8, pub leaf_randomness: Vec, } + +impl TryFrom<&TypedStateLeaf> for StateLeafValues { + type Error = StateLeafValuesError; + + fn try_from(state_leaf: &TypedStateLeaf) -> Result { + // Lookup path + let path_value = get_parameter_value(PATH_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); + let path = input_to_nested_u8_vec(path_value).unwrap(); + + // Lookup memo + let memo_value = get_parameter_value(MEMO_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); + let memo = input_to_u8_vec(memo_value).unwrap(); + + // Lookup network id + let network_id_value = get_parameter_value(NETWORK_ID_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); + let network_id = input_to_integer_string(network_id_value) + .unwrap() + .parse::() + .unwrap(); + + // Lookup leaf randomness + let leaf_randomness_value = + get_parameter_value(LEAF_RANDOMNESS_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); + let leaf_randomness = input_to_u8_vec(leaf_randomness_value).unwrap(); + + Ok(Self { + path, + memo, + network_id, + leaf_randomness, + }) + } +} + +fn get_parameter_value(name: String, state: &TypedStateLeaf) -> Result { + let parameters = state.values(); + let matched_parameter = parameters + .iter() + .find(|(parameter, _value)| parameter.variable.name == name); + + match matched_parameter { + Some((_parameter, value_option)) => match value_option { + Some(value) => Ok(value.clone()), + None => Err(StateLeafValuesError::MissingParameter(name)), + }, + None => Err(StateLeafValuesError::MissingParameter(name)), + } +} diff --git a/state/src/local_data_commitment/verify_local_data_commitment.rs b/state/src/local_data_commitment/verify_local_data_commitment.rs index 51e52a415a..63f38c956e 100644 --- a/state/src/local_data_commitment/verify_local_data_commitment.rs +++ b/state/src/local_data_commitment/verify_local_data_commitment.rs @@ -1,4 +1,4 @@ -use crate::{record_commitment::verify_record_commitment, LocalDataVerificationError, StateValues}; +use crate::{record_commitment::verify_record_commitment, LocalDataVerificationError, StateLeafValues, StateValues}; use leo_typed::Input as TypedInput; use snarkos_algorithms::commitment_tree::CommitmentMerklePath; @@ -30,10 +30,12 @@ pub fn verify_local_data_commitment( let root: Vec = state_values.root; // parse typed state leaf values - let _path: Vec> = vec![]; - let memo: Vec = vec![]; - let network_id: Vec = vec![]; - let leaf_randomness: Vec = vec![]; + let typed_state_leaf = typed_input.get_state_leaf(); + let state_leaf_values = StateLeafValues::try_from(typed_state_leaf).unwrap(); + let _path: Vec> = state_leaf_values.path; + let memo: Vec = state_leaf_values.memo; + let network_id: u8 = state_leaf_values.network_id; + let leaf_randomness: Vec = state_leaf_values.leaf_randomness; // Select local data commitment input bytes let is_death = leaf_index < (Components::NUM_INPUT_RECORDS as u32); @@ -45,10 +47,10 @@ pub fn verify_local_data_commitment( }; // Construct local data commitment leaf - let leaf_randomness = Fp256::read(&leaf_randomness[..]).unwrap(); + let local_data_leaf_randomness = Fp256::read(&leaf_randomness[..]).unwrap(); let local_data_commitment_leaf = - LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &leaf_randomness).unwrap(); + LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &local_data_leaf_randomness).unwrap(); // Construct record commitment merkle path diff --git a/state/src/utilities/input_value.rs b/state/src/utilities/input_value.rs index 99299f7d58..9746011e80 100644 --- a/state/src/utilities/input_value.rs +++ b/state/src/utilities/input_value.rs @@ -25,3 +25,20 @@ pub fn input_to_u8_vec(input: InputValue) -> Result, InputValueError> { Ok(result_vec) } + +pub fn input_to_nested_u8_vec(input: InputValue) -> Result>, InputValueError> { + let inner_arrays = match input { + InputValue::Array(arrays) => arrays, + value => return Err(InputValueError::ExpectedBytes(value.to_string())), + }; + + let mut result_vec = vec![]; + + for input_array in inner_arrays { + let array = input_to_u8_vec(input_array)?; + + result_vec.push(array); + } + + Ok(result_vec) +} From 251783b9bca166ba850e2380b1f80a152e48dfb0 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 12:58:32 -0700 Subject: [PATCH 05/30] rename files --- ..._local_data_commitment.rs => local_data_commitment.rs} | 0 state/src/errors/mod.rs | 8 ++++---- .../{verify_record_commitment.rs => record_commitment.rs} | 0 ..._local_data_commitment.rs => local_data_commitment.rs} | 2 +- state/src/local_data_commitment/mod.rs | 4 ++-- state/src/record_commitment/mod.rs | 4 ++-- .../{verify_record_commitment.rs => record_commitment.rs} | 0 7 files changed, 9 insertions(+), 9 deletions(-) rename state/src/errors/{verify_local_data_commitment.rs => local_data_commitment.rs} (100%) rename state/src/errors/{verify_record_commitment.rs => record_commitment.rs} (100%) rename state/src/local_data_commitment/{verify_local_data_commitment.rs => local_data_commitment.rs} (96%) rename state/src/record_commitment/{verify_record_commitment.rs => record_commitment.rs} (100%) diff --git a/state/src/errors/verify_local_data_commitment.rs b/state/src/errors/local_data_commitment.rs similarity index 100% rename from state/src/errors/verify_local_data_commitment.rs rename to state/src/errors/local_data_commitment.rs diff --git a/state/src/errors/mod.rs b/state/src/errors/mod.rs index cfa49d974c..38a61a49ea 100644 --- a/state/src/errors/mod.rs +++ b/state/src/errors/mod.rs @@ -7,8 +7,8 @@ pub use self::state_leaf_values::*; pub mod state_values; pub use self::state_values::*; -pub mod verify_local_data_commitment; -pub use self::verify_local_data_commitment::*; +pub mod local_data_commitment; +pub use self::local_data_commitment::*; -pub mod verify_record_commitment; -pub use self::verify_record_commitment::*; +pub mod record_commitment; +pub use self::record_commitment::*; diff --git a/state/src/errors/verify_record_commitment.rs b/state/src/errors/record_commitment.rs similarity index 100% rename from state/src/errors/verify_record_commitment.rs rename to state/src/errors/record_commitment.rs diff --git a/state/src/local_data_commitment/verify_local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs similarity index 96% rename from state/src/local_data_commitment/verify_local_data_commitment.rs rename to state/src/local_data_commitment/local_data_commitment.rs index 63f38c956e..09bceda873 100644 --- a/state/src/local_data_commitment/verify_local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -1,4 +1,4 @@ -use crate::{record_commitment::verify_record_commitment, LocalDataVerificationError, StateLeafValues, StateValues}; +use crate::{verify_record_commitment, LocalDataVerificationError, StateLeafValues, StateValues}; use leo_typed::Input as TypedInput; use snarkos_algorithms::commitment_tree::CommitmentMerklePath; diff --git a/state/src/local_data_commitment/mod.rs b/state/src/local_data_commitment/mod.rs index 2f13f6333c..77a5949d51 100644 --- a/state/src/local_data_commitment/mod.rs +++ b/state/src/local_data_commitment/mod.rs @@ -4,5 +4,5 @@ pub use self::state_values::*; pub mod state_leaf_values; pub use self::state_leaf_values::*; -pub mod verify_local_data_commitment; -pub use self::verify_local_data_commitment::*; +pub mod local_data_commitment; +pub use self::local_data_commitment::*; diff --git a/state/src/record_commitment/mod.rs b/state/src/record_commitment/mod.rs index 9f92e4a742..9d2f688f6e 100644 --- a/state/src/record_commitment/mod.rs +++ b/state/src/record_commitment/mod.rs @@ -1,5 +1,5 @@ pub mod dpc_record_values; pub use self::dpc_record_values::*; -pub mod verify_record_commitment; -pub use self::verify_record_commitment::*; +pub mod record_commitment; +pub use self::record_commitment::*; diff --git a/state/src/record_commitment/verify_record_commitment.rs b/state/src/record_commitment/record_commitment.rs similarity index 100% rename from state/src/record_commitment/verify_record_commitment.rs rename to state/src/record_commitment/record_commitment.rs From 7ff3fb1b96ac2a96398b223441fc3ad8613964df Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 13:16:29 -0700 Subject: [PATCH 06/30] handle errors --- state/src/errors/dpc_record_values.rs | 23 ++++++++++++++++ state/src/errors/local_data_commitment.rs | 26 ++++++++++++++++++- state/src/errors/mod.rs | 3 +++ state/src/errors/record_commitment.rs | 20 +++----------- state/src/errors/state_leaf_values.rs | 15 ++++++++++- state/src/errors/state_values.rs | 13 ++++++++++ .../local_data_commitment.rs | 20 +++++++------- .../state_leaf_values.rs | 20 ++++++-------- .../src/local_data_commitment/state_values.rs | 11 +++----- .../record_commitment/dpc_record_values.rs | 10 +++---- 10 files changed, 108 insertions(+), 53 deletions(-) create mode 100644 state/src/errors/dpc_record_values.rs diff --git a/state/src/errors/dpc_record_values.rs b/state/src/errors/dpc_record_values.rs new file mode 100644 index 0000000000..d063ac8824 --- /dev/null +++ b/state/src/errors/dpc_record_values.rs @@ -0,0 +1,23 @@ +use crate::InputValueError; + +use snarkos_errors::objects::account::AccountError; + +use std::{num::ParseIntError, str::ParseBoolError}; + +#[derive(Debug, Error)] +pub enum DPCRecordValuesError { + #[error("{}", _0)] + AccountError(#[from] AccountError), + + #[error("{}", _0)] + InputValueError(#[from] InputValueError), + + #[error("record parameter `{}` not found in state file", _0)] + MissingParameter(String), + + #[error("{}", _0)] + ParseBoolError(#[from] ParseBoolError), + + #[error("{}", _0)] + ParseIntError(#[from] ParseIntError), +} diff --git a/state/src/errors/local_data_commitment.rs b/state/src/errors/local_data_commitment.rs index e3e116eb9b..ecdc2b8c18 100644 --- a/state/src/errors/local_data_commitment.rs +++ b/state/src/errors/local_data_commitment.rs @@ -1,2 +1,26 @@ +use crate::{RecordVerificationError, StateLeafValuesError, StateValuesError}; + +use snarkos_errors::algorithms::{CommitmentError, MerkleError}; + +use std::io::Error as IOError; + #[derive(Debug, Error)] -pub enum LocalDataVerificationError {} +pub enum LocalDataVerificationError { + #[error("{}", _0)] + CommitmentError(#[from] CommitmentError), + + #[error("{}", _0)] + MerkleError(#[from] MerkleError), + + #[error("{}", _0)] + IOError(#[from] IOError), + + #[error("{}", _0)] + RecordVerificationError(#[from] RecordVerificationError), + + #[error("{}", _0)] + StateLeafValuesError(#[from] StateLeafValuesError), + + #[error("{}", _0)] + StateValuesError(#[from] StateValuesError), +} diff --git a/state/src/errors/mod.rs b/state/src/errors/mod.rs index 38a61a49ea..fd5b2ade5a 100644 --- a/state/src/errors/mod.rs +++ b/state/src/errors/mod.rs @@ -1,3 +1,6 @@ +pub mod dpc_record_values; +pub use self::dpc_record_values::*; + pub mod input_value; pub use self::input_value::*; diff --git a/state/src/errors/record_commitment.rs b/state/src/errors/record_commitment.rs index 441eb25f1f..a00bb8eead 100644 --- a/state/src/errors/record_commitment.rs +++ b/state/src/errors/record_commitment.rs @@ -1,14 +1,11 @@ -use crate::InputValueError; +use crate::DPCRecordValuesError; -use snarkos_errors::{algorithms::CommitmentError, objects::account::AccountError}; +use snarkos_errors::algorithms::CommitmentError; -use std::{io::Error as IOError, num::ParseIntError, str::ParseBoolError}; +use std::io::Error as IOError; #[derive(Debug, Error)] pub enum RecordVerificationError { - #[error("{}", _0)] - AccountError(#[from] AccountError), - #[error("record commitment does not match record data")] CommitmentsDoNotMatch, @@ -16,17 +13,8 @@ pub enum RecordVerificationError { CommitmentError(#[from] CommitmentError), #[error("{}", _0)] - InputValueError(#[from] InputValueError), + DPCRecordValuesError(#[from] DPCRecordValuesError), #[error("{}", _0)] IOError(#[from] IOError), - - #[error("record parameter `{}` not found in state file", _0)] - MissingParameter(String), - - #[error("{}", _0)] - ParseBoolError(#[from] ParseBoolError), - - #[error("{}", _0)] - ParseIntError(#[from] ParseIntError), } diff --git a/state/src/errors/state_leaf_values.rs b/state/src/errors/state_leaf_values.rs index e8f49411b3..60237452e9 100644 --- a/state/src/errors/state_leaf_values.rs +++ b/state/src/errors/state_leaf_values.rs @@ -1,5 +1,18 @@ +use crate::InputValueError; + +use std::{num::ParseIntError, str::ParseBoolError}; + #[derive(Debug, Error)] pub enum StateLeafValuesError { - #[error("state parameter `{}` not found in state file", _0)] + #[error("{}", _0)] + InputValueError(#[from] InputValueError), + + #[error("state leaf parameter `{}` not found in state file", _0)] MissingParameter(String), + + #[error("{}", _0)] + ParseBoolError(#[from] ParseBoolError), + + #[error("{}", _0)] + ParseIntError(#[from] ParseIntError), } diff --git a/state/src/errors/state_values.rs b/state/src/errors/state_values.rs index c4ae7e45c6..7d079e6b25 100644 --- a/state/src/errors/state_values.rs +++ b/state/src/errors/state_values.rs @@ -1,5 +1,18 @@ +use crate::InputValueError; + +use std::{num::ParseIntError, str::ParseBoolError}; + #[derive(Debug, Error)] pub enum StateValuesError { + #[error("{}", _0)] + InputValueError(#[from] InputValueError), + #[error("state parameter `{}` not found in state file", _0)] MissingParameter(String), + + #[error("{}", _0)] + ParseBoolError(#[from] ParseBoolError), + + #[error("{}", _0)] + ParseIntError(#[from] ParseIntError), } diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index 09bceda873..a2cb6567bf 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -19,19 +19,19 @@ pub fn verify_local_data_commitment( ) -> Result { // verify record commitment let typed_record = typed_input.get_record(); - let dpc_record_values = verify_record_commitment(typed_record, record_commitment_params).unwrap(); + let dpc_record_values = verify_record_commitment(typed_record, record_commitment_params)?; let record_commitment: Vec = dpc_record_values.commitment; let record_serial_number: Vec = dpc_record_values.serial_number; // parse typed state values let typed_state = typed_input.get_state(); - let state_values = StateValues::try_from(typed_state).unwrap(); + let state_values = StateValues::try_from(typed_state)?; let leaf_index: u32 = state_values.leaf_index; let root: Vec = state_values.root; // parse typed state leaf values let typed_state_leaf = typed_input.get_state_leaf(); - let state_leaf_values = StateLeafValues::try_from(typed_state_leaf).unwrap(); + let state_leaf_values = StateLeafValues::try_from(typed_state_leaf)?; let _path: Vec> = state_leaf_values.path; let memo: Vec = state_leaf_values.memo; let network_id: u8 = state_leaf_values.network_id; @@ -41,16 +41,16 @@ pub fn verify_local_data_commitment( let is_death = leaf_index < (Components::NUM_INPUT_RECORDS as u32); let input_bytes = if is_death { - to_bytes![record_serial_number, record_commitment, memo, network_id].unwrap() + to_bytes![record_serial_number, record_commitment, memo, network_id]? } else { - to_bytes![record_commitment, memo, network_id].unwrap() + to_bytes![record_commitment, memo, network_id]? }; // Construct local data commitment leaf - let local_data_leaf_randomness = Fp256::read(&leaf_randomness[..]).unwrap(); + let local_data_leaf_randomness = Fp256::read(&leaf_randomness[..])?; let local_data_commitment_leaf = - LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &local_data_leaf_randomness).unwrap(); + LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &local_data_leaf_randomness)?; // Construct record commitment merkle path @@ -74,11 +74,9 @@ pub fn verify_local_data_commitment( }; // Check record commitment merkle path is valid for the given local data commitment root - let local_data_commitment_root = Fp256::read(&root[..]).unwrap(); + let local_data_commitment_root = Fp256::read(&root[..])?; - let result = local_data_merkle_path - .verify(&local_data_commitment_root, &local_data_commitment_leaf) - .unwrap(); + let result = local_data_merkle_path.verify(&local_data_commitment_root, &local_data_commitment_leaf)?; Ok(result) } diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs index 29803450f3..3b60e5037a 100644 --- a/state/src/local_data_commitment/state_leaf_values.rs +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -20,24 +20,20 @@ impl TryFrom<&TypedStateLeaf> for StateLeafValues { fn try_from(state_leaf: &TypedStateLeaf) -> Result { // Lookup path - let path_value = get_parameter_value(PATH_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); - let path = input_to_nested_u8_vec(path_value).unwrap(); + let path_value = get_parameter_value(PATH_PARAMETER_STRING.to_owned(), state_leaf)?; + let path = input_to_nested_u8_vec(path_value)?; // Lookup memo - let memo_value = get_parameter_value(MEMO_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); - let memo = input_to_u8_vec(memo_value).unwrap(); + let memo_value = get_parameter_value(MEMO_PARAMETER_STRING.to_owned(), state_leaf)?; + let memo = input_to_u8_vec(memo_value)?; // Lookup network id - let network_id_value = get_parameter_value(NETWORK_ID_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); - let network_id = input_to_integer_string(network_id_value) - .unwrap() - .parse::() - .unwrap(); + let network_id_value = get_parameter_value(NETWORK_ID_PARAMETER_STRING.to_owned(), state_leaf)?; + let network_id = input_to_integer_string(network_id_value)?.parse::()?; // Lookup leaf randomness - let leaf_randomness_value = - get_parameter_value(LEAF_RANDOMNESS_PARAMETER_STRING.to_owned(), state_leaf).unwrap(); - let leaf_randomness = input_to_u8_vec(leaf_randomness_value).unwrap(); + let leaf_randomness_value = get_parameter_value(LEAF_RANDOMNESS_PARAMETER_STRING.to_owned(), state_leaf)?; + let leaf_randomness = input_to_u8_vec(leaf_randomness_value)?; Ok(Self { path, diff --git a/state/src/local_data_commitment/state_values.rs b/state/src/local_data_commitment/state_values.rs index d8dc715457..bb848a79d0 100644 --- a/state/src/local_data_commitment/state_values.rs +++ b/state/src/local_data_commitment/state_values.rs @@ -16,15 +16,12 @@ impl TryFrom<&TypedState> for StateValues { fn try_from(state: &TypedState) -> Result { // Lookup leaf index - let leaf_index_value = get_parameter_value(LEAF_INDEX_PARAMETER_STRING.to_owned(), state).unwrap(); - let leaf_index = input_to_integer_string(leaf_index_value) - .unwrap() - .parse::() - .unwrap(); + let leaf_index_value = get_parameter_value(LEAF_INDEX_PARAMETER_STRING.to_owned(), state)?; + let leaf_index = input_to_integer_string(leaf_index_value)?.parse::()?; // Lookup root - let root_value = get_parameter_value(ROOT_PARAMETER_STRING.to_owned(), state).unwrap(); - let root = input_to_u8_vec(root_value).unwrap(); + let root_value = get_parameter_value(ROOT_PARAMETER_STRING.to_owned(), state)?; + let root = input_to_u8_vec(root_value)?; Ok(Self { leaf_index, root }) } diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index 443934b049..4559383a55 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -1,4 +1,4 @@ -use crate::{utilities::*, RecordVerificationError}; +use crate::{utilities::*, DPCRecordValuesError}; use leo_typed::{InputValue, Record as TypedRecord}; use snarkos_dpc::base_dpc::instantiated::Components; @@ -30,7 +30,7 @@ pub struct DPCRecordValues { } impl TryFrom<&TypedRecord> for DPCRecordValues { - type Error = RecordVerificationError; + type Error = DPCRecordValuesError; fn try_from(record: &TypedRecord) -> Result { // Lookup serial number @@ -89,7 +89,7 @@ impl TryFrom<&TypedRecord> for DPCRecordValues { } } -fn get_parameter_value(name: String, record: &TypedRecord) -> Result { +fn get_parameter_value(name: String, record: &TypedRecord) -> Result { let parameters = record.values(); let matched_parameter = parameters .iter() @@ -98,8 +98,8 @@ fn get_parameter_value(name: String, record: &TypedRecord) -> Result match value_option { Some(value) => Ok(value.clone()), - None => Err(RecordVerificationError::MissingParameter(name)), + None => Err(DPCRecordValuesError::MissingParameter(name)), }, - None => Err(RecordVerificationError::MissingParameter(name)), + None => Err(DPCRecordValuesError::MissingParameter(name)), } } From a50dfb07bf0aef2e87459384ed78cc15233719b0 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 13:29:02 -0700 Subject: [PATCH 07/30] add find input function to utilities --- state/src/errors/dpc_record_values.rs | 3 -- state/src/errors/input_value.rs | 3 ++ state/src/errors/state_leaf_values.rs | 3 -- state/src/errors/state_values.rs | 3 -- .../state_leaf_values.rs | 29 ++++---------- .../src/local_data_commitment/state_values.rs | 25 +++--------- .../record_commitment/dpc_record_values.rs | 40 ++++++------------- state/src/utilities/input_value.rs | 20 +++++++++- 8 files changed, 49 insertions(+), 77 deletions(-) diff --git a/state/src/errors/dpc_record_values.rs b/state/src/errors/dpc_record_values.rs index d063ac8824..f659b134b0 100644 --- a/state/src/errors/dpc_record_values.rs +++ b/state/src/errors/dpc_record_values.rs @@ -12,9 +12,6 @@ pub enum DPCRecordValuesError { #[error("{}", _0)] InputValueError(#[from] InputValueError), - #[error("record parameter `{}` not found in state file", _0)] - MissingParameter(String), - #[error("{}", _0)] ParseBoolError(#[from] ParseBoolError), diff --git a/state/src/errors/input_value.rs b/state/src/errors/input_value.rs index 0af7057d5d..1504d0ebef 100644 --- a/state/src/errors/input_value.rs +++ b/state/src/errors/input_value.rs @@ -8,6 +8,9 @@ pub enum InputValueError { #[error("expected integer parameter, found `{}`", _0)] ExpectedInteger(String), + #[error("input parameter `{}` not found in state file", _0)] + MissingParameter(String), + #[error("{}", _0)] ParseIntError(#[from] ParseIntError), } diff --git a/state/src/errors/state_leaf_values.rs b/state/src/errors/state_leaf_values.rs index 60237452e9..b14620eb89 100644 --- a/state/src/errors/state_leaf_values.rs +++ b/state/src/errors/state_leaf_values.rs @@ -7,9 +7,6 @@ pub enum StateLeafValuesError { #[error("{}", _0)] InputValueError(#[from] InputValueError), - #[error("state leaf parameter `{}` not found in state file", _0)] - MissingParameter(String), - #[error("{}", _0)] ParseBoolError(#[from] ParseBoolError), diff --git a/state/src/errors/state_values.rs b/state/src/errors/state_values.rs index 7d079e6b25..72b47c51bc 100644 --- a/state/src/errors/state_values.rs +++ b/state/src/errors/state_values.rs @@ -7,9 +7,6 @@ pub enum StateValuesError { #[error("{}", _0)] InputValueError(#[from] InputValueError), - #[error("state parameter `{}` not found in state file", _0)] - MissingParameter(String), - #[error("{}", _0)] ParseBoolError(#[from] ParseBoolError), diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs index 3b60e5037a..b0a9ef34b7 100644 --- a/state/src/local_data_commitment/state_leaf_values.rs +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -1,6 +1,6 @@ -use crate::{input_to_integer_string, input_to_nested_u8_vec, input_to_u8_vec, StateLeafValuesError}; +use crate::{find_input, input_to_integer_string, input_to_nested_u8_vec, input_to_u8_vec, StateLeafValuesError}; -use leo_typed::{InputValue, StateLeaf as TypedStateLeaf}; +use leo_typed::StateLeaf as TypedStateLeaf; use std::convert::TryFrom; static PATH_PARAMETER_STRING: &str = "path"; @@ -19,20 +19,22 @@ impl TryFrom<&TypedStateLeaf> for StateLeafValues { type Error = StateLeafValuesError; fn try_from(state_leaf: &TypedStateLeaf) -> Result { + let parameters = state_leaf.values(); + // Lookup path - let path_value = get_parameter_value(PATH_PARAMETER_STRING.to_owned(), state_leaf)?; + let path_value = find_input(PATH_PARAMETER_STRING.to_owned(), ¶meters)?; let path = input_to_nested_u8_vec(path_value)?; // Lookup memo - let memo_value = get_parameter_value(MEMO_PARAMETER_STRING.to_owned(), state_leaf)?; + let memo_value = find_input(MEMO_PARAMETER_STRING.to_owned(), ¶meters)?; let memo = input_to_u8_vec(memo_value)?; // Lookup network id - let network_id_value = get_parameter_value(NETWORK_ID_PARAMETER_STRING.to_owned(), state_leaf)?; + let network_id_value = find_input(NETWORK_ID_PARAMETER_STRING.to_owned(), ¶meters)?; let network_id = input_to_integer_string(network_id_value)?.parse::()?; // Lookup leaf randomness - let leaf_randomness_value = get_parameter_value(LEAF_RANDOMNESS_PARAMETER_STRING.to_owned(), state_leaf)?; + let leaf_randomness_value = find_input(LEAF_RANDOMNESS_PARAMETER_STRING.to_owned(), ¶meters)?; let leaf_randomness = input_to_u8_vec(leaf_randomness_value)?; Ok(Self { @@ -43,18 +45,3 @@ impl TryFrom<&TypedStateLeaf> for StateLeafValues { }) } } - -fn get_parameter_value(name: String, state: &TypedStateLeaf) -> Result { - let parameters = state.values(); - let matched_parameter = parameters - .iter() - .find(|(parameter, _value)| parameter.variable.name == name); - - match matched_parameter { - Some((_parameter, value_option)) => match value_option { - Some(value) => Ok(value.clone()), - None => Err(StateLeafValuesError::MissingParameter(name)), - }, - None => Err(StateLeafValuesError::MissingParameter(name)), - } -} diff --git a/state/src/local_data_commitment/state_values.rs b/state/src/local_data_commitment/state_values.rs index bb848a79d0..cd017b2d4e 100644 --- a/state/src/local_data_commitment/state_values.rs +++ b/state/src/local_data_commitment/state_values.rs @@ -1,6 +1,6 @@ -use crate::{input_to_integer_string, input_to_u8_vec, StateValuesError}; +use crate::{find_input, input_to_integer_string, input_to_u8_vec, StateValuesError}; -use leo_typed::{InputValue, State as TypedState}; +use leo_typed::State as TypedState; use std::convert::TryFrom; static LEAF_INDEX_PARAMETER_STRING: &str = "leaf_index"; @@ -15,29 +15,16 @@ impl TryFrom<&TypedState> for StateValues { type Error = StateValuesError; fn try_from(state: &TypedState) -> Result { + let parameters = state.values(); + // Lookup leaf index - let leaf_index_value = get_parameter_value(LEAF_INDEX_PARAMETER_STRING.to_owned(), state)?; + let leaf_index_value = find_input(LEAF_INDEX_PARAMETER_STRING.to_owned(), ¶meters)?; let leaf_index = input_to_integer_string(leaf_index_value)?.parse::()?; // Lookup root - let root_value = get_parameter_value(ROOT_PARAMETER_STRING.to_owned(), state)?; + let root_value = find_input(ROOT_PARAMETER_STRING.to_owned(), ¶meters)?; let root = input_to_u8_vec(root_value)?; Ok(Self { leaf_index, root }) } } - -fn get_parameter_value(name: String, state: &TypedState) -> Result { - let parameters = state.values(); - let matched_parameter = parameters - .iter() - .find(|(parameter, _value)| parameter.variable.name == name); - - match matched_parameter { - Some((_parameter, value_option)) => match value_option { - Some(value) => Ok(value.clone()), - None => Err(StateValuesError::MissingParameter(name)), - }, - None => Err(StateValuesError::MissingParameter(name)), - } -} diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index 4559383a55..5460d0bb46 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -1,5 +1,5 @@ use crate::{utilities::*, DPCRecordValuesError}; -use leo_typed::{InputValue, Record as TypedRecord}; +use leo_typed::Record as TypedRecord; use snarkos_dpc::base_dpc::instantiated::Components; use snarkos_objects::AccountAddress; @@ -33,45 +33,46 @@ impl TryFrom<&TypedRecord> for DPCRecordValues { type Error = DPCRecordValuesError; fn try_from(record: &TypedRecord) -> Result { + let parameters = record.values(); + // Lookup serial number - let serial_number_value = get_parameter_value(SERIAL_NUMBER_PARAMETER_STRING.to_owned(), record)?; + let serial_number_value = find_input(SERIAL_NUMBER_PARAMETER_STRING.to_owned(), ¶meters)?; let serial_number = input_to_u8_vec(serial_number_value)?; // Lookup record owner - let owner_value = get_parameter_value(OWNER_PARAMETER_STRING.to_owned(), record)?; + let owner_value = find_input(OWNER_PARAMETER_STRING.to_owned(), ¶meters)?; let owner = AccountAddress::::from_str(&format!("{}", owner_value))?; // Lookup record is_dummy - let is_dummy_value = get_parameter_value(IS_DUMMY_PARAMETER_STRING.to_owned(), record)?; + let is_dummy_value = find_input(IS_DUMMY_PARAMETER_STRING.to_owned(), ¶meters)?; let is_dummy = is_dummy_value.to_string().parse::()?; // Lookup record value - let value_value = get_parameter_value(VALUE_PARAMETER_STRING.to_owned(), record)?; + let value_value = find_input(VALUE_PARAMETER_STRING.to_owned(), ¶meters)?; let value = input_to_integer_string(value_value)?.parse::()?; // Lookup record payload - let payload_value = get_parameter_value(PAYLOAD_PARAMETER_STRING.to_owned(), record)?; + let payload_value = find_input(PAYLOAD_PARAMETER_STRING.to_owned(), ¶meters)?; let payload = input_to_u8_vec(payload_value)?; // Lookup record birth program id - let birth_program_id_value = get_parameter_value(BIRTH_PROGRAM_ID_PARAMETER_STRING.to_owned(), record)?; + let birth_program_id_value = find_input(BIRTH_PROGRAM_ID_PARAMETER_STRING.to_owned(), ¶meters)?; let birth_program_id = input_to_u8_vec(birth_program_id_value)?; // Lookup record death program id - let death_program_id_value = get_parameter_value(DEATH_PROGRAM_ID_PARAMETER_STRING.to_owned(), record)?; + let death_program_id_value = find_input(DEATH_PROGRAM_ID_PARAMETER_STRING.to_owned(), ¶meters)?; let death_program_id = input_to_u8_vec(death_program_id_value)?; // Lookup record serial number nonce - let serial_number_nonce_value = get_parameter_value(SERIAL_NUMBER_NONCE_PARAMETER_STRING.to_owned(), record)?; + let serial_number_nonce_value = find_input(SERIAL_NUMBER_NONCE_PARAMETER_STRING.to_owned(), ¶meters)?; let serial_number_nonce = input_to_u8_vec(serial_number_nonce_value)?; // Lookup record commitment - let commitment_value = get_parameter_value(COMMITMENT_PARAMETER_STRING.to_owned(), record)?; + let commitment_value = find_input(COMMITMENT_PARAMETER_STRING.to_owned(), ¶meters)?; let commitment = input_to_u8_vec(commitment_value)?; // Lookup record commitment randomness - let commitment_randomness_value = - get_parameter_value(COMMITMENT_RANDOMNESS_PARAMETER_STRING.to_owned(), record)?; + let commitment_randomness_value = find_input(COMMITMENT_RANDOMNESS_PARAMETER_STRING.to_owned(), ¶meters)?; let commitment_randomness = input_to_u8_vec(commitment_randomness_value)?; Ok(Self { @@ -88,18 +89,3 @@ impl TryFrom<&TypedRecord> for DPCRecordValues { }) } } - -fn get_parameter_value(name: String, record: &TypedRecord) -> Result { - let parameters = record.values(); - let matched_parameter = parameters - .iter() - .find(|(parameter, _value)| parameter.variable.name == name); - - match matched_parameter { - Some((_parameter, value_option)) => match value_option { - Some(value) => Ok(value.clone()), - None => Err(DPCRecordValuesError::MissingParameter(name)), - }, - None => Err(DPCRecordValuesError::MissingParameter(name)), - } -} diff --git a/state/src/utilities/input_value.rs b/state/src/utilities/input_value.rs index 9746011e80..0e427a3bc7 100644 --- a/state/src/utilities/input_value.rs +++ b/state/src/utilities/input_value.rs @@ -1,5 +1,23 @@ use crate::InputValueError; -use leo_typed::InputValue; +use leo_typed::{InputValue, Parameter}; +use std::collections::HashMap; + +pub fn find_input( + name: String, + parameters: &HashMap>, +) -> Result { + let matched_parameter = parameters + .iter() + .find(|(parameter, _value)| parameter.variable.name == name); + + match matched_parameter { + Some((_parameter, value_option)) => match value_option { + Some(value) => Ok(value.clone()), + None => Err(InputValueError::MissingParameter(name)), + }, + None => Err(InputValueError::MissingParameter(name)), + } +} pub fn input_to_integer_string(input: InputValue) -> Result { match input { From 61bafc96a950185f93de0b2202745985d25c1637 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 15:35:32 -0700 Subject: [PATCH 08/30] add verify_record_commitment test --- .../local_data_commitment.rs | 1 + .../state_leaf_values.rs | 2 +- .../src/local_data_commitment/state_values.rs | 2 +- .../record_commitment/dpc_record_values.rs | 3 +- .../record_commitment/record_commitment.rs | 8 ++++-- state/src/utilities/input_value.rs | 1 + state/tests/inputs/test.state | 23 +++++++++++++++ state/tests/mod.rs | 2 ++ state/tests/test_verify_record_commitment.rs | 28 +++++++++++++++++++ 9 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 state/tests/inputs/test.state create mode 100644 state/tests/test_verify_record_commitment.rs diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index a2cb6567bf..1cf1888597 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -9,6 +9,7 @@ use snarkos_models::{ dpc::DPCComponents, }; use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; + use std::convert::TryFrom; pub fn verify_local_data_commitment( diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs index b0a9ef34b7..4babf398f2 100644 --- a/state/src/local_data_commitment/state_leaf_values.rs +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -1,6 +1,6 @@ use crate::{find_input, input_to_integer_string, input_to_nested_u8_vec, input_to_u8_vec, StateLeafValuesError}; - use leo_typed::StateLeaf as TypedStateLeaf; + use std::convert::TryFrom; static PATH_PARAMETER_STRING: &str = "path"; diff --git a/state/src/local_data_commitment/state_values.rs b/state/src/local_data_commitment/state_values.rs index cd017b2d4e..5a71e19395 100644 --- a/state/src/local_data_commitment/state_values.rs +++ b/state/src/local_data_commitment/state_values.rs @@ -1,6 +1,6 @@ use crate::{find_input, input_to_integer_string, input_to_u8_vec, StateValuesError}; - use leo_typed::State as TypedState; + use std::convert::TryFrom; static LEAF_INDEX_PARAMETER_STRING: &str = "leaf_index"; diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index 5460d0bb46..986eaee90d 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -3,13 +3,14 @@ use leo_typed::Record as TypedRecord; use snarkos_dpc::base_dpc::instantiated::Components; use snarkos_objects::AccountAddress; + use std::{convert::TryFrom, str::FromStr}; static SERIAL_NUMBER_PARAMETER_STRING: &str = "serial_number"; static OWNER_PARAMETER_STRING: &str = "owner"; static IS_DUMMY_PARAMETER_STRING: &str = "is_dummy"; static VALUE_PARAMETER_STRING: &str = "value"; -static PAYLOAD_PARAMETER_STRING: &str = "parameter"; +static PAYLOAD_PARAMETER_STRING: &str = "payload"; static BIRTH_PROGRAM_ID_PARAMETER_STRING: &str = "birth_program_id"; static DEATH_PROGRAM_ID_PARAMETER_STRING: &str = "death_program_id"; static SERIAL_NUMBER_NONCE_PARAMETER_STRING: &str = "serial_number_nonce"; diff --git a/state/src/record_commitment/record_commitment.rs b/state/src/record_commitment/record_commitment.rs index 52ead66821..9adea95076 100644 --- a/state/src/record_commitment/record_commitment.rs +++ b/state/src/record_commitment/record_commitment.rs @@ -2,8 +2,9 @@ use crate::{DPCRecordValues, RecordVerificationError}; use leo_typed::Record as TypedRecord; use snarkos_dpc::base_dpc::instantiated::RecordCommitment; -use snarkos_models::{algorithms::CommitmentScheme, curves::Fp256}; +use snarkos_models::algorithms::CommitmentScheme; use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; + use std::convert::TryFrom; pub fn verify_record_commitment( @@ -23,8 +24,9 @@ pub fn verify_record_commitment( record.serial_number_nonce ]?; - let commitment = Fp256::read(&record.commitment[..])?; - let commitment_randomness = Fp256::read(&record.commitment_randomness[..])?; + let commitment = ::Output::read(&record.commitment[..])?; + let commitment_randomness = + ::Randomness::read(&record.commitment_randomness[..])?; let record_commitment = RecordCommitment::commit( &record_commitment_params, diff --git a/state/src/utilities/input_value.rs b/state/src/utilities/input_value.rs index 0e427a3bc7..e453093d8f 100644 --- a/state/src/utilities/input_value.rs +++ b/state/src/utilities/input_value.rs @@ -1,5 +1,6 @@ use crate::InputValueError; use leo_typed::{InputValue, Parameter}; + use std::collections::HashMap; pub fn find_input( diff --git a/state/tests/inputs/test.state b/state/tests/inputs/test.state new file mode 100644 index 0000000000..bcf404045f --- /dev/null +++ b/state/tests/inputs/test.state @@ -0,0 +1,23 @@ +[[public]] +[state] +leaf_index: u32 = 0; +root: u8[32] = [0u8; 32]; + +[[private]] +[record] +serial_number: u8[32] = [0u8; 32]; +commitment: u8[32] = [24, 156, 6, 189, 180, 191, 65, 243, 196, 227, 127, 239, 207, 46, 119, 151, 6, 98, 159, 197, 6, 239, 1, 149, 94, 119, 37, 190, 168, 146, 198, 6]; +owner: address = aleo1daxej63vwrmn2zhl4dymygagh89k5d2vaw6rjauueme7le6k2q8sjn0ng9; +is_dummy: bool = false; +value: u64 = 13895627391323573723; +payload: u8[32] = [235, 120, 28, 41, 42, 46, 237, 32, 50, 70, 185, 70, 180, 174, 198, 169, 149, 118, 227, 124, 192, 36, 43, 2, 239, 2, 207, 166, 142, 240, 246, 39]; +birth_program_id: u8[48] = [89, 70, 116, 103, 190, 86, 194, 133, 37, 77, 113, 166, 160, 156, 98, 252, 16, 219, 94, 12, 214, 12, 151, 139, 239, 1, 79, 79, 86, 235, 209, 168, 240, 156, 224, 86, 35, 63, 185, 196, 0, 10, 148, 56, 92, 199, 45, 0]; +death_program_id: u8[48] = [89, 70, 116, 103, 190, 86, 194, 133, 37, 77, 113, 166, 160, 156, 98, 252, 16, 219, 94, 12, 214, 12, 151, 139, 239, 1, 79, 79, 86, 235, 209, 168, 240, 156, 224, 86, 35, 63, 185, 196, 0, 10, 148, 56, 92, 199, 45, 0]; +serial_number_nonce: u8[32] = [13, 163, 44, 146, 30, 254, 39, 255, 41, 20, 154, 181, 69, 34, 205, 82, 37, 173, 21, 57, 100, 180, 40, 7, 57, 209, 107, 89, 142, 91, 122, 16]; +commitment_randomness: u8[32] = [55, 189, 0, 182, 148, 137, 120, 223, 121, 7, 140, 240, 100, 202, 196, 41, 236, 128, 38, 189, 60, 59, 23, 210, 25, 102, 65, 117, 38, 140, 136, 1]; + +[state_leaf] +path: u8[32][2] = [ [0u8; 32], [0u8; 32] ]; +memo: u8[32] = [0u8; 32]; +network_id: u8 = 0; +leaf_randomness: u8[32] = [0u8; 32]; \ No newline at end of file diff --git a/state/tests/mod.rs b/state/tests/mod.rs index 981d4655af..39d7ec66f8 100644 --- a/state/tests/mod.rs +++ b/state/tests/mod.rs @@ -1 +1,3 @@ // mod test; + +mod test_verify_record_commitment; diff --git a/state/tests/test_verify_record_commitment.rs b/state/tests/test_verify_record_commitment.rs new file mode 100644 index 0000000000..6defe9e344 --- /dev/null +++ b/state/tests/test_verify_record_commitment.rs @@ -0,0 +1,28 @@ +use snarkos_dpc::base_dpc::instantiated::*; + +use leo_input::LeoInputParser; +use leo_state::verify_record_commitment; +use leo_typed::Input; +use rand::SeedableRng; +use rand_xorshift::XorShiftRng; + +#[test] +fn test_verify_record_from_file() { + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); + + // Generate parameters for the record commitment scheme + let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); + + // Load test record state file from `inputs/test.state` + let file_bytes = include_bytes!("inputs/test.state"); + let file_string = String::from_utf8_lossy(file_bytes); + let file = LeoInputParser::parse_file(&file_string).unwrap(); + + let mut program_input = Input::new(); + program_input.parse_state(file).unwrap(); + + let typed_record = program_input.get_record(); + + // check record state is correct by verifying commitment + let _values = verify_record_commitment(typed_record, system_parameters.record_commitment).unwrap(); +} From 4f3722033a1dcfd869860d5886accc7d19363423 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 19:04:41 -0700 Subject: [PATCH 09/30] add verify_local_data_commitment test --- .../local_data_commitment.rs | 31 +- .../state_leaf_values.rs | 6 +- .../record_commitment/record_commitment.rs | 1 + .../inputs/{test.state => test_record.state} | 2 +- state/tests/inputs/test_state.state | 23 ++ state/tests/mod.rs | 2 +- state/tests/test.rs | 316 ------------------ .../test_verify_local_data_commitment.rs | 204 +++++++++++ state/tests/test_verify_record_commitment.rs | 7 +- 9 files changed, 242 insertions(+), 350 deletions(-) rename state/tests/inputs/{test.state => test_record.state} (97%) create mode 100644 state/tests/inputs/test_state.state delete mode 100644 state/tests/test.rs create mode 100644 state/tests/test_verify_local_data_commitment.rs diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index 1cf1888597..f111e45f81 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -5,7 +5,6 @@ use snarkos_algorithms::commitment_tree::CommitmentMerklePath; use snarkos_dpc::base_dpc::instantiated::{Components, LocalDataCRH, LocalDataCommitment, RecordCommitment}; use snarkos_models::{ algorithms::{CommitmentScheme, CRH}, - curves::Fp256, dpc::DPCComponents, }; use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; @@ -33,14 +32,13 @@ pub fn verify_local_data_commitment( // parse typed state leaf values let typed_state_leaf = typed_input.get_state_leaf(); let state_leaf_values = StateLeafValues::try_from(typed_state_leaf)?; - let _path: Vec> = state_leaf_values.path; + let path: Vec = state_leaf_values.path; let memo: Vec = state_leaf_values.memo; let network_id: u8 = state_leaf_values.network_id; let leaf_randomness: Vec = state_leaf_values.leaf_randomness; // Select local data commitment input bytes let is_death = leaf_index < (Components::NUM_INPUT_RECORDS as u32); - let input_bytes = if is_death { to_bytes![record_serial_number, record_commitment, memo, network_id]? } else { @@ -48,35 +46,16 @@ pub fn verify_local_data_commitment( }; // Construct local data commitment leaf - let local_data_leaf_randomness = Fp256::read(&leaf_randomness[..])?; - + let local_data_leaf_randomness = ::Randomness::read(&leaf_randomness[..])?; let local_data_commitment_leaf = LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &local_data_leaf_randomness)?; // Construct record commitment merkle path - - // let local_data_merkle_path = CommitmentMerklePath::from(path); // Ideally we want something like this - - // Initialize failing blank values for now - let leaves = ( - ::Output::default(), - ::Output::default(), - ); - - let inner_hashes = ( - ::Output::default(), - ::Output::default(), - ); - - let local_data_merkle_path = CommitmentMerklePath:: { - leaves, - inner_hashes, - parameters: local_data_crh_params, - }; + let mut local_data_merkle_path = CommitmentMerklePath::::read(&path[..])?; + local_data_merkle_path.parameters = Some(local_data_crh_params); // Check record commitment merkle path is valid for the given local data commitment root - let local_data_commitment_root = Fp256::read(&root[..])?; - + let local_data_commitment_root = ::Output::read(&root[..])?; let result = local_data_merkle_path.verify(&local_data_commitment_root, &local_data_commitment_leaf)?; Ok(result) diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs index 4babf398f2..b52badd1da 100644 --- a/state/src/local_data_commitment/state_leaf_values.rs +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -1,4 +1,4 @@ -use crate::{find_input, input_to_integer_string, input_to_nested_u8_vec, input_to_u8_vec, StateLeafValuesError}; +use crate::{find_input, input_to_integer_string, input_to_u8_vec, StateLeafValuesError}; use leo_typed::StateLeaf as TypedStateLeaf; use std::convert::TryFrom; @@ -9,7 +9,7 @@ static NETWORK_ID_PARAMETER_STRING: &str = "network_id"; static LEAF_RANDOMNESS_PARAMETER_STRING: &str = "leaf_randomness"; pub struct StateLeafValues { - pub path: Vec>, + pub path: Vec, pub memo: Vec, pub network_id: u8, pub leaf_randomness: Vec, @@ -23,7 +23,7 @@ impl TryFrom<&TypedStateLeaf> for StateLeafValues { // Lookup path let path_value = find_input(PATH_PARAMETER_STRING.to_owned(), ¶meters)?; - let path = input_to_nested_u8_vec(path_value)?; + let path = input_to_u8_vec(path_value)?; // Lookup memo let memo_value = find_input(MEMO_PARAMETER_STRING.to_owned(), ¶meters)?; diff --git a/state/src/record_commitment/record_commitment.rs b/state/src/record_commitment/record_commitment.rs index 9adea95076..89d671ea71 100644 --- a/state/src/record_commitment/record_commitment.rs +++ b/state/src/record_commitment/record_commitment.rs @@ -14,6 +14,7 @@ pub fn verify_record_commitment( // generate a dpc record from the typed record let record = DPCRecordValues::try_from(typed_record)?; + // verify record commitment let record_commitment_input = to_bytes![ record.owner, record.is_dummy, diff --git a/state/tests/inputs/test.state b/state/tests/inputs/test_record.state similarity index 97% rename from state/tests/inputs/test.state rename to state/tests/inputs/test_record.state index bcf404045f..dcc712d3de 100644 --- a/state/tests/inputs/test.state +++ b/state/tests/inputs/test_record.state @@ -17,7 +17,7 @@ serial_number_nonce: u8[32] = [13, 163, 44, 146, 30, 254, 39, 255, 41, 20, 154, commitment_randomness: u8[32] = [55, 189, 0, 182, 148, 137, 120, 223, 121, 7, 140, 240, 100, 202, 196, 41, 236, 128, 38, 189, 60, 59, 23, 210, 25, 102, 65, 117, 38, 140, 136, 1]; [state_leaf] -path: u8[32][2] = [ [0u8; 32], [0u8; 32] ]; +path: u8[128] = [0u8; 128]; memo: u8[32] = [0u8; 32]; network_id: u8 = 0; leaf_randomness: u8[32] = [0u8; 32]; \ No newline at end of file diff --git a/state/tests/inputs/test_state.state b/state/tests/inputs/test_state.state new file mode 100644 index 0000000000..4336865638 --- /dev/null +++ b/state/tests/inputs/test_state.state @@ -0,0 +1,23 @@ +[[public]] +[state] +leaf_index: u32 = 0; +root: u8[32] = [70, 27, 231, 101, 102, 20, 37, 118, 77, 38, 56, 106, 49, 17, 135, 81, 134, 61, 255, 147, 230, 94, 218, 157, 98, 31, 132, 10, 116, 201, 78, 15]; + +[[private]] +[record] +serial_number: u8[64] = [98, 228, 41, 139, 42, 245, 63, 73, 45, 255, 134, 169, 18, 86, 90, 209, 31, 207, 161, 83, 183, 126, 53, 86, 142, 64, 59, 29, 185, 204, 179, 8, 43, 199, 156, 127, 124, 7, 91, 56, 27, 101, 57, 52, 166, 145, 153, 137, 17, 1, 140, 42, 205, 91, 32, 99, 22, 119, 141, 253, 235, 213, 112, 14]; +commitment: u8[32] = [233, 180, 207, 91, 31, 4, 177, 7, 21, 177, 170, 63, 134, 227, 249, 217, 193, 113, 220, 188, 97, 228, 70, 43, 160, 112, 228, 151, 110, 58, 85, 7]; +owner: address = aleo1daxej63vwrmn2zhl4dymygagh89k5d2vaw6rjauueme7le6k2q8sjn0ng9; +is_dummy: bool = false; +value: u64 = 18186969098991041491; +payload: u8[32] = [192, 118, 4, 191, 56, 79, 165, 142, 20, 92, 140, 207, 81, 125, 226, 247, 184, 40, 101, 235, 205, 174, 175, 180, 18, 104, 251, 132, 117, 163, 219, 125]; +birth_program_id: u8[48] = [89, 70, 116, 103, 190, 86, 194, 133, 37, 77, 113, 166, 160, 156, 98, 252, 16, 219, 94, 12, 214, 12, 151, 139, 239, 1, 79, 79, 86, 235, 209, 168, 240, 156, 224, 86, 35, 63, 185, 196, 0, 10, 148, 56, 92, 199, 45, 0]; +death_program_id: u8[48] = [89, 70, 116, 103, 190, 86, 194, 133, 37, 77, 113, 166, 160, 156, 98, 252, 16, 219, 94, 12, 214, 12, 151, 139, 239, 1, 79, 79, 86, 235, 209, 168, 240, 156, 224, 86, 35, 63, 185, 196, 0, 10, 148, 56, 92, 199, 45, 0]; +serial_number_nonce: u8[32] = [74, 128, 103, 188, 105, 165, 185, 183, 83, 178, 164, 202, 65, 224, 154, 216, 132, 146, 103, 158, 153, 229, 73, 162, 0, 182, 176, 162, 17, 201, 27, 6]; +commitment_randomness: u8[32] = [129, 174, 175, 20, 1, 168, 248, 69, 51, 186, 30, 34, 82, 6, 148, 174, 128, 163, 156, 197, 94, 129, 117, 226, 240, 95, 203, 196, 65, 222, 96, 4]; + +[state_leaf] +path: u8[128] = [144, 36, 140, 16, 110, 109, 215, 172, 251, 234, 246, 145, 192, 60, 79, 255, 58, 199, 52, 107, 224, 235, 152, 27, 232, 42, 96, 225, 170, 62, 118, 12, 8, 205, 94, 96, 200, 133, 229, 122, 179, 198, 124, 104, 197, 86, 67, 1, 52, 61, 168, 92, 201, 240, 61, 116, 221, 76, 172, 83, 174, 194, 118, 5, 221, 106, 153, 186, 50, 200, 155, 245, 255, 253, 169, 40, 236, 88, 58, 147, 46, 160, 55, 132, 157, 0, 134, 15, 40, 223, 53, 175, 220, 13, 222, 15, 143, 179, 79, 184, 75, 238, 87, 199, 102, 168, 167, 60, 232, 62, 64, 107, 12, 182, 200, 155, 107, 138, 224, 193, 233, 221, 54, 96, 206, 191, 83, 9]; +memo: u8[32] = [0u8; 32]; +network_id: u8 = 0; +leaf_randomness: u8[32] = [102, 202, 135, 202, 235, 133, 143, 160, 137, 212, 216, 158, 17, 44, 104, 126, 157, 109, 93, 213, 174, 57, 194, 113, 75, 184, 26, 204, 143, 131, 95, 1]; \ No newline at end of file diff --git a/state/tests/mod.rs b/state/tests/mod.rs index 39d7ec66f8..3f3fd2339d 100644 --- a/state/tests/mod.rs +++ b/state/tests/mod.rs @@ -1,3 +1,3 @@ -// mod test; +mod test_verify_local_data_commitment; mod test_verify_record_commitment; diff --git a/state/tests/test.rs b/state/tests/test.rs deleted file mode 100644 index 9666a7e12f..0000000000 --- a/state/tests/test.rs +++ /dev/null @@ -1,316 +0,0 @@ -use snarkos_curves::edwards_bls12::{EdwardsParameters, EdwardsProjective as EdwardsBls}; -use snarkos_dpc::base_dpc::{ - instantiated::*, - record_encryption::*, - record_payload::RecordPayload, - record_serializer::*, - BaseDPCComponents, - ExecuteContext, - DPC, -}; -use snarkos_models::{ - algorithms::{CommitmentScheme, CRH}, - dpc::{Record, RecordSerializerScheme}, - objects::AccountScheme, -}; -use snarkos_objects::{ - Account, - AccountViewKey, - Block, - BlockHeader, - BlockHeaderHash, - DPCTransactions, - MerkleRootHash, - PedersenMerkleRootHash, - ProofOfSuccinctWork, -}; -use snarkos_utilities::{bytes::ToBytes, rand::UniformRand, to_bytes}; - -use rand::{Rng, SeedableRng}; -use rand_xorshift::XorShiftRng; -use snarkos_algorithms::commitment_tree::CommitmentMerklePath; -use snarkos_dpc::{DummyProgram, NoopProgram}; -use snarkos_models::{ - algorithms::MerkleParameters, - dpc::{DPCScheme, Program}, - objects::LedgerScheme, -}; - -#[test] -fn test_integrate_with_dpc() { - use snarkos_testing::storage::*; - type L = Ledger; - - let mut rng = XorShiftRng::seed_from_u64(1231275789u64); - - // Specify network_id - let network_id: u8 = 0; - - // Generate parameters for the ledger, commitment schemes, CRH, and the - // "always-accept" program. - let ledger_parameters = CommitmentMerkleParameters::setup(&mut rng); - let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); - let noop_program_snark_pp = - InstantiatedDPC::generate_noop_program_snark_parameters(&system_parameters, &mut rng).unwrap(); - let dummy_program_snark_pp = - InstantiatedDPC::generate_dummy_program_snark_parameters(&system_parameters, &mut rng).unwrap(); - - let noop_program_id = to_bytes![ - ProgramVerificationKeyHash::hash( - &system_parameters.program_verification_key_hash, - &to_bytes![noop_program_snark_pp.verification_key].unwrap() - ) - .unwrap() - ] - .unwrap(); - - let dummy_program_id = to_bytes![ - ProgramVerificationKeyHash::hash( - &system_parameters.program_verification_key_hash, - &to_bytes![dummy_program_snark_pp.verification_key].unwrap() - ) - .unwrap() - ] - .unwrap(); - - let signature_parameters = &system_parameters.account_signature; - let commitment_parameters = &system_parameters.account_commitment; - let encryption_parameters = &system_parameters.account_encryption; - - // Generate metadata and an account for a dummy initial record. - let dummy_account = Account::new( - signature_parameters, - commitment_parameters, - encryption_parameters, - &mut rng, - ) - .unwrap(); - - let genesis_block = Block { - header: BlockHeader { - previous_block_hash: BlockHeaderHash([0u8; 32]), - merkle_root_hash: MerkleRootHash([0u8; 32]), - time: 0, - difficulty_target: 0x07FF_FFFF_FFFF_FFFF_u64, - nonce: 0, - pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]), - proof: ProofOfSuccinctWork::default(), - }, - transactions: DPCTransactions::new(), - }; - - // Use genesis record, serial number, and memo to initialize the ledger. - let ledger = initialize_test_blockchain::(ledger_parameters, genesis_block); - - let sn_nonce = SerialNumberNonce::hash(&system_parameters.serial_number_nonce, &[0u8; 1]).unwrap(); - // let old_record = DPC::generate_record( - // &system_parameters, - // &sn_nonce, - // &dummy_account.address, - // true, - // 0, - // &RecordPayload::default(), - // &dummy_program_id, - // &dummy_program_id, - // &mut rng, - // ) - // .unwrap(); - - let value = rng.gen(); - let payload: [u8; 32] = rng.gen(); - let old_record = DPC::generate_record( - &system_parameters, - &sn_nonce, - &dummy_account.address, - false, - value, - &RecordPayload::from_bytes(&payload), - &noop_program_id, - &noop_program_id, - &mut rng, - ) - .unwrap(); - - // Set the input records for our transaction to be the initial dummy records. - let old_records = vec![old_record.clone(); NUM_INPUT_RECORDS]; - let old_account_private_keys = vec![dummy_account.private_key.clone(); NUM_INPUT_RECORDS]; - - // Construct new records. - - // Create an account for an actual new record. - - let new_account = Account::new( - signature_parameters, - commitment_parameters, - encryption_parameters, - &mut rng, - ) - .unwrap(); - - // Set the new record's program to be the "always-accept" program. - - let new_record_owners = vec![new_account.address.clone(); NUM_OUTPUT_RECORDS]; - let new_is_dummy_flags = vec![false; NUM_OUTPUT_RECORDS]; - let new_values = vec![10; NUM_OUTPUT_RECORDS]; - let new_payloads = vec![RecordPayload::default(); NUM_OUTPUT_RECORDS]; - let new_birth_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; - let new_death_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; - let memo = [0u8; 32]; - - let context = >::execute_offline( - &system_parameters, - &old_records, - &old_account_private_keys, - &new_record_owners, - &new_is_dummy_flags, - &new_values, - &new_payloads, - &new_birth_program_ids, - &new_death_program_ids, - &memo, - network_id, - &mut rng, - ) - .unwrap(); - - let local_data = context.into_local_data(); - - for (i, record) in local_data.old_records.iter().enumerate() { - println!("{} : {}", i, record.is_dummy()); - } - - ////////////////////////////////////////////////////////////// - // Todo: parse state from file instead of DPC::generate_record - // compare commitments - /* - let commitment = Commit( - record.owner, - record.value, - record.payload, - record.is_dummy, - record.birth_program_id, - record.death_program_id, - record.serial_number_nonce, - record.commitment_randomness, - ); - - record.commitment == commitment - */ - - let record_commitment_input = to_bytes![ - old_record.owner(), - old_record.is_dummy(), - old_record.value(), - old_record.payload(), - old_record.birth_program_id(), - old_record.death_program_id(), - old_record.serial_number_nonce() - ] - .unwrap(); - - let record_commitment = RecordCommitment::commit( - &system_parameters.record_commitment, - &record_commitment_input, - &old_record.commitment_randomness(), - ) - .unwrap(); - - assert_eq!(record_commitment, old_record.commitment()); - - ////////////////////////////////////////////////////////////// - - // Verify local data commitment - - // let leaf_index = 0; - // let root = local_data.local_data_merkle_tree.root(); - // - // let path = ledger.prove_cm(&old_record.commitment()).unwrap(); - // let memo = local_data.memorandum; - // let network_id = local_data.network_id; - // let leaf_randomness = local_data.local_data_commitment_randomizers[0].clone(); - - // Verify that the local data commitment leaf is valid for the root - - // let path = ledger.prove_cm(&record.commitment()).unwrap(); - // let digest = ledger.digest().unwrap(); - // let verified = path.verify(&digest, &record.commitment()).unwrap(); - - ///////////////////////////////////////////////// - - // Generate the program proofs - - // let noop_program = NoopProgram::<_, ::NoopProgramSNARK>::new(noop_program_id); - // let dummy_program = DummyProgram::<_, ::DummyProgramSNARK>::new(dummy_program_id); - // - // let mut old_proof_and_vk = vec![]; - // for i in 0..NUM_INPUT_RECORDS { - // let private_input = dummy_program - // .execute( - // &dummy_program_snark_pp.proving_key, - // &dummy_program_snark_pp.verification_key, - // &local_data, - // i as u8, - // &mut rng, - // ) - // .unwrap(); - // - // old_proof_and_vk.push(private_input); - // } - // - // let mut new_proof_and_vk = vec![]; - // for j in 0..NUM_OUTPUT_RECORDS { - // let private_input = noop_program - // .execute( - // &noop_program_snark_pp.proving_key, - // &noop_program_snark_pp.verification_key, - // &local_data, - // (NUM_INPUT_RECORDS + j) as u8, - // &mut rng, - // ) - // .unwrap(); - // - // new_proof_and_vk.push(private_input); - // } - // - // let ExecuteContext { - // system_parameters: _, - // - // old_records, - // old_account_private_keys, - // old_serial_numbers, - // old_randomizers: _, - // - // new_records, - // new_sn_nonce_randomness, - // new_commitments, - // - // new_records_encryption_randomness, - // new_encrypted_records: _, - // new_encrypted_record_hashes, - // - // program_commitment, - // program_randomness, - // local_data_merkle_tree, - // local_data_commitment_randomizers, - // value_balance, - // memorandum, - // network_id, - // } = context; - // - // let local_data_root = local_data_merkle_tree.root(); - - // Verify that the local data commitment leaf is valid for the root - - // let local_data_commitment = LocalDataCommitment::commit( - // &system_parameters.local_data_commitment, - // - // ) - - // let merkle = CommitmentMerklePath::verify( - // system_parameters.local_data_commitment - // state.root - // state.path - // ) - - // system_parameters.local_data_commitment -} diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs new file mode 100644 index 0000000000..43a530cb1d --- /dev/null +++ b/state/tests/test_verify_local_data_commitment.rs @@ -0,0 +1,204 @@ +use leo_input::LeoInputParser; +use leo_state::verify_local_data_commitment; +use leo_typed::Input; + +use snarkos_dpc::base_dpc::{instantiated::*, record_payload::RecordPayload, DPC}; +use snarkos_models::{ + algorithms::{CommitmentScheme, CRH}, + dpc::Record, + objects::AccountScheme, +}; +use snarkos_objects::Account; +use snarkos_utilities::{bytes::ToBytes, to_bytes}; + +use rand::{Rng, SeedableRng}; +use rand_xorshift::XorShiftRng; +use snarkos_models::dpc::DPCScheme; + +#[test] +fn test_integrate_with_dpc() { + use snarkos_testing::storage::*; + type L = Ledger; + + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); + + // Specify network_id + let network_id: u8 = 0; + + // Generate parameters for the ledger, commitment schemes, CRH, and the + // "always-accept" program. + let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); + let noop_program_snark_pp = + InstantiatedDPC::generate_noop_program_snark_parameters(&system_parameters, &mut rng).unwrap(); + + let noop_program_id = to_bytes![ + ProgramVerificationKeyHash::hash( + &system_parameters.program_verification_key_hash, + &to_bytes![noop_program_snark_pp.verification_key].unwrap() + ) + .unwrap() + ] + .unwrap(); + + let signature_parameters = &system_parameters.account_signature; + let commitment_parameters = &system_parameters.account_commitment; + let encryption_parameters = &system_parameters.account_encryption; + + // Generate metadata and an account for a dummy initial record. + let dummy_account = Account::new( + signature_parameters, + commitment_parameters, + encryption_parameters, + &mut rng, + ) + .unwrap(); + + let sn_nonce = SerialNumberNonce::hash(&system_parameters.serial_number_nonce, &[0u8; 1]).unwrap(); + let value = rng.gen(); + let payload: [u8; 32] = rng.gen(); + + let old_record = DPC::generate_record( + &system_parameters, + &sn_nonce, + &dummy_account.address, + false, + value, + &RecordPayload::from_bytes(&payload), + &noop_program_id, + &noop_program_id, + &mut rng, + ) + .unwrap(); + + // Set the input records for our transaction to be the initial dummy records. + let old_records = vec![old_record.clone(); NUM_INPUT_RECORDS]; + let old_account_private_keys = vec![dummy_account.private_key.clone(); NUM_INPUT_RECORDS]; + + // Construct new records. + + // Create an account for an actual new record. + + let new_account = Account::new( + signature_parameters, + commitment_parameters, + encryption_parameters, + &mut rng, + ) + .unwrap(); + + // Set the new record's program to be the "always-accept" program. + + let new_record_owners = vec![new_account.address.clone(); NUM_OUTPUT_RECORDS]; + let new_is_dummy_flags = vec![false; NUM_OUTPUT_RECORDS]; + let new_values = vec![10; NUM_OUTPUT_RECORDS]; + let new_payloads = vec![RecordPayload::default(); NUM_OUTPUT_RECORDS]; + let new_birth_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; + let new_death_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; + let memo = [0u8; 32]; + + let context = >::execute_offline( + &system_parameters, + &old_records, + &old_account_private_keys, + &new_record_owners, + &new_is_dummy_flags, + &new_values, + &new_payloads, + &new_birth_program_ids, + &new_death_program_ids, + &memo, + network_id, + &mut rng, + ) + .unwrap(); + let local_data = context.into_local_data(); + let leaf_index = 0; + let record = &local_data.old_records[leaf_index]; + + let root = local_data.local_data_merkle_tree.root(); + + let serial_number = local_data.old_serial_numbers[0].clone(); + let serial_number_bytes = to_bytes![serial_number].unwrap(); + + let memorandum = local_data.memorandum; + let network_id = local_data.network_id; + let input_bytes = to_bytes![serial_number, record.commitment(), memorandum, network_id].unwrap(); + let leaf_randomness = local_data.local_data_commitment_randomizers[0].clone(); + + let old_record_leaf = ::commit( + &system_parameters.local_data_commitment, + &input_bytes, + &leaf_randomness, + ) + .unwrap(); + + // generate the path + + let path = local_data + .local_data_merkle_tree + .generate_proof(&old_record_leaf) + .unwrap(); + + println!("////////////////////////////////////////////////////"); + println!(); + println!("[state]"); + println!("leaf index {}", leaf_index); + println!("root {:?}", to_bytes![root].unwrap()); + println!(); + println!("[record]"); + println!( + "serial number {:?} len {}", + serial_number_bytes, + serial_number_bytes.len() + ); + println!("commitment {:?}", to_bytes![record.commitment()].unwrap()); + println!("owner {}", record.owner()); + println!("is_dummy {:?}", record.is_dummy()); + println!("value {:?}", record.value()); + println!("payload {:?}", record.payload()); + println!("birth_program_id {:?}", record.birth_program_id()); + println!("death_program_id {:?}", record.death_program_id()); + println!( + "serial number nonce {:?}", + to_bytes![record.serial_number_nonce()].unwrap() + ); + println!( + "commitment randomness {:?}", + to_bytes![record.commitment_randomness()].unwrap() + ); + println!(); + println!("[state_leaf]"); + println!("path {:?}", to_bytes![path].unwrap()); + println!("memo {:?}", memorandum); + println!("network id {:?}", network_id); + println!("leaf randomness {:?}", to_bytes![leaf_randomness].unwrap()); + println!(); + println!("////////////////////////////////////////////////////"); +} + +#[test] +fn test_verify_local_data_commitment_from_file() { + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); + + // Generate parameters for the record commitment scheme + let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); + + // Load test record state file from `inputs/test.state` + let file_bytes = include_bytes!("inputs/test_state.state"); + let file_string = String::from_utf8_lossy(file_bytes); + let file = LeoInputParser::parse_file(&file_string).unwrap(); + + let mut program_input = Input::new(); + program_input.parse_state(file).unwrap(); + + // check record state is correct by verifying commitment + let result = verify_local_data_commitment( + &program_input, + system_parameters.record_commitment, + system_parameters.local_data_commitment, + system_parameters.local_data_crh, + ) + .unwrap(); + + assert!(result); +} diff --git a/state/tests/test_verify_record_commitment.rs b/state/tests/test_verify_record_commitment.rs index 6defe9e344..74cbfa708d 100644 --- a/state/tests/test_verify_record_commitment.rs +++ b/state/tests/test_verify_record_commitment.rs @@ -1,8 +1,9 @@ -use snarkos_dpc::base_dpc::instantiated::*; - use leo_input::LeoInputParser; use leo_state::verify_record_commitment; use leo_typed::Input; + +use snarkos_dpc::base_dpc::instantiated::*; + use rand::SeedableRng; use rand_xorshift::XorShiftRng; @@ -14,7 +15,7 @@ fn test_verify_record_from_file() { let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); // Load test record state file from `inputs/test.state` - let file_bytes = include_bytes!("inputs/test.state"); + let file_bytes = include_bytes!("inputs/test_record.state"); let file_string = String::from_utf8_lossy(file_bytes); let file = LeoInputParser::parse_file(&file_string).unwrap(); From 9b5d14970dcc2af9707ff123695771030ac425c0 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 19:15:55 -0700 Subject: [PATCH 10/30] use system parameters struct --- .../local_data_commitment.rs | 20 +++++--- .../record_commitment/record_commitment.rs | 9 ++-- .../test_verify_local_data_commitment.rs | 51 +++++++++---------- state/tests/test_verify_record_commitment.rs | 2 +- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index f111e45f81..7254050bfa 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -2,7 +2,10 @@ use crate::{verify_record_commitment, LocalDataVerificationError, StateLeafValue use leo_typed::Input as TypedInput; use snarkos_algorithms::commitment_tree::CommitmentMerklePath; -use snarkos_dpc::base_dpc::instantiated::{Components, LocalDataCRH, LocalDataCommitment, RecordCommitment}; +use snarkos_dpc::base_dpc::{ + instantiated::{Components, LocalDataCRH, LocalDataCommitment}, + parameters::SystemParameters, +}; use snarkos_models::{ algorithms::{CommitmentScheme, CRH}, dpc::DPCComponents, @@ -12,14 +15,12 @@ use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; pub fn verify_local_data_commitment( + system_parameters: &SystemParameters, typed_input: &TypedInput, - record_commitment_params: RecordCommitment, - local_data_commitment_params: LocalDataCommitment, - local_data_crh_params: LocalDataCRH, ) -> Result { // verify record commitment let typed_record = typed_input.get_record(); - let dpc_record_values = verify_record_commitment(typed_record, record_commitment_params)?; + let dpc_record_values = verify_record_commitment(system_parameters, typed_record)?; let record_commitment: Vec = dpc_record_values.commitment; let record_serial_number: Vec = dpc_record_values.serial_number; @@ -47,12 +48,15 @@ pub fn verify_local_data_commitment( // Construct local data commitment leaf let local_data_leaf_randomness = ::Randomness::read(&leaf_randomness[..])?; - let local_data_commitment_leaf = - LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &local_data_leaf_randomness)?; + let local_data_commitment_leaf = LocalDataCommitment::commit( + &system_parameters.local_data_commitment, + &input_bytes, + &local_data_leaf_randomness, + )?; // Construct record commitment merkle path let mut local_data_merkle_path = CommitmentMerklePath::::read(&path[..])?; - local_data_merkle_path.parameters = Some(local_data_crh_params); + local_data_merkle_path.parameters = Some(system_parameters.local_data_crh.clone()); // Check record commitment merkle path is valid for the given local data commitment root let local_data_commitment_root = ::Output::read(&root[..])?; diff --git a/state/src/record_commitment/record_commitment.rs b/state/src/record_commitment/record_commitment.rs index 89d671ea71..55493e874f 100644 --- a/state/src/record_commitment/record_commitment.rs +++ b/state/src/record_commitment/record_commitment.rs @@ -1,15 +1,18 @@ use crate::{DPCRecordValues, RecordVerificationError}; use leo_typed::Record as TypedRecord; -use snarkos_dpc::base_dpc::instantiated::RecordCommitment; +use snarkos_dpc::base_dpc::{ + instantiated::{Components, RecordCommitment}, + parameters::SystemParameters, +}; use snarkos_models::algorithms::CommitmentScheme; use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; pub fn verify_record_commitment( + system_parameters: &SystemParameters, typed_record: &TypedRecord, - record_commitment_params: RecordCommitment, ) -> Result { // generate a dpc record from the typed record let record = DPCRecordValues::try_from(typed_record)?; @@ -30,7 +33,7 @@ pub fn verify_record_commitment( ::Randomness::read(&record.commitment_randomness[..])?; let record_commitment = RecordCommitment::commit( - &record_commitment_params, + &system_parameters.record_commitment, &record_commitment_input, &commitment_randomness, )?; diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 43a530cb1d..56b3da4a6c 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -16,7 +16,29 @@ use rand_xorshift::XorShiftRng; use snarkos_models::dpc::DPCScheme; #[test] -fn test_integrate_with_dpc() { +fn test_verify_local_data_commitment_from_file() { + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); + + // Generate parameters for the record commitment scheme + let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); + + // Load test record state file from `inputs/test.state` + let file_bytes = include_bytes!("inputs/test_state.state"); + let file_string = String::from_utf8_lossy(file_bytes); + let file = LeoInputParser::parse_file(&file_string).unwrap(); + + let mut program_input = Input::new(); + program_input.parse_state(file).unwrap(); + + // check record state is correct by verifying commitment + let result = verify_local_data_commitment(&system_parameters, &program_input).unwrap(); + + assert!(result); +} + +#[test] +#[ignore] +fn test_generate_values_from_dpc() { use snarkos_testing::storage::*; type L = Ledger; @@ -175,30 +197,3 @@ fn test_integrate_with_dpc() { println!(); println!("////////////////////////////////////////////////////"); } - -#[test] -fn test_verify_local_data_commitment_from_file() { - let mut rng = XorShiftRng::seed_from_u64(1231275789u64); - - // Generate parameters for the record commitment scheme - let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); - - // Load test record state file from `inputs/test.state` - let file_bytes = include_bytes!("inputs/test_state.state"); - let file_string = String::from_utf8_lossy(file_bytes); - let file = LeoInputParser::parse_file(&file_string).unwrap(); - - let mut program_input = Input::new(); - program_input.parse_state(file).unwrap(); - - // check record state is correct by verifying commitment - let result = verify_local_data_commitment( - &program_input, - system_parameters.record_commitment, - system_parameters.local_data_commitment, - system_parameters.local_data_crh, - ) - .unwrap(); - - assert!(result); -} diff --git a/state/tests/test_verify_record_commitment.rs b/state/tests/test_verify_record_commitment.rs index 74cbfa708d..e7bde411eb 100644 --- a/state/tests/test_verify_record_commitment.rs +++ b/state/tests/test_verify_record_commitment.rs @@ -25,5 +25,5 @@ fn test_verify_record_from_file() { let typed_record = program_input.get_record(); // check record state is correct by verifying commitment - let _values = verify_record_commitment(typed_record, system_parameters.record_commitment).unwrap(); + let _values = verify_record_commitment(&system_parameters, typed_record).unwrap(); } From cc3136193e069b518d970c9ef7314cc7fedb1579 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 19:45:19 -0700 Subject: [PATCH 11/30] update cargo lock --- Cargo.lock | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index daabbf1b46..ab612404cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,6 +605,18 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "filetime" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi 0.3.9", +] + [[package]] name = "flate2" version = "1.0.16" @@ -648,6 +660,25 @@ dependencies = [ "void", ] +[[package]] +name = "fsevent" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" +dependencies = [ + "bitflags", + "fsevent-sys", +] + +[[package]] +name = "fsevent-sys" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" +dependencies = [ + "libc", +] + [[package]] name = "fsio" version = "0.1.3" @@ -921,6 +952,26 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inotify" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" +dependencies = [ + "bitflags", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" +dependencies = [ + "libc", +] + [[package]] name = "instant" version = "0.1.6" @@ -1034,6 +1085,7 @@ dependencies = [ "leo-package", "leo-state", "log", + "notify", "rand", "rand_core", "reqwest", @@ -1306,6 +1358,18 @@ dependencies = [ "winapi 0.2.8", ] +[[package]] +name = "mio-extras" +version = "2.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" +dependencies = [ + "lazycell", + "log", + "mio", + "slab", +] + [[package]] name = "mio-named-pipes" version = "0.1.7" @@ -1396,6 +1460,24 @@ dependencies = [ "version_check", ] +[[package]] +name = "notify" +version = "4.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd" +dependencies = [ + "bitflags", + "filetime", + "fsevent", + "fsevent-sys", + "inotify", + "libc", + "mio", + "mio-extras", + "walkdir", + "winapi 0.3.9", +] + [[package]] name = "num-bigint" version = "0.3.0" From 89718218209743f84c0e78711a1492522b6cc043 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 12 Aug 2020 20:50:37 -0700 Subject: [PATCH 12/30] pass crh parameters into commitment merkle path verify method --- state/src/local_data_commitment/local_data_commitment.rs | 9 ++++++--- state/tests/test_verify_local_data_commitment.rs | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index 7254050bfa..53a84b8149 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -55,12 +55,15 @@ pub fn verify_local_data_commitment( )?; // Construct record commitment merkle path - let mut local_data_merkle_path = CommitmentMerklePath::::read(&path[..])?; - local_data_merkle_path.parameters = Some(system_parameters.local_data_crh.clone()); + let local_data_merkle_path = CommitmentMerklePath::::read(&path[..])?; // Check record commitment merkle path is valid for the given local data commitment root let local_data_commitment_root = ::Output::read(&root[..])?; - let result = local_data_merkle_path.verify(&local_data_commitment_root, &local_data_commitment_leaf)?; + let result = local_data_merkle_path.verify( + &system_parameters.local_data_crh, + &local_data_commitment_root, + &local_data_commitment_leaf, + )?; Ok(result) } diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 56b3da4a6c..24e9de213c 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -133,6 +133,7 @@ fn test_generate_values_from_dpc() { &mut rng, ) .unwrap(); + let local_data = context.into_local_data(); let leaf_index = 0; let record = &local_data.old_records[leaf_index]; From c8682d2a076965167d67097e9de209928f7f2027 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 13 Aug 2020 11:04:35 -0700 Subject: [PATCH 13/30] update cargo.toml --- Cargo.lock | 16 +++++++++------- state/Cargo.toml | 15 ++++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab612404cc..2795073507 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1198,14 +1198,14 @@ dependencies = [ "leo-typed", "rand", "rand_xorshift", - "snarkos-algorithms 0.8.0", - "snarkos-curves 0.8.0", - "snarkos-dpc 0.8.0", - "snarkos-errors 0.8.0", - "snarkos-models 0.8.0", - "snarkos-objects 0.8.0", + "snarkos-algorithms 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-curves 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-dpc 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-models 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-objects 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", "snarkos-testing", - "snarkos-utilities 0.8.0", + "snarkos-utilities 0.8.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", "thiserror", ] @@ -2318,8 +2318,10 @@ dependencies = [ "base58", "bech32", "bincode", + "curl", "hex", "jsonrpc-core", + "rocksdb", "thiserror", ] diff --git a/state/Cargo.toml b/state/Cargo.toml index 3099b9d9ac..32dfe8d7b7 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -8,13 +8,14 @@ edition = "2018" leo-input = { path = "../input", version = "0.1.0" } leo-typed = { path = "../typed", version = "0.1.0" } -snarkos-algorithms = { path = "../../snarkOS/algorithms" } -snarkos-curves = { path = "../../snarkOS/curves" } -snarkos-dpc = { path = "../../snarkOS/dpc" } -snarkos-errors = { path = "../../snarkOS/errors" } -snarkos-models = { path = "../../snarkOS/models" } -snarkos-objects = { path = "../../snarkOS/objects" } -snarkos-utilities = { path = "../../snarkOS/utilities" } +snarkos-algorithms = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-algorithms", default-features = false } +snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false } +snarkos-dpc = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-dpc", default-features = false } +snarkos-errors = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-errors", default-features = false } +snarkos-models = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-models", default-features = false } +snarkos-objects = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-objects" } +snarkos-utilities = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-utilities" } + rand = { version = "0.7" } rand_xorshift = { version = "0.2" } From 0226c09e4dd25d62b117655886183b2fde3bf762 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 14:35:45 -0700 Subject: [PATCH 14/30] impl new group notation pest --- ast/src/leo.pest | 17 +++++++-- ast/src/values/group_coordinate.rs | 61 ++++++++++++++++++++++++++++++ ast/src/values/group_value.rs | 24 ++---------- ast/src/values/mod.rs | 3 ++ 4 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 ast/src/values/group_coordinate.rs diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 0ce0c2a3ec..07181faff0 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -230,9 +230,20 @@ value_boolean = { "true" | "false" } value_field = ${ value_number ~ type_field } // Declared in values/group_value.rs -value_group = ${ group_single_or_tuple ~ type_group } -group_tuple = !{"(" ~ value_number ~ "," ~ value_number ~ ")"} -group_single_or_tuple = {value_number | group_tuple} +value_group = ${ group_tuple ~ type_group } +group_tuple = !{"(" ~ group_coordinate ~ "," ~ group_coordinate ~ ")"} + +// Declared in values/group_coordinate.rs +group_coordinate = { + value_number + | sign_high + | sign_low + | inferred +} + +sign_high = @{"+"} +sign_low = @{"-"} +inferred = @{"_"} // Declared in values/address.rs address = @{ "aleo1" ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} } diff --git a/ast/src/values/group_coordinate.rs b/ast/src/values/group_coordinate.rs new file mode 100644 index 0000000000..01b7fbda55 --- /dev/null +++ b/ast/src/values/group_coordinate.rs @@ -0,0 +1,61 @@ +use crate::{ast::Rule, values::NumberValue, SpanDef}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; +use std::fmt; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::group_coordinate))] +pub enum GroupCoordinate<'ast> { + Number(NumberValue<'ast>), + SignHigh(SignHigh<'ast>), + SignLow(SignLow<'ast>), + Inferred(Inferred<'ast>), +} + +impl<'ast> GroupCoordinate<'ast> { + pub fn span(&self) -> &Span<'ast> { + match self { + GroupCoordinate::Number(number) => &number.span(), + GroupCoordinate::SignHigh(sign_high) => &sign_high.span, + GroupCoordinate::SignLow(sign_low) => &sign_low.span, + GroupCoordinate::Inferred(inferred) => &inferred.span, + } + } +} + +impl<'ast> fmt::Display for GroupCoordinate<'ast> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + GroupCoordinate::Number(number) => write!(f, "{}", number), + GroupCoordinate::SignHigh(_) => write!(f, "+"), + GroupCoordinate::SignLow(_) => write!(f, "-"), + GroupCoordinate::Inferred(_) => write!(f, "_"), + } + } +} + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::sign_high))] +pub struct SignHigh<'ast> { + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::sign_low))] +pub struct SignLow<'ast> { + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::inferred))] +pub struct Inferred<'ast> { + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} diff --git a/ast/src/values/group_value.rs b/ast/src/values/group_value.rs index 606940bd36..f406635172 100644 --- a/ast/src/values/group_value.rs +++ b/ast/src/values/group_value.rs @@ -1,4 +1,4 @@ -use crate::{ast::Rule, types::GroupType, values::NumberValue, SpanDef}; +use crate::{ast::Rule, types::GroupType, values::GroupCoordinate, SpanDef}; use pest::Span; use pest_ast::FromPest; @@ -8,7 +8,7 @@ use std::fmt; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] #[pest_ast(rule(Rule::value_group))] pub struct GroupValue<'ast> { - pub value: GroupRepresentation<'ast>, + pub value: GroupTuple<'ast>, pub _type: GroupType, #[pest_ast(outer())] #[serde(with = "SpanDef")] @@ -21,27 +21,11 @@ impl<'ast> fmt::Display for GroupValue<'ast> { } } -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::group_single_or_tuple))] -pub enum GroupRepresentation<'ast> { - Single(NumberValue<'ast>), - Tuple(GroupTuple<'ast>), -} - -impl<'ast> fmt::Display for GroupRepresentation<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - GroupRepresentation::Single(number) => write!(f, "{}", number), - GroupRepresentation::Tuple(tuple) => write!(f, "{}", tuple), - } - } -} - #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] #[pest_ast(rule(Rule::group_tuple))] pub struct GroupTuple<'ast> { - pub x: NumberValue<'ast>, - pub y: NumberValue<'ast>, + pub x: GroupCoordinate<'ast>, + pub y: GroupCoordinate<'ast>, #[pest_ast(outer())] #[serde(with = "SpanDef")] pub span: Span<'ast>, diff --git a/ast/src/values/mod.rs b/ast/src/values/mod.rs index e9015180d4..e1ca123f27 100644 --- a/ast/src/values/mod.rs +++ b/ast/src/values/mod.rs @@ -10,6 +10,9 @@ pub use boolean_value::*; pub mod field_value; pub use field_value::*; +pub mod group_coordinate; +pub use group_coordinate::*; + pub mod group_value; pub use group_value::*; From 60bf079e333c3376aad5f2a9dd3f55d0e80aaa7d Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 15:30:19 -0700 Subject: [PATCH 15/30] impl new group notation typed --- typed/src/expression.rs | 16 +++---- typed/src/groups/group_coordinate.rs | 68 ++++++++++++++++++++++++++++ typed/src/groups/group_value.rs | 31 +++++++++++++ typed/src/groups/mod.rs | 5 ++ typed/src/lib.rs | 3 ++ 5 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 typed/src/groups/group_coordinate.rs create mode 100644 typed/src/groups/group_value.rs create mode 100644 typed/src/groups/mod.rs diff --git a/typed/src/expression.rs b/typed/src/expression.rs index 27d366bb25..beed6ee8b5 100644 --- a/typed/src/expression.rs +++ b/typed/src/expression.rs @@ -1,4 +1,4 @@ -use crate::{CircuitFieldDefinition, Identifier, IntegerType, RangeOrExpression, Span, SpreadOrExpression}; +use crate::{CircuitFieldDefinition, GroupValue, Identifier, IntegerType, RangeOrExpression, Span, SpreadOrExpression}; use leo_ast::{ access::{Access, AssigneeAccess}, common::{Assignee, Identifier as AstIdentifier}, @@ -17,7 +17,7 @@ use leo_ast::{ AddressValue, BooleanValue, FieldValue, - GroupValue, + GroupValue as AstGroupValue, IntegerValue, NumberValue as AstNumber, PositiveNumber as AstPositiveNumber, @@ -40,7 +40,7 @@ pub enum Expression { Address(String, Span), Boolean(String, Span), Field(String, Span), - Group(String, Span), + Group(GroupValue), Implicit(String, Span), Integer(IntegerType, String, Span), @@ -86,7 +86,7 @@ impl Expression { pub fn set_span(&mut self, new_span: &Span) { match self { Expression::Field(_, old_span) => *old_span = new_span.clone(), - Expression::Group(_, old_span) => *old_span = new_span.clone(), + Expression::Group(value) => value.span = new_span.clone(), Expression::Add(_, _, old_span) => *old_span = new_span.clone(), Expression::Sub(_, _, old_span) => *old_span = new_span.clone(), @@ -146,7 +146,7 @@ impl<'ast> fmt::Display for Expression { Expression::Address(ref address, ref _span) => write!(f, "{}", address), Expression::Boolean(ref bool, ref _span) => write!(f, "{}", bool), Expression::Field(ref field, ref _span) => write!(f, "{}", field), - Expression::Group(ref group, ref _span) => write!(f, "{}", group), + Expression::Group(ref group) => write!(f, "{}", group), Expression::Implicit(ref value, ref _span) => write!(f, "{}", value), Expression::Integer(ref type_, ref integer, ref _span) => write!(f, "{}{}", integer, type_), @@ -509,9 +509,9 @@ impl<'ast> From> for Expression { } } -impl<'ast> From> for Expression { - fn from(group: GroupValue<'ast>) -> Self { - Expression::Group(group.to_string(), Span::from(group.span)) +impl<'ast> From> for Expression { + fn from(ast_group: AstGroupValue<'ast>) -> Self { + Expression::Group(GroupValue::from(ast_group)) } } diff --git a/typed/src/groups/group_coordinate.rs b/typed/src/groups/group_coordinate.rs new file mode 100644 index 0000000000..76ed0df86f --- /dev/null +++ b/typed/src/groups/group_coordinate.rs @@ -0,0 +1,68 @@ +use crate::common::span::Span; +use leo_ast::values::{ + GroupCoordinate as AstGroupCoordinate, + Inferred as AstInferred, + NumberValue as AstNumberValue, + SignHigh as AstSignHigh, + SignLow as AstSignLow, +}; + +use serde::{Deserialize, Serialize}; +use std::fmt; + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub enum GroupCoordinate { + Number(String, Span), + SignHigh(Span), + SignLow(Span), + Inferred(Span), +} + +impl<'ast> From> for GroupCoordinate { + fn from(coordinate: AstGroupCoordinate<'ast>) -> Self { + match coordinate { + AstGroupCoordinate::Number(number) => GroupCoordinate::from(number), + AstGroupCoordinate::SignHigh(sign_high) => GroupCoordinate::from(sign_high), + AstGroupCoordinate::SignLow(sign_low) => GroupCoordinate::from(sign_low), + AstGroupCoordinate::Inferred(inferred) => GroupCoordinate::from(inferred), + } + } +} + +impl fmt::Display for GroupCoordinate { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + GroupCoordinate::Number(number, _) => write!(f, "{}", number), + GroupCoordinate::SignHigh(_) => write!(f, "+"), + GroupCoordinate::SignLow(_) => write!(f, "-"), + GroupCoordinate::Inferred(_) => write!(f, "_"), + } + } +} + +impl<'ast> From> for GroupCoordinate { + fn from(number: AstNumberValue<'ast>) -> Self { + let value = number.to_string(); + let span = Span::from(number.span().clone()); + + GroupCoordinate::Number(value, span) + } +} + +impl<'ast> From> for GroupCoordinate { + fn from(sign: AstSignHigh<'ast>) -> Self { + GroupCoordinate::SignHigh(Span::from(sign.span)) + } +} + +impl<'ast> From> for GroupCoordinate { + fn from(sign: AstSignLow<'ast>) -> Self { + GroupCoordinate::SignLow(Span::from(sign.span)) + } +} + +impl<'ast> From> for GroupCoordinate { + fn from(sign: AstInferred<'ast>) -> Self { + GroupCoordinate::Inferred(Span::from(sign.span)) + } +} diff --git a/typed/src/groups/group_value.rs b/typed/src/groups/group_value.rs new file mode 100644 index 0000000000..7ff16ad89c --- /dev/null +++ b/typed/src/groups/group_value.rs @@ -0,0 +1,31 @@ +use crate::{common::span::Span, groups::GroupCoordinate}; +use leo_ast::values::GroupValue as AstGroupValue; + +use serde::{Deserialize, Serialize}; +use std::fmt; + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct GroupValue { + pub x: GroupCoordinate, + pub y: GroupCoordinate, + pub span: Span, +} + +impl<'ast> From> for GroupValue { + fn from(ast_group: AstGroupValue<'ast>) -> Self { + let ast_x = ast_group.value.x; + let ast_y = ast_group.value.y; + + Self { + x: GroupCoordinate::from(ast_x), + y: GroupCoordinate::from(ast_y), + span: Span::from(ast_group.span), + } + } +} + +impl fmt::Display for GroupValue { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "({}, {})", self.x, self.y) + } +} diff --git a/typed/src/groups/mod.rs b/typed/src/groups/mod.rs new file mode 100644 index 0000000000..98533d2893 --- /dev/null +++ b/typed/src/groups/mod.rs @@ -0,0 +1,5 @@ +pub mod group_coordinate; +pub use self::group_coordinate::*; + +pub mod group_value; +pub use self::group_value::*; diff --git a/typed/src/lib.rs b/typed/src/lib.rs index c1d90de64c..c44215e27a 100644 --- a/typed/src/lib.rs +++ b/typed/src/lib.rs @@ -16,6 +16,9 @@ pub use self::expression::*; pub mod functions; pub use self::functions::*; +pub mod groups; +pub use self::groups::*; + pub mod imports; pub use self::imports::*; From 3fe25da23f6902ccac36aa98cc6e6252affe20db Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 16:20:43 -0700 Subject: [PATCH 16/30] impl new group notation compiler --- compiler/src/errors/value/group.rs | 30 +++++ compiler/src/errors/value/value.rs | 6 + compiler/src/expression/expression.rs | 2 +- compiler/src/value/group/group_type.rs | 4 +- .../src/value/group/targets/edwards_bls12.rs | 124 ++++++++++++++++-- compiler/src/value/value.rs | 2 +- typed/src/groups/group_coordinate.rs | 24 ++-- 7 files changed, 167 insertions(+), 25 deletions(-) diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index 5934282406..6720397913 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -52,4 +52,34 @@ impl GroupError { Self::new_from_span(message, span) } + + pub fn x_invalid(x: String, span: Span) -> Self { + let message = format!("invalid x coordinate `{}`", x); + + Self::new_from_span(message, span) + } + + pub fn y_invalid(y: String, span: Span) -> Self { + let message = format!("invalid y coordinate `{}`", y); + + Self::new_from_span(message, span) + } + + pub fn not_on_curve(element: String, span: Span) -> Self { + let message = format!("group element `{}` is not on the supported curve", element); + + Self::new_from_span(message, span) + } + + pub fn x_recover(span: Span) -> Self { + let message = format!("could not recover group element from x coordinate"); + + Self::new_from_span(message, span) + } + + pub fn y_recover(span: Span) -> Self { + let message = format!("could not recover group element from x coordinate"); + + Self::new_from_span(message, span) + } } diff --git a/compiler/src/errors/value/value.rs b/compiler/src/errors/value/value.rs index af47546962..5c824f40ec 100644 --- a/compiler/src/errors/value/value.rs +++ b/compiler/src/errors/value/value.rs @@ -45,4 +45,10 @@ impl ValueError { Self::new_from_span(message, span) } + + pub fn implicit_group(span: Span) -> Self { + let message = format!("group coordinates should be in (x, y)group format"); + + Self::new_from_span(message, span) + } } diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index 3aaca3e829..e8b2ebaef2 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -38,7 +38,7 @@ impl> ConstrainedProgram { Expression::Address(address, span) => Ok(ConstrainedValue::Address(Address::new(address, span)?)), Expression::Boolean(boolean, span) => Ok(ConstrainedValue::Boolean(new_bool_constant(boolean, span)?)), Expression::Field(field, span) => Ok(ConstrainedValue::Field(FieldType::constant(field, span)?)), - Expression::Group(group_affine, span) => Ok(ConstrainedValue::Group(G::constant(group_affine, span)?)), + Expression::Group(group_affine) => Ok(ConstrainedValue::Group(G::constant(group_affine)?)), Expression::Implicit(value, span) => Ok(enforce_number_implicit(expected_type, value, span)?), Expression::Integer(type_, integer, span) => { Ok(ConstrainedValue::Integer(Integer::new_constant(&type_, integer, span)?)) diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index 71cbdad435..ed863625c7 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -1,7 +1,7 @@ //! A data type that represents members in the group formed by the set of affine points on a curve. use crate::errors::GroupError; -use leo_typed::Span; +use leo_typed::{GroupValue, Span}; use snarkos_models::{ curves::{Field, One}, @@ -32,7 +32,7 @@ pub trait GroupType: + ToBitsGadget + ToBytesGadget { - fn constant(string: String, span: Span) -> Result; + fn constant(value: GroupValue) -> Result; fn to_allocated>(&self, cs: CS, span: Span) -> Result; diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 0b9fadd7ca..308d56d276 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -1,5 +1,5 @@ use crate::{errors::GroupError, GroupType}; -use leo_typed::Span; +use leo_typed::{GroupCoordinate, GroupValue, Span}; use snarkos_curves::{ edwards_bls12::{EdwardsAffine, EdwardsParameters, Fq}, @@ -36,14 +36,43 @@ pub enum EdwardsGroupType { } impl GroupType for EdwardsGroupType { - fn constant(string: String, span: Span) -> Result { - // 1group = generator - if string.eq("1") { - return Ok(Self::one()); - } + fn constant(group: GroupValue) -> Result { + let span = group.span; + let x = group.x; + let y = group.y; - let value = - Self::edwards_affine_from_str(string.clone()).map_err(|_| GroupError::invalid_group(string, span))?; + let value = match (x, y) { + // (x, y) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_pair(x_string, y_string, x_span, y_span, span)? + } + // (x, +) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::SignHigh) => { + Self::edwards_affine_from_x_str(x_string, x_span, Some(true), span)? + } + // (x, -) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::SignLow) => { + Self::edwards_affine_from_x_str(x_string, x_span, Some(false), span)? + } + // (x, _) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::Inferred) => { + Self::edwards_affine_from_x_str(x_string, x_span, None, span)? + } + // (+, y) + (GroupCoordinate::SignHigh, GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_y_str(y_string, y_span, Some(true), span)? + } + // (-, y) + (GroupCoordinate::SignLow, GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_y_str(y_string, y_span, Some(false), span)? + } + // (_, y) + (GroupCoordinate::Inferred, GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_y_str(y_string, y_span, None, span)? + } + // Invalid + (x, y) => return Err(GroupError::invalid_group(format!("({}, {})", x, y), span)), + }; Ok(EdwardsGroupType::Constant(value)) } @@ -124,8 +153,85 @@ impl GroupType for EdwardsGroupType { } impl EdwardsGroupType { + pub fn edwards_affine_from_x_str( + x_string: String, + x_span: Span, + greatest: Option, + element_span: Span, + ) -> Result { + let x = Fq::from_str(&x_string).map_err(|_| GroupError::x_invalid(x_string, x_span))?; + match greatest { + // Sign provided + Some(greatest) => EdwardsAffine::from_x_coordinate(x, greatest).ok_or(GroupError::x_recover(element_span)), + // Sign inferred + None => { + // Attempt to recover with a sign_low bit. + if let Some(element) = EdwardsAffine::from_x_coordinate(x.clone(), false) { + return Ok(element); + } + + // Attempt to recover with a sign_high bit. + if let Some(element) = EdwardsAffine::from_x_coordinate(x, true) { + return Ok(element); + } + + // Otherwise return error. + Err(GroupError::x_recover(element_span)) + } + } + } + + pub fn edwards_affine_from_y_str( + y_string: String, + y_span: Span, + _greatest: Option, + _element_span: Span, + ) -> Result { + let _y = Fq::from_str(&y_string).map_err(|_| GroupError::y_invalid(y_string, y_span))?; + + unimplemented!("recover from_y_coordinate not implemented for Edwards Affine") + // match greatest { + // // Sign provided + // Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or(GroupError::y_recover(element_span)), + // // Sign inferred + // None => { + // // Attempt to recover with a sign_low bit. + // if let Some(element) = EdwardsAffine::from_y_coordinate(y.clone(), false) { + // return Ok(element); + // } + // + // // Attempt to recover with a sign_high bit. + // if let Some(element) = EdwardsAffine::from_y_coordinate(y, true) { + // return Ok(element); + // } + // + // // Otherwise return error. + // Err(GroupError::y_recover(element_span)) + // } + // } + } + + pub fn edwards_affine_from_pair( + x_string: String, + y_string: String, + x_span: Span, + y_span: Span, + element_span: Span, + ) -> Result { + let x = Fq::from_str(&x_string).map_err(|_| GroupError::x_invalid(x_string, x_span))?; + let y = Fq::from_str(&y_string).map_err(|_| GroupError::y_invalid(y_string, y_span))?; + + let element = EdwardsAffine::new(x, y); + + if element.is_on_curve() { + Ok(element) + } else { + Err(GroupError::not_on_curve(format!("{}", element), element_span)) + } + } + pub fn edwards_affine_from_str(string: String) -> Result { - // x or (x, y) + // (x, y) match Fq::from_str(&string).ok() { Some(x) => { // Attempt to recover with a sign_low bit. diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 1f96127f33..2fc3c0053a 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -69,7 +69,7 @@ impl> ConstrainedValue { Type::Address => Ok(ConstrainedValue::Address(Address::new(value, span)?)), Type::Boolean => Ok(ConstrainedValue::Boolean(new_bool_constant(value, span)?)), Type::Field => Ok(ConstrainedValue::Field(FieldType::constant(value, span)?)), - Type::Group => Ok(ConstrainedValue::Group(G::constant(value, span)?)), + Type::Group => Err(ValueError::implicit_group(span)), Type::IntegerType(integer_type) => Ok(ConstrainedValue::Integer(Integer::new_constant( integer_type, value, diff --git a/typed/src/groups/group_coordinate.rs b/typed/src/groups/group_coordinate.rs index 76ed0df86f..a2806d0af7 100644 --- a/typed/src/groups/group_coordinate.rs +++ b/typed/src/groups/group_coordinate.rs @@ -13,9 +13,9 @@ use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum GroupCoordinate { Number(String, Span), - SignHigh(Span), - SignLow(Span), - Inferred(Span), + SignHigh, + SignLow, + Inferred, } impl<'ast> From> for GroupCoordinate { @@ -33,9 +33,9 @@ impl fmt::Display for GroupCoordinate { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { GroupCoordinate::Number(number, _) => write!(f, "{}", number), - GroupCoordinate::SignHigh(_) => write!(f, "+"), - GroupCoordinate::SignLow(_) => write!(f, "-"), - GroupCoordinate::Inferred(_) => write!(f, "_"), + GroupCoordinate::SignHigh => write!(f, "+"), + GroupCoordinate::SignLow => write!(f, "-"), + GroupCoordinate::Inferred => write!(f, "_"), } } } @@ -50,19 +50,19 @@ impl<'ast> From> for GroupCoordinate { } impl<'ast> From> for GroupCoordinate { - fn from(sign: AstSignHigh<'ast>) -> Self { - GroupCoordinate::SignHigh(Span::from(sign.span)) + fn from(_sign: AstSignHigh<'ast>) -> Self { + GroupCoordinate::SignHigh } } impl<'ast> From> for GroupCoordinate { - fn from(sign: AstSignLow<'ast>) -> Self { - GroupCoordinate::SignLow(Span::from(sign.span)) + fn from(_sign: AstSignLow<'ast>) -> Self { + GroupCoordinate::SignLow } } impl<'ast> From> for GroupCoordinate { - fn from(sign: AstInferred<'ast>) -> Self { - GroupCoordinate::Inferred(Span::from(sign.span)) + fn from(_sign: AstInferred<'ast>) -> Self { + GroupCoordinate::Inferred } } From 37bedc8662de0158c3e6c125ddf67f8bf6e050ee Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 16:31:07 -0700 Subject: [PATCH 17/30] impl tests for group notation --- compiler/tests/group/double_high.leo | 3 + compiler/tests/group/double_inferred.leo | 3 + compiler/tests/group/double_low.leo | 3 + compiler/tests/group/mod.rs | 92 +++++++++++++++++++----- compiler/tests/group/one.leo | 3 - compiler/tests/group/x_sign_high.leo | 3 + compiler/tests/group/x_sign_inferred.leo | 3 + compiler/tests/group/x_sign_low.leo | 3 + compiler/tests/group/y_sign_high.leo | 3 + compiler/tests/group/y_sign_inferred.leo | 3 + compiler/tests/group/y_sign_low.leo | 3 + compiler/tests/group/zero.leo | 3 - 12 files changed, 103 insertions(+), 22 deletions(-) create mode 100644 compiler/tests/group/double_high.leo create mode 100644 compiler/tests/group/double_inferred.leo create mode 100644 compiler/tests/group/double_low.leo delete mode 100644 compiler/tests/group/one.leo create mode 100644 compiler/tests/group/x_sign_high.leo create mode 100644 compiler/tests/group/x_sign_inferred.leo create mode 100644 compiler/tests/group/x_sign_low.leo create mode 100644 compiler/tests/group/y_sign_high.leo create mode 100644 compiler/tests/group/y_sign_inferred.leo create mode 100644 compiler/tests/group/y_sign_low.leo delete mode 100644 compiler/tests/group/zero.leo diff --git a/compiler/tests/group/double_high.leo b/compiler/tests/group/double_high.leo new file mode 100644 index 0000000000..a8217d6d40 --- /dev/null +++ b/compiler/tests/group/double_high.leo @@ -0,0 +1,3 @@ +function main() { + let element = (+, +)group; +} \ No newline at end of file diff --git a/compiler/tests/group/double_inferred.leo b/compiler/tests/group/double_inferred.leo new file mode 100644 index 0000000000..b3b8b512c3 --- /dev/null +++ b/compiler/tests/group/double_inferred.leo @@ -0,0 +1,3 @@ +function main() { + let element = (_, _)group; +} \ No newline at end of file diff --git a/compiler/tests/group/double_low.leo b/compiler/tests/group/double_low.leo new file mode 100644 index 0000000000..0519c6d17d --- /dev/null +++ b/compiler/tests/group/double_low.leo @@ -0,0 +1,3 @@ +function main() { + let element = (-, -)group; +} \ No newline at end of file diff --git a/compiler/tests/group/mod.rs b/compiler/tests/group/mod.rs index b10e6b0842..70b986c701 100644 --- a/compiler/tests/group/mod.rs +++ b/compiler/tests/group/mod.rs @@ -1,5 +1,6 @@ use crate::{ assert_satisfied, + expect_compiler_error, expect_synthesis_error, field::field_to_decimal_string, generate_main_input, @@ -20,22 +21,6 @@ pub fn group_to_decimal_string(g: EdwardsAffine) -> String { format!("({}, {})", x, y) } -#[test] -fn test_zero() { - let bytes = include_bytes!("zero.leo"); - let program = parse_program(bytes).unwrap(); - - assert_satisfied(program); -} - -#[test] -fn test_one() { - let bytes = include_bytes!("one.leo"); - let program = parse_program(bytes).unwrap(); - - assert_satisfied(program) -} - #[test] fn test_point() { let bytes = include_bytes!("point.leo"); @@ -44,6 +29,81 @@ fn test_point() { assert_satisfied(program); } +#[test] +fn test_x_sign_high() { + let bytes = include_bytes!("x_sign_high.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_x_sign_low() { + let bytes = include_bytes!("x_sign_low.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_x_sign_inferred() { + let bytes = include_bytes!("x_sign_inferred.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +// #[test] +// fn test_y_sign_high() { +// let bytes = include_bytes!("y_sign_high.leo"); +// let program = parse_program(bytes).unwrap(); +// +// assert_satisfied(program); +// } +// +// #[test] +// fn test_y_sign_low() { +// let bytes = include_bytes!("y_sign_low.leo"); +// let program = parse_program(bytes).unwrap(); +// +// assert_satisfied(program); +// } +// +// #[test] +// fn test_y_sign_inferred() { +// let bytes = include_bytes!("y_sign_inferred.leo"); +// let program = parse_program(bytes).unwrap(); +// +// assert_satisfied(program); +// } + +#[test] +fn test_double_high() { + let bytes = include_bytes!("double_high.leo"); + + let program = parse_program(bytes).unwrap(); + + expect_compiler_error(program); +} + +#[test] +fn test_double_low() { + let bytes = include_bytes!("double_low.leo"); + + let program = parse_program(bytes).unwrap(); + + expect_compiler_error(program); +} + +#[test] +fn test_double_inferred() { + let bytes = include_bytes!("double_inferred.leo"); + + let program = parse_program(bytes).unwrap(); + + expect_compiler_error(program); +} + #[test] fn test_point_input() { let program_bytes = include_bytes!("point_input.leo"); diff --git a/compiler/tests/group/one.leo b/compiler/tests/group/one.leo deleted file mode 100644 index 78188d4893..0000000000 --- a/compiler/tests/group/one.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() { - let a = 1group; -} \ No newline at end of file diff --git a/compiler/tests/group/x_sign_high.leo b/compiler/tests/group/x_sign_high.leo new file mode 100644 index 0000000000..1b8d397d02 --- /dev/null +++ b/compiler/tests/group/x_sign_high.leo @@ -0,0 +1,3 @@ +function main() { + let element = (0, +)group; +} \ No newline at end of file diff --git a/compiler/tests/group/x_sign_inferred.leo b/compiler/tests/group/x_sign_inferred.leo new file mode 100644 index 0000000000..9e9622a4a4 --- /dev/null +++ b/compiler/tests/group/x_sign_inferred.leo @@ -0,0 +1,3 @@ +function main() { + let element = (0, _)group; +} \ No newline at end of file diff --git a/compiler/tests/group/x_sign_low.leo b/compiler/tests/group/x_sign_low.leo new file mode 100644 index 0000000000..a5058bda52 --- /dev/null +++ b/compiler/tests/group/x_sign_low.leo @@ -0,0 +1,3 @@ +function main() { + let element = (0, -)group; +} \ No newline at end of file diff --git a/compiler/tests/group/y_sign_high.leo b/compiler/tests/group/y_sign_high.leo new file mode 100644 index 0000000000..fe16883b39 --- /dev/null +++ b/compiler/tests/group/y_sign_high.leo @@ -0,0 +1,3 @@ +function main() { + let element = (+, 1)group; +} \ No newline at end of file diff --git a/compiler/tests/group/y_sign_inferred.leo b/compiler/tests/group/y_sign_inferred.leo new file mode 100644 index 0000000000..003c373cf2 --- /dev/null +++ b/compiler/tests/group/y_sign_inferred.leo @@ -0,0 +1,3 @@ +function main() { + let element = (_, 1)group; +} \ No newline at end of file diff --git a/compiler/tests/group/y_sign_low.leo b/compiler/tests/group/y_sign_low.leo new file mode 100644 index 0000000000..9e61bfd2bb --- /dev/null +++ b/compiler/tests/group/y_sign_low.leo @@ -0,0 +1,3 @@ +function main() { + let element = (-, 1)group; +} \ No newline at end of file diff --git a/compiler/tests/group/zero.leo b/compiler/tests/group/zero.leo deleted file mode 100644 index 199a8498a7..0000000000 --- a/compiler/tests/group/zero.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() { - let a = 0group; -} \ No newline at end of file From 172431c2223531019d02105bd9639af065af48af Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 16:45:43 -0700 Subject: [PATCH 18/30] impl new group notation for inputs ast + typed --- ast/src/values/group_value.rs | 2 +- input/src/errors/parser.rs | 6 +++ input/src/leo-input.pest | 17 +++++++-- input/src/values/group_coordinate.rs | 57 ++++++++++++++++++++++++++++ input/src/values/group_value.rs | 24 ++---------- input/src/values/mod.rs | 3 ++ typed/src/groups/group_coordinate.rs | 45 ++++++++++++++++++++++ typed/src/groups/group_value.rs | 14 +++++++ typed/src/input/input_value.rs | 11 +++--- 9 files changed, 150 insertions(+), 29 deletions(-) create mode 100644 input/src/values/group_coordinate.rs diff --git a/ast/src/values/group_value.rs b/ast/src/values/group_value.rs index f406635172..ee9310de90 100644 --- a/ast/src/values/group_value.rs +++ b/ast/src/values/group_value.rs @@ -9,7 +9,7 @@ use std::fmt; #[pest_ast(rule(Rule::value_group))] pub struct GroupValue<'ast> { pub value: GroupTuple<'ast>, - pub _type: GroupType, + pub type_: GroupType, #[pest_ast(outer())] #[serde(with = "SpanDef")] pub span: Span<'ast>, diff --git a/input/src/errors/parser.rs b/input/src/errors/parser.rs index d09c6e9fe7..d5ae505ae8 100644 --- a/input/src/errors/parser.rs +++ b/input/src/errors/parser.rs @@ -48,6 +48,12 @@ impl InputParserError { Self::new_from_span(message, implicit.span().clone()) } + pub fn implicit_group(number: NumberValue) -> Self { + let message = format!("group coordinates should be in (x, y)group format, found `{}`", number); + + Self::new_from_span(message, number.span().clone()) + } + pub fn data_type_mismatch(data_type: DataType, value: Value) -> Self { let message = format!("expected `{}`, found `{}`", data_type.to_string(), value.to_string()); let span = value.span().to_owned(); diff --git a/input/src/leo-input.pest b/input/src/leo-input.pest index afafbf8ba3..2c9469317e 100644 --- a/input/src/leo-input.pest +++ b/input/src/leo-input.pest @@ -131,9 +131,20 @@ value_boolean = { "true" | "false" } value_field = ${ value_number ~ type_field } // Declared in values/group_value.rs -value_group = ${ group_single_or_tuple ~ type_group } -group_tuple = !{"(" ~ value_number ~ "," ~ value_number ~ ")"} -group_single_or_tuple = {value_number | group_tuple} +value_group = ${ group_tuple ~ type_group } +group_tuple = !{"(" ~ group_coordinate ~ "," ~ group_coordinate ~ ")"} + +// Declared in values/group_coordinate.rs +group_coordinate = { + value_number + | sign_high + | sign_low + | inferred +} + +sign_high = @{"+"} +sign_low = @{"-"} +inferred = @{"_"} // Declared in values/address.rs address = @{ "aleo" ~ ASCII_DIGIT ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} } diff --git a/input/src/values/group_coordinate.rs b/input/src/values/group_coordinate.rs new file mode 100644 index 0000000000..1592ad9fd8 --- /dev/null +++ b/input/src/values/group_coordinate.rs @@ -0,0 +1,57 @@ +use crate::{ast::Rule, values::NumberValue}; + +use pest::Span; +use pest_ast::FromPest; +use std::fmt; + +#[derive(Clone, Debug, FromPest, PartialEq, Eq)] +#[pest_ast(rule(Rule::group_coordinate))] +pub enum GroupCoordinate<'ast> { + Number(NumberValue<'ast>), + SignHigh(SignHigh<'ast>), + SignLow(SignLow<'ast>), + Inferred(Inferred<'ast>), +} + +impl<'ast> GroupCoordinate<'ast> { + pub fn span(&self) -> &Span<'ast> { + match self { + GroupCoordinate::Number(number) => &number.span(), + GroupCoordinate::SignHigh(sign_high) => &sign_high.span, + GroupCoordinate::SignLow(sign_low) => &sign_low.span, + GroupCoordinate::Inferred(inferred) => &inferred.span, + } + } +} + +impl<'ast> fmt::Display for GroupCoordinate<'ast> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + GroupCoordinate::Number(number) => write!(f, "{}", number), + GroupCoordinate::SignHigh(_) => write!(f, "+"), + GroupCoordinate::SignLow(_) => write!(f, "-"), + GroupCoordinate::Inferred(_) => write!(f, "_"), + } + } +} + +#[derive(Clone, Debug, FromPest, PartialEq, Eq)] +#[pest_ast(rule(Rule::sign_high))] +pub struct SignHigh<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +} + +#[derive(Clone, Debug, FromPest, PartialEq, Eq)] +#[pest_ast(rule(Rule::sign_low))] +pub struct SignLow<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +} + +#[derive(Clone, Debug, FromPest, PartialEq, Eq)] +#[pest_ast(rule(Rule::inferred))] +pub struct Inferred<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, +} diff --git a/input/src/values/group_value.rs b/input/src/values/group_value.rs index c31e070b49..c37de3ffd5 100644 --- a/input/src/values/group_value.rs +++ b/input/src/values/group_value.rs @@ -1,4 +1,4 @@ -use crate::{ast::Rule, types::GroupType, values::NumberValue}; +use crate::{ast::Rule, types::GroupType, values::GroupCoordinate}; use pest::Span; use pest_ast::FromPest; @@ -7,7 +7,7 @@ use std::fmt; #[derive(Clone, Debug, FromPest, PartialEq, Eq)] #[pest_ast(rule(Rule::value_group))] pub struct GroupValue<'ast> { - pub value: GroupRepresentation<'ast>, + pub value: GroupTuple<'ast>, pub type_: GroupType, #[pest_ast(outer())] pub span: Span<'ast>, @@ -19,27 +19,11 @@ impl<'ast> fmt::Display for GroupValue<'ast> { } } -#[derive(Clone, Debug, FromPest, PartialEq, Eq)] -#[pest_ast(rule(Rule::group_single_or_tuple))] -pub enum GroupRepresentation<'ast> { - Single(NumberValue<'ast>), - Tuple(GroupTuple<'ast>), -} - -impl<'ast> fmt::Display for GroupRepresentation<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - GroupRepresentation::Single(number) => write!(f, "{}", number), - GroupRepresentation::Tuple(tuple) => write!(f, "{}", tuple), - } - } -} - #[derive(Clone, Debug, FromPest, PartialEq, Eq)] #[pest_ast(rule(Rule::group_tuple))] pub struct GroupTuple<'ast> { - pub x: NumberValue<'ast>, - pub y: NumberValue<'ast>, + pub x: GroupCoordinate<'ast>, + pub y: GroupCoordinate<'ast>, #[pest_ast(outer())] pub span: Span<'ast>, } diff --git a/input/src/values/mod.rs b/input/src/values/mod.rs index 089a9420ed..f8ded05f4e 100644 --- a/input/src/values/mod.rs +++ b/input/src/values/mod.rs @@ -13,6 +13,9 @@ pub use boolean_value::*; pub mod field_value; pub use field_value::*; +pub mod group_coordinate; +pub use group_coordinate::*; + pub mod group_value; pub use group_value::*; diff --git a/typed/src/groups/group_coordinate.rs b/typed/src/groups/group_coordinate.rs index a2806d0af7..9475a7c4eb 100644 --- a/typed/src/groups/group_coordinate.rs +++ b/typed/src/groups/group_coordinate.rs @@ -6,6 +6,13 @@ use leo_ast::values::{ SignHigh as AstSignHigh, SignLow as AstSignLow, }; +use leo_input::values::{ + GroupCoordinate as InputGroupCoordinate, + Inferred as InputInferred, + NumberValue as InputNumberValue, + SignHigh as InputSignHigh, + SignLow as InputSignLow, +}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -29,6 +36,17 @@ impl<'ast> From> for GroupCoordinate { } } +impl<'ast> From> for GroupCoordinate { + fn from(coordinate: InputGroupCoordinate<'ast>) -> Self { + match coordinate { + InputGroupCoordinate::Number(number) => GroupCoordinate::from(number), + InputGroupCoordinate::SignHigh(sign_high) => GroupCoordinate::from(sign_high), + InputGroupCoordinate::SignLow(sign_low) => GroupCoordinate::from(sign_low), + InputGroupCoordinate::Inferred(inferred) => GroupCoordinate::from(inferred), + } + } +} + impl fmt::Display for GroupCoordinate { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -66,3 +84,30 @@ impl<'ast> From> for GroupCoordinate { GroupCoordinate::Inferred } } + +impl<'ast> From> for GroupCoordinate { + fn from(number: InputNumberValue<'ast>) -> Self { + let value = number.to_string(); + let span = Span::from(number.span().clone()); + + GroupCoordinate::Number(value, span) + } +} + +impl<'ast> From> for GroupCoordinate { + fn from(_sign: InputSignHigh<'ast>) -> Self { + GroupCoordinate::SignHigh + } +} + +impl<'ast> From> for GroupCoordinate { + fn from(_sign: InputSignLow<'ast>) -> Self { + GroupCoordinate::SignLow + } +} + +impl<'ast> From> for GroupCoordinate { + fn from(_sign: InputInferred<'ast>) -> Self { + GroupCoordinate::Inferred + } +} diff --git a/typed/src/groups/group_value.rs b/typed/src/groups/group_value.rs index 7ff16ad89c..8c54ef4939 100644 --- a/typed/src/groups/group_value.rs +++ b/typed/src/groups/group_value.rs @@ -1,5 +1,6 @@ use crate::{common::span::Span, groups::GroupCoordinate}; use leo_ast::values::GroupValue as AstGroupValue; +use leo_input::values::GroupValue as InputGroupValue; use serde::{Deserialize, Serialize}; use std::fmt; @@ -24,6 +25,19 @@ impl<'ast> From> for GroupValue { } } +impl<'ast> From> for GroupValue { + fn from(ast_group: InputGroupValue<'ast>) -> Self { + let ast_x = ast_group.value.x; + let ast_y = ast_group.value.y; + + Self { + x: GroupCoordinate::from(ast_x), + y: GroupCoordinate::from(ast_y), + span: Span::from(ast_group.span), + } + } +} + impl fmt::Display for GroupValue { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "({}, {})", self.x, self.y) diff --git a/typed/src/input/input_value.rs b/typed/src/input/input_value.rs index a17f0fd5e0..4d064e728c 100644 --- a/typed/src/input/input_value.rs +++ b/typed/src/input/input_value.rs @@ -1,8 +1,9 @@ +use crate::GroupValue; use leo_input::{ errors::InputParserError, expressions::{ArrayInitializerExpression, ArrayInlineExpression, Expression}, types::{ArrayType, DataType, IntegerType, Type}, - values::{BooleanValue, FieldValue, GroupValue, NumberValue, Value}, + values::{BooleanValue, FieldValue, GroupValue as InputGroupValue, NumberValue, Value}, }; use leo_input::{ @@ -17,7 +18,7 @@ pub enum InputValue { Address(String), Boolean(bool), Field(String), - Group(String), + Group(GroupValue), Integer(IntegerType, String), Array(Vec), Tuple(Vec), @@ -44,8 +45,8 @@ impl InputValue { Ok(InputValue::Integer(integer_type, number)) } - fn from_group(group: GroupValue) -> Self { - InputValue::Group(group.to_string()) + fn from_group(group: InputGroupValue) -> Self { + InputValue::Group(GroupValue::from(group)) } fn from_field(field: FieldValue) -> Self { @@ -57,7 +58,7 @@ impl InputValue { DataType::Address(_) => Err(InputParserError::implicit_type(data_type, implicit)), DataType::Boolean(_) => Err(InputParserError::implicit_type(data_type, implicit)), DataType::Integer(integer_type) => InputValue::from_number(integer_type, implicit.to_string()), - DataType::Group(_) => Ok(InputValue::Group(implicit.to_string())), + DataType::Group(_) => Err(InputParserError::implicit_group(implicit)), DataType::Field(_) => Ok(InputValue::Field(implicit.to_string())), } } From a4b29d26519fb3b6d38e57405f351d6f88449353 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 17:21:18 -0700 Subject: [PATCH 19/30] impl new group notation for inputs compiler --- compiler/src/value/group/group_type.rs | 2 +- compiler/src/value/group/input.rs | 4 +- .../src/value/group/targets/edwards_bls12.rs | 122 +++++++----------- compiler/tests/group/input/invalid.in | 3 + compiler/tests/group/input/one_one.in | 3 - compiler/tests/group/input/one_zero.in | 3 - compiler/tests/group/input/valid.in | 3 + compiler/tests/group/mod.rs | 99 ++++++++------ compiler/tests/group/x_and_y.leo | 3 + 9 files changed, 118 insertions(+), 124 deletions(-) create mode 100644 compiler/tests/group/input/invalid.in delete mode 100644 compiler/tests/group/input/one_one.in delete mode 100644 compiler/tests/group/input/one_zero.in create mode 100644 compiler/tests/group/input/valid.in create mode 100644 compiler/tests/group/x_and_y.leo diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index ed863625c7..fc7534e2ed 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -27,7 +27,7 @@ pub trait GroupType: + EvaluateEqGadget + EqGadget + ConditionalEqGadget - + AllocGadget + + AllocGadget + CondSelectGadget + ToBitsGadget + ToBytesGadget diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index 4f0e44017f..a5df8f4112 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -1,7 +1,7 @@ //! Methods to enforce constraints on input group values in a Leo program. use crate::{errors::GroupError, ConstrainedValue, GroupType}; -use leo_typed::{InputValue, Span}; +use leo_typed::{GroupValue, InputValue, Span}; use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ @@ -12,7 +12,7 @@ use snarkos_models::{ pub(crate) fn allocate_group, CS: ConstraintSystem>( cs: &mut CS, name: String, - option: Option, + option: Option, span: Span, ) -> Result { let group_name = format!("{}: group", name); diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 308d56d276..a53be4e1f7 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -37,42 +37,7 @@ pub enum EdwardsGroupType { impl GroupType for EdwardsGroupType { fn constant(group: GroupValue) -> Result { - let span = group.span; - let x = group.x; - let y = group.y; - - let value = match (x, y) { - // (x, y) - (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::Number(y_string, y_span)) => { - Self::edwards_affine_from_pair(x_string, y_string, x_span, y_span, span)? - } - // (x, +) - (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::SignHigh) => { - Self::edwards_affine_from_x_str(x_string, x_span, Some(true), span)? - } - // (x, -) - (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::SignLow) => { - Self::edwards_affine_from_x_str(x_string, x_span, Some(false), span)? - } - // (x, _) - (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::Inferred) => { - Self::edwards_affine_from_x_str(x_string, x_span, None, span)? - } - // (+, y) - (GroupCoordinate::SignHigh, GroupCoordinate::Number(y_string, y_span)) => { - Self::edwards_affine_from_y_str(y_string, y_span, Some(true), span)? - } - // (-, y) - (GroupCoordinate::SignLow, GroupCoordinate::Number(y_string, y_span)) => { - Self::edwards_affine_from_y_str(y_string, y_span, Some(false), span)? - } - // (_, y) - (GroupCoordinate::Inferred, GroupCoordinate::Number(y_string, y_span)) => { - Self::edwards_affine_from_y_str(y_string, y_span, None, span)? - } - // Invalid - (x, y) => return Err(GroupError::invalid_group(format!("({}, {})", x, y), span)), - }; + let value = Self::edwards_affine_from_value(group)?; Ok(EdwardsGroupType::Constant(value)) } @@ -153,6 +118,45 @@ impl GroupType for EdwardsGroupType { } impl EdwardsGroupType { + pub fn edwards_affine_from_value(group: GroupValue) -> Result { + let span = group.span; + let x = group.x; + let y = group.y; + + match (x, y) { + // (x, y) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_pair(x_string, y_string, x_span, y_span, span) + } + // (x, +) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::SignHigh) => { + Self::edwards_affine_from_x_str(x_string, x_span, Some(true), span) + } + // (x, -) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::SignLow) => { + Self::edwards_affine_from_x_str(x_string, x_span, Some(false), span) + } + // (x, _) + (GroupCoordinate::Number(x_string, x_span), GroupCoordinate::Inferred) => { + Self::edwards_affine_from_x_str(x_string, x_span, None, span) + } + // (+, y) + (GroupCoordinate::SignHigh, GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_y_str(y_string, y_span, Some(true), span) + } + // (-, y) + (GroupCoordinate::SignLow, GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_y_str(y_string, y_span, Some(false), span) + } + // (_, y) + (GroupCoordinate::Inferred, GroupCoordinate::Number(y_string, y_span)) => { + Self::edwards_affine_from_y_str(y_string, y_span, None, span) + } + // Invalid + (x, y) => Err(GroupError::invalid_group(format!("({}, {})", x, y), span)), + } + } + pub fn edwards_affine_from_x_str( x_string: String, x_span: Span, @@ -230,44 +234,18 @@ impl EdwardsGroupType { } } - pub fn edwards_affine_from_str(string: String) -> Result { - // (x, y) - match Fq::from_str(&string).ok() { - Some(x) => { - // Attempt to recover with a sign_low bit. - if let Some(element) = EdwardsAffine::from_x_coordinate(x.clone(), false) { - return Ok(element); - } - - // Attempt to recover with a sign_high bit. - if let Some(element) = EdwardsAffine::from_x_coordinate(x, true) { - return Ok(element); - } - - // Otherwise return error. - Err(SynthesisError::AssignmentMissing) - } - None => EdwardsAffine::from_str(&string).map_err(|_| SynthesisError::AssignmentMissing), - } - } - - pub fn alloc_x_helper Result, T: Borrow>( + pub fn alloc_helper Result, T: Borrow>( value_gen: Fn, ) -> Result { - let affine_string = match value_gen() { + let group_value = match value_gen() { Ok(value) => { - let string_value = value.borrow().clone(); - Ok(string_value) + let group_value = value.borrow().clone(); + Ok(group_value) } _ => Err(SynthesisError::AssignmentMissing), }?; - // 1group = generator - if affine_string.eq("1") { - Ok(edwards_affine_one()) - } else { - Self::edwards_affine_from_str(affine_string) - } + Self::edwards_affine_from_value(group_value).map_err(|_| SynthesisError::AssignmentMissing) } pub fn allocated>(&self, mut cs: CS) -> Result { @@ -295,24 +273,24 @@ impl EdwardsGroupType { } } -impl AllocGadget for EdwardsGroupType { - fn alloc Result, T: Borrow, CS: ConstraintSystem>( +impl AllocGadget for EdwardsGroupType { + fn alloc Result, T: Borrow, CS: ConstraintSystem>( cs: CS, value_gen: Fn, ) -> Result { let value = , Fq>>::alloc(cs, || { - Self::alloc_x_helper(value_gen) + Self::alloc_helper(value_gen) })?; Ok(EdwardsGroupType::Allocated(value)) } - fn alloc_input Result, T: Borrow, CS: ConstraintSystem>( + fn alloc_input Result, T: Borrow, CS: ConstraintSystem>( cs: CS, value_gen: Fn, ) -> Result { let value = , Fq>>::alloc_input(cs, || { - Self::alloc_x_helper(value_gen) + Self::alloc_helper(value_gen) })?; Ok(EdwardsGroupType::Allocated(value)) diff --git a/compiler/tests/group/input/invalid.in b/compiler/tests/group/input/invalid.in new file mode 100644 index 0000000000..d55c096738 --- /dev/null +++ b/compiler/tests/group/input/invalid.in @@ -0,0 +1,3 @@ +[main] +a: group = (1, 0)group; +b: group = (+, +)group; diff --git a/compiler/tests/group/input/one_one.in b/compiler/tests/group/input/one_one.in deleted file mode 100644 index 27d529509f..0000000000 --- a/compiler/tests/group/input/one_one.in +++ /dev/null @@ -1,3 +0,0 @@ -[main] -a: group = 1; -b: group = 1; diff --git a/compiler/tests/group/input/one_zero.in b/compiler/tests/group/input/one_zero.in deleted file mode 100644 index 98bcfb999d..0000000000 --- a/compiler/tests/group/input/one_zero.in +++ /dev/null @@ -1,3 +0,0 @@ -[main] -a: group = 1; -b: group = 0; diff --git a/compiler/tests/group/input/valid.in b/compiler/tests/group/input/valid.in new file mode 100644 index 0000000000..651a28bea6 --- /dev/null +++ b/compiler/tests/group/input/valid.in @@ -0,0 +1,3 @@ +[main] +a: group = (0, -)group; +b: group = (0, _)group; diff --git a/compiler/tests/group/mod.rs b/compiler/tests/group/mod.rs index 70b986c701..eebdd96bb2 100644 --- a/compiler/tests/group/mod.rs +++ b/compiler/tests/group/mod.rs @@ -7,18 +7,31 @@ use crate::{ parse_program, parse_program_with_input, }; -use leo_typed::InputValue; +use leo_typed::{GroupCoordinate, GroupValue, InputValue, Span}; use snarkos_curves::edwards_bls12::EdwardsAffine; use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; -pub fn group_to_decimal_string(g: EdwardsAffine) -> String { +pub fn group_element_to_input_value(g: EdwardsAffine) -> GroupValue { let x = field_to_decimal_string(g.x); let y = field_to_decimal_string(g.y); - format!("({}, {})", x, y) + format!("({}, {})", x, y); + + let fake_span = Span { + text: "".to_string(), + line: 0, + start: 0, + end: 0, + }; + + GroupValue { + x: GroupCoordinate::Number(x, fake_span.clone()), + y: GroupCoordinate::Number(y, fake_span.clone()), + span: fake_span, + } } #[test] @@ -117,8 +130,8 @@ fn test_point_input() { #[test] fn test_input() { let program_bytes = include_bytes!("input.leo"); - let input_bytes_pass = include_bytes!("input/one_one.in"); - let input_bytes_fail = include_bytes!("input/one_zero.in"); + let input_bytes_pass = include_bytes!("input/valid.in"); + let input_bytes_fail = include_bytes!("input/invalid.in"); let program = parse_program_with_input(program_bytes, input_bytes_pass).unwrap(); @@ -126,7 +139,7 @@ fn test_input() { let program = parse_program_with_input(program_bytes, input_bytes_fail).unwrap(); - expect_synthesis_error(program); + expect_compiler_error(program); } #[test] @@ -139,15 +152,15 @@ fn test_negate() { let a: EdwardsAffine = rng.gen(); let b = a.neg(); - let a_string = group_to_decimal_string(a); - let b_string = group_to_decimal_string(b); + let a_element = group_element_to_input_value(a); + let b_element = group_element_to_input_value(b); let bytes = include_bytes!("negate.leo"); let mut program = parse_program(bytes).unwrap(); let main_input = generate_main_input(vec![ - ("a", Some(InputValue::Group(a_string))), - ("b", Some(InputValue::Group(b_string))), + ("a", Some(InputValue::Group(a_element))), + ("b", Some(InputValue::Group(b_element))), ]); program.set_main_input(main_input); @@ -166,17 +179,17 @@ fn test_add() { let b: EdwardsAffine = rng.gen(); let c = a.add(&b); - let a_string = group_to_decimal_string(a); - let b_string = group_to_decimal_string(b); - let c_string = group_to_decimal_string(c); + let a_element = group_element_to_input_value(a); + let b_element = group_element_to_input_value(b); + let c_element = group_element_to_input_value(c); let bytes = include_bytes!("add.leo"); let mut program = parse_program(bytes).unwrap(); let main_input = generate_main_input(vec![ - ("a", Some(InputValue::Group(a_string))), - ("b", Some(InputValue::Group(b_string))), - ("c", Some(InputValue::Group(c_string))), + ("a", Some(InputValue::Group(a_element))), + ("b", Some(InputValue::Group(b_element))), + ("c", Some(InputValue::Group(c_element))), ]); program.set_main_input(main_input); @@ -195,17 +208,17 @@ fn test_sub() { let b: EdwardsAffine = rng.gen(); let c = a.sub(&b); - let a_string = group_to_decimal_string(a); - let b_string = group_to_decimal_string(b); - let c_string = group_to_decimal_string(c); + let a_element = group_element_to_input_value(a); + let b_element = group_element_to_input_value(b); + let c_element = group_element_to_input_value(c); let bytes = include_bytes!("sub.leo"); let mut program = parse_program(bytes).unwrap(); let main_input = generate_main_input(vec![ - ("a", Some(InputValue::Group(a_string))), - ("b", Some(InputValue::Group(b_string))), - ("c", Some(InputValue::Group(c_string))), + ("a", Some(InputValue::Group(a_element))), + ("b", Some(InputValue::Group(b_element))), + ("c", Some(InputValue::Group(c_element))), ]); program.set_main_input(main_input); @@ -220,14 +233,14 @@ fn test_assert_eq_pass() { for _ in 0..10 { let a: EdwardsAffine = rng.gen(); - let a_string = group_to_decimal_string(a); + let a_element = group_element_to_input_value(a); let bytes = include_bytes!("assert_eq.leo"); let mut program = parse_program(bytes).unwrap(); let main_input = generate_main_input(vec![ - ("a", Some(InputValue::Group(a_string.clone()))), - ("b", Some(InputValue::Group(a_string))), + ("a", Some(InputValue::Group(a_element.clone()))), + ("b", Some(InputValue::Group(a_element))), ]); program.set_main_input(main_input); @@ -248,15 +261,15 @@ fn test_assert_eq_fail() { continue; } - let a_string = group_to_decimal_string(a); - let b_string = group_to_decimal_string(b); + let a_element = group_element_to_input_value(a); + let b_element = group_element_to_input_value(b); let bytes = include_bytes!("assert_eq.leo"); let mut program = parse_program(bytes).unwrap(); let main_input = generate_main_input(vec![ - ("a", Some(InputValue::Group(a_string))), - ("b", Some(InputValue::Group(b_string))), + ("a", Some(InputValue::Group(a_element))), + ("b", Some(InputValue::Group(b_element))), ]); program.set_main_input(main_input); @@ -274,8 +287,8 @@ fn test_eq() { let a: EdwardsAffine = rng.gen(); let b: EdwardsAffine = rng.gen(); - let a_string = group_to_decimal_string(a); - let b_string = group_to_decimal_string(b); + let a_element = group_element_to_input_value(a); + let b_element = group_element_to_input_value(b); // test equal @@ -283,8 +296,8 @@ fn test_eq() { let mut program = parse_program(bytes).unwrap(); let main_input = generate_main_input(vec![ - ("a", Some(InputValue::Group(a_string.clone()))), - ("b", Some(InputValue::Group(a_string.clone()))), + ("a", Some(InputValue::Group(a_element.clone()))), + ("b", Some(InputValue::Group(a_element.clone()))), ("c", Some(InputValue::Boolean(true))), ]); @@ -299,8 +312,8 @@ fn test_eq() { let mut program = parse_program(bytes).unwrap(); let main_input = generate_main_input(vec![ - ("a", Some(InputValue::Group(a_string))), - ("b", Some(InputValue::Group(b_string))), + ("a", Some(InputValue::Group(a_element))), + ("b", Some(InputValue::Group(b_element))), ("c", Some(InputValue::Boolean(c))), ]); @@ -317,8 +330,8 @@ fn test_ternary() { let a: EdwardsAffine = rng.gen(); let b: EdwardsAffine = rng.gen(); - let a_string = group_to_decimal_string(a); - let b_string = group_to_decimal_string(b); + let a_element = group_element_to_input_value(a); + let b_element = group_element_to_input_value(b); let bytes = include_bytes!("ternary.leo"); let mut program = parse_program(bytes).unwrap(); @@ -326,9 +339,9 @@ fn test_ternary() { // true -> field a let main_input = generate_main_input(vec![ ("s", Some(InputValue::Boolean(true))), - ("a", Some(InputValue::Group(a_string.clone()))), - ("b", Some(InputValue::Group(b_string.clone()))), - ("c", Some(InputValue::Group(a_string.clone()))), + ("a", Some(InputValue::Group(a_element.clone()))), + ("b", Some(InputValue::Group(b_element.clone()))), + ("c", Some(InputValue::Group(a_element.clone()))), ]); program.set_main_input(main_input); @@ -340,9 +353,9 @@ fn test_ternary() { // false -> field b let main_input = generate_main_input(vec![ ("s", Some(InputValue::Boolean(false))), - ("a", Some(InputValue::Group(a_string))), - ("b", Some(InputValue::Group(b_string.clone()))), - ("c", Some(InputValue::Group(b_string))), + ("a", Some(InputValue::Group(a_element))), + ("b", Some(InputValue::Group(b_element.clone()))), + ("c", Some(InputValue::Group(b_element))), ]); program.set_main_input(main_input); diff --git a/compiler/tests/group/x_and_y.leo b/compiler/tests/group/x_and_y.leo new file mode 100644 index 0000000000..1b64702db1 --- /dev/null +++ b/compiler/tests/group/x_and_y.leo @@ -0,0 +1,3 @@ +function main(element: group) { + let b = element; +} \ No newline at end of file From e27b4e1560814a3c4490dbc6bd3bb909e6c78537 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 17:37:46 -0700 Subject: [PATCH 20/30] fix error message --- compiler/src/errors/value/group.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index 6720397913..59175aabc9 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -78,7 +78,7 @@ impl GroupError { } pub fn y_recover(span: Span) -> Self { - let message = format!("could not recover group element from x coordinate"); + let message = format!("could not recover group element from y coordinate"); Self::new_from_span(message, span) } From 384e9e6cfd5187dacfc2b97c0da32a6fd68a1a2a Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 18:36:39 -0700 Subject: [PATCH 21/30] impl annotations pest ast --- ast/src/annotations/annotation_arguments.rs | 14 ++++++++++++ ast/src/annotations/annotation_name.rs | 19 ++++++++++++++++ ast/src/annotations/annotation_symbol.rs | 13 +++++++++++ ast/src/annotations/annotations.rs | 20 +++++++++++++++++ ast/src/annotations/mod.rs | 11 +++++++++ ast/src/definitions/annotated_definition.rs | 15 +++++++++++++ ast/src/definitions/definition.rs | 2 ++ ast/src/definitions/mod.rs | 3 +++ ast/src/leo.pest | 25 ++++++++++++++++++++- ast/src/lib.rs | 1 + 10 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 ast/src/annotations/annotation_arguments.rs create mode 100644 ast/src/annotations/annotation_name.rs create mode 100644 ast/src/annotations/annotation_symbol.rs create mode 100644 ast/src/annotations/annotations.rs create mode 100644 ast/src/annotations/mod.rs create mode 100644 ast/src/definitions/annotated_definition.rs diff --git a/ast/src/annotations/annotation_arguments.rs b/ast/src/annotations/annotation_arguments.rs new file mode 100644 index 0000000000..182b7d617d --- /dev/null +++ b/ast/src/annotations/annotation_arguments.rs @@ -0,0 +1,14 @@ +use crate::{ast::Rule, common::Identifier, SpanDef}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::annotation_arguments))] +pub struct AnnotationArguments<'ast> { + pub arguments: Vec>, + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} diff --git a/ast/src/annotations/annotation_name.rs b/ast/src/annotations/annotation_name.rs new file mode 100644 index 0000000000..e5260cda85 --- /dev/null +++ b/ast/src/annotations/annotation_name.rs @@ -0,0 +1,19 @@ +use crate::{ast::Rule, SpanDef}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::annotation_name))] +pub enum AnnotationName<'ast> { + Context(Context<'ast>), +} + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::context))] +pub struct Context<'ast> { + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} diff --git a/ast/src/annotations/annotation_symbol.rs b/ast/src/annotations/annotation_symbol.rs new file mode 100644 index 0000000000..b5e2b10bf5 --- /dev/null +++ b/ast/src/annotations/annotation_symbol.rs @@ -0,0 +1,13 @@ +use crate::{ast::Rule, SpanDef}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::annotation_symbol))] +pub struct AnnotationSymbol<'ast> { + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} diff --git a/ast/src/annotations/annotations.rs b/ast/src/annotations/annotations.rs new file mode 100644 index 0000000000..69b01558dd --- /dev/null +++ b/ast/src/annotations/annotations.rs @@ -0,0 +1,20 @@ +use crate::{ + annotations::{AnnotationArguments, AnnotationName, AnnotationSymbol}, + ast::Rule, + SpanDef, +}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::annotation))] +pub struct Annotation<'ast> { + pub symbol: AnnotationSymbol<'ast>, + pub name: AnnotationName<'ast>, + pub arguments: AnnotationArguments<'ast>, + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} diff --git a/ast/src/annotations/mod.rs b/ast/src/annotations/mod.rs new file mode 100644 index 0000000000..787b15ef19 --- /dev/null +++ b/ast/src/annotations/mod.rs @@ -0,0 +1,11 @@ +pub mod annotations; +pub use annotations::*; + +pub mod annotation_symbol; +pub use annotation_symbol::*; + +pub mod annotation_name; +pub use annotation_name::*; + +pub mod annotation_arguments; +pub use annotation_arguments::*; diff --git a/ast/src/definitions/annotated_definition.rs b/ast/src/definitions/annotated_definition.rs new file mode 100644 index 0000000000..8c3b15f6d8 --- /dev/null +++ b/ast/src/definitions/annotated_definition.rs @@ -0,0 +1,15 @@ +use crate::{annotations::Annotation, ast::Rule, definitions::Definition, SpanDef}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::definition_annotated))] +pub struct AnnotatedDefinition<'ast> { + pub annotation: Annotation<'ast>, + pub definition: Box>, + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} diff --git a/ast/src/definitions/definition.rs b/ast/src/definitions/definition.rs index 5f643f3cc0..c2858f4535 100644 --- a/ast/src/definitions/definition.rs +++ b/ast/src/definitions/definition.rs @@ -1,6 +1,7 @@ use crate::{ ast::Rule, circuits::Circuit, + definitions::AnnotatedDefinition, functions::{Function, TestFunction}, imports::Import, }; @@ -11,6 +12,7 @@ use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] #[pest_ast(rule(Rule::definition))] pub enum Definition<'ast> { + Annotated(AnnotatedDefinition<'ast>), Import(Import<'ast>), Circuit(Circuit<'ast>), Function(Function<'ast>), diff --git a/ast/src/definitions/mod.rs b/ast/src/definitions/mod.rs index c4cce58786..83cde009a3 100644 --- a/ast/src/definitions/mod.rs +++ b/ast/src/definitions/mod.rs @@ -1,2 +1,5 @@ +pub mod annotated_definition; +pub use annotated_definition::*; + pub mod definition; pub use definition::*; diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 0ce0c2a3ec..5433a9e906 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -8,12 +8,16 @@ file = { SOI ~ NEWLINE* ~ definition* ~ NEWLINE* ~ EOI } // Declared in definitions/definition.rs definition = { - import + definition_annotated + | import | circuit | function | test_function } +// Declared in definitions/annotated_definition.rs +definition_annotated = { annotation ~ NEWLINE* ~ definition} + // Declared in common/identifier.rs identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* } protected_name = { @@ -457,3 +461,22 @@ debug = {"debug"} // Declared in macros/error.rs error = {"error"} +/// Annotations + +// Declared in annotations/annotation.rs +annotation = @{annotation_symbol ~ annotation_name ~ annotation_arguments} + +// Declared in annotations/annotation_symbol.rs +annotation_symbol = @{"@"} + +// Declared in annotations/annotation_name.rs +annotation_name = { + context +} + +// Declared in annotations/context.rs +context = {"context"} + +// Declared in annotations/annotation_argument.rs +annotation_arguments = !{"(" ~ NEWLINE* ~ identifier ~ ("," ~ NEWLINE* ~ identifier)* ~ ","? ~ NEWLINE* ~ ")"} + diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 8585fcec6e..8b11d62b33 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -8,6 +8,7 @@ extern crate thiserror; mod ast; pub mod access; +pub mod annotations; pub mod circuits; pub mod common; pub mod definitions; From 779d926e6997f80cdc72c1278faae27b7e9d6b08 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 19:20:41 -0700 Subject: [PATCH 22/30] impl annotations typed --- typed/src/annotation.rs | 58 ++++++++++++++++++++++++++++ typed/src/functions/test_function.rs | 12 ++++-- typed/src/lib.rs | 3 ++ typed/src/program.rs | 14 ++++++- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 typed/src/annotation.rs diff --git a/typed/src/annotation.rs b/typed/src/annotation.rs new file mode 100644 index 0000000000..761dea19e3 --- /dev/null +++ b/typed/src/annotation.rs @@ -0,0 +1,58 @@ +use crate::{Circuit, Function, Identifier, Import, InputVariable, TestFunction}; +use leo_ast::{ + annotations::{Annotation, AnnotationArguments, AnnotationName}, + definitions::{AnnotatedDefinition, Definition}, +}; + +use std::collections::HashMap; + +pub fn load_annotation( + annotated_definition: AnnotatedDefinition, + _imports: &mut Vec, + _circuits: &mut HashMap, + _functions: &mut HashMap, + tests: &mut HashMap, + _expected: &mut Vec, +) { + let ast_annotation = annotated_definition.annotation; + let ast_definition = *annotated_definition.definition; + + match ast_definition { + Definition::Import(_) => unimplemented!("annotated imports are not supported yet"), + Definition::Circuit(_) => unimplemented!("annotated circuits are not supported yet"), + Definition::Function(_) => unimplemented!("annotated functions are not supported yet"), + Definition::TestFunction(ast_test) => { + let test = TestFunction::from(ast_test); + load_annotated_test(test, ast_annotation, tests) + } + Definition::Annotated(_) => unimplemented!("nested annotations are not supported yet"), + } +} + +pub fn load_annotated_test(test: TestFunction, annotation: Annotation, tests: &mut HashMap) { + let name = annotation.name; + let ast_arguments = annotation.arguments; + + match name { + AnnotationName::Context(_) => load_annotated_test_context(test, ast_arguments, tests), + } +} + +pub fn load_annotated_test_context( + mut test: TestFunction, + ast_arguments: AnnotationArguments, + tests: &mut HashMap, +) { + let arguments = ast_arguments.arguments; + + if arguments.len() != 1 { + panic!("text context annotation must have one argument identifier") + } + + let ast_input_file = arguments[0].to_owned(); + let input_file = Identifier::from(ast_input_file); + + test.input_file = Some(input_file); + + tests.insert(test.function.identifier.clone(), test); +} diff --git a/typed/src/functions/test_function.rs b/typed/src/functions/test_function.rs index cc20c13ad7..f82344afc2 100644 --- a/typed/src/functions/test_function.rs +++ b/typed/src/functions/test_function.rs @@ -1,13 +1,19 @@ -use crate::Function; +use crate::{Function, Identifier}; use leo_ast::functions::TestFunction as AstTestFunction; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct TestFunction(pub Function); +pub struct TestFunction { + pub function: Function, + pub input_file: Option, +} impl<'ast> From> for TestFunction { fn from(test: AstTestFunction) -> Self { - TestFunction(Function::from(test.function)) + TestFunction { + function: Function::from(test.function), + input_file: None, // pass custom input file with `@context` annotation + } } } diff --git a/typed/src/lib.rs b/typed/src/lib.rs index c1d90de64c..e52df4e8cb 100644 --- a/typed/src/lib.rs +++ b/typed/src/lib.rs @@ -1,6 +1,9 @@ //! A typed syntax tree is represented as a `Program` and consists of import, circuit, and function definitions. //! Each defined type consists of typed statements and expressions. +pub mod annotation; +pub use self::annotation::*; + pub mod circuits; pub use self::circuits::*; diff --git a/typed/src/program.rs b/typed/src/program.rs index c4964ffd10..abe5cb8bf0 100644 --- a/typed/src/program.rs +++ b/typed/src/program.rs @@ -1,7 +1,7 @@ //! A typed Leo program consists of import, circuit, and function definitions. //! Each defined type consists of typed statements and expressions. -use crate::{Circuit, Function, Identifier, Import, InputVariable, TestFunction}; +use crate::{load_annotation, Circuit, Function, Identifier, Import, InputVariable, TestFunction}; use leo_ast::{definitions::Definition, files::File}; use serde::{Deserialize, Serialize}; @@ -47,7 +47,17 @@ impl<'ast> Program { } Definition::TestFunction(test_def) => { let test = TestFunction::from(test_def); - tests.insert(test.0.identifier.clone(), test); + tests.insert(test.function.identifier.clone(), test); + } + Definition::Annotated(annotated_definition) => { + load_annotation( + annotated_definition, + &mut imports, + &mut circuits, + &mut functions, + &mut tests, + &mut expected_input, + ); } }); From fcd8de4a9d5785087aed1b093a29edc21c43bc4c Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 20:40:56 -0700 Subject: [PATCH 23/30] impl input state file pairs --- package/src/errors/inputs/directory.rs | 13 ++++- package/src/inputs/directory.rs | 15 +---- package/src/inputs/mod.rs | 3 + package/src/inputs/pairs.rs | 79 ++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 package/src/inputs/pairs.rs diff --git a/package/src/errors/inputs/directory.rs b/package/src/errors/inputs/directory.rs index 398271b2fd..b18f1f1292 100644 --- a/package/src/errors/inputs/directory.rs +++ b/package/src/errors/inputs/directory.rs @@ -1,3 +1,5 @@ +use crate::{InputFileError, StateFileError}; + use std::{ffi::OsString, fs::FileType, io}; #[derive(Debug, Error)] @@ -11,15 +13,24 @@ pub enum InputsDirectoryError { #[error("file {:?} extension getting", _0)] GettingFileExtension(OsString), + #[error("file {:?} name getting", _0)] + GettingFileName(OsString), + #[error("file {:?} type getting: {}", _0, _1)] GettingFileType(OsString, io::Error), + #[error("{}", _0)] + InputFileError(#[from] InputFileError), + #[error("invalid file {:?} extension: {:?}", _0, _1)] - InvalidFileExtension(OsString, OsString), + InvalidFileExtension(String, OsString), #[error("invalid file {:?} type: {:?}", _0, _1)] InvalidFileType(OsString, FileType), #[error("reading: {}", _0)] Reading(io::Error), + + #[error("{}", _0)] + StateFileError(#[from] StateFileError), } diff --git a/package/src/inputs/directory.rs b/package/src/inputs/directory.rs index 8a9bd1d8a6..547be961d1 100644 --- a/package/src/inputs/directory.rs +++ b/package/src/inputs/directory.rs @@ -1,4 +1,4 @@ -use crate::{errors::InputsDirectoryError, inputs::INPUT_FILE_EXTENSION}; +use crate::errors::InputsDirectoryError; use std::{fs, path::PathBuf}; @@ -17,7 +17,7 @@ impl InputsDirectory { fs::create_dir_all(&path).map_err(InputsDirectoryError::Creating) } - /// Returns a list of files in the source directory. + /// Returns a list of files in the input directory. pub fn files(path: &PathBuf) -> Result, InputsDirectoryError> { let mut path = path.to_owned(); path.push(PathBuf::from(INPUTS_DIRECTORY_NAME)); @@ -39,17 +39,6 @@ impl InputsDirectory { )); } - // Verify that the file has the default file extension - let file_extension = file_path - .extension() - .ok_or_else(|| InputsDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?; - if file_extension != INPUT_FILE_EXTENSION { - return Err(InputsDirectoryError::InvalidFileExtension( - file_path.as_os_str().to_owned(), - file_extension.to_owned(), - )); - } - file_paths.push(file_path); } diff --git a/package/src/inputs/mod.rs b/package/src/inputs/mod.rs index 504289bc48..befb73256e 100644 --- a/package/src/inputs/mod.rs +++ b/package/src/inputs/mod.rs @@ -4,5 +4,8 @@ pub use directory::*; pub mod input; pub use input::*; +pub mod pairs; +pub use pairs::*; + pub mod state; pub use state::*; diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs new file mode 100644 index 0000000000..5dbd35d175 --- /dev/null +++ b/package/src/inputs/pairs.rs @@ -0,0 +1,79 @@ +use crate::{ + inputs::{InputFile, InputsDirectory, StateFile, INPUT_FILE_EXTENSION, STATE_FILE_EXTENSION}, + InputsDirectoryError, +}; + +use std::{collections::HashMap, convert::TryFrom, path::PathBuf}; + +pub struct InputPairs { + /// Maps file names to input file pairs + pub pairs: HashMap, +} + +pub struct InputPair { + pub input_file: String, + pub state_file: String, +} + +impl InputPairs { + pub fn new() -> Self { + Self { pairs: HashMap::new() } + } +} + +impl TryFrom<&PathBuf> for InputPairs { + type Error = InputsDirectoryError; + + fn try_from(directory: &PathBuf) -> Result { + let files = InputsDirectory::files(directory)?; + + let mut pairs = HashMap::::new(); + + for file in files { + let file_extension = file + .extension() + .ok_or_else(|| InputsDirectoryError::GettingFileExtension(file.as_os_str().to_owned()))?; + + let file_name = file + .file_name() + .ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))? + .to_str() + .ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?; + + if file_extension == INPUT_FILE_EXTENSION { + let input_file = InputFile::new(file_name).read_from(&file)?; + + if pairs.contains_key(file_name) { + let pair = pairs.get_mut(file_name).unwrap(); + pair.input_file = input_file; + } else { + let pair = InputPair { + input_file, + state_file: "".to_owned(), + }; + pairs.insert(file_name.to_owned(), pair); + } + } else if file_extension == STATE_FILE_EXTENSION { + let state_file = StateFile::new(file_name).read_from(&file)?; + + if pairs.contains_key(file_name) { + let pair = pairs.get_mut(file_name).unwrap(); + pair.state_file = state_file; + } else { + let pair = InputPair { + input_file: "".to_owned(), + state_file, + }; + pairs.insert(file_name.to_owned(), pair); + } + } else { + return Err(InputsDirectoryError::InvalidFileExtension( + file_name.to_owned(), + file_extension.to_owned(), + )); + } + } + + Ok(InputPairs { pairs }) + } +} From 5efa131c655a432bfc068febfe441a695412506d Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 22:09:22 -0700 Subject: [PATCH 24/30] impl test context with test inputs --- Cargo.lock | 1 + ast/src/annotations/annotation_arguments.rs | 17 +++++++- ast/src/leo.pest | 7 +-- compiler/Cargo.toml | 1 + compiler/src/compiler.rs | 5 ++- compiler/src/constraints/constraints.rs | 40 +++++++++++++++--- compiler/src/errors/compiler.rs | 6 +++ compiler/src/program/program.rs | 1 + leo/commands/publish.rs | 2 +- leo/commands/test.rs | 25 ++++------- package/src/inputs/directory.rs | 47 +++++++++++++-------- package/src/inputs/pairs.rs | 6 +-- typed/src/common/identifier.rs | 15 ++++++- typed/src/input/input.rs | 3 ++ 14 files changed, 125 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71b34d3eeb..fd65e5e2f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1014,6 +1014,7 @@ dependencies = [ "leo-ast", "leo-gadgets", "leo-input", + "leo-package", "leo-typed", "log", "num-bigint", diff --git a/ast/src/annotations/annotation_arguments.rs b/ast/src/annotations/annotation_arguments.rs index 182b7d617d..b25859a50b 100644 --- a/ast/src/annotations/annotation_arguments.rs +++ b/ast/src/annotations/annotation_arguments.rs @@ -1,4 +1,7 @@ -use crate::{ast::Rule, common::Identifier, SpanDef}; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; @@ -7,7 +10,17 @@ use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] #[pest_ast(rule(Rule::annotation_arguments))] pub struct AnnotationArguments<'ast> { - pub arguments: Vec>, + pub arguments: Vec>, + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::annotation_argument))] +pub struct AnnotationArgument<'ast> { + #[pest_ast(outer(with(span_into_string)))] + pub value: String, #[pest_ast(outer())] #[serde(with = "SpanDef")] pub span: Span<'ast>, diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 5433a9e906..44889394b5 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -464,10 +464,10 @@ error = {"error"} /// Annotations // Declared in annotations/annotation.rs -annotation = @{annotation_symbol ~ annotation_name ~ annotation_arguments} +annotation = ${annotation_symbol ~ annotation_name ~ annotation_arguments} // Declared in annotations/annotation_symbol.rs -annotation_symbol = @{"@"} +annotation_symbol = ${"@"} // Declared in annotations/annotation_name.rs annotation_name = { @@ -478,5 +478,6 @@ annotation_name = { context = {"context"} // Declared in annotations/annotation_argument.rs -annotation_arguments = !{"(" ~ NEWLINE* ~ identifier ~ ("," ~ NEWLINE* ~ identifier)* ~ ","? ~ NEWLINE* ~ ")"} +annotation_arguments = !{"(" ~ NEWLINE* ~ annotation_argument ~ ("," ~ NEWLINE* ~ annotation_argument)* ~ ","? ~ NEWLINE* ~ ")"} +annotation_argument = @{ (ASCII_ALPHANUMERIC | "_")+ } diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 35bf31e318..a0ad8e3472 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" leo-ast = { path = "../ast", version = "0.1.0" } leo-gadgets = { path = "../gadgets", version = "0.1.0" } leo-input = { path = "../input", version = "0.1.0" } +leo-package = { path = "../package", version = "0.1.0"} leo-typed = { path = "../typed", version = "0.1.0" } snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false } diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index bcde2061c4..2405efb79b 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -10,6 +10,7 @@ use crate::{ }; use leo_ast::LeoAst; use leo_input::LeoInputParser; +use leo_package::inputs::InputPairs; use leo_typed::{Input, LeoTypedAst, MainInput, Program}; use snarkos_errors::gadgets::SynthesisError; @@ -151,8 +152,8 @@ impl> Compiler { } /// Synthesizes the circuit for test functions with program input. - pub fn compile_test_constraints(self) -> Result<(), CompilerError> { - generate_test_constraints::(self.program, self.program_input, &self.imported_programs) + pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(), CompilerError> { + generate_test_constraints::(self.program, input_pairs, &self.imported_programs) } /// Calls the internal generate_constraints method with arguments diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index ba4aaec894..6fefa8f259 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -11,6 +11,8 @@ use crate::{ }; use leo_typed::{Input, Program}; +use leo_input::LeoInputParser; +use leo_package::inputs::InputPairs; use snarkos_models::{ curves::{Field, PrimeField}, gadgets::r1cs::{ConstraintSystem, TestConstraintSystem}, @@ -43,7 +45,7 @@ pub fn generate_constraints, CS: Constrai pub fn generate_test_constraints>( program: Program, - input: Input, + input: InputPairs, imported_programs: &ImportParser, ) -> Result<(), CompilerError> { let mut resolved_program = ConstrainedProgram::::new(); @@ -51,19 +53,45 @@ pub fn generate_test_constraints>( let tests = program.tests.clone(); + // Store definitions resolved_program.store_definitions(program, imported_programs)?; + // Get default input + let default = input.pairs.get(&program_name); + log::info!("Running {} tests", tests.len()); - for (test_name, test_function) in tests.into_iter() { + for (test_name, test) in tests.into_iter() { let cs = &mut TestConstraintSystem::::new(); let full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string()); - let result = resolved_program.enforce_main_function( + // get input file name from annotation or use test_name + let input_pair = match test.input_file { + Some(file_name) => match input.pairs.get(&file_name.name) { + Some(pair) => pair.to_owned(), + None => return Err(CompilerError::InvalidTestContext(file_name.name)), + }, + None => default.ok_or(CompilerError::NoTestInput)?, + }; + + // parse input files to abstract syntax trees + let input_file = &input_pair.input_file; + let state_file = &input_pair.state_file; + + let input_ast = LeoInputParser::parse_file(input_file)?; + let state_ast = LeoInputParser::parse_file(state_file)?; + + // parse input files into input struct + let mut input = Input::new(); + input.parse_input(input_ast)?; + input.parse_state(state_ast)?; + + // run test function on new program with input + let result = resolved_program.clone().enforce_main_function( cs, program_name.clone(), - test_function.0, - input.clone(), // pass program input into every test + test.function, + input, // pass program input into every test ); if result.is_ok() { @@ -72,6 +100,8 @@ pub fn generate_test_constraints>( full_test_name, cs.is_satisfied() ); + + // write result to file } else { log::error!("test {} errored: {}", full_test_name, result.unwrap_err()); } diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index ff76268520..422ed81a09 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -13,6 +13,9 @@ pub enum CompilerError { #[error("{}", _0)] InputParserError(#[from] InputParserError), + #[error("Cannot find input files with context name `{}`", _0)] + InvalidTestContext(String), + #[error("{}", _0)] FunctionError(#[from] FunctionError), @@ -25,6 +28,9 @@ pub enum CompilerError { #[error("`main` must be a function")] NoMainFunction, + #[error("Failed to find input files for the current test")] + NoTestInput, + #[error("{}", _0)] OutputError(#[from] OutputFileError), diff --git a/compiler/src/program/program.rs b/compiler/src/program/program.rs index c8f97cf0ae..9aa4d85657 100644 --- a/compiler/src/program/program.rs +++ b/compiler/src/program/program.rs @@ -6,6 +6,7 @@ use snarkos_models::curves::{Field, PrimeField}; use std::collections::HashMap; +#[derive(Clone)] pub struct ConstrainedProgram> { pub identifiers: HashMap>, } diff --git a/leo/commands/publish.rs b/leo/commands/publish.rs index 8fbbe37f56..ec3925f942 100644 --- a/leo/commands/publish.rs +++ b/leo/commands/publish.rs @@ -1,7 +1,7 @@ use crate::{ cli::*, cli_types::*, - commands::{BuildCommand, LoginCommand}, + commands::LoginCommand, errors::{ commands::PublishError::{ConnectionUnavalaible, PackageNotPublished}, CLIError, diff --git a/leo/commands/test.rs b/leo/commands/test.rs index 458edfb241..1523c24761 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -63,27 +63,20 @@ impl CLI for TestCommand { let mut output_directory = package_path.clone(); output_directory.push(OUTPUTS_DIRECTORY_NAME); - // Load the input file at `package_name` - let input_string = InputFile::new(&package_name).read_from(&path)?; - - // Load the state file at `package_name.in` - let state_string = StateFile::new(&package_name).read_from(&path)?; - - // Compute the current program checksum - let program = Compiler::::parse_program_with_input( + // Parse the current main program file + let program = Compiler::::parse_program_without_input( package_name.clone(), main_file_path.clone(), output_directory, - &input_string, - &state_string, )?; - // Generate the program on the constraint system and verify correctness - { - let temporary_program = program.clone(); - let output = temporary_program.compile_test_constraints()?; - log::debug!("Compiled constraints - {:#?}", output); - } + // Parse all inputs as input pairs + let pairs = InputPairs::try_from(&package_path)?; + + // Run tests + let temporary_program = program.clone(); + let output = temporary_program.compile_test_constraints(pairs)?; + log::debug!("Compiled constraints - {:#?}", output); Ok(()) } diff --git a/package/src/inputs/directory.rs b/package/src/inputs/directory.rs index 547be961d1..4dc70b9e28 100644 --- a/package/src/inputs/directory.rs +++ b/package/src/inputs/directory.rs @@ -1,6 +1,6 @@ use crate::errors::InputsDirectoryError; -use std::{fs, path::PathBuf}; +use std::{fs, fs::ReadDir, path::PathBuf}; pub static INPUTS_DIRECTORY_NAME: &str = "inputs/"; @@ -24,24 +24,35 @@ impl InputsDirectory { let directory = fs::read_dir(&path).map_err(InputsDirectoryError::Reading)?; let mut file_paths = Vec::new(); - for file_entry in directory.into_iter() { - let file_entry = file_entry.map_err(InputsDirectoryError::GettingFileEntry)?; - let file_path = file_entry.path(); - - // Verify that the entry is structured as a valid file - let file_type = file_entry - .file_type() - .map_err(|error| InputsDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?; - if !file_type.is_file() { - return Err(InputsDirectoryError::InvalidFileType( - file_path.as_os_str().to_owned(), - file_type, - )); - } - - file_paths.push(file_path); - } + parse_file_paths(directory, &mut file_paths)?; Ok(file_paths) } } + +fn parse_file_paths(directory: ReadDir, file_paths: &mut Vec) -> Result<(), InputsDirectoryError> { + for file_entry in directory.into_iter() { + let file_entry = file_entry.map_err(InputsDirectoryError::GettingFileEntry)?; + let file_path = file_entry.path(); + + // Verify that the entry is structured as a valid file or directory + let file_type = file_entry + .file_type() + .map_err(|error| InputsDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?; + if file_type.is_dir() { + let directory = fs::read_dir(&file_path).map_err(InputsDirectoryError::Reading)?; + + parse_file_paths(directory, file_paths)?; + continue; + } else if !file_type.is_file() { + return Err(InputsDirectoryError::InvalidFileType( + file_path.as_os_str().to_owned(), + file_type, + )); + } + + file_paths.push(file_path); + } + + Ok(()) +} diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index 5dbd35d175..b41947cc46 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -35,12 +35,12 @@ impl TryFrom<&PathBuf> for InputPairs { .ok_or_else(|| InputsDirectoryError::GettingFileExtension(file.as_os_str().to_owned()))?; let file_name = file - .file_name() + .file_stem() .ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))? .to_str() .ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?; - if file_extension == INPUT_FILE_EXTENSION { + if file_extension == INPUT_FILE_EXTENSION.trim_start_matches(".") { let input_file = InputFile::new(file_name).read_from(&file)?; if pairs.contains_key(file_name) { @@ -53,7 +53,7 @@ impl TryFrom<&PathBuf> for InputPairs { }; pairs.insert(file_name.to_owned(), pair); } - } else if file_extension == STATE_FILE_EXTENSION { + } else if file_extension == STATE_FILE_EXTENSION.trim_start_matches(".") { let state_file = StateFile::new(file_name).read_from(&file)?; if pairs.contains_key(file_name) { diff --git a/typed/src/common/identifier.rs b/typed/src/common/identifier.rs index 3a31e08599..777e404a4d 100644 --- a/typed/src/common/identifier.rs +++ b/typed/src/common/identifier.rs @@ -1,5 +1,9 @@ use crate::Span; -use leo_ast::{common::Identifier as AstIdentifier, imports::PackageName as AstPackageName}; +use leo_ast::{ + annotations::AnnotationArgument, + common::Identifier as AstIdentifier, + imports::PackageName as AstPackageName, +}; use leo_input::common::Identifier as InputAstIdentifier; use serde::{ @@ -55,6 +59,15 @@ impl<'ast> From> for Identifier { } } +impl<'ast> From> for Identifier { + fn from(argument: AnnotationArgument<'ast>) -> Self { + Self { + name: argument.value, + span: Span::from(argument.span), + } + } +} + impl fmt::Display for Identifier { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) diff --git a/typed/src/input/input.rs b/typed/src/input/input.rs index cacc2d9d8f..8f1dd54bfc 100644 --- a/typed/src/input/input.rs +++ b/typed/src/input/input.rs @@ -6,6 +6,7 @@ use leo_input::{ #[derive(Clone, PartialEq, Eq)] pub struct Input { + name: String, program_input: ProgramInput, program_state: ProgramState, } @@ -13,6 +14,7 @@ pub struct Input { impl Input { pub fn new() -> Self { Self { + name: "default".to_owned(), program_input: ProgramInput::new(), program_state: ProgramState::new(), } @@ -25,6 +27,7 @@ impl Input { let state = self.program_state.empty(); Self { + name: self.name.clone(), program_input: input, program_state: state, } From ced738f852b641b3804f4292fe4f37fd4d8fbe87 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 22:59:26 -0700 Subject: [PATCH 25/30] use from y coordinate from snarkos --- Cargo.lock | 75 ++++++++++--------- .../src/value/group/targets/edwards_bls12.rs | 45 ++++++----- compiler/tests/group/mod.rs | 46 ++++++------ 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71b34d3eeb..0192e3c510 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,7 +128,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -220,9 +220,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chrono" -version = "0.4.13" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6" +checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" dependencies = [ "num-integer", "num-traits", @@ -420,7 +420,7 @@ checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -438,7 +438,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -449,9 +449,9 @@ checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" [[package]] name = "either" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "encoding_rs" @@ -503,7 +503,7 @@ checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "synstructure", ] @@ -677,9 +677,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.3" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", "version_check", @@ -738,9 +738,9 @@ checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" [[package]] name = "hashbrown" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" dependencies = [ "autocfg", ] @@ -846,9 +846,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" +checksum = "86b45e59b16c76b11bf9738fd5d38879d3bd28ad292d7b313608becb17ae2df9" dependencies = [ "autocfg", "hashbrown", @@ -1411,7 +1411,7 @@ dependencies = [ "pest_meta", "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1442,7 +1442,7 @@ checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1805,7 +1805,7 @@ checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1873,14 +1873,14 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" +checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "snarkos-algorithms" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "blake2", "derivative", @@ -1900,7 +1900,7 @@ dependencies = [ [[package]] name = "snarkos-curves" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "derivative", "rand", @@ -1915,17 +1915,17 @@ dependencies = [ [[package]] name = "snarkos-derives" version = "0.1.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] name = "snarkos-dpc" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "blake2", "derivative", @@ -1946,7 +1946,7 @@ dependencies = [ [[package]] name = "snarkos-errors" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "base58", "bech32", @@ -1954,12 +1954,13 @@ dependencies = [ "hex", "jsonrpc-core", "thiserror", + "toml", ] [[package]] name = "snarkos-gadgets" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "derivative", "digest 0.8.1", @@ -1974,7 +1975,7 @@ dependencies = [ [[package]] name = "snarkos-models" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "bincode", "derivative", @@ -1990,7 +1991,7 @@ dependencies = [ [[package]] name = "snarkos-objects" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "base58", "bech32", @@ -2011,7 +2012,7 @@ dependencies = [ [[package]] name = "snarkos-parameters" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "hex", "snarkos-algorithms", @@ -2023,12 +2024,12 @@ dependencies = [ [[package]] name = "snarkos-profiler" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" [[package]] name = "snarkos-utilities" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#4d2465933876f6cd2a55ed122292b33dbabe9228" dependencies = [ "bincode", "rand", @@ -2073,9 +2074,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250" +checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", @@ -2090,7 +2091,7 @@ checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "unicode-xid 0.2.1", ] @@ -2143,7 +2144,7 @@ checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -2406,7 +2407,7 @@ dependencies = [ "log", "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "wasm-bindgen-shared", ] @@ -2440,7 +2441,7 @@ checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index a53be4e1f7..a6e20a4769 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -188,31 +188,30 @@ impl EdwardsGroupType { pub fn edwards_affine_from_y_str( y_string: String, y_span: Span, - _greatest: Option, - _element_span: Span, + greatest: Option, + element_span: Span, ) -> Result { - let _y = Fq::from_str(&y_string).map_err(|_| GroupError::y_invalid(y_string, y_span))?; + let y = Fq::from_str(&y_string).map_err(|_| GroupError::y_invalid(y_string, y_span))?; - unimplemented!("recover from_y_coordinate not implemented for Edwards Affine") - // match greatest { - // // Sign provided - // Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or(GroupError::y_recover(element_span)), - // // Sign inferred - // None => { - // // Attempt to recover with a sign_low bit. - // if let Some(element) = EdwardsAffine::from_y_coordinate(y.clone(), false) { - // return Ok(element); - // } - // - // // Attempt to recover with a sign_high bit. - // if let Some(element) = EdwardsAffine::from_y_coordinate(y, true) { - // return Ok(element); - // } - // - // // Otherwise return error. - // Err(GroupError::y_recover(element_span)) - // } - // } + match greatest { + // Sign provided + Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or(GroupError::y_recover(element_span)), + // Sign inferred + None => { + // Attempt to recover with a sign_low bit. + if let Some(element) = EdwardsAffine::from_y_coordinate(y.clone(), false) { + return Ok(element); + } + + // Attempt to recover with a sign_high bit. + if let Some(element) = EdwardsAffine::from_y_coordinate(y, true) { + return Ok(element); + } + + // Otherwise return error. + Err(GroupError::y_recover(element_span)) + } + } } pub fn edwards_affine_from_pair( diff --git a/compiler/tests/group/mod.rs b/compiler/tests/group/mod.rs index eebdd96bb2..676059271f 100644 --- a/compiler/tests/group/mod.rs +++ b/compiler/tests/group/mod.rs @@ -66,29 +66,29 @@ fn test_x_sign_inferred() { assert_satisfied(program); } -// #[test] -// fn test_y_sign_high() { -// let bytes = include_bytes!("y_sign_high.leo"); -// let program = parse_program(bytes).unwrap(); -// -// assert_satisfied(program); -// } -// -// #[test] -// fn test_y_sign_low() { -// let bytes = include_bytes!("y_sign_low.leo"); -// let program = parse_program(bytes).unwrap(); -// -// assert_satisfied(program); -// } -// -// #[test] -// fn test_y_sign_inferred() { -// let bytes = include_bytes!("y_sign_inferred.leo"); -// let program = parse_program(bytes).unwrap(); -// -// assert_satisfied(program); -// } +#[test] +fn test_y_sign_high() { + let bytes = include_bytes!("y_sign_high.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_y_sign_low() { + let bytes = include_bytes!("y_sign_low.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_y_sign_inferred() { + let bytes = include_bytes!("y_sign_inferred.leo"); + let program = parse_program(bytes).unwrap(); + + assert_satisfied(program); +} #[test] fn test_double_high() { From 9a2fe61c6fd03b026ceef28da7de41f5deb826e0 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 23:25:34 -0700 Subject: [PATCH 26/30] write test output to filename specified by context --- compiler/src/compiler.rs | 10 +++++++++- compiler/src/constraints/constraints.rs | 26 ++++++++++++++++++++----- compiler/src/output/output_file.rs | 1 - leo/commands/test.rs | 5 ++++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 2405efb79b..60ee516f8e 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -153,7 +153,12 @@ impl> Compiler { /// Synthesizes the circuit for test functions with program input. pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(), CompilerError> { - generate_test_constraints::(self.program, input_pairs, &self.imported_programs) + generate_test_constraints::( + self.program, + input_pairs, + &self.imported_programs, + &self.output_directory, + ) } /// Calls the internal generate_constraints method with arguments @@ -205,6 +210,9 @@ impl> ConstraintSynthesizer for Compil // Write results to file let output_file = OutputFile::new(&package_name); + + log::info!("Writing to output registers..."); + output_file.write(&output_directory, result.bytes()).unwrap(); Ok(()) diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 6fefa8f259..5880bdadc7 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -8,6 +8,7 @@ use crate::{ GroupType, ImportParser, OutputBytes, + OutputFile, }; use leo_typed::{Input, Program}; @@ -17,6 +18,7 @@ use snarkos_models::{ curves::{Field, PrimeField}, gadgets::r1cs::{ConstraintSystem, TestConstraintSystem}, }; +use std::path::PathBuf; pub fn generate_constraints, CS: ConstraintSystem>( cs: &mut CS, @@ -47,6 +49,7 @@ pub fn generate_test_constraints>( program: Program, input: InputPairs, imported_programs: &ImportParser, + output_directory: &PathBuf, ) -> Result<(), CompilerError> { let mut resolved_program = ConstrainedProgram::::new(); let program_name = program.get_name(); @@ -64,13 +67,20 @@ pub fn generate_test_constraints>( for (test_name, test) in tests.into_iter() { let cs = &mut TestConstraintSystem::::new(); let full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string()); + let mut output_file_name = program_name.clone(); // get input file name from annotation or use test_name let input_pair = match test.input_file { - Some(file_name) => match input.pairs.get(&file_name.name) { - Some(pair) => pair.to_owned(), - None => return Err(CompilerError::InvalidTestContext(file_name.name)), - }, + Some(file_id) => { + let file_name = file_id.name; + + output_file_name = file_name.clone(); + + match input.pairs.get(&file_name) { + Some(pair) => pair.to_owned(), + None => return Err(CompilerError::InvalidTestContext(file_name)), + } + } None => default.ok_or(CompilerError::NoTestInput)?, }; @@ -101,7 +111,13 @@ pub fn generate_test_constraints>( cs.is_satisfied() ); - // write result to file + // write result to file + let output = result?; + let output_file = OutputFile::new(&output_file_name); + + log::info!("\tWriting output to registers in `{}.out` ...", output_file_name); + + output_file.write(output_directory, output.bytes()).unwrap(); } else { log::error!("test {} errored: {}", full_test_name, result.unwrap_err()); } diff --git a/compiler/src/output/output_file.rs b/compiler/src/output/output_file.rs index d60f60321d..b495422919 100644 --- a/compiler/src/output/output_file.rs +++ b/compiler/src/output/output_file.rs @@ -40,7 +40,6 @@ impl OutputFile { // create output file let path = self.setup_file_path(path); let mut file = File::create(&path)?; - log::info!("Writing to output registers..."); Ok(file.write_all(bytes)?) } diff --git a/leo/commands/test.rs b/leo/commands/test.rs index 1523c24761..ec998675b2 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -6,7 +6,7 @@ use crate::{ use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType}; use leo_package::{ inputs::*, - outputs::OUTPUTS_DIRECTORY_NAME, + outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, root::Manifest, source::{MainFile, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME}, }; @@ -63,6 +63,9 @@ impl CLI for TestCommand { let mut output_directory = package_path.clone(); output_directory.push(OUTPUTS_DIRECTORY_NAME); + // Create the output directory + OutputsDirectory::create(&package_path)?; + // Parse the current main program file let program = Compiler::::parse_program_without_input( package_name.clone(), From 14055407cf812a946715c280fc1d4c6284f91a73 Mon Sep 17 00:00:00 2001 From: collin Date: Sat, 15 Aug 2020 23:47:35 -0700 Subject: [PATCH 27/30] cargo lock --- Cargo.lock | 75 +++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd65e5e2f3..a34b7911cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,7 +128,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -220,9 +220,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chrono" -version = "0.4.13" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6" +checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" dependencies = [ "num-integer", "num-traits", @@ -420,7 +420,7 @@ checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -438,7 +438,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -449,9 +449,9 @@ checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" [[package]] name = "either" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "encoding_rs" @@ -503,7 +503,7 @@ checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "synstructure", ] @@ -677,9 +677,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.3" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", "version_check", @@ -738,9 +738,9 @@ checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" [[package]] name = "hashbrown" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" dependencies = [ "autocfg", ] @@ -846,9 +846,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" +checksum = "86b45e59b16c76b11bf9738fd5d38879d3bd28ad292d7b313608becb17ae2df9" dependencies = [ "autocfg", "hashbrown", @@ -1412,7 +1412,7 @@ dependencies = [ "pest_meta", "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1443,7 +1443,7 @@ checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1806,7 +1806,7 @@ checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -1874,14 +1874,14 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" +checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "snarkos-algorithms" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "blake2", "derivative", @@ -1901,7 +1901,7 @@ dependencies = [ [[package]] name = "snarkos-curves" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "derivative", "rand", @@ -1916,17 +1916,17 @@ dependencies = [ [[package]] name = "snarkos-derives" version = "0.1.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] name = "snarkos-dpc" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "blake2", "derivative", @@ -1947,7 +1947,7 @@ dependencies = [ [[package]] name = "snarkos-errors" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "base58", "bech32", @@ -1955,12 +1955,13 @@ dependencies = [ "hex", "jsonrpc-core", "thiserror", + "toml", ] [[package]] name = "snarkos-gadgets" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "derivative", "digest 0.8.1", @@ -1975,7 +1976,7 @@ dependencies = [ [[package]] name = "snarkos-models" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "bincode", "derivative", @@ -1991,7 +1992,7 @@ dependencies = [ [[package]] name = "snarkos-objects" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "base58", "bech32", @@ -2012,7 +2013,7 @@ dependencies = [ [[package]] name = "snarkos-parameters" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "hex", "snarkos-algorithms", @@ -2024,12 +2025,12 @@ dependencies = [ [[package]] name = "snarkos-profiler" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" [[package]] name = "snarkos-utilities" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#a0d7afb4398abc9b2eb7980811b8b9b808df4019" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" dependencies = [ "bincode", "rand", @@ -2074,9 +2075,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cdb98bcb1f9d81d07b536179c269ea15999b5d14ea958196413869445bb5250" +checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", @@ -2091,7 +2092,7 @@ checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "unicode-xid 0.2.1", ] @@ -2144,7 +2145,7 @@ checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", ] [[package]] @@ -2407,7 +2408,7 @@ dependencies = [ "log", "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "wasm-bindgen-shared", ] @@ -2441,7 +2442,7 @@ checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", - "syn 1.0.36", + "syn 1.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] From 25468c4ed8167e1d1122673df1d4c6b433b03b81 Mon Sep 17 00:00:00 2001 From: collin Date: Sun, 16 Aug 2020 00:28:39 -0700 Subject: [PATCH 28/30] add verify local data commitment method to compiler --- Cargo.lock | 1 + compiler/Cargo.toml | 1 + compiler/src/compiler.rs | 12 ++++++++++++ compiler/src/errors/compiler.rs | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1f459ba6e8..f35728510e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1122,6 +1122,7 @@ dependencies = [ "leo-ast", "leo-gadgets", "leo-input", + "leo-state", "leo-typed", "log", "num-bigint", diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 35bf31e318..c4d27487d9 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -9,6 +9,7 @@ leo-ast = { path = "../ast", version = "0.1.0" } leo-gadgets = { path = "../gadgets", version = "0.1.0" } leo-input = { path = "../input", version = "0.1.0" } leo-typed = { path = "../typed", version = "0.1.0" } +leo-state = { path = "../state", version = "0.1.0" } snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false } snarkos-dpc = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-dpc", default-features = false } diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index bcde2061c4..949a46e5f9 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -10,8 +10,10 @@ use crate::{ }; use leo_ast::LeoAst; use leo_input::LeoInputParser; +use leo_state::verify_local_data_commitment; use leo_typed::{Input, LeoTypedAst, MainInput, Program}; +use snarkos_dpc::{base_dpc::instantiated::Components, SystemParameters}; use snarkos_errors::gadgets::SynthesisError; use snarkos_models::{ curves::{Field, PrimeField}, @@ -124,6 +126,16 @@ impl> Compiler { self.program_input.set_main_input(input); } + /// Verifies the input to the program + pub fn verify_local_data_commitment( + &self, + system_parameters: &SystemParameters, + ) -> Result { + let result = verify_local_data_commitment(system_parameters, &self.program_input)?; + + Ok(result) + } + pub fn checksum(&self) -> Result { // Read in the main file as string let unparsed_file = fs::read_to_string(&self.main_file_path) diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index ff76268520..42293a676c 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -1,6 +1,7 @@ use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError}; use leo_ast::ParserError; use leo_input::InputParserError; +use leo_state::LocalDataVerificationError; use bincode::Error as SerdeError; use std::path::PathBuf; @@ -19,6 +20,9 @@ pub enum CompilerError { #[error("Cannot read from the provided file path - {:?}", _0)] FileReadError(PathBuf), + #[error("{}", _0)] + LocalDataVerificationError(#[from] LocalDataVerificationError), + #[error("`main` function not found")] NoMain, From 748ffcca3bd698b5f56f5bca021f1b12f020c764 Mon Sep 17 00:00:00 2001 From: collin Date: Sun, 16 Aug 2020 12:10:16 -0700 Subject: [PATCH 29/30] update snarkos --- Cargo.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a34b7911cc..4bb4ca45e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1881,7 +1881,7 @@ checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "snarkos-algorithms" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "blake2", "derivative", @@ -1901,7 +1901,7 @@ dependencies = [ [[package]] name = "snarkos-curves" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "derivative", "rand", @@ -1916,7 +1916,7 @@ dependencies = [ [[package]] name = "snarkos-derives" version = "0.1.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", @@ -1926,7 +1926,7 @@ dependencies = [ [[package]] name = "snarkos-dpc" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "blake2", "derivative", @@ -1947,7 +1947,7 @@ dependencies = [ [[package]] name = "snarkos-errors" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "base58", "bech32", @@ -1961,7 +1961,7 @@ dependencies = [ [[package]] name = "snarkos-gadgets" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "derivative", "digest 0.8.1", @@ -1976,7 +1976,7 @@ dependencies = [ [[package]] name = "snarkos-models" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "bincode", "derivative", @@ -1992,7 +1992,7 @@ dependencies = [ [[package]] name = "snarkos-objects" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "base58", "bech32", @@ -2013,7 +2013,7 @@ dependencies = [ [[package]] name = "snarkos-parameters" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "hex", "snarkos-algorithms", @@ -2025,12 +2025,12 @@ dependencies = [ [[package]] name = "snarkos-profiler" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" [[package]] name = "snarkos-utilities" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#87d9993a366274482961461e11a2a356e5087896" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "bincode", "rand", From b1f7457f1f26f58b548cc383eaa543957b865862 Mon Sep 17 00:00:00 2001 From: collin Date: Sun, 16 Aug 2020 12:14:05 -0700 Subject: [PATCH 30/30] update snarkos --- Cargo.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f35728510e..3ffb496734 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2115,7 +2115,7 @@ checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "snarkos-algorithms" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "blake2", "derivative", @@ -2135,7 +2135,7 @@ dependencies = [ [[package]] name = "snarkos-curves" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "derivative", "rand", @@ -2150,7 +2150,7 @@ dependencies = [ [[package]] name = "snarkos-derives" version = "0.1.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", @@ -2160,7 +2160,7 @@ dependencies = [ [[package]] name = "snarkos-dpc" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "blake2", "derivative", @@ -2181,7 +2181,7 @@ dependencies = [ [[package]] name = "snarkos-errors" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "base58", "bech32", @@ -2197,7 +2197,7 @@ dependencies = [ [[package]] name = "snarkos-gadgets" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "derivative", "digest 0.8.1", @@ -2212,7 +2212,7 @@ dependencies = [ [[package]] name = "snarkos-models" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "bincode", "derivative", @@ -2228,7 +2228,7 @@ dependencies = [ [[package]] name = "snarkos-objects" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "base58", "bech32", @@ -2249,7 +2249,7 @@ dependencies = [ [[package]] name = "snarkos-parameters" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "curl", "hex", @@ -2262,12 +2262,12 @@ dependencies = [ [[package]] name = "snarkos-profiler" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" [[package]] name = "snarkos-storage" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "bincode", "hex", @@ -2286,7 +2286,7 @@ dependencies = [ [[package]] name = "snarkos-utilities" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#66243c33e7df47c7d5f5cb1b181c1f8140c660c1" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#57fef6a27035419e0b22fee5b72ca6639e15e1ac" dependencies = [ "bincode", "rand",