diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index f3b3322f00..e2d50f7f44 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -271,6 +271,11 @@ jobs: demo_name: demo-direct-call host: test-runner-sgx sgx_mode: HW + - test: relayed-notes + flavor_id: sidechain + demo_name: demo-send-relayed-note + host: test-runner-sgx + sgx_mode: HW - test: Sidechain flavor_id: sidechain demo_name: demo-sidechain diff --git a/Cargo.lock b/Cargo.lock index cf48f08355..9c4d4df6f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,7 +18,7 @@ version = "0.4.2" source = "git+https://github.com/encointer/substrate-api-client.git?branch=v0.9.42-tag-v0.14.0-integritee-patch#946f3ae82c5d48023107c1890728582561e94725" dependencies = [ "ac-primitives", - "log 0.4.22", + "log 0.4.28", "maybe-async", ] @@ -33,13 +33,13 @@ dependencies = [ "either", "frame-metadata", "hex", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-bits", "scale-decode", "scale-encode", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "sp-application-crypto", "sp-core", @@ -60,7 +60,7 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "sp-application-crypto", "sp-core", @@ -292,6 +292,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + [[package]] name = "base16ct" version = "0.2.0" @@ -352,7 +358,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" dependencies = [ - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -361,7 +367,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", - "log 0.4.22", + "log 0.4.28", ] [[package]] @@ -370,7 +376,7 @@ version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" dependencies = [ - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -488,10 +494,10 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb5b05133427c07c4776906f673ccf36c21b102c9829c641a5b56bd151d44fd6" dependencies = [ - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -507,7 +513,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" dependencies = [ "memchr 2.6.3", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -642,12 +648,25 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits 0.2.16", - "serde 1.0.193", + "serde 1.0.226", "time", "wasm-bindgen", "winapi 0.3.9", ] +[[package]] +name = "cid" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd94671561e36e4e7de75f753f577edafb0e7c05d6e4547229fdf7938fbcd2c3" +dependencies = [ + "core2", + "multibase", + "multihash 0.18.1", + "serde 1.0.226", + "unsigned-varint", +] + [[package]] name = "cipher" version = "0.2.5" @@ -725,12 +744,13 @@ dependencies = [ [[package]] name = "common-multipart-rfc7578" -version = "0.3.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d0a7a42b9c13f2b2a1a7e64b949a19bcb56a49b190076e60261001ceaa5304" +checksum = "5baee326bc603965b0f26583e1ecd7c111c41b49bd92a344897476a352798869" dependencies = [ "bytes 1.4.0", - "futures 0.3.28", + "futures-core 0.3.28", + "futures-util 0.3.28", "http 0.2.9", "mime", "mime_guess", @@ -785,6 +805,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr 2.6.3", +] + [[package]] name = "cpp_demangle" version = "0.3.5" @@ -809,7 +838,7 @@ version = "0.93.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f42ea692c7b450ad18b8c9889661505d51c09ec4380cf1c2d278dbb2da22cae1" dependencies = [ - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -988,6 +1017,26 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +[[package]] +name = "data-encoding-macro" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c904b33cc60130e1aeea4956ab803d08a3f4a0ca82d64ed757afac3891f2bb99" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fdf3fce3ce863539ec1d7fd1b6dcc3c645663376b43ed376bbf887733e4f772" +dependencies = [ + "data-encoding", + "syn 1.0.109", +] + [[package]] name = "der" version = "0.6.1" @@ -1090,6 +1139,15 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + [[package]] name = "dirs-sys" version = "0.3.7" @@ -1226,10 +1284,10 @@ version = "0.1.0" source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13.0-polkadot-v0.9.42#abf29acd41a0fca9cd7025b297b6a9fa272a122f" dependencies = [ "common-primitives", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-runtime", @@ -1253,7 +1311,7 @@ checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" dependencies = [ "atty", "humantime", - "log 0.4.22", + "log 0.4.28", "regex 1.9.5", "termcolor", ] @@ -1266,7 +1324,7 @@ checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ "humantime", "is-terminal", - "log 0.4.22", + "log 0.4.28", "regex 1.9.5", "termcolor", ] @@ -1339,7 +1397,7 @@ dependencies = [ "parity-scale-codec", "rlp", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sha3", "triehash", ] @@ -1372,12 +1430,12 @@ dependencies = [ "evm-core", "evm-gasometer", "evm-runtime", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "primitive-types", "rlp", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sha3", ] @@ -1390,7 +1448,7 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -1431,28 +1489,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "synstructure", -] - [[package]] name = "fake-simd" version = "0.1.2" @@ -1490,7 +1526,7 @@ dependencies = [ "either", "futures 0.3.28", "futures-timer", - "log 0.4.22", + "log 0.4.28", "num-traits 0.2.16", "parity-scale-codec", "parking_lot 0.12.1", @@ -1588,10 +1624,10 @@ dependencies = [ "hex", "impl-serde", "libsecp256k1", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-runtime", @@ -1607,7 +1643,7 @@ dependencies = [ "frame-support", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-runtime", "sp-std", @@ -1628,11 +1664,11 @@ dependencies = [ "frame-support-procedural", "frame-system", "linregress", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "paste", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-api", "sp-application-crypto", "sp-core", @@ -1669,7 +1705,7 @@ dependencies = [ "cfg-if 1.0.0", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -1683,12 +1719,12 @@ dependencies = [ "frame-support-procedural", "impl-trait-for-tuples", "k256", - "log 0.4.22", + "log 0.4.28", "once_cell 1.18.0", "parity-scale-codec", "paste", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "smallvec 1.11.0", "sp-api", "sp-arithmetic", @@ -1749,10 +1785,10 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-runtime", @@ -2066,7 +2102,7 @@ dependencies = [ "aho-corasick", "bstr", "fnv 1.0.7", - "log 0.4.22", + "log 0.4.28", "regex 1.9.5", ] @@ -2153,9 +2189,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" [[package]] name = "hashbrown_tstd" @@ -2329,7 +2365,7 @@ name = "http_req" version = "0.8.1" source = "git+https://github.com/integritee-network/http_req?branch=master#3723e88235f2b29bc1a31835853b072ffd0455fd" dependencies = [ - "log 0.4.22", + "log 0.4.28", "rustls 0.19.1", "unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2341,7 +2377,7 @@ name = "http_req" version = "0.8.1" source = "git+https://github.com/integritee-network/http_req#3723e88235f2b29bc1a31835853b072ffd0455fd" dependencies = [ - "log 0.4.22", + "log 0.4.28", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx)", "sgx_tstd", "unicase 2.6.0 (git+https://github.com/mesalock-linux/unicase-sgx)", @@ -2401,13 +2437,13 @@ dependencies = [ [[package]] name = "hyper-multipart-rfc7578" -version = "0.5.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538ce6aeb81f7cd0d547a42435944d2283714a3f696630318bc47bd839fcfc9" +checksum = "f0eb2cf73e96e9925f4bed948e763aa2901c2f1a3a5f713ee41917433ced6671" dependencies = [ "bytes 1.4.0", "common-multipart-rfc7578", - "futures 0.3.28", + "futures-core 0.3.28", "http 0.2.9", "hyper", ] @@ -2421,7 +2457,7 @@ dependencies = [ "ct-logs", "futures-util 0.3.28", "hyper", - "log 0.4.22", + "log 0.4.28", "rustls 0.19.1", "rustls-native-certs", "tokio", @@ -2516,7 +2552,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" dependencies = [ - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -2548,17 +2584,17 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg 1.1.0", "hashbrown 0.12.3", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] name = "indexmap" -version = "2.0.0" +version = "2.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.16.0", ] [[package]] @@ -2604,7 +2640,7 @@ dependencies = [ "itp-types", "itp-utils", "its-primitives", - "log 0.4.22", + "log 0.4.28", "pallet-assets", "pallet-balances", "pallet-credits", @@ -2621,7 +2657,7 @@ dependencies = [ "rayon", "regex 1.9.5", "reqwest", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "sgx_crypto_helper", "sp-application-crypto", @@ -2648,14 +2684,14 @@ dependencies = [ "base58", "chrono 0.4.26", "clap 2.34.0", - "dirs", + "dirs 3.0.2", "enclave-bridge-primitives", "env_logger 0.9.3", "frame-support", "futures 0.3.28", "hex", "humantime", - "ipfs-api", + "ipfs-api-backend-hyper", "ita-parentchain-interface", "itc-parentchain", "itc-parentchain-test", @@ -2665,6 +2701,7 @@ dependencies = [ "itp-api-client-types", "itp-enclave-api", "itp-enclave-metrics", + "itp-ipfs-cid", "itp-node-api", "itp-settings", "itp-sgx-temp-dir", @@ -2681,7 +2718,7 @@ dependencies = [ "its-test", "jsonrpsee", "lazy_static", - "log 0.4.22", + "log 0.4.28", "mockall", "pallet-balances", "parity-scale-codec", @@ -2691,8 +2728,8 @@ dependencies = [ "prometheus 0.13.3", "regex 1.9.5", "scale-info", - "serde 1.0.193", - "serde_derive 1.0.193", + "serde 1.0.226", + "serde_derive 1.0.226", "serde_json 1.0.103", "sgx-verify", "sgx_crypto_helper", @@ -2739,25 +2776,44 @@ dependencies = [ ] [[package]] -name = "ipfs-api" -version = "0.11.0" +name = "ipfs-api-backend-hyper" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3824538e42e84c792988098df4ad5a35b47be98b19e31454e09f4e322f00fc" +checksum = "8a9d131b408b4caafe1e7c00d410a09ad3eb7e3ab68690cf668e86904b2176b4" dependencies = [ + "async-trait", + "base64 0.13.1", "bytes 1.4.0", - "dirs", - "failure", "futures 0.3.28", "http 0.2.9", "hyper", "hyper-multipart-rfc7578", "hyper-tls", - "parity-multiaddr", - "serde 1.0.193", + "ipfs-api-prelude", + "thiserror 1.0.44", +] + +[[package]] +name = "ipfs-api-prelude" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b74065805db266ba2c6edbd670b23c4714824a955628472b2e46cc9f3a869cb" +dependencies = [ + "async-trait", + "bytes 1.4.0", + "cfg-if 1.0.0", + "common-multipart-rfc7578", + "dirs 4.0.0", + "futures 0.3.28", + "http 0.2.9", + "multiaddr", + "multibase", + "serde 1.0.226", "serde_json 1.0.103", "serde_urlencoded", + "thiserror 1.0.44", "tokio", - "tokio-util 0.6.10", + "tokio-util 0.7.8", "tracing", "typed-builder", "walkdir", @@ -2790,7 +2846,7 @@ dependencies = [ "itp-types", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -2801,9 +2857,9 @@ dependencies = [ "itp-enclave-metrics", "itp-ocall-api", "lazy_static", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", - "serde 1.0.193", + "serde 1.0.226", "sgx_tstd", "substrate-fixed", "thiserror 1.0.44", @@ -2834,7 +2890,7 @@ dependencies = [ "itp-top-pool-author", "itp-types", "itp-utils", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "regex 1.9.5", "sgx_tstd", @@ -2850,7 +2906,7 @@ version = "0.1.0" dependencies = [ "hex-literal 0.4.1", "itp-types", - "log 0.4.22", + "log 0.4.28", ] [[package]] @@ -2891,14 +2947,17 @@ dependencies = [ "base58", "frame-support", "frame-system", + "hex", "ita-assets-map", "ita-parentchain-specs", "ita-sgx-runtime", "itp-hashing", + "itp-ipfs-cid", "itp-node-api", "itp-node-api-metadata", "itp-pallet-storage", "itp-randomness", + "itp-sgx-crypto", "itp-sgx-externalities", "itp-sgx-runtime-primitives", "itp-stf-interface", @@ -2906,7 +2965,7 @@ dependencies = [ "itp-storage", "itp-types", "itp-utils", - "log 0.4.22", + "log 0.4.28", "pallet-assets", "pallet-balances", "pallet-notes", @@ -2935,7 +2994,7 @@ dependencies = [ "itp-utils", "jsonrpc-core 18.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "serde_json 1.0.103", "sgx_tstd", @@ -2958,7 +3017,7 @@ dependencies = [ "itp-test", "itp-top-pool-author", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-io 7.0.0", @@ -2987,7 +3046,7 @@ dependencies = [ "itc-parentchain-block-importer", "itp-import-queue", "itp-types", - "log 0.4.22", + "log 0.4.28", "sgx_tstd", "sgx_types", "thiserror 1.0.44", @@ -3005,7 +3064,7 @@ dependencies = [ "itp-stf-executor", "itp-stf-interface", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -3033,7 +3092,7 @@ dependencies = [ "itp-test", "itp-top-pool-author", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -3055,7 +3114,7 @@ dependencies = [ "itp-storage", "itp-test", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -3082,8 +3141,8 @@ dependencies = [ "http 0.2.9", "http_req 0.8.1 (git+https://github.com/integritee-network/http_req?branch=master)", "http_req 0.8.1 (git+https://github.com/integritee-network/http_req)", - "log 0.4.22", - "serde 1.0.193", + "log 0.4.28", + "serde 1.0.226", "serde_json 1.0.103", "sgx_tstd", "thiserror 1.0.44", @@ -3104,7 +3163,7 @@ dependencies = [ "itp-rpc", "itp-types", "itp-utils", - "log 0.4.22", + "log 0.4.28", "openssl", "parity-scale-codec", "parking_lot 0.12.1", @@ -3131,7 +3190,7 @@ dependencies = [ "its-storage", "its-test", "jsonrpsee", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sp-core", "tokio", @@ -3144,7 +3203,7 @@ dependencies = [ "bit-vec", "chrono 0.4.26", "env_logger 0.9.3", - "log 0.4.22", + "log 0.4.28", "mio 0.6.21", "mio 0.6.23", "mio-extras 2.0.6 (git+https://github.com/integritee-network/mio-extras-sgx?rev=963234b)", @@ -3201,8 +3260,9 @@ name = "itp-api-client-extensions" version = "0.9.0" dependencies = [ "itp-api-client-types", + "itp-ipfs-cid", "itp-types", - "log 0.4.22", + "log 0.4.28", "sp-consensus-grandpa", "sp-runtime", "substrate-api-client", @@ -3235,7 +3295,7 @@ dependencies = [ "itp-sgx-crypto", "itp-sgx-io", "itp-time-utils", - "log 0.4.22", + "log 0.4.28", "num-bigint 0.2.5", "parity-scale-codec", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?rev=sgx_1.1.3)", @@ -3262,7 +3322,7 @@ version = "0.8.0" dependencies = [ "binary-merkle-tree", "parity-scale-codec", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -3286,7 +3346,7 @@ dependencies = [ "itp-stf-interface", "itp-storage", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "serde_json 1.0.103", "sgx_crypto_helper", @@ -3322,7 +3382,7 @@ dependencies = [ "itp-node-api", "itp-nonce-cache", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -3350,6 +3410,22 @@ dependencies = [ "thiserror 1.0.9", ] +[[package]] +name = "itp-ipfs-cid" +version = "0.1.0" +dependencies = [ + "cid", + "hex", + "log 0.4.28", + "multibase", + "multihash 0.18.1", + "parity-scale-codec", + "sgx_tcrypto", + "sgx_tstd", + "sgx_types", + "sha2 0.10.9", +] + [[package]] name = "itp-networking-utils" version = "0.9.0" @@ -3456,7 +3532,7 @@ version = "0.9.0" dependencies = [ "itp-types", "parity-scale-codec", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "sgx_tstd", ] @@ -3473,7 +3549,7 @@ dependencies = [ "derive_more", "itp-sgx-io", "itp-sgx-temp-dir", - "log 0.4.22", + "log 0.4.28", "ofb", "parity-scale-codec", "serde_json 1.0.103", @@ -3492,10 +3568,10 @@ dependencies = [ "derive_more", "environmental 1.1.3", "itp-hashing", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "postcard", - "serde 1.0.193", + "serde 1.0.226", "sgx_tstd", "sp-core", ] @@ -3548,7 +3624,7 @@ dependencies = [ "itp-top-pool", "itp-top-pool-author", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -3595,7 +3671,7 @@ dependencies = [ "itp-stf-state-observer", "itp-time-utils", "itp-types", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "rust-base58 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rust-base58 0.0.4 (git+https://github.com/mesalock-linux/rust-base58-sgx?rev=sgx_1.1.3)", @@ -3611,7 +3687,7 @@ name = "itp-stf-state-observer" version = "0.9.0" dependencies = [ "itp-types", - "log 0.4.22", + "log 0.4.28", "sgx_tstd", "thiserror 1.0.44", "thiserror 1.0.9", @@ -3654,7 +3730,7 @@ dependencies = [ "itp-time-utils", "itp-types", "jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_crypto_helper", "sgx_tstd", @@ -3687,10 +3763,10 @@ dependencies = [ "jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)", "linked-hash-map 0.5.2", "linked-hash-map 0.5.6", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "parity-util-mem", - "serde 1.0.193", + "serde 1.0.226", "sgx_tstd", "sp-application-crypto", "sp-core", @@ -3713,7 +3789,7 @@ dependencies = [ "itp-types", "jsonrpc-core 18.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_crypto_helper", "sgx_tstd", @@ -3735,7 +3811,7 @@ dependencies = [ "pallet-assets", "pallet-balances", "parity-scale-codec", - "serde 1.0.193", + "serde 1.0.226", "sidechain-primitives", "sp-core", "sp-runtime", @@ -3749,8 +3825,13 @@ dependencies = [ name = "itp-utils" version = "0.9.0" dependencies = [ + "cid", "hex", + "log 0.4.28", + "multibase", + "multihash 0.18.1", "parity-scale-codec", + "sha2 0.10.9", ] [[package]] @@ -3768,7 +3849,7 @@ dependencies = [ "itp-types", "its-primitives", "its-state", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -3798,7 +3879,7 @@ dependencies = [ "itp-utils", "its-primitives", "its-test", - "log 0.4.22", + "log 0.4.28", "sgx_tstd", "sp-consensus-slots", "sp-core", @@ -3840,7 +3921,7 @@ dependencies = [ "its-state", "its-test", "its-validateer-fetch", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -3872,7 +3953,7 @@ dependencies = [ "its-primitives", "its-state", "its-test", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -3897,7 +3978,7 @@ dependencies = [ "its-primitives", "its-test", "lazy_static", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-consensus-slots", @@ -3920,8 +4001,8 @@ dependencies = [ "its-storage", "its-test", "jsonrpsee", - "log 0.4.22", - "serde 1.0.193", + "log 0.4.28", + "serde 1.0.226", "serde_json 1.0.103", "thiserror 1.0.44", "tokio", @@ -3934,7 +4015,7 @@ dependencies = [ "itp-types", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-runtime", "sp-std", @@ -3955,7 +4036,7 @@ dependencies = [ "its-primitives", "jsonrpc-core 18.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 18.0.0 (git+https://github.com/scs/jsonrpc?branch=no_std_v18)", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "rust-base58 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rust-base58 0.0.4 (git+https://github.com/mesalock-linux/rust-base58-sgx?rev=sgx_1.1.3)", @@ -3985,7 +4066,7 @@ dependencies = [ "itp-sgx-externalities", "itp-storage", "its-primitives", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -4004,7 +4085,7 @@ dependencies = [ "itp-types", "its-primitives", "its-test", - "log 0.4.22", + "log 0.4.28", "mockall", "parity-scale-codec", "parking_lot 0.12.1", @@ -4035,7 +4116,7 @@ dependencies = [ "itp-test", "itp-types", "its-primitives", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sp-core", "sp-runtime", @@ -4069,9 +4150,9 @@ dependencies = [ "futures 0.3.28", "futures-executor 0.3.28", "futures-util 0.3.28", - "log 0.4.22", - "serde 1.0.193", - "serde_derive 1.0.193", + "log 0.4.28", + "serde 1.0.226", + "serde_derive 1.0.226", "serde_json 1.0.103", ] @@ -4114,8 +4195,8 @@ dependencies = [ "hyper-rustls", "jsonrpsee-types", "jsonrpsee-utils", - "log 0.4.22", - "serde 1.0.193", + "log 0.4.28", + "serde 1.0.226", "serde_json 1.0.103", "thiserror 1.0.44", "url 2.5.0", @@ -4134,8 +4215,8 @@ dependencies = [ "jsonrpsee-types", "jsonrpsee-utils", "lazy_static", - "log 0.4.22", - "serde 1.0.193", + "log 0.4.28", + "serde 1.0.226", "serde_json 1.0.103", "socket2", "thiserror 1.0.44", @@ -4167,8 +4248,8 @@ dependencies = [ "futures-channel 0.3.28", "futures-util 0.3.28", "hyper", - "log 0.4.22", - "serde 1.0.193", + "log 0.4.28", + "serde 1.0.226", "serde_json 1.0.103", "soketto", "thiserror 1.0.44", @@ -4184,11 +4265,11 @@ dependencies = [ "futures-util 0.3.28", "hyper", "jsonrpsee-types", - "log 0.4.22", + "log 0.4.28", "parking_lot 0.11.2", "rand 0.8.5", "rustc-hash", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "thiserror 1.0.44", ] @@ -4203,11 +4284,11 @@ dependencies = [ "fnv 1.0.7", "futures 0.3.28", "jsonrpsee-types", - "log 0.4.22", + "log 0.4.28", "pin-project", "rustls 0.19.1", "rustls-native-certs", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "soketto", "thiserror 1.0.44", @@ -4227,9 +4308,9 @@ dependencies = [ "futures-util 0.3.28", "jsonrpsee-types", "jsonrpsee-utils", - "log 0.4.22", + "log 0.4.28", "rustc-hash", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "soketto", "thiserror 1.0.44", @@ -4248,7 +4329,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell 1.18.0", - "sha2 0.10.7", + "sha2 0.10.9", ] [[package]] @@ -4337,7 +4418,7 @@ dependencies = [ "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", "rand 0.8.5", - "serde 1.0.193", + "serde 1.0.226", "sha2 0.9.9", "typenum 1.16.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4453,9 +4534,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "lz4-sys" @@ -4638,7 +4719,7 @@ dependencies = [ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys", "libc", - "log 0.4.22", + "log 0.4.28", "miow", "net2 0.2.39", "slab 0.4.8", @@ -4663,7 +4744,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", - "log 0.4.22", + "log 0.4.28", "mio 0.6.23", "slab 0.4.8", ] @@ -4674,7 +4755,7 @@ version = "2.0.6" source = "git+https://github.com/integritee-network/mio-extras-sgx?rev=963234b#963234bf55e44f9efff921938255126c48deef3a" dependencies = [ "lazycell", - "log 0.4.22", + "log 0.4.28", "mio 0.6.21", "mio 0.6.23", "sgx_tstd", @@ -4732,29 +4813,72 @@ dependencies = [ "futures-util 0.3.28", "http 0.2.9", "httparse 1.8.0", - "log 0.4.22", + "log 0.4.28", "memchr 2.6.3", "mime", "spin 0.9.8", "version_check", ] +[[package]] +name = "multiaddr" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b36f567c7099511fa8612bbbb52dda2419ce0bdbacf31714e3a5ffdb766d3bd" +dependencies = [ + "arrayref", + "byteorder 1.4.3", + "data-encoding", + "log 0.4.28", + "multibase", + "multihash 0.17.0", + "percent-encoding 2.3.1", + "serde 1.0.226", + "static_assertions", + "unsigned-varint", + "url 2.5.0", +] + +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + [[package]] name = "multihash" -version = "0.13.2" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dac63698b887d2d929306ea48b63760431ff8a24fac40ddb22f9c7f49fb7cab" +checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" dependencies = [ - "generic-array 0.14.7", + "core2", "multihash-derive", - "unsigned-varint 0.5.1", + "unsigned-varint", +] + +[[package]] +name = "multihash" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfd8a792c1694c6da4f68db0a9d707c72bd260994da179e6030a5dcee00bb815" +dependencies = [ + "core2", + "digest 0.10.7", + "multihash-derive", + "sha2 0.10.9", + "unsigned-varint", ] [[package]] name = "multihash-derive" -version = "0.7.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "424f6e86263cd5294cbd7f1e95746b95aca0e0d66bff31e5a40d6baa87b4aa99" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -4799,7 +4923,7 @@ checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", - "log 0.4.22", + "log 0.4.28", "openssl", "openssl-probe", "openssl-sys", @@ -5210,7 +5334,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-runtime", @@ -5225,12 +5349,12 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log 0.4.22", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-keyring", @@ -5246,12 +5370,12 @@ dependencies = [ "enclave-bridge-primitives", "frame-support", "frame-system", - "log 0.4.22", + "log 0.4.28", "pallet-teerex", "pallet-timestamp", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-runtime", @@ -5273,7 +5397,7 @@ dependencies = [ "frame-system", "hex", "impl-trait-for-tuples", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "rlp", "scale-info", @@ -5291,12 +5415,12 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log 0.4.22", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-keyring", @@ -5313,12 +5437,12 @@ dependencies = [ "frame-system", "ita-stf", "itp-randomness", - "log 0.4.22", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-keyring", @@ -5333,11 +5457,11 @@ dependencies = [ "env_logger 0.9.3", "frame-support", "frame-system", - "log 0.4.22", + "log 0.4.28", "pallet-balances", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-keyring", @@ -5354,12 +5478,12 @@ dependencies = [ "frame-system", "ita-stf", "itp-randomness", - "log 0.4.22", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-keyring", @@ -5374,7 +5498,7 @@ dependencies = [ "enclave-bridge-primitives", "frame-support", "frame-system", - "log 0.4.22", + "log 0.4.28", "pallet-balances", "parity-scale-codec", "scale-info", @@ -5392,13 +5516,13 @@ dependencies = [ "enclave-bridge-primitives", "frame-support", "frame-system", - "log 0.4.22", + "log 0.4.28", "pallet-enclave-bridge", "pallet-teerex", "pallet-timestamp", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sidechain-primitives", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", @@ -5428,7 +5552,7 @@ source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13 dependencies = [ "frame-support", "frame-system", - "log 0.4.22", + "log 0.4.28", "pallet-teerex", "parity-scale-codec", "scale-info", @@ -5449,12 +5573,12 @@ dependencies = [ "frame-support", "frame-system", "hex", - "log 0.4.22", + "log 0.4.28", "pallet-timestamp", "parity-scale-codec", "rustls-webpki", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sgx-verify", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", @@ -5471,7 +5595,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-inherents", @@ -5490,31 +5614,13 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std", ] -[[package]] -name = "parity-multiaddr" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58341485071825827b7f03cf7efd1cb21e6a709bea778fb50227fd45d2f361b4" -dependencies = [ - "arrayref", - "bs58", - "byteorder 1.4.3", - "data-encoding", - "multihash", - "percent-encoding 2.3.1", - "serde 1.0.193", - "static_assertions", - "unsigned-varint 0.7.1", - "url 2.5.0", -] - [[package]] name = "parity-scale-codec" version = "3.6.4" @@ -5527,7 +5633,7 @@ dependencies = [ "bytes 1.4.0", "impl-trait-for-tuples", "parity-scale-codec-derive", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -5747,7 +5853,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a25c0b0ae06fcffe600ad392aabfa535696c8973f2253d9ac83171924c58a858" dependencies = [ "postcard-cobs", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -5813,12 +5919,12 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell 1.18.0", - "toml_edit", + "thiserror 1.0.44", + "toml", ] [[package]] @@ -6268,13 +6374,13 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "log 0.4.22", + "log 0.4.28", "mime", "native-tls", "once_cell 1.18.0", "percent-encoding 2.3.1", "pin-project-lite", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "serde_urlencoded", "tokio", @@ -6315,7 +6421,7 @@ source = "git+https://github.com/betrusted-io/ring-xous?branch=0.16.20-cleanup#4 dependencies = [ "cc", "libc", - "log 0.4.22", + "log 0.4.28", "once_cell 1.18.0", "rkyv", "spin 0.5.2", @@ -6512,7 +6618,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ "base64 0.13.1", - "log 0.4.22", + "log 0.4.28", "ring 0.16.20", "sct 0.6.1", "webpki 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6605,7 +6711,7 @@ checksum = "036575c29af9b6e4866ffb7fa055dbf623fe7a9cc159b33786de6013a6969d89" dependencies = [ "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -6673,7 +6779,7 @@ dependencies = [ "derive_more", "parity-scale-codec", "scale-info-derive", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -6839,11 +6945,12 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.193" +version = "1.0.226" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "0dca6411025b24b60bfa7ec1fe1f8e710ac09782dca409ee8237ba74b51295fd" dependencies = [ - "serde_derive 1.0.193", + "serde_core", + "serde_derive 1.0.226", ] [[package]] @@ -6852,8 +6959,8 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b926cfbabfe8011609dda0350cb24d884955d294909ac71c0db7027366c77e3e" dependencies = [ - "serde 1.0.193", - "serde_derive 1.0.193", + "serde 1.0.226", + "serde_derive 1.0.226", ] [[package]] @@ -6865,6 +6972,15 @@ dependencies = [ "serde_derive 1.0.118", ] +[[package]] +name = "serde_core" +version = "1.0.226" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba2ba63999edb9dac981fb34b3e5c0d111a69b0924e253ed29d83f7c99e966a4" +dependencies = [ + "serde_derive 1.0.226", +] + [[package]] name = "serde_derive" version = "1.0.118" @@ -6877,9 +6993,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.226" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "8db53ae22f34573731bafa1db20f04027b2d25e02d8205921b569171699cdb33" dependencies = [ "proc-macro2", "quote", @@ -6915,10 +7031,10 @@ version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.11.4", "itoa 1.0.9", "ryu", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -6930,7 +7046,7 @@ dependencies = [ "form_urlencoded", "itoa 1.0.9", "ryu", - "serde 1.0.193", + "serde 1.0.226", ] [[package]] @@ -6944,12 +7060,12 @@ dependencies = [ "frame-support", "hex", "hex-literal 0.3.4", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "ring 0.16.20", "rustls-webpki", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", @@ -6986,11 +7102,11 @@ dependencies = [ "itertools 0.11.0", "libc", "serde 1.0.118", - "serde 1.0.193", + "serde 1.0.226", "serde-big-array 0.1.5", "serde-big-array 0.3.0", "serde_derive 1.0.118", - "serde_derive 1.0.193", + "serde_derive 1.0.226", "sgx_tcrypto", "sgx_tstd", "sgx_types", @@ -7174,9 +7290,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if 1.0.0", "cpufeatures", @@ -7215,7 +7331,7 @@ source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13 dependencies = [ "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-runtime", @@ -7311,7 +7427,7 @@ dependencies = [ "bytes 1.4.0", "futures 0.3.28", "httparse 1.8.0", - "log 0.4.22", + "log 0.4.28", "rand 0.8.5", "sha-1 0.9.8", ] @@ -7322,7 +7438,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-api-proc-macro", @@ -7357,7 +7473,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", "sp-std", @@ -7372,7 +7488,7 @@ dependencies = [ "num-traits 0.2.16", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-std", "static_assertions", ] @@ -7384,7 +7500,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "async-trait", "futures 0.3.28", - "log 0.4.22", + "log 0.4.28", "sp-core", "sp-inherents", "sp-runtime", @@ -7416,10 +7532,10 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "finality-grandpa", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-api", "sp-application-crypto", "sp-core", @@ -7435,7 +7551,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-std", "sp-timestamp", ] @@ -7458,7 +7574,7 @@ dependencies = [ "impl-serde", "lazy_static", "libsecp256k1", - "log 0.4.22", + "log 0.4.28", "merlin", "parity-scale-codec", "parking_lot 0.12.1", @@ -7470,7 +7586,7 @@ dependencies = [ "schnorrkel", "secp256k1", "secrecy", - "serde 1.0.193", + "serde 1.0.226", "sp-core-hashing", "sp-debug-derive", "sp-externalities", @@ -7492,7 +7608,7 @@ dependencies = [ "blake2b_simd", "byteorder 1.4.3", "digest 0.10.7", - "sha2 0.10.7", + "sha2 0.10.9", "sha3", "sp-std", "twox-hash", @@ -7551,7 +7667,7 @@ version = "7.0.0" dependencies = [ "itp-sgx-externalities", "libsecp256k1", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -7567,7 +7683,7 @@ dependencies = [ "ed25519-dalek", "futures 0.3.28", "libsecp256k1", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "rustversion", "secp256k1", @@ -7602,7 +7718,7 @@ dependencies = [ "futures 0.3.28", "parity-scale-codec", "parking_lot 0.12.1", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-externalities", "thiserror 1.0.44", @@ -7637,12 +7753,12 @@ dependencies = [ "either", "hash256-std-hasher", "impl-trait-for-tuples", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "paste", "rand 0.8.5", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-application-crypto", "sp-arithmetic", "sp-core", @@ -7688,7 +7804,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-runtime", "sp-std", @@ -7700,7 +7816,7 @@ version = "0.13.0" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "parking_lot 0.12.1", "rand 0.8.5", @@ -7727,7 +7843,7 @@ dependencies = [ "impl-serde", "parity-scale-codec", "ref-cast", - "serde 1.0.193", + "serde 1.0.226", "sp-debug-derive", "sp-std", ] @@ -7739,7 +7855,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "async-trait", "futures-timer", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sp-inherents", "sp-runtime", @@ -7791,7 +7907,7 @@ dependencies = [ "parity-scale-codec", "parity-wasm", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core-hashing-proc-macro", "sp-runtime", "sp-std", @@ -7817,7 +7933,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "anyhow", "impl-trait-for-tuples", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "sp-std", "wasmi", @@ -7831,7 +7947,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "smallvec 1.11.0", "sp-arithmetic", "sp-core", @@ -7881,7 +7997,7 @@ dependencies = [ "num-format", "proc-macro2", "quote", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "unicode-xid", ] @@ -7945,10 +8061,10 @@ dependencies = [ "frame-metadata", "frame-support", "hex", - "log 0.4.22", + "log 0.4.28", "maybe-async", "parity-scale-codec", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "sp-core", "sp-runtime", @@ -7993,7 +8109,7 @@ source = "git+https://github.com/encointer/substrate-fixed?tag=v0.5.9#a4fb461aae dependencies = [ "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "typenum 1.16.0 (git+https://github.com/encointer/typenum?tag=v1.16.0)", ] @@ -8066,10 +8182,10 @@ source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13 dependencies = [ "common-primitives", "derive_more", - "log 0.4.22", + "log 0.4.28", "parity-scale-codec", "scale-info", - "serde 1.0.193", + "serde 1.0.226", "sp-core", "sp-runtime", "sp-std", @@ -8196,7 +8312,7 @@ dependencies = [ "pbkdf2 0.11.0", "rand 0.8.5", "rustc-hash", - "sha2 0.10.7", + "sha2 0.10.9", "thiserror 1.0.44", "unicode-normalization 0.1.22", "wasm-bindgen", @@ -8297,7 +8413,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" dependencies = [ "futures-util 0.3.28", - "log 0.4.22", + "log 0.4.28", "tokio", "tungstenite 0.21.0", ] @@ -8312,7 +8428,7 @@ dependencies = [ "futures-core 0.3.28", "futures-io 0.3.28", "futures-sink 0.3.28", - "log 0.4.22", + "log 0.4.28", "pin-project-lite", "tokio", ] @@ -8332,20 +8448,12 @@ dependencies = [ ] [[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" - -[[package]] -name = "toml_edit" -version = "0.19.15" +name = "toml" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ - "indexmap 2.0.0", - "toml_datetime", - "winnow", + "serde 1.0.226", ] [[package]] @@ -8361,7 +8469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", - "log 0.4.22", + "log 0.4.28", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -8395,7 +8503,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" dependencies = [ "lazy_static", - "log 0.4.22", + "log 0.4.28", "tracing-core", ] @@ -8405,7 +8513,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" dependencies = [ - "serde 1.0.193", + "serde 1.0.226", "tracing-core", ] @@ -8420,7 +8528,7 @@ dependencies = [ "lazy_static", "matchers", "regex 1.9.5", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "sharded-slab", "smallvec 1.11.0", @@ -8439,7 +8547,7 @@ checksum = "767abe6ffed88a1889671a102c2861ae742726f52e0a5a425b92c9fbfa7e9c85" dependencies = [ "hash-db 0.16.0", "hashbrown 0.13.2", - "log 0.4.22", + "log 0.4.28", "rustc-hex", "smallvec 1.11.0", ] @@ -8508,7 +8616,7 @@ dependencies = [ "bytes 1.4.0", "http 0.2.9", "httparse 1.8.0", - "log 0.4.22", + "log 0.4.28", "rand 0.8.5", "rustls 0.19.1", "sha-1 0.9.8", @@ -8530,7 +8638,7 @@ dependencies = [ "bytes 1.4.0", "http 0.2.9", "httparse 1.8.0", - "log 0.4.22", + "log 0.4.28", "native-tls", "rand 0.8.5", "sha1 0.10.5", @@ -8550,7 +8658,7 @@ dependencies = [ "data-encoding", "http 1.2.0", "httparse 1.8.0", - "log 0.4.22", + "log 0.4.28", "rand 0.8.5", "sha1 0.10.5", "thiserror 1.0.44", @@ -8564,7 +8672,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "digest 0.10.7", "rand 0.8.5", "static_assertions", @@ -8572,9 +8680,9 @@ dependencies = [ [[package]] name = "typed-builder" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a46ee5bd706ff79131be9c94e7edcb82b703c487766a114434e5790361cf08c5" +checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c" dependencies = [ "proc-macro2", "quote", @@ -8676,12 +8784,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "unsigned-varint" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fdeedbf205afadfe39ae559b75c3240f24e257d0ca27e85f85cb82aa19ac35" - [[package]] name = "unsigned-varint" version = "0.7.1" @@ -8797,14 +8899,14 @@ dependencies = [ "headers", "http 0.2.9", "hyper", - "log 0.4.22", + "log 0.4.28", "mime", "mime_guess", "multer", "percent-encoding 2.3.1", "pin-project", "scoped-tls", - "serde 1.0.193", + "serde 1.0.226", "serde_json 1.0.103", "serde_urlencoded", "tokio", @@ -8849,7 +8951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", - "log 0.4.22", + "log 0.4.28", "once_cell 1.18.0", "proc-macro2", "quote", @@ -8952,12 +9054,12 @@ dependencies = [ "cfg-if 1.0.0", "indexmap 1.9.3", "libc", - "log 0.4.22", + "log 0.4.28", "object 0.29.0", "once_cell 1.18.0", "paste", "psm", - "serde 1.0.193", + "serde 1.0.226", "target-lexicon", "wasmparser", "wasmtime-environ", @@ -8985,9 +9087,9 @@ dependencies = [ "cranelift-entity", "gimli 0.26.2", "indexmap 1.9.3", - "log 0.4.22", + "log 0.4.28", "object 0.29.0", - "serde 1.0.193", + "serde 1.0.226", "target-lexicon", "thiserror 1.0.44", "wasmparser", @@ -9006,10 +9108,10 @@ dependencies = [ "cfg-if 1.0.0", "cpp_demangle", "gimli 0.26.2", - "log 0.4.22", + "log 0.4.28", "object 0.29.0", "rustc-demangle", - "serde 1.0.193", + "serde 1.0.226", "target-lexicon", "wasmtime-environ", "wasmtime-jit-icache-coherence", @@ -9048,7 +9150,7 @@ dependencies = [ "cfg-if 1.0.0", "indexmap 1.9.3", "libc", - "log 0.4.22", + "log 0.4.28", "mach", "memfd", "memoffset 0.6.5", @@ -9068,7 +9170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83e5572c5727c1ee7e8f28717aaa8400e4d22dcbd714ea5457d85b5005206568" dependencies = [ "cranelift-entity", - "serde 1.0.193", + "serde 1.0.226", "thiserror 1.0.44", "wasmparser", ] @@ -9339,15 +9441,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" -[[package]] -name = "winnow" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25b5872fa2e10bd067ae946f927e726d7d603eaeb6e02fa6a350e0722d2b8c11" -dependencies = [ - "memchr 2.6.3", -] - [[package]] name = "winreg" version = "0.50.0" @@ -9367,7 +9460,7 @@ dependencies = [ "byteorder 1.4.3", "bytes 0.4.12", "httparse 1.8.0", - "log 0.4.22", + "log 0.4.28", "mio 0.6.23", "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl", @@ -9423,7 +9516,7 @@ version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03e07c190c743d6d9e076f715333e94c48de41b99078343d174c707803df28c7" dependencies = [ - "log 0.4.22", + "log 0.4.28", "num-derive", "num-traits 0.2.16", "xous", @@ -9436,7 +9529,7 @@ version = "0.9.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32d8361077e67966d25922056284d17d042cbb1c96a7ebc2584eb8181427cbb0" dependencies = [ - "log 0.4.22", + "log 0.4.28", "num-derive", "num-traits 0.2.16", "rkyv", diff --git a/Cargo.toml b/Cargo.toml index 95c637d1b0..3ca2ebe487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ members = [ "core-primitives/enclave-metrics", "core-primitives/extrinsics-factory", "core-primitives/hashing", + "core-primitives/ipfs-cid", "core-primitives/networking-utils", "core-primitives/node-api", "core-primitives/node-api/api-client-extensions", diff --git a/app-libs/stf/Cargo.toml b/app-libs/stf/Cargo.toml index a48763e044..ce58a0300b 100644 --- a/app-libs/stf/Cargo.toml +++ b/app-libs/stf/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] # crates.io codec = { version = "3.0.0", default-features = false, features = ["derive"], package = "parity-scale-codec" } +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } log = { version = "0.4", default-features = false } rlp = { version = "0.5", default-features = false } sha3 = { version = "0.10", default-features = false } @@ -19,10 +20,12 @@ ita-assets-map = { path = "../assets-map", default-features = false } ita-parentchain-specs = { default-features = false, path = "../parentchain-specs" } ita-sgx-runtime = { default-features = false, path = "../sgx-runtime" } itp-hashing = { default-features = false, path = "../../core-primitives/hashing" } +itp-ipfs-cid = { default-features = false, path = "../../core-primitives/ipfs-cid" } itp-node-api = { default-features = false, path = "../../core-primitives/node-api" } itp-node-api-metadata = { default-features = false, path = "../../core-primitives/node-api/metadata" } itp-pallet-storage = { path = "../../core-primitives/pallet-storage", default-features = false } itp-randomness = { path = "../../core-primitives/randomness", default-features = false } +itp-sgx-crypto = { default-features = false, path = "../../core-primitives/sgx/crypto" } itp-sgx-externalities = { default-features = false, path = "../../core-primitives/substrate-sgx/externalities" } itp-sgx-runtime-primitives = { default-features = false, path = "../../core-primitives/sgx-runtime-primitives" } itp-stf-interface = { default-features = false, path = "../../core-primitives/stf-interface" } @@ -57,6 +60,7 @@ default = ["std"] evm = ["ita-sgx-runtime/evm"] sgx = [ "sgx_tstd", + "itp-ipfs-cid/sgx", "itp-sgx-externalities/sgx", "sp-io/sgx", "itp-node-api/sgx", @@ -70,6 +74,7 @@ std = [ "ita-sgx-runtime/std", "ita-parentchain-specs/std", "itp-hashing/std", + "itp-ipfs-cid/std", "itp-pallet-storage/std", "itp-sgx-externalities/std", "itp-stf-interface/std", diff --git a/app-libs/stf/src/credits.rs b/app-libs/stf/src/credits.rs index 4ba66f2594..6a83e47591 100644 --- a/app-libs/stf/src/credits.rs +++ b/app-libs/stf/src/credits.rs @@ -32,7 +32,7 @@ use itp_node_api_metadata::NodeMetadataTrait; use itp_sgx_runtime_primitives::types::{Balance, Moment, ShardIdentifier}; use itp_stf_interface::{ExecuteCall, ExecuteGetter}; use itp_stf_primitives::error::StfError; -use itp_types::{parentchain::ParentchainCall, AccountId, Hash}; +use itp_types::{AccountId, Hash, TrustedCallSideEffect}; use sp_std::{sync::Arc, vec, vec::Vec}; #[derive(Encode, Decode, Debug, Clone, PartialEq, Eq)] @@ -77,7 +77,7 @@ where fn execute( self, - _calls: &mut Vec, + _side_effects: &mut Vec, _shard: &ShardIdentifier, _node_metadata_repo: Arc, ) -> Result<(), Self::Error> { diff --git a/app-libs/stf/src/guess_the_number.rs b/app-libs/stf/src/guess_the_number.rs index 6612d52d97..033f41514d 100644 --- a/app-libs/stf/src/guess_the_number.rs +++ b/app-libs/stf/src/guess_the_number.rs @@ -32,7 +32,7 @@ use itp_node_api_metadata::NodeMetadataTrait; use itp_sgx_runtime_primitives::types::{Balance, Moment, ShardIdentifier}; use itp_stf_interface::{ExecuteCall, ExecuteGetter}; use itp_stf_primitives::error::StfError; -use itp_types::{parentchain::ParentchainCall, AccountId}; +use itp_types::{AccountId, TrustedCallSideEffect}; use itp_utils::stringify::account_id_to_string; use log::*; use sp_std::{sync::Arc, vec, vec::Vec}; @@ -85,7 +85,7 @@ where fn execute( self, - _calls: &mut Vec, + _side_effects: &mut Vec, _shard: &ShardIdentifier, _node_metadata_repo: Arc, ) -> Result<(), Self::Error> { diff --git a/app-libs/stf/src/helpers.rs b/app-libs/stf/src/helpers.rs index 9e51ff116f..25c8c9c157 100644 --- a/app-libs/stf/src/helpers.rs +++ b/app-libs/stf/src/helpers.rs @@ -18,6 +18,8 @@ use crate::{TrustedCall, ENCLAVE_ACCOUNT_KEY}; use codec::{Decode, Encode}; use frame_support::dispatch::UnfilteredDispatchable; use ita_sgx_runtime::{ParentchainIntegritee, ParentchainTargetA, ParentchainTargetB, Runtime}; +use itp_randomness::{Randomness, SgxRandomness}; +use itp_sgx_crypto::{aes::Aes, StateCrypto}; use itp_stf_interface::{BlockMetadata, ShardCreationInfo}; use itp_stf_primitives::{ error::{StfError, StfResult}, @@ -256,3 +258,31 @@ pub fn store_note( .map_err(|e| StfError::Dispatch(format!("Store note error: {:?}", e.error)))?; Ok(()) } + +/// Encrypt data with AES-128-OFB with a fresh key and IV. +/// Encrypts data in-place and returns the ciphertext and the full encryption key (key + iv). +/// The full encryption key is 32 bytes: first 16 bytes are the AES key, +/// the last 16 bytes are the IV. +pub fn encrypt_with_fresh_key(mut data: Vec) -> StfResult<(Vec, [u8; 32])> { + let key = SgxRandomness::random_128bits(); + let iv = SgxRandomness::random_128bits(); + let aes = Aes::new(key, iv); + aes.encrypt(&mut data) + .map_err(|e| StfError::Dispatch(format!("AES encrypt error: {:?}", e)))?; + let full_encryption_key: [u8; 32] = + [key.as_ref(), iv.as_ref()].concat().try_into().expect("2x16=32. q.e.d."); + Ok((data, full_encryption_key)) +} + +/// Encrypt data with AES-128-OFB with a provided key and IV. +/// Encrypts data in-place and returns the ciphertext and the full encryption key (key + iv). +/// The full encryption key is 32 bytes: first 16 bytes are the AES key, +/// the last 16 bytes are the IV. +pub fn encrypt_with_key(mut data: Vec, full_key: [u8; 32]) -> StfResult> { + let key: [u8; 16] = full_key[..16].try_into().expect("Slice with 16 bytes"); + let iv: [u8; 16] = full_key[16..].try_into().expect("Slice with 16 bytes"); + let aes = Aes::new(key, iv); + aes.encrypt(&mut data) + .map_err(|e| StfError::Dispatch(format!("AES encrypt error: {:?}", e)))?; + Ok(data) +} diff --git a/app-libs/stf/src/lib.rs b/app-libs/stf/src/lib.rs index 151a019ee7..d4b2de8bb3 100644 --- a/app-libs/stf/src/lib.rs +++ b/app-libs/stf/src/lib.rs @@ -40,6 +40,7 @@ pub mod guess_the_number; pub mod hash; pub mod helpers; pub mod parentchain_mirror; +pub mod relayed_note; pub mod stf_sgx; pub mod stf_sgx_primitives; #[cfg(all(feature = "test", feature = "sgx"))] diff --git a/app-libs/stf/src/relayed_note.rs b/app-libs/stf/src/relayed_note.rs new file mode 100644 index 0000000000..d1baebcdf4 --- /dev/null +++ b/app-libs/stf/src/relayed_note.rs @@ -0,0 +1,86 @@ +/* + Copyright 2021 Integritee AG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +use codec::{Decode, Encode}; +use core::fmt::Debug; +use itp_ipfs_cid::IpfsCid; +use sp_std::vec::Vec; +pub type ConversationId = u32; + +#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)] +pub enum NoteRelayType { + /// the note will be stored in chain state entirely + Here, + /// the note is stored on ipfs, encrypted with a symmetric key + Ipfs, + /// the note is relayed through an undeclared channel which is assumed to be + /// known by the recipient + Undeclared, +} + +/// Necessary information for recipient to retrieve and potentially decrypt a relayed note +#[derive(Encode, Decode, Clone, PartialEq, Eq)] +pub enum RelayedNoteRetrievalInfo { + /// the message is included within and not actually relayed + Here { msg: Vec }, + /// the message is stored on ipfs, encrypted with the provided key + Ipfs { cid: IpfsCid, encryption_key: [u8; 32] }, + /// the message is relayed through an undeclared channel which is assumed to be + /// known by the recipient, but the encryption key is provided + Undeclared { encryption_key: [u8; 32] }, +} + +impl Debug for RelayedNoteRetrievalInfo { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + RelayedNoteRetrievalInfo::Here { msg } => write!( + f, + "Here {{ msg: {} }}", + core::str::from_utf8(msg).unwrap_or("") + ), + RelayedNoteRetrievalInfo::Ipfs { cid, encryption_key } => write!( + f, + "Ipfs {{ cid: {:?}, encryption_key: 0x{} }}", + cid, + hex::encode(encryption_key) + ), + RelayedNoteRetrievalInfo::Undeclared { encryption_key } => + write!(f, "Undeclared {{ encryption_key: 0x{} }}", hex::encode(encryption_key)), + } + } +} + +/// A user request to relay a note to a specific conversation. +#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)] +pub struct RelayedNoteRequest { + pub allow_onchain_fallback: bool, + pub relay_type: NoteRelayType, + pub msg: Vec, + /// in the case of `Undeclared` relaying, this can be used to securely share the encryption key with the recipient + pub maybe_encryption_key: Option<[u8; 32]>, +} + +impl Default for RelayedNoteRequest { + fn default() -> Self { + RelayedNoteRequest { + allow_onchain_fallback: true, + relay_type: NoteRelayType::Here, + msg: Vec::new(), + maybe_encryption_key: None, + } + } +} diff --git a/app-libs/stf/src/stf_sgx.rs b/app-libs/stf/src/stf_sgx.rs index 8749cf80b7..be88b169d4 100644 --- a/app-libs/stf/src/stf_sgx.rs +++ b/app-libs/stf/src/stf_sgx.rs @@ -55,7 +55,10 @@ use itp_stf_primitives::{ types::{ShardIdentifier, Signature}, }; use itp_storage::storage_value_key; -use itp_types::parentchain::{AccountId, BlockNumber, Hash, Index, ParentchainCall, ParentchainId}; +use itp_types::{ + parentchain::{AccountId, BlockNumber, Hash, Index, ParentchainId}, + TrustedCallSideEffect, +}; use itp_utils::{hex::hex_encode, stringify::account_id_to_string}; use log::*; use sp_runtime::traits::StaticLookup; @@ -225,10 +228,10 @@ where state: &mut State, shard: &ShardIdentifier, call: TCS, - calls: &mut Vec, + side_effects: &mut Vec, node_metadata_repo: Arc, ) -> Result<(), Self::Error> { - state.execute_with(|| call.execute(calls, shard, node_metadata_repo)) + state.execute_with(|| call.execute(side_effects, shard, node_metadata_repo)) } fn on_initialize( @@ -269,7 +272,7 @@ where state: &mut State, shard: &ShardIdentifier, integritee_block_number: BlockNumber, - calls: &mut Vec, + side_effects: &mut Vec, node_metadata_repo: Arc, ) -> Result<(), Self::Error> { state.execute_with(|| { @@ -314,7 +317,7 @@ where retire_account( account, &mut enclave_nonce, - calls, + side_effects, shard, node_metadata_repo.clone(), ); @@ -342,7 +345,7 @@ where fn retire_account( account: AccountId, enclave_nonce: &mut Index, - calls: &mut Vec, + side_effects: &mut Vec, shard: &ShardIdentifier, node_metadata_repo: Arc, ) where @@ -368,7 +371,7 @@ fn retire_account( signature: fake_signature.clone(), }; // Replace with `inspect_err` once it's stable. - tcs.execute(calls, shard, node_metadata_repo.clone()) + tcs.execute(side_effects, shard, node_metadata_repo.clone()) .map_err(|e| { error!( "Failed to force-unshield {:?} for {}: {:?}", @@ -390,7 +393,7 @@ fn retire_account( signature: fake_signature, }; // Replace with `inspect_err` once it's stable. - tcs.execute(calls, shard, node_metadata_repo) + tcs.execute(side_effects, shard, node_metadata_repo) .map_err(|e| { error!( "Failed to force-unshield native for {:?}: {:?}", diff --git a/app-libs/stf/src/trusted_call.rs b/app-libs/stf/src/trusted_call.rs index aec48509a2..1cac6bca78 100644 --- a/app-libs/stf/src/trusted_call.rs +++ b/app-libs/stf/src/trusted_call.rs @@ -29,9 +29,11 @@ use crate::{ guess_the_number, guess_the_number::GuessTheNumberTrustedCall, helpers::{ - enclave_signer_account, ensure_enclave_signer_account, ensure_maintainer_account, - get_mortality, shard_vault, shielding_target_genesis_hash, store_note, wrap_bytes, + enclave_signer_account, encrypt_with_fresh_key, encrypt_with_key, + ensure_enclave_signer_account, ensure_maintainer_account, get_mortality, shard_vault, + shielding_target_genesis_hash, store_note, wrap_bytes, }, + relayed_note::{ConversationId, NoteRelayType, RelayedNoteRequest, RelayedNoteRetrievalInfo}, Getter, STF_BYTE_FEE_UNIT_DIVIDER, STF_SESSION_PROXY_DEPOSIT_DIVIDER, STF_SHIELDING_FEE_AMOUNT_DIVIDER, STF_TX_FEE_UNIT_DIVIDER, }; @@ -45,11 +47,12 @@ use ita_parentchain_specs::MinimalChainSpec; #[cfg(feature = "evm")] use ita_sgx_runtime::{AddressMapping, HashedAddressMapping}; use ita_sgx_runtime::{ - Assets, ParentchainInstanceIntegritee, ParentchainInstanceTargetA, ParentchainInstanceTargetB, - ParentchainIntegritee, Runtime, SessionProxyCredentials, SessionProxyRole, ShardManagement, - System, + Assets, MaxNoteSize, ParentchainInstanceIntegritee, ParentchainInstanceTargetA, + ParentchainInstanceTargetB, ParentchainIntegritee, Runtime, SessionProxyCredentials, + SessionProxyRole, ShardManagement, System, }; pub use ita_sgx_runtime::{Balance, Index}; +use itp_ipfs_cid::IpfsCid; use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait}; use itp_node_api_metadata::{ frame_system::SystemCallIndexes, @@ -66,7 +69,7 @@ use itp_stf_primitives::{ }; use itp_types::{ parentchain::{GenericMortality, ParentchainCall, ParentchainId, ProxyType}, - Address, Moment, OpaqueCall, + Address, Moment, OpaqueCall, TrustedCallSideEffect, }; use itp_utils::stringify::account_id_to_string; use log::*; @@ -77,7 +80,7 @@ use sp_core::{ ed25519, }; use sp_runtime::{traits::Verify, MultiAddress, MultiSignature}; -use std::{format, prelude::v1::*, sync::Arc, vec}; +use std::{cmp::min, format, prelude::v1::*, sync::Arc, vec}; #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)] #[allow(non_camel_case_types)] @@ -97,6 +100,8 @@ pub enum TrustedCall { waste_time(AccountId, u32) = 11, spam_extrinsics(AccountId, u32, ParentchainId) = 12, send_note(AccountId, AccountId, Vec) = 20, + send_relayed_note(AccountId, AccountId, ConversationId, RelayedNoteRequest) = 21, + send_relayed_note_stripped(AccountId, AccountId, ConversationId, RelayedNoteRetrievalInfo) = 22, // without payload add_session_proxy(AccountId, AccountId, SessionProxyCredentials) = 30, assets_transfer(AccountId, AccountId, AssetId, Balance) = 42, assets_unshield(AccountId, AccountId, AssetId, Balance, ShardIdentifier) = 43, @@ -168,6 +173,8 @@ impl TrustedCall { sender_account, Self::timestamp_set(sender_account, ..) => sender_account, Self::send_note(sender_account, ..) => sender_account, + Self::send_relayed_note(sender_account, ..) => sender_account, + Self::send_relayed_note_stripped(sender_account, ..) => sender_account, Self::spam_extrinsics(sender_account, ..) => sender_account, Self::add_session_proxy(sender_account, ..) => sender_account, Self::note_bloat(sender_account, ..) => sender_account, @@ -301,7 +308,7 @@ where fn execute( self, - calls: &mut Vec, + side_effects: &mut Vec, shard: &ShardIdentifier, node_metadata_repo: Arc, ) -> Result<(), Self::Error> { @@ -414,7 +421,7 @@ where self.call, vec![account_incognito.clone(), beneficiary], ); - calls.push(parentchain_call); + side_effects.push(TrustedCallSideEffect::ParentchainCall(parentchain_call)); Ok(()) }, TrustedCall::balance_unshield_through_enclave_bridge_pallet( @@ -462,7 +469,7 @@ where let mortality = get_mortality(ParentchainId::Integritee, 32) .unwrap_or_else(GenericMortality::immortal); let parentchain_call = ParentchainCall::Integritee { call, mortality }; - calls.push(parentchain_call); + side_effects.push(TrustedCallSideEffect::ParentchainCall(parentchain_call)); Ok(()) }, TrustedCall::balance_shield(enclave_account, who, value, parentchain_id) => { @@ -618,16 +625,63 @@ where ParentchainId::TargetB => ParentchainCall::TargetB { call, mortality: mortality.clone() }, }; - calls.push(pcall); + side_effects.push(TrustedCallSideEffect::ParentchainCall(pcall)); } Ok(()) }, TrustedCall::send_note(from, to, _note) => { - let _origin = ita_sgx_runtime::RuntimeOrigin::signed(from.clone()); std::println!("⣿STF⣿ 🔄 send_note from ⣿⣿⣿ to ⣿⣿⣿ with note ⣿⣿⣿"); store_note(&from, self.call, vec![from.clone(), to])?; Ok(()) }, + TrustedCall::send_relayed_note(from, to, conversation_id, request) => { + std::println!("⣿STF⣿ 🔄 send_relayed_note from ⣿⣿⣿ to ⣿⣿⣿ with note ⣿⣿⣿"); + let retrieval_info = if (self.call.encoded_size() <= MaxNoteSize::get() as usize) + && (request.allow_onchain_fallback) + { + Ok(RelayedNoteRetrievalInfo::Here { msg: request.msg }) + } else if (request.relay_type == NoteRelayType::Undeclared) + && request.maybe_encryption_key.is_some() + { + Ok(RelayedNoteRetrievalInfo::Undeclared { + encryption_key: request + .maybe_encryption_key + .expect("is_some has been tested previously"), + }) + } else if request.relay_type == NoteRelayType::Here + && request.msg.len() <= MaxNoteSize::get() as usize + { + Ok(RelayedNoteRetrievalInfo::Here { msg: request.msg }) + } else if request.relay_type == NoteRelayType::Ipfs { + let (ciphertext, encryption_key) = + if let Some(key) = request.maybe_encryption_key { + (encrypt_with_key(request.msg, key)?, key) + } else { + encrypt_with_fresh_key(request.msg)? + }; + let cid = IpfsCid::from_chunk(&ciphertext) + .map_err(|e| StfError::Dispatch(format!("IPFS error: {:?}", e)))?; + info!("storing relayed note to IPFS with CID {:?}", cid); + side_effects.push(TrustedCallSideEffect::IpfsAdd(ciphertext)); + Ok(RelayedNoteRetrievalInfo::Ipfs { cid, encryption_key }) + } else { + Err(StfError::Dispatch("Invalid relayed note request".into())) + }?; + + let stripped_call = TrustedCall::send_relayed_note_stripped( + from.clone(), + to.clone(), + conversation_id, + retrieval_info, + ); + store_note(&from, stripped_call, vec![from.clone(), to])?; + Ok(()) + }, + TrustedCall::send_relayed_note_stripped(from, to, _conversation_id, _retrieval) => { + std::println!("⣿STF⣿ 🔄 send_relayed_note_stripped from ⣿⣿⣿ to ⣿⣿⣿ with note ⣿⣿⣿"); + store_note(&from, self.call, vec![from.clone(), to])?; + Ok(()) + }, TrustedCall::add_session_proxy(delegator, delegate, credentials) => { let origin = ita_sgx_runtime::RuntimeOrigin::signed(delegator.clone()); std::println!("⣿STF⣿ 🔄 add_proxy delegator ⣿⣿⣿ delegate ⣿⣿⣿"); @@ -721,7 +775,7 @@ where self.call, vec![account_incognito.clone(), beneficiary], )?; - calls.push(parentchain_call); + side_effects.push(TrustedCallSideEffect::ParentchainCall(parentchain_call)); Ok(()) }, TrustedCall::assets_shield(enclave_account, who, asset_id, value, parentchain_id) => { @@ -865,8 +919,9 @@ where info!("Trying to create evm contract with address {:?}", contract_address); Ok(()) }, - TrustedCall::guess_the_number(call) => call.execute(calls, shard, node_metadata_repo), - TrustedCall::credits(call) => call.execute(calls, shard, node_metadata_repo), + TrustedCall::guess_the_number(call) => + call.execute(side_effects, shard, node_metadata_repo), + TrustedCall::credits(call) => call.execute(side_effects, shard, node_metadata_repo), TrustedCall::force_unshield_all(enclave_account, who, maybe_asset_id) => { ensure_enclave_signer_account(&enclave_account)?; if let Some(asset_id) = maybe_asset_id { @@ -892,7 +947,7 @@ where store_note(&who, self.call, vec![who.clone()])?; burn_assets(&who, balance, asset_id)?; if unshield_amount > 0 { - calls.push(parentchain_call); + side_effects.push(TrustedCallSideEffect::ParentchainCall(parentchain_call)); } } else { let info = System::account(&who); @@ -946,7 +1001,7 @@ where Self::Error::Dispatch(format!("Balance burn balance error: {:?}", e.error)) })?; if unshield_amount > 0 { - calls.push(parentchain_call); + side_effects.push(TrustedCallSideEffect::ParentchainCall(parentchain_call)); } } Ok(()) @@ -994,6 +1049,23 @@ fn get_fee_for(tc: &TrustedCallSigned, fee_asset: Option) -> Fee { TrustedCall::send_note(_, _, note) => one / STF_TX_FEE_UNIT_DIVIDER + (one.saturating_mul(Balance::from(note.len() as u32))) / STF_BYTE_FEE_UNIT_DIVIDER, + TrustedCall::send_relayed_note(_, _, _, blob) => + one / STF_TX_FEE_UNIT_DIVIDER + + one.saturating_mul(Balance::from(min( + MaxNoteSize::get(), + blob.encoded_size() as u32, + ))) / STF_BYTE_FEE_UNIT_DIVIDER, + TrustedCall::send_relayed_note_stripped(_, _, _, retrieval_info) => { + let byte_fee = match retrieval_info { + RelayedNoteRetrievalInfo::Undeclared { .. } => 32 * one / STF_BYTE_FEE_UNIT_DIVIDER, // flat fee for undeclared + RelayedNoteRetrievalInfo::Ipfs { .. } => + (46 + 32) * one / STF_BYTE_FEE_UNIT_DIVIDER, // flat fee for ipfs + RelayedNoteRetrievalInfo::Here { msg } => + (one.saturating_mul(Balance::from(msg.len() as u32))) + / STF_BYTE_FEE_UNIT_DIVIDER, + }; + byte_fee + one / STF_TX_FEE_UNIT_DIVIDER + }, #[cfg(feature = "evm")] TrustedCall::evm_call(..) => one / STF_TX_FEE_UNIT_DIVIDER, #[cfg(feature = "evm")] diff --git a/cli/demo_send_relayed_note.sh b/cli/demo_send_relayed_note.sh new file mode 100755 index 0000000000..ddcf5efaf4 --- /dev/null +++ b/cli/demo_send_relayed_note.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +# Sends a relayed note with a direct call to the worker which is expected +# to relay it via IPFS in encrypted form +# + + +# usage: +# demo-send-relayed-note.sh -p -P -i +# +# TEST_BALANCE_RUN is either "first" or "second" + + +while getopts ":p:P:t:u:V:C:i:" opt; do + case $opt in + p) + INTEGRITEE_RPC_PORT=$OPTARG + ;; + P) + WORKER_1_PORT=$OPTARG + ;; + u) + INTEGRITEE_RPC_URL=$OPTARG + ;; + V) + WORKER_1_URL=$OPTARG + ;; + i) + IPFS_GATEWAY=$OPTARG + ;; + C) + CLIENT_BIN=$OPTARG + ;; + *) + echo "invalid arg ${OPTARG}" + exit 1 + esac +done + +# Using default port if none given as arguments. +INTEGRITEE_RPC_PORT=${INTEGRITEE_RPC_PORT:-9944} +INTEGRITEE_RPC_URL=${INTEGRITEE_RPC_URL:-"ws://127.0.0.1"} + +WORKER_1_PORT=${WORKER_1_PORT:-2000} +WORKER_1_URL=${WORKER_1_URL:-"wss://127.0.0.1"} +IPFS_GATEWAY=${IPFS_GATEWAY:-"http://127.0.0.1:8080"} + +CLIENT_BIN=${CLIENT_BIN:-"./../bin/integritee-cli"} + +echo "Using client binary ${CLIENT_BIN}" +${CLIENT_BIN} --version +echo "Using node uri ${INTEGRITEE_RPC_URL}:${INTEGRITEE_RPC_PORT}" +echo "Using trusted-worker uri ${WORKER_1_URL}:${WORKER_1_PORT}" +echo "Using IPFS gateway ${IPFS_GATEWAY}" +echo "" + +CLIENT="${CLIENT_BIN} -p ${INTEGRITEE_RPC_PORT} -P ${WORKER_1_PORT} -u ${INTEGRITEE_RPC_URL} -U ${WORKER_1_URL} -i ${IPFS_GATEWAY}" +# we simply believe the enclave here without verifying the teerex RA +MRENCLAVE="$($CLIENT trusted get-fingerprint)" +echo "Using MRENCLAVE: ${MRENCLAVE}" +TCLIENT="${CLIENT} trusted --mrenclave ${MRENCLAVE} --direct" + +NOTE="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." +${TCLIENT} send-note --ipfs-proxy //Alice //Bob "${NOTE}" +echo "Alice sent note to Bob:" +echo $NOTE + +RECEIVED_NOTE=$(${TCLIENT} get-notes //Bob 0 | grep "${NOTE}") + +echo "Bob received:" +echo $RECEIVED_NOTE + +if echo "$RECEIVED_NOTE" | grep -qF "$NOTE"; then + echo "✔ NOTE found in RECEIVED_NOTE" +else + echo "✗ NOTE not found in RECEIVED_NOTE" + exit 1 +fi + +echo "Alice will send an 80kB heavy note to Bob" + +HEAVY_NOTE_PLAINTEXT_LENGTH=81920 +HEAVY_NOTE=$(head -c ${HEAVY_NOTE_PLAINTEXT_LENGTH} /dev/zero | tr '\0' 'A') +${TCLIENT} send-note --ipfs-proxy //Alice //Bob "${HEAVY_NOTE}" +echo "Alice sent heavy note to Bob" +RECEIVED_HEAVY_NOTE=$(${TCLIENT} get-notes //Bob 0 | grep "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | tail -n 1) +RECEIVED_HEAVY_NOTE_LENGTH=$(echo -n "$RECEIVED_HEAVY_NOTE" | wc -c) +echo "Bob received $RECEIVED_HEAVY_NOTE_LENGTH bytes" + +if [ "$RECEIVED_HEAVY_NOTE_LENGTH" -gt $HEAVY_NOTE_PLAINTEXT_LENGTH ]; then + echo "✔ heavy note found" + exit 0 +else + echo "✗ heavy note not found" + exit 1 +fi \ No newline at end of file diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 7cbb980807..ae7b861a62 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -97,6 +97,10 @@ pub struct Cli { #[clap(short = 'P', long, default_value_t = String::from("2000"))] trusted_worker_port: String, + /// IPFS gateway url, e.g. "https://ipfs.integritee.network" + #[clap(short = 'i', long, default_value_t = String::from("https://ipfs.integritee.network"))] + ipfs_gateway_url: String, + #[clap(subcommand)] command: Commands, } diff --git a/cli/src/trusted_base_cli/commands/get_notes.rs b/cli/src/trusted_base_cli/commands/get_notes.rs index 4d02492594..9940126b50 100644 --- a/cli/src/trusted_base_cli/commands/get_notes.rs +++ b/cli/src/trusted_base_cli/commands/get_notes.rs @@ -19,17 +19,18 @@ use crate::{ trusted_command_utils::get_pair_from_str, trusted_operation::perform_trusted_operation, Cli, CliResult, CliResultOk, }; - use codec::Decode; use ita_stf::{ - guess_the_number::GuessTheNumberTrustedCall, Getter, TrustedCall, TrustedCallSigned, - TrustedGetter, + guess_the_number::GuessTheNumberTrustedCall, relayed_note::RelayedNoteRetrievalInfo, Getter, + TrustedCall, TrustedCallSigned, TrustedGetter, }; +use itp_sgx_crypto::{aes::Aes, StateCrypto}; use itp_stf_primitives::types::{KeyPair, TrustedOperation}; -use itp_types::Moment; -use log::error; +use itp_types::{AccountId, Moment}; +use log::{debug, error}; use pallet_notes::{BucketIndex, TimestampedTrustedNote, TrustedNote}; -use sp_core::Pair; +use reqwest::blocking::get; +use sp_core::{crypto::Ss58Codec, Pair}; #[derive(Parser)] pub struct GetNotesCommand { @@ -42,8 +43,9 @@ pub struct GetNotesCommand { impl GetNotesCommand { pub(crate) fn run(&self, cli: &Cli, trusted_args: &TrustedCli) -> CliResult { let who = get_pair_from_str(cli, trusted_args, self.account.as_str()); + let who_accountid: AccountId = who.public().into(); let top = TrustedOperation::::get(Getter::trusted( - TrustedGetter::notes_for(who.public().into(), self.bucket_index) + TrustedGetter::notes_for(who_accountid.clone(), self.bucket_index) .sign(&KeyPair::Sr25519(Box::new(who))), )); let notes = perform_trusted_operation::>>( @@ -104,6 +106,64 @@ impl GetNotesCommand { sender, guess, ); }, + TrustedCall::send_note(from, to, note) => + if from == who_accountid { + println!( + "[{}] Message to: {}: {}", + datetime_str, + to.to_ss58check(), + String::from_utf8_lossy(note.as_ref()) + ); + } else { + println!( + "[{}] Message from: {}: {}", + datetime_str, + from.to_ss58check(), + String::from_utf8_lossy(note.as_ref()) + ); + }, + TrustedCall::send_relayed_note_stripped( + from, + to, + conversation_id, + retrieval, + ) => { + let msg = match retrieval { + RelayedNoteRetrievalInfo::Ipfs { cid, encryption_key } => { + debug!("fetching ipfs data for cid: {:?}", cid); + let ciphertext = fetch_ipfs_data( + &cli.ipfs_gateway_url, + &cid.to_string(), + ) + .unwrap(); + let plaintext = decrypt(&ciphertext, &encryption_key); + String::from_utf8_lossy(&plaintext).to_string() + }, + RelayedNoteRetrievalInfo::Here { msg } => + String::from_utf8_lossy(msg.as_ref()).to_string(), + RelayedNoteRetrievalInfo::Undeclared { .. } => { + "[encryption key provided: *****, but message relay is undeclared]".into() + }, + }; + + if from == who_accountid { + println!( + "[{}] Message in conversation {} to: {}: {:?}", + datetime_str, + conversation_id, + to.to_ss58check(), + msg + ); + } else { + println!( + "[{}] Message in conversation {} from: {}: {:?}", + datetime_str, + conversation_id, + from.to_ss58check(), + msg + ); + } + }, _ => println!("[{}] {:?}", datetime_str, call), } } else { @@ -116,3 +176,21 @@ impl GetNotesCommand { Ok(CliResultOk::Notes { notes }) } } + +fn fetch_ipfs_data(gateway_url: &str, ipfs_hash: &str) -> Result, reqwest::Error> { + let url = format!("{}/ipfs/{}", gateway_url.trim_end_matches('/'), ipfs_hash); + debug!("Fetching ipfs data from url: {}", url); + let response = get(&url)?; + let bytes = response.bytes()?.to_vec(); + Ok(bytes) +} + +fn decrypt(data: &[u8], encryption_key: &[u8; 32]) -> Vec { + let key: [u8; 16] = encryption_key[0..16].try_into().unwrap(); + let iv: [u8; 16] = encryption_key[16..32].try_into().unwrap(); + debug!("decrypting with \n key 0x{} \n iv 0x{}", hex::encode(key), hex::encode(iv)); + let aes = Aes::new(key, iv); + let mut decrypted_data = data.to_vec(); + aes.decrypt(&mut decrypted_data).unwrap(); + decrypted_data +} diff --git a/cli/src/trusted_base_cli/commands/mod.rs b/cli/src/trusted_base_cli/commands/mod.rs index ff2a872b5b..e0d6864e0f 100644 --- a/cli/src/trusted_base_cli/commands/mod.rs +++ b/cli/src/trusted_base_cli/commands/mod.rs @@ -14,6 +14,7 @@ pub mod get_total_issuance; pub mod get_undistributed_fees; pub mod nonce; pub mod note_bloat; +pub mod send_note; pub mod spam_extrinsics; pub mod transfer; pub mod unshield_funds; diff --git a/cli/src/trusted_base_cli/commands/send_note.rs b/cli/src/trusted_base_cli/commands/send_note.rs new file mode 100644 index 0000000000..960f99b3cf --- /dev/null +++ b/cli/src/trusted_base_cli/commands/send_note.rs @@ -0,0 +1,111 @@ +/* + Copyright 2021 Integritee AG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +use crate::{ + get_basic_signing_info_from_args, + trusted_cli::TrustedCli, + trusted_command_utils::{get_accountid_from_str, get_trusted_account_info}, + trusted_operation::{perform_trusted_operation, send_direct_request}, + Cli, CliResult, CliResultOk, +}; +use ita_stf::{ + relayed_note::{ConversationId, NoteRelayType, RelayedNoteRequest}, + Getter, TrustedCall, TrustedCallSigned, +}; +use itp_stf_primitives::{ + traits::TrustedCallSigning, + types::{KeyPair, TrustedOperation}, +}; +use log::*; +use std::boxed::Box; + +#[derive(Parser)] +pub struct SendNoteCommand { + /// sender's account. AccountId in ss58check format, mnemonic or hex seed. + sender: String, + /// recipient of note. AccountId in ss58check format. + recipient: String, + + /// plain message body in UTF8 encoding + message: String, + + /// session proxy who can sign on behalf of the account + #[clap(long)] + session_proxy: Option, + + /// Instruct the worker enclave to encrypt and relay the message via IPFS instead of onchain + #[clap(long)] + ipfs_proxy: bool, + + /// specify conversation ID + #[clap(long)] + conversation_id: Option, +} + +impl SendNoteCommand { + pub(crate) fn run(&self, cli: &Cli, trusted_args: &TrustedCli) -> CliResult { + let (sender, signer, mrenclave, shard) = + get_basic_signing_info_from_args!(self.sender, self.session_proxy, cli, trusted_args); + + let to = get_accountid_from_str(&self.recipient); + let trimmed_msg = if self.message.len() > 100 { + let short = &self.message[..100]; + format!("[{} bytes]: {}...", self.message.len(), short) + } else { + self.message.clone() + }; + println!("send trusted call send-note to {}: {}", to, trimmed_msg); + + let nonce = get_trusted_account_info(cli, trusted_args, &sender, &signer) + .map(|info| info.nonce) + .unwrap_or_default(); + let top: TrustedOperation = if self.ipfs_proxy { + let request = RelayedNoteRequest { + allow_onchain_fallback: false, + relay_type: NoteRelayType::Ipfs, + msg: self.message.as_bytes().to_vec(), + maybe_encryption_key: None, + }; + let conversation_id = self.conversation_id.unwrap_or_default(); + TrustedCall::send_relayed_note(sender, to, conversation_id, request) + .sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard) + .into_trusted_operation(trusted_args.direct) + } else if self.conversation_id.is_some() { + let request = RelayedNoteRequest { + allow_onchain_fallback: false, + relay_type: NoteRelayType::Here, + msg: self.message.as_bytes().to_vec(), + maybe_encryption_key: None, + }; + let conversation_id = self.conversation_id.unwrap_or_default(); + TrustedCall::send_relayed_note(sender, to, conversation_id, request) + .sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard) + .into_trusted_operation(trusted_args.direct) + } else { + TrustedCall::send_note(sender, to, self.message.as_bytes().to_vec()) + .sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard) + .into_trusted_operation(trusted_args.direct) + }; + + if trusted_args.direct { + Ok(send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?) + } else { + Ok(perform_trusted_operation::<()>(cli, trusted_args, &top) + .map(|_| CliResultOk::None)?) + } + } +} diff --git a/cli/src/trusted_base_cli/mod.rs b/cli/src/trusted_base_cli/mod.rs index d452601c91..404419f81d 100644 --- a/cli/src/trusted_base_cli/mod.rs +++ b/cli/src/trusted_base_cli/mod.rs @@ -27,8 +27,9 @@ use crate::{ get_shard_info::GetShardInfoCommand, get_shard_vault::GetShardVaultCommand, get_total_issuance::GetTotalIssuanceCommand, get_undistributed_fees::GetUndistributedFeesCommand, nonce::NonceCommand, - note_bloat::NoteBloatCommand, spam_extrinsics::SpamExtrinsicsCommand, - transfer::TransferCommand, unshield_funds::UnshieldFundsCommand, version::VersionCommand, + note_bloat::NoteBloatCommand, send_note::SendNoteCommand, + spam_extrinsics::SpamExtrinsicsCommand, transfer::TransferCommand, + unshield_funds::UnshieldFundsCommand, version::VersionCommand, waste_time::WasteTimeCommand, watchdog::WatchdogCommand, }, trusted_cli::TrustedCli, @@ -118,6 +119,9 @@ pub enum TrustedBaseCommand { /// run a chatbot service Chatbot(ChatbotCommand), + /// send a private note to someone + SendNote(SendNoteCommand), + /// get a version string for the enclave Version(VersionCommand), } @@ -125,32 +129,33 @@ pub enum TrustedBaseCommand { impl TrustedBaseCommand { pub fn run(&self, cli: &Cli, trusted_cli: &TrustedCli) -> CliResult { match self { - TrustedBaseCommand::NewAccount => new_account(cli, trusted_cli), - TrustedBaseCommand::ListAccounts => list_accounts(cli, trusted_cli), - TrustedBaseCommand::Transfer(cmd) => cmd.run(cli, trusted_cli), + Self::NewAccount => new_account(cli, trusted_cli), + Self::ListAccounts => list_accounts(cli, trusted_cli), + Self::Transfer(cmd) => cmd.run(cli, trusted_cli), #[cfg(feature = "test")] - TrustedBaseCommand::SetBalance(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::Balance(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::UnshieldFunds(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::Nonce(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetFingerprint(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetParentchainsInfo(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetNoteBucketsInfo(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetNotes(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetShard(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetShardInfo(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetShardVault(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetSidechainHeader(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetTotalIssuance(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetUndistributedFees(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::AddSessionProxy(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::GetSessionProxies(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::NoteBloat(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::WasteTime(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::SpamExtrinsics(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::Watchdog(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::Chatbot(cmd) => cmd.run(cli, trusted_cli), - TrustedBaseCommand::Version(cmd) => cmd.run(cli, trusted_cli), + Self::SetBalance(cmd) => cmd.run(cli, trusted_cli), + Self::Balance(cmd) => cmd.run(cli, trusted_cli), + Self::UnshieldFunds(cmd) => cmd.run(cli, trusted_cli), + Self::Nonce(cmd) => cmd.run(cli, trusted_cli), + Self::GetFingerprint(cmd) => cmd.run(cli, trusted_cli), + Self::GetParentchainsInfo(cmd) => cmd.run(cli, trusted_cli), + Self::GetNoteBucketsInfo(cmd) => cmd.run(cli, trusted_cli), + Self::GetNotes(cmd) => cmd.run(cli, trusted_cli), + Self::GetShard(cmd) => cmd.run(cli, trusted_cli), + Self::GetShardInfo(cmd) => cmd.run(cli, trusted_cli), + Self::GetShardVault(cmd) => cmd.run(cli, trusted_cli), + Self::GetSidechainHeader(cmd) => cmd.run(cli, trusted_cli), + Self::GetTotalIssuance(cmd) => cmd.run(cli, trusted_cli), + Self::GetUndistributedFees(cmd) => cmd.run(cli, trusted_cli), + Self::AddSessionProxy(cmd) => cmd.run(cli, trusted_cli), + Self::GetSessionProxies(cmd) => cmd.run(cli, trusted_cli), + Self::NoteBloat(cmd) => cmd.run(cli, trusted_cli), + Self::SendNote(cmd) => cmd.run(cli, trusted_cli), + Self::WasteTime(cmd) => cmd.run(cli, trusted_cli), + Self::SpamExtrinsics(cmd) => cmd.run(cli, trusted_cli), + Self::Watchdog(cmd) => cmd.run(cli, trusted_cli), + Self::Chatbot(cmd) => cmd.run(cli, trusted_cli), + Self::Version(cmd) => cmd.run(cli, trusted_cli), } } } diff --git a/core-primitives/ipfs-cid/Cargo.toml b/core-primitives/ipfs-cid/Cargo.toml new file mode 100644 index 0000000000..1afdf1e109 --- /dev/null +++ b/core-primitives/ipfs-cid/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "itp-ipfs-cid" +version = "0.1.0" +authors = ["Integritee AG "] +edition = "2021" + +[dependencies] +cid = { version = "0.10.1", default-features = false, features = ["alloc"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +log = { version = "0.4", default-features = false } +multibase = { version = "0.9.1", default-features = false } +multihash = { version = "0.18.0", default-features = false, features = ["alloc"] } +sgx_tcrypto = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true } +sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", features = ["untrusted_fs", "net", "backtrace"], optional = true } +sgx_types = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", features = ["extra_traits"] } +sha2 = { version = "0.10.9", default-features = false, optional = true } + +[features] +default = ["std"] +std = [ + "codec/std", + "hex/std", + "log/std", + "sgx_tcrypto", + "sha2", +] + +sgx = [ + "sgx_tstd", + "sgx_tcrypto", +] +test = [] +production = [] diff --git a/core-primitives/ipfs-cid/src/lib.rs b/core-primitives/ipfs-cid/src/lib.rs new file mode 100644 index 0000000000..837a13fde4 --- /dev/null +++ b/core-primitives/ipfs-cid/src/lib.rs @@ -0,0 +1,189 @@ +/* + Copyright 2021 Integritee AG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(all(feature = "std", feature = "sgx"))] +compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +#[macro_use] +extern crate sgx_tstd as std; + +use log::*; + +use cid::Cid; +use codec::{Decode, Encode}; +use multibase::Base; +use multihash::Multihash; +use std::{ + convert::TryFrom, + fmt::{Debug, Display}, + vec::Vec, +}; +const SHA2_256: u64 = 0x12; +const RAW: u64 = 0x55; + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +// sha2 crashes enclaves. therefore we need to use this SDK-provided hasher for sgx builds +fn hasher(chunk: &[u8]) -> Result<[u8; 32], IpfsError> { + use sgx_tcrypto::rsgx_sha256_slice; + rsgx_sha256_slice(&chunk).map_err(|_| IpfsError::InputTooLarge) +} +#[cfg(not(all(not(feature = "std"), feature = "sgx")))] +fn hasher(chunk: &[u8]) -> Result<[u8; 32], IpfsError> { + use sha2::{Digest, Sha256}; + Ok(Sha256::digest(chunk).into()) +} + +#[derive(Clone, Copy, PartialEq, Eq)] +pub struct IpfsCid(pub Cid); + +impl IpfsCid { + pub fn from_chunk(chunk: &[u8]) -> Result { + if chunk.len() > 256 * 1024 { + return Err(IpfsError::InputTooLarge) + }; + let hash = hasher(chunk)?; + info!("hash: {:?}", hash); + let mh = Multihash::wrap(SHA2_256, &hash).map_err(|_| IpfsError::MultiHashFailure)?; + let cid = Cid::new_v1(RAW, mh); + info!("cid: {:?}", cid); + Ok(Self(cid)) + } +} + +#[derive(Debug, PartialEq)] +pub enum IpfsError { + InputTooLarge, + MultiHashFailure, +} + +impl From for IpfsCid { + fn from(value: Cid) -> Self { + IpfsCid(value) + } +} + +impl TryFrom<&str> for IpfsCid { + type Error = cid::Error; + + fn try_from(value: &str) -> Result { + let cid = Cid::try_from(value)?; + Ok(IpfsCid(cid)) + } +} + +impl Encode for IpfsCid { + fn encode(&self) -> Vec { + self.0.to_bytes().encode() + } +} + +impl Decode for IpfsCid { + fn decode(input: &mut I) -> Result { + let bytes: Vec = Decode::decode(input)?; + let cid = Cid::try_from(bytes) + .map_err(|_| codec::Error::from("Failed to decode IpfsCid from bytes"))?; + Ok(IpfsCid(cid)) + } +} + +impl Display for IpfsCid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let cid_str = if self.0.codec() == RAW { + multibase::encode(Base::Base32Lower, self.0.to_bytes()) + } else { + multibase::encode(Base::Base58Btc, self.0.to_bytes()) + }; + write!(f, "{}", cid_str) + } +} + +impl Debug for IpfsCid { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let cid = &self.0; + let version = cid.version(); + let codec = cid.codec(); + let mh = cid.hash(); + let mh_code = mh.code(); + let mh_size = mh.size(); + let mh_digest = mh.digest(); + + f.debug_struct("IpfsCid") + .field("version", &version) + .field("codec", &codec) + .field("multihash_code", &mh_code) + .field("multihash_size", &mh_size) + .field("multihash_digest", &hex::encode(mh_digest)) + .finish() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use std::vec; + + #[test] + pub fn test_from_max_chunk_content_works() { + // cross-check with ipfs cli: + // head -c 262144 /dev/zero | tr '\0' 'A' | ipfs block put --format=raw + // bafkreiexul6fkqo4zhagxgnsvbgdjfq7udb26ig3uoli34xznjlmnpaaze + let expected_cid_str = "bafkreiexul6fkqo4zhagxgnsvbgdjfq7udb26ig3uoli34xznjlmnpaaze"; + let expected_cid = IpfsCid::try_from(expected_cid_str).unwrap(); + let content: Vec = vec![65; 256 * 1024]; // exactly one chunk of 256kB of "A" chars + let derived_cid = IpfsCid::from_chunk(&content).unwrap(); + assert_eq!(derived_cid, expected_cid); + } + + #[test] + pub fn test_cid_verification_fails_for_incorrect_single_chunk_content() { + let expected_cid_str = "bafkreihdcgl5emugcgwjavoknx76kmfdahpzz3jyghg5mhslvhbrznfkky"; + let expected_cid = IpfsCid::try_from(expected_cid_str).unwrap(); + let content: Vec = vec![99; 256 * 1024]; + let wrong_cid = IpfsCid::from_chunk(&content).unwrap(); + assert!(wrong_cid != expected_cid); + } + #[test] + pub fn test_from_text_works() { + // cross-check with ipfs cli: + // echo -n "FooBar" | ipfs block put --format=raw + // bafkreianosnl4e3xk42jhyg7otpy2euc4ruwo5kkd26hzrrsher2pcfnlq + let expected_cid_str = "bafkreianosnl4e3xk42jhyg7otpy2euc4ruwo5kkd26hzrrsher2pcfnlq"; + let expected_cid = IpfsCid::try_from(expected_cid_str).unwrap(); + let content = "FooBar".as_bytes(); + let derived_cid = IpfsCid::from_chunk(content).unwrap(); + assert_eq!(derived_cid, expected_cid); + } + + #[test] + pub fn test_cid_verification_fails_for_oversize_chunk_content() { + let content: Vec = vec![99; 256 * 1024 + 1]; + assert!(IpfsCid::from_chunk(&content) == Err(IpfsError::InputTooLarge)); + } + + #[test] + pub fn test_encode_decode_ipfscid_works() { + let expected_cid_str = "QmSaFjwJ2QtS3rZDKzC98XEzv2bqT4TfpWLCpphPPwyQTr"; + let expected_cid = IpfsCid::try_from(expected_cid_str).unwrap(); + let encoded = expected_cid.encode(); + assert_eq!(encoded.len(), 34 + 1); + let decoded = IpfsCid::decode(&mut &encoded[..]).unwrap(); + assert_eq!(decoded, expected_cid); + } +} diff --git a/core-primitives/node-api/api-client-extensions/Cargo.toml b/core-primitives/node-api/api-client-extensions/Cargo.toml index d54f560750..e3b84909db 100644 --- a/core-primitives/node-api/api-client-extensions/Cargo.toml +++ b/core-primitives/node-api/api-client-extensions/Cargo.toml @@ -17,6 +17,7 @@ substrate-api-client = { default-features = false, features = ["std", "sync-api" # local deps itp-api-client-types = { path = "../api-client-types" } +itp-ipfs-cid = { path = "../../ipfs-cid" } itp-types = { path = "../../types" } [features] diff --git a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs index e8007729be..69bbbf0b4b 100644 --- a/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs +++ b/core-primitives/node-api/api-client-extensions/src/pallet_teerex.rs @@ -17,9 +17,8 @@ use crate::ApiResult; use itp_api_client_types::{traits::GetStorage, Api, Config, Request}; -use itp_types::{ - AccountId, IpfsHash, MultiEnclave, ShardIdentifier, ShardSignerStatus, ShardStatus, -}; +use itp_ipfs_cid::IpfsCid; +use itp_types::{AccountId, MultiEnclave, ShardIdentifier, ShardSignerStatus, ShardStatus}; use log::error; pub const TEEREX: &str = "Teerex"; @@ -51,7 +50,7 @@ pub trait PalletTeerexApi { &self, shard: &ShardIdentifier, at_block: Option, - ) -> ApiResult>; + ) -> ApiResult>; } impl PalletTeerexApi for Api @@ -119,7 +118,7 @@ where &self, shard: &ShardIdentifier, at_block: Option, - ) -> ApiResult> { + ) -> ApiResult> { self.get_storage_map(TEEREX, "LatestIPFSHash", shard, at_block) } } diff --git a/core-primitives/ocall-api/src/lib.rs b/core-primitives/ocall-api/src/lib.rs index c9890bf5a3..5284fb5070 100644 --- a/core-primitives/ocall-api/src/lib.rs +++ b/core-primitives/ocall-api/src/lib.rs @@ -141,12 +141,7 @@ pub trait EnclaveSidechainOCallApi: Clone + Send + Sync { ) -> SgxResult>; } -/// Newtype for IPFS CID -pub struct IpfsCid(pub [u8; 46]); - /// trait for o-call related to IPFS pub trait EnclaveIpfsOCallApi: Clone + Send + Sync { - fn write_ipfs(&self, encoded_state: &[u8]) -> SgxResult; - - fn read_ipfs(&self, cid: &IpfsCid) -> SgxResult<()>; + fn write_ipfs(&self, encoded_state: Vec) -> SgxResult<()>; } diff --git a/core-primitives/randomness/src/lib.rs b/core-primitives/randomness/src/lib.rs index 5a722180e8..4de7f2c4d6 100644 --- a/core-primitives/randomness/src/lib.rs +++ b/core-primitives/randomness/src/lib.rs @@ -6,6 +6,7 @@ use sgx_rand::{thread_rng, Rng}; pub trait Randomness { fn shuffle(values: &mut [T]); fn random_u32(min: u32, max: u32) -> u32; + fn random_128bits() -> [u8; 16]; } pub struct SgxRandomness; @@ -22,6 +23,13 @@ impl Randomness for SgxRandomness { let mut rng = thread_rng(); // Use thread-local random number generator rng.gen_range(min, max) } + + fn random_128bits() -> [u8; 16] { + let mut rng = thread_rng(); // Use thread-local random number generator + let mut buf = [0u8; 16]; + rng.fill_bytes(&mut buf); + buf + } } #[cfg(not(feature = "sgx"))] @@ -29,10 +37,12 @@ impl Randomness for SgxRandomness { fn shuffle(_values: &mut [T]) { unimplemented!() } - fn random_u32(_min: u32, _max: u32) -> u32 { unimplemented!() } + fn random_128bits() -> [u8; 16] { + unimplemented!() + } } pub struct MockRandomness; @@ -49,4 +59,9 @@ impl Randomness for MockRandomness { fn random_u32(min: u32, max: u32) -> u32 { min + max / 2 } + + /// return a deterministic 256-bit value + fn random_128bits() -> [u8; 16] { + [0u8; 16] + } } diff --git a/core-primitives/stf-executor/src/executor.rs b/core-primitives/stf-executor/src/executor.rs index 8487694ee5..73b11cbda2 100644 --- a/core-primitives/stf-executor/src/executor.rs +++ b/core-primitives/stf-executor/src/executor.rs @@ -42,7 +42,7 @@ use itp_time_utils::{duration_now, now_as_millis}; use itp_types::{ parentchain::{BlockNumber, Header as ParentchainHeader, ParentchainCall, ParentchainId}, storage::StorageEntryVerified, - Balance, ShardConfig, UpgradableShardConfig, H256, + Balance, ShardConfig, TrustedCallSideEffect, UpgradableShardConfig, H256, }; use log::*; use sp_runtime::{traits::Header as HeaderTrait, SaturatedConversion}; @@ -124,12 +124,12 @@ where } debug!("execute on STF, call with nonce {}", trusted_call.nonce()); - let mut extrinsic_call_backs: Vec = Vec::new(); + let mut trusted_call_side_effects: Vec = Vec::new(); if let Err(e) = Stf::execute_call( state, shard, trusted_call.clone(), - &mut extrinsic_call_backs, + &mut trusted_call_side_effects, self.node_metadata_repo.clone(), ) { error!("Stf execute failed: {:?}", e); @@ -143,23 +143,27 @@ where state.prune_state_diff(); } - for call in extrinsic_call_backs.clone() { - match call { - ParentchainCall::Integritee { call, mortality } => trace!( - "trusted_call wants to send encoded call to [Integritee] parentchain: 0x{} with mortality {:?}", - hex::encode(call.encode()), mortality - ), - ParentchainCall::TargetA { call, mortality } => trace!( - "trusted_call wants to send encoded call to [TargetA] parentchain: 0x{} with mortality {:?}", - hex::encode(call.encode()), mortality - ), - ParentchainCall::TargetB { call, mortality } => trace!( - "trusted_call wants to send encoded call to [TargetB] parentchain: 0x{} with mortality {:?}", - hex::encode(call.encode()), mortality - ), + for side_effect in trusted_call_side_effects.clone() { + match side_effect { + TrustedCallSideEffect::ParentchainCall(call) => match call { + ParentchainCall::Integritee { call, mortality } => trace!( + "trusted_call wants to send encoded call to [Integritee] parentchain: 0x{} with mortality {:?}", + hex::encode(call.encode()), mortality + ), + ParentchainCall::TargetA { call, mortality } => trace!( + "trusted_call wants to send encoded call to [TargetA] parentchain: 0x{} with mortality {:?}", + hex::encode(call.encode()), mortality + ), + ParentchainCall::TargetB { call, mortality } => trace!( + "trusted_call wants to send encoded call to [TargetB] parentchain: 0x{} with mortality {:?}", + hex::encode(call.encode()), mortality + ), + }, + TrustedCallSideEffect::IpfsAdd(blob) => + trace!("trusted_call wants to add blob of size {} to ipfs", blob.len()), } } - Ok(ExecutedOperation::success(operation_hash, top_or_hash, extrinsic_call_backs)) + Ok(ExecutedOperation::success(operation_hash, top_or_hash, trusted_call_side_effects)) } } @@ -318,25 +322,25 @@ where // the risk of overdue block production is minimal as all user calls are filtered during maintenance mode anyway if maintenance_mode { info!("Maintenance mode is active."); - let mut extrinsic_call_backs: Vec = Vec::new(); + let mut trusted_call_side_effects: Vec = Vec::new(); Stf::maintenance_mode_tasks( &mut state, &shard, *header.number(), - &mut extrinsic_call_backs, + &mut trusted_call_side_effects, self.node_metadata_repo.clone(), ) .map_err(|e| error!("maintenance_mode tasks failed: {:?}", e)) .ok(); info!( "maintenance tasks have triggered {} parentchain calls", - extrinsic_call_backs.len() + trusted_call_side_effects.len() ); // we're hacking our unshielding calls into the queue executed_and_failed_calls.push(ExecutedOperation::success( H256::default(), TrustedOperationOrHash::Hash(H256::default()), - extrinsic_call_backs, + trusted_call_side_effects, )); } diff --git a/core-primitives/stf-executor/src/lib.rs b/core-primitives/stf-executor/src/lib.rs index a3e22f4de7..d6203ca8c8 100644 --- a/core-primitives/stf-executor/src/lib.rs +++ b/core-primitives/stf-executor/src/lib.rs @@ -28,7 +28,7 @@ use codec::{Decode, Encode}; use core::fmt::Debug; use itp_sgx_externalities::SgxExternalitiesTrait; use itp_stf_primitives::types::TrustedOperationOrHash; -use itp_types::{parentchain::ParentchainCall, H256}; +use itp_types::{TrustedCallSideEffect, H256}; use std::vec::Vec; // re-export module to properly feature gate sgx and regular std environment @@ -60,12 +60,12 @@ pub mod mocks; /// any extrinsic callbacks (e.g. unshield extrinsics) that need to be executed on-chain #[derive(Clone, Debug, PartialEq)] pub enum ExecutionStatus { - Success(H256, Vec), + Success(H256, Vec), Failure, } impl ExecutionStatus { - pub fn get_extrinsic_callbacks(&self) -> Vec { + pub fn get_extrinsic_callbacks(&self) -> Vec { match self { ExecutionStatus::Success(_, opaque_calls) => opaque_calls.clone(), _ => Vec::new(), @@ -102,7 +102,7 @@ where pub fn success( operation_hash: H256, trusted_operation_or_hash: TrustedOperationOrHash, - extrinsic_call_backs: Vec, + extrinsic_call_backs: Vec, ) -> Self { ExecutedOperation { status: ExecutionStatus::Success(operation_hash, extrinsic_call_backs), @@ -141,7 +141,7 @@ where TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync, G: PartialEq + Encode + Decode + Debug + Clone + Send + Sync, { - pub fn get_extrinsic_callbacks(&self) -> Vec { + pub fn get_extrinsic_callbacks(&self) -> Vec { self.executed_operations .iter() .flat_map(|e| e.status.get_extrinsic_callbacks()) @@ -173,7 +173,10 @@ mod tests { use super::*; use itp_sgx_externalities::SgxExternalities; use itp_test::mock::stf_mock::{GetterMock, TrustedCallSignedMock}; - use itp_types::{parentchain::GenericMortality, OpaqueCall}; + use itp_types::{ + parentchain::{GenericMortality, ParentchainCall}, + OpaqueCall, + }; use sp_runtime::generic::Era; #[test] @@ -235,10 +238,11 @@ mod tests { int: u8, ) -> (ExecutedOperation, H256) { let hash = H256::from([int; 32]); - let opaque_call: Vec = vec![ParentchainCall::Integritee { - call: OpaqueCall(vec![int; 10]), - mortality: GenericMortality { era: Era::mortal(0, 0), mortality_checkpoint: None }, - }]; + let opaque_call: Vec = + vec![TrustedCallSideEffect::ParentchainCall(ParentchainCall::Integritee { + call: OpaqueCall(vec![int; 10]), + mortality: GenericMortality { era: Era::mortal(0, 0), mortality_checkpoint: None }, + })]; let operation = ExecutedOperation::success(hash, TrustedOperationOrHash::Hash(hash), opaque_call); (operation, hash) diff --git a/core-primitives/stf-interface/src/lib.rs b/core-primitives/stf-interface/src/lib.rs index 82ccdb8ba4..65171ae7ee 100644 --- a/core-primitives/stf-interface/src/lib.rs +++ b/core-primitives/stf-interface/src/lib.rs @@ -29,8 +29,8 @@ use itp_node_api_metadata::NodeMetadataTrait; use itp_node_api_metadata_provider::AccessNodeMetadata; use itp_stf_primitives::traits::TrustedCallVerification; use itp_types::{ - parentchain::{AccountId, BlockHash, BlockNumber, ParentchainCall, ParentchainId}, - Moment, ShardIdentifier, + parentchain::{AccountId, BlockHash, BlockNumber, ParentchainId}, + Moment, ShardIdentifier, TrustedCallSideEffect, }; #[cfg(feature = "mocks")] @@ -83,7 +83,7 @@ where state: &mut State, shard: &ShardIdentifier, call: TCS, - calls: &mut Vec, + side_effects: &mut Vec, node_metadata_repo: Arc, ) -> Result<(), Self::Error>; @@ -100,7 +100,7 @@ where state: &mut State, shard: &itp_stf_primitives::types::ShardIdentifier, integritee_block_number: BlockNumber, - calls: &mut Vec, + side_effects: &mut Vec, node_metadata_repo: Arc, ) -> Result<(), Self::Error>; @@ -131,7 +131,7 @@ where /// Execute a call. Callbacks are added as an `OpaqueCall`. fn execute( self, - calls: &mut Vec, + side_effects: &mut Vec, shard: &ShardIdentifier, node_metadata_repo: Arc, ) -> Result<(), Self::Error>; diff --git a/core-primitives/stf-interface/src/mocks.rs b/core-primitives/stf-interface/src/mocks.rs index 3707a991c0..542f3fd846 100644 --- a/core-primitives/stf-interface/src/mocks.rs +++ b/core-primitives/stf-interface/src/mocks.rs @@ -29,8 +29,8 @@ use itp_node_api_metadata::metadata_mocks::NodeMetadataMock; use itp_node_api_metadata_provider::NodeMetadataRepository; use itp_stf_primitives::traits::TrustedCallVerification; use itp_types::{ - parentchain::{BlockNumber, ParentchainCall, ParentchainId}, - AccountId, Index, Moment, ShardIdentifier, + parentchain::{BlockNumber, ParentchainId}, + AccountId, Index, Moment, ShardIdentifier, TrustedCallSideEffect, }; #[derive(Default)] @@ -71,7 +71,7 @@ where _state: &mut State, _shard: &ShardIdentifier, _call: TCS, - _calls: &mut Vec, + _side_effects: &mut Vec, _node_metadata_repo: Arc>, ) -> Result<(), Self::Error> { unimplemented!() @@ -90,7 +90,7 @@ where _state: &mut State, _shard: &itp_stf_primitives::types::ShardIdentifier, _integritee_block_number: BlockNumber, - _calls: &mut Vec, + _side_effects: &mut Vec, _node_metadata_repo: Arc>, ) -> Result<(), Self::Error> { todo!() @@ -138,7 +138,7 @@ impl ExecuteCall> for CallExecutorMock fn execute( self, - _calls: &mut Vec, + _side_effects: &mut Vec, _shard: &ShardIdentifier, _node_metadata_repo: Arc>, ) -> Result<(), Self::Error> { diff --git a/core-primitives/substrate-sgx/sp-io/src/lib.rs b/core-primitives/substrate-sgx/sp-io/src/lib.rs index 9e39143376..6031cd85ae 100644 --- a/core-primitives/substrate-sgx/sp-io/src/lib.rs +++ b/core-primitives/substrate-sgx/sp-io/src/lib.rs @@ -694,10 +694,7 @@ pub mod hashing { /// Conduct a 256-bit Sha2 hash. pub fn sha2_256(data: &[u8]) -> [u8; 32] { - debug!("sha2_256 of {}", encode_hex(data)); - let hash = sp_core::hashing::sha2_256(data); - debug!(" returning hash {}", encode_hex(&hash)); - hash + unimplemented!("sha2_256 is unimplemented because it is known to crash SGX enclaves. If you need this, use rsgx_sha256_slice"); } /// Conduct a 128-bit Blake2 hash. diff --git a/core-primitives/test/src/mock/stf_mock.rs b/core-primitives/test/src/mock/stf_mock.rs index aeda7d017e..4772f82d38 100644 --- a/core-primitives/test/src/mock/stf_mock.rs +++ b/core-primitives/test/src/mock/stf_mock.rs @@ -31,8 +31,8 @@ use itp_stf_primitives::{ types::{KeyPair, Nonce, TrustedOperation}, }; use itp_types::{ - parentchain::{BlockNumber, ParentchainCall, ParentchainId}, - AccountId, Balance, Index, Moment, ShardIdentifier, Signature, + parentchain::{BlockNumber, ParentchainId}, + AccountId, Balance, Index, Moment, ShardIdentifier, Signature, TrustedCallSideEffect, }; use log::*; use sp_core::{sr25519, Pair}; @@ -75,10 +75,10 @@ impl StateCallInterface, + side_effects: &mut Vec, node_metadata_repo: Arc, ) -> Result<(), Self::Error> { - state.execute_with(|| call.execute(calls, shard, node_metadata_repo)) + state.execute_with(|| call.execute(side_effects, shard, node_metadata_repo)) } fn on_initialize( @@ -95,7 +95,7 @@ impl StateCallInterface, + _calls: &mut Vec, _node_metadata_repo: Arc, ) -> Result<(), Self::Error> { todo!() @@ -202,7 +202,7 @@ impl ExecuteCall for TrustedCallSignedMock { fn execute( self, - _calls: &mut Vec, + _calls: &mut Vec, _shard: &ShardIdentifier, _node_metadata_repo: Arc, ) -> Result<(), Self::Error> { diff --git a/core-primitives/top-pool-author/src/author.rs b/core-primitives/top-pool-author/src/author.rs index eb4e9befc1..a64f7dd0ba 100644 --- a/core-primitives/top-pool-author/src/author.rs +++ b/core-primitives/top-pool-author/src/author.rs @@ -170,8 +170,7 @@ where Err(_) => return Box::pin(ready(Err(ClientError::BadFormat.into()))), }; - trace!("decrypted indirect invocation: {:?}", trusted_operation); - + trace!("decrypted TOP: {:?}", trusted_operation); // apply top filter - return error if this specific type of trusted operation // is not allowed by the filter if !self.top_filter.filter(&trusted_operation) { diff --git a/core-primitives/types/src/lib.rs b/core-primitives/types/src/lib.rs index c3ad5d1447..9f51b94582 100644 --- a/core-primitives/types/src/lib.rs +++ b/core-primitives/types/src/lib.rs @@ -41,7 +41,6 @@ pub type Nonce = u32; pub use itp_sgx_runtime_primitives::types::*; -pub type IpfsHash = [u8; 46]; pub type MrEnclave = [u8; 32]; pub type ConfirmCallFn = ([u8; 2], ShardIdentifier, H256, Vec); @@ -57,10 +56,12 @@ pub type ShardConfig = enclave_bridge_primitives::ShardConfig; pub type UpgradableShardConfig = enclave_bridge_primitives::UpgradableShardConfig; +use crate::parentchain::ParentchainCall; pub use enclave_bridge_primitives::Request; pub use teerex_primitives::{ EnclaveFingerprint, MultiEnclave, SgxBuildMode, SgxEnclave, SgxReportData, SgxStatus, }; + pub type Enclave = MultiEnclave>; /// Simple blob to hold an encoded call @@ -80,6 +81,16 @@ impl Encode for OpaqueCall { } } +impl Decode for OpaqueCall { + fn decode(input: &mut I) -> Result { + let mut bytes = Vec::new(); + while let Ok(byte) = input.read_byte() { + bytes.push(byte); + } + Ok(OpaqueCall(bytes)) + } +} + #[derive(Debug, Clone, PartialEq, Encode, Decode)] pub enum DirectRequestStatus { /// Direct request was successfully executed @@ -133,6 +144,12 @@ pub enum WorkerResponse { NextNonce(Option), } +#[derive(Encode, Decode, Clone, Debug, PartialEq)] +pub enum TrustedCallSideEffect { + ParentchainCall(ParentchainCall), + IpfsAdd(Vec), +} + impl From>> for StorageEntry> { fn from(response: WorkerResponse>) -> Self { match response { @@ -147,9 +164,12 @@ mod tests { use super::*; #[test] - fn opaque_call_encodes_correctly() { + fn opaque_call_encodes_and_decodes_correctly() { let call_tuple = ([1u8, 2u8], 5u8); let call = OpaqueCall::from_tuple(&call_tuple); - assert_eq!(call.encode(), call_tuple.encode()) + let encoded_call = call.encode(); + assert_eq!(encoded_call, call_tuple.encode()); + let decoded_call = OpaqueCall::decode(&mut encoded_call.as_slice()).unwrap(); + assert_eq!(decoded_call, call); } } diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index 24b663669f..15c5305eb6 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -418,7 +418,7 @@ impl From for () { } // All info for additionalParam except tip whi -#[derive(Encode, Debug, Clone, PartialEq, Eq)] +#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq)] pub struct GenericMortality { pub era: Era, pub mortality_checkpoint: Option, @@ -431,7 +431,7 @@ impl GenericMortality { } /// a wrapper to target calls to specific parentchains -#[derive(Encode, Debug, Clone, PartialEq, Eq)] +#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq)] pub enum ParentchainCall { Integritee { call: OpaqueCall, mortality: GenericMortality }, TargetA { call: OpaqueCall, mortality: GenericMortality }, diff --git a/core-primitives/utils/Cargo.toml b/core-primitives/utils/Cargo.toml index ad02e01c66..fa5343592d 100644 --- a/core-primitives/utils/Cargo.toml +++ b/core-primitives/utils/Cargo.toml @@ -8,12 +8,19 @@ license = "Apache-2.0" edition = "2021" [dependencies] +cid = { version = "0.10.1", default-features = false, features = ["alloc"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +log = "0.4.28" +multibase = { version = "0.9.1", default-features = false } +multihash = { version = "0.18.0", default-features = false, features = ["alloc", "multihash-impl", "sha2"] } +sha2 = { version = "0.10.9", default-features = false } [features] default = ["std"] std = [ + "cid/std", + "multibase/std", "codec/std", "hex/std", ] diff --git a/core/offchain-worker-executor/src/executor.rs b/core/offchain-worker-executor/src/executor.rs index 8ad30c38c0..c9b6a9a760 100644 --- a/core/offchain-worker-executor/src/executor.rs +++ b/core/offchain-worker-executor/src/executor.rs @@ -29,8 +29,8 @@ use itp_stf_primitives::{traits::TrustedCallVerification, types::TrustedOperatio use itp_stf_state_handler::{handle_state::HandleState, query_shard_state::QueryShardState}; use itp_top_pool_author::traits::AuthorApi; use itp_types::{ - parentchain::{BlockNumber, GenericMortality, ParentchainCall}, - OpaqueCall, ShardIdentifier, H256, + parentchain::{BlockNumber, GenericMortality}, + OpaqueCall, ShardIdentifier, TrustedCallSideEffect, H256, }; use log::*; use sp_runtime::traits::{Block, Header}; @@ -118,7 +118,7 @@ impl< let max_duration = Duration::from_secs(5); let latest_parentchain_header = self.get_latest_parentchain_header()?; - let mut parentchain_effects: Vec = Vec::new(); + let mut trusted_call_side_effects: Vec = Vec::new(); let shards = self.state_handler.list_shards()?; trace!("Executing calls on {} shard(s)", shards.len()); @@ -142,7 +142,7 @@ impl< }, )?; - parentchain_effects + trusted_call_side_effects .append(&mut batch_execution_result.get_extrinsic_callbacks().clone()); let failed_operations = batch_execution_result.get_failed_operations(); @@ -164,8 +164,8 @@ impl< // TODO: notify parentchain about executed operations? -> add to parentchain effects } - if !parentchain_effects.is_empty() { - self.send_parentchain_effects(parentchain_effects)?; + if !trusted_call_side_effects.is_empty() { + self.execute_trusted_call_side_effects(trusted_call_side_effects)?; } Ok(()) @@ -188,18 +188,40 @@ impl< Ok(()) } - fn send_parentchain_effects(&self, parentchain_effects: Vec) -> Result<()> { - let integritee_calls: Vec<(OpaqueCall, GenericMortality)> = parentchain_effects + fn execute_trusted_call_side_effects( + &self, + side_effects: Vec, + ) -> Result<()> { + let integritee_calls: Vec<(OpaqueCall, GenericMortality)> = side_effects + .iter() + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::ParentchainCall(call) => Some(call.clone()), + _ => None, + }) + .filter_map(|call| call.as_integritee()) + .collect(); + let target_a_calls: Vec<(OpaqueCall, GenericMortality)> = side_effects .iter() - .filter_map(|parentchain_call| parentchain_call.as_integritee()) + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::ParentchainCall(call) => Some(call.clone()), + _ => None, + }) + .filter_map(|call| call.as_target_a()) .collect(); - let target_a_calls: Vec<(OpaqueCall, GenericMortality)> = parentchain_effects + let target_b_calls: Vec<(OpaqueCall, GenericMortality)> = side_effects .iter() - .filter_map(|parentchain_call| parentchain_call.as_target_a()) + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::ParentchainCall(call) => Some(call.clone()), + _ => None, + }) + .filter_map(|call| call.as_target_b()) .collect(); - let target_b_calls: Vec<(OpaqueCall, GenericMortality)> = parentchain_effects + let ipfs_blobs_to_add: Vec> = side_effects .iter() - .filter_map(|parentchain_call| parentchain_call.as_target_b()) + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::IpfsAdd(blob) => Some(blob.clone()), + _ => None, + }) .collect(); debug!( "stf wants to send calls to parentchains: Integritee: {} TargetA: {} TargetB: {}", @@ -218,6 +240,13 @@ impl< self.extrinsics_factory.create_extrinsics(integritee_calls.as_slice(), None)?; self.validator_accessor .execute_mut_on_validator(|v| v.send_extrinsics(extrinsics))?; + + if !ipfs_blobs_to_add.is_empty() { + warn!( + "stf wants to add {} blobs to ipfs, which is unimplemented for the OCW", + ipfs_blobs_to_add.len() + ) + } Ok(()) } diff --git a/docker/README.md b/docker/README.md index ff58343449..d82a7ea403 100644 --- a/docker/README.md +++ b/docker/README.md @@ -69,12 +69,13 @@ FLAVOR_ID=offchain-worker docker compose -f <(envsubst < docker-compose.yml) -f Build ``` -COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < demo-direct-call.yml) build --build-arg WORKER_MODE_ARG=sidechain +COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < demo-direct-call.yml) build --build-arg WORKER_MODE_ARG=sidechain --build-arg ADDITIONAL_FEATURES_ARG=dcap ``` Run ``` +export ADDITIONAL_RUNTIME_FLAGS="--skip-ra" docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < demo-direct-call.yml) up demo-direct-call --exit-code-from demo-direct-call ``` @@ -83,7 +84,7 @@ docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < demo-direct-c Build ``` -COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < demo-sidechain.yml) build --build-arg WORKER_MODE_ARG=sidechain +COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < demo-sidechain.yml) build --build-arg WORKER_MODE_ARG=sidechain --build-arg ADDITIONAL_FEATURES_ARG=dcap ``` Run @@ -127,7 +128,7 @@ hosts, not on Windows with WSL unfortunately. Build the docker compose setup with ``` -COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < fork-inducer.yml) -f <(envsubst < demo-sidechain.yml) build --build-arg WORKER_MODE_ARG=sidechain +COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -f <(envsubst < docker-compose.yml) -f <(envsubst < fork-inducer.yml) -f <(envsubst < demo-sidechain.yml) build --build-arg WORKER_MODE_ARG=sidechain --build-arg ADDITIONAL_FEATURES_ARG=dcap ``` This requires the docker BuildKit (docker version >= 18.09) and support for it in docker compose (version >= 1.25.0) diff --git a/docker/demo-send-relayed-note.yml b/docker/demo-send-relayed-note.yml new file mode 100644 index 0000000000..41a2cdffa8 --- /dev/null +++ b/docker/demo-send-relayed-note.yml @@ -0,0 +1,31 @@ +# Set the `ADDITIONAL_RUNTIME_FLAGS` variable to for additional flags. +# To skip remote attestation: `export ADDITIONAL_RUNTIME_FLAGS="--skip-ra"` +services: + demo-send-relayed-note: + image: integritee-cli:${VERSION:-dev} + devices: + - "${SGX_PROVISION:-/dev/null}:/dev/sgx/provision" + - "${SGX_ENCLAVE:-/dev/null}:/dev/sgx/enclave" + volumes: + - "${AESMD:-/dev/null}:/var/run/aesmd" + - "${SGX_QCNL:-/dev/null}:/etc/sgx_default_qcnl.conf" + build: + context: ${PWD}/.. + dockerfile: build.Dockerfile + target: deployed-client + depends_on: + integritee-node-${VERSION}: + condition: service_healthy + integritee-worker-1-${VERSION}: + condition: service_healthy + ipfs-node: + condition: service_started + networks: + - integritee-test-network + entrypoint: + "/usr/local/worker-cli/demo_send_relayed_note.sh -p 9912 -u ws://integritee-node + -V wss://integritee-worker-1 -P 2011 -i http://ipfs-node:8080 -C /usr/local/bin/integritee-cli 2>&1" + restart: "no" +networks: + integritee-test-network: + driver: bridge \ No newline at end of file diff --git a/docker/demo-teeracle-generic.yml b/docker/demo-teeracle-generic.yml index 1f14489bff..2a8f3605a5 100644 --- a/docker/demo-teeracle-generic.yml +++ b/docker/demo-teeracle-generic.yml @@ -3,7 +3,7 @@ # The demo is parameterized with the interval that the teeracle uses to query its sources. # Set the `TEERACLE_INTERVAL_SECONDS` variable when invoking, e.g. `TEERACLE_INTERVAL_SECONDS=4 docker compose -f docker-compose.yml -f demo-teeracle-generic.yml up --exit-code-from demo-teeracle-generic` # Set the `ADDITIONAL_RUNTIME_FLAGS` variable to for additional flags. -# To skip remote attestation: `export ADDITIONAL_RUNTIME_FLAG="--skip-ra"` +# To skip remote attestation: `export ADDITIONAL_RUNTIME_FLAGS="--skip-ra"` services: integritee-teeracle-worker-${VERSION}: image: integritee-worker:${VERSION:-dev} @@ -31,7 +31,7 @@ services: timeout: 10s retries: 25 command: - "--clean-reset --ws-external -M integritee-teeracle-worker -T wss://integritee-teeracle-worker + "--clean-reset --ws-external -M integritee-teeracle-worker -T wss://integritee-teeracle-worker -u ws://integritee-node -U ws://integritee-teeracle-worker -P 2011 -w 2101 -p 9912 -h 4645 run --dev ${ADDITIONAL_RUNTIME_FLAGS} --teeracle-interval ${TEERACLE_INTERVAL_SECONDS}s" restart: always diff --git a/docker/demo-teeracle.yml b/docker/demo-teeracle.yml index e0bbd2a20f..75759fb50b 100644 --- a/docker/demo-teeracle.yml +++ b/docker/demo-teeracle.yml @@ -5,7 +5,7 @@ # This setup requires an API key for CoinMarketCap # Add the API key to the environment variable `COINMARKETCAP_KEY`, with `export COINMARKETCAP_KEY=` # Set the `ADDITIONAL_RUNTIME_FLAGS` variable to for additional flags. -# To skip remote attestation: `export ADDITIONAL_RUNTIME_FLAG="--skip-ra"` +# To skip remote attestation: `export ADDITIONAL_RUNTIME_FLAGS="--skip-ra"` services: integritee-teeracle-worker-${VERSION}: image: integritee-worker:${VERSION:-dev} @@ -34,7 +34,7 @@ services: timeout: 10s retries: 25 command: - "--clean-reset --ws-external -M integritee-teeracle-worker -T wss://integritee-teeracle-worker + "--clean-reset --ws-external -M integritee-teeracle-worker -T wss://integritee-teeracle-worker -u ws://integritee-node -U ws://integritee-teeracle-worker -P 2011 -w 2101 -p 9912 -h 4645 run --dev ${ADDITIONAL_RUNTIME_FLAGS} --teeracle-interval ${TEERACLE_INTERVAL_SECONDS}s" restart: always diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 23c0338d46..26b5aa669c 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -28,6 +28,8 @@ services: depends_on: "integritee-node-${VERSION}": condition: service_healthy + ipfs-node: + condition: service_started devices: - "${SGX_PROVISION:-/dev/null}:/dev/sgx/provision" - "${SGX_ENCLAVE:-/dev/null}:/dev/sgx/enclave" @@ -35,7 +37,7 @@ services: - "${AESMD:-/dev/null}:/var/run/aesmd" - "${SGX_QCNL:-/dev/null}:/etc/sgx_default_qcnl.conf" environment: - - RUST_LOG=info,substrate_api_client=warn,ws=warn,mio=warn,ac_node_api=warn,sp_io=warn,tungstenite=warn,integritee_service=debug,enclave_runtime=debug + - RUST_LOG=trace,substrate_api_client=warn,ws=warn,mio=warn,ac_node_api=warn,sp_io=warn,sp_io::storage=error,tungstenite=warn,rustls=info,soketto=info,itc_tls_websocket_server=info,itc_rpc_client=info networks: - integritee-test-network healthcheck: @@ -43,7 +45,7 @@ services: interval: 10s timeout: 10s retries: 25 - command: "--clean-reset --data-dir /tmp/worker1 --ws-external -M integritee-worker-1 -T wss://integritee-worker-1 -u ws://integritee-node -U ws://integritee-worker-1 -P 2011 -w 2101 -p 9912 -h 4645 run --dev ${ADDITIONAL_RUNTIME_FLAGS}" + command: "--clean-reset --data-dir /tmp/worker1 --ws-external -M integritee-worker-1 -T wss://integritee-worker-1 -u ws://integritee-node -U ws://integritee-worker-1 -P 2011 -w 2101 -p 9912 -h 4645 --ipfs-api-url http://ipfs-node:5001 run --dev ${ADDITIONAL_RUNTIME_FLAGS}" restart: "no" "integritee-worker-2-${VERSION}": image: integritee-worker:${VERSION:-dev} @@ -57,6 +59,8 @@ services: condition: service_healthy "integritee-worker-1-${VERSION}": condition: service_healthy + ipfs-node: + condition: service_started devices: - "${SGX_PROVISION:-/dev/null}:/dev/sgx/provision" - "${SGX_ENCLAVE:-/dev/null}:/dev/sgx/enclave" @@ -64,7 +68,7 @@ services: - "${AESMD:-/dev/null}:/var/run/aesmd" - "${SGX_QCNL:-/dev/null}:/etc/sgx_default_qcnl.conf" environment: - - RUST_LOG=info,substrate_api_client=warn,ws=warn,mio=warn,ac_node_api=warn,sp_io=warn,tungstenite=warn,integritee_service=debug,enclave_runtime=debug + - RUST_LOG=trace,substrate_api_client=warn,ws=warn,mio=warn,ac_node_api=warn,sp_io=warn,sp_io::storage=error,tungstenite=warn,rustls=info,soketto=info,itc_tls_websocket_server=info,itc_rpc_client=info networks: - integritee-test-network healthcheck: @@ -72,8 +76,13 @@ services: interval: 10s timeout: 10s retries: 25 - command: "--clean-reset --data-dir /tmp/worker2 --ws-external -M integritee-worker-2 -T wss://integritee-worker-2 -u ws://integritee-node -U ws://integritee-worker-2 -P 2012 -w 2102 -p 9912 -h 4646 run --dev ${ADDITIONAL_RUNTIME_FLAGS}" + command: "--clean-reset --data-dir /tmp/worker2 --ws-external -M integritee-worker-2 -T wss://integritee-worker-2 -u ws://integritee-node -U ws://integritee-worker-2 -P 2012 -w 2102 -p 9912 -h 4646 --ipfs-api-url http://ipfs-node:5001 run --dev ${ADDITIONAL_RUNTIME_FLAGS}" restart: "no" + ipfs-node: + image: ipfs/kubo:latest + hostname: ipfs-node + networks: + - integritee-test-network networks: integritee-test-network: driver: bridge diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index b081ed7ec4..d59c5215a7 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -18,7 +18,7 @@ version = "0.4.2" source = "git+https://github.com/encointer/substrate-api-client.git?branch=v0.9.42-tag-v0.14.0-integritee-patch#946f3ae82c5d48023107c1890728582561e94725" dependencies = [ "ac-primitives", - "log", + "log 0.4.28", "maybe-async", ] @@ -33,7 +33,7 @@ dependencies = [ "either", "frame-metadata", "hex", - "log", + "log 0.4.28", "parity-scale-codec", "scale-bits", "scale-decode", @@ -219,6 +219,12 @@ name = "base-x" version = "0.2.6" source = "git+https://github.com/whalelephant/base-x-rs?branch=no_std#906c9ac59282ff5a2eec86efd25d50ad9927b147" +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + [[package]] name = "base16ct" version = "0.2.0" @@ -381,7 +387,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb5b05133427c07c4776906f673ccf36c21b102c9829c641a5b56bd151d44fd6" dependencies = [ - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", ] @@ -484,9 +490,22 @@ name = "cid" version = "0.5.1" source = "git+https://github.com/whalelephant/rust-cid?branch=nstd#cca87467c46106c801ca3727500477258b0f13b0" dependencies = [ - "multibase", - "multihash", - "unsigned-varint", + "multibase 0.8.0", + "multihash 0.11.4", + "unsigned-varint 0.5.1", +] + +[[package]] +name = "cid" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd94671561e36e4e7de75f753f577edafb0e7c05d6e4547229fdf7938fbcd2c3" +dependencies = [ + "core2", + "multibase 0.9.1", + "multihash 0.18.1", + "serde 1.0.192", + "unsigned-varint 0.7.2", ] [[package]] @@ -535,6 +554,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr 2.5.0", +] + [[package]] name = "cpufeatures" version = "0.2.9" @@ -639,6 +667,26 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +[[package]] +name = "data-encoding-macro" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c904b33cc60130e1aeea4956ab803d08a3f4a0ca82d64ed757afac3891f2bb99" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fdf3fce3ce863539ec1d7fd1b6dcc3c645663376b43ed376bbf887733e4f772" +dependencies = [ + "data-encoding", + "syn 1.0.109", +] + [[package]] name = "der" version = "0.7.8" @@ -760,7 +808,7 @@ version = "0.1.0" source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13.0-polkadot-v0.9.42#abf29acd41a0fca9cd7025b297b6a9fa272a122f" dependencies = [ "common-primitives", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "serde 1.0.192", @@ -775,7 +823,7 @@ name = "enclave-runtime" version = "0.17.0" dependencies = [ "array-bytes 6.2.2", - "cid", + "cid 0.5.1", "derive_more", "enclave-bridge-primitives", "env_logger", @@ -799,6 +847,7 @@ dependencies = [ "itp-enclave-metrics", "itp-extrinsics-factory", "itp-import-queue", + "itp-ipfs-cid", "itp-node-api", "itp-node-api-metadata", "itp-nonce-cache", @@ -829,8 +878,8 @@ dependencies = [ "its-sidechain", "jsonrpc-core", "lazy_static", - "log", - "multibase", + "log 0.4.17", + "multibase 0.8.0", "once_cell 1.4.0", "parity-scale-codec", "primitive-types", @@ -860,7 +909,7 @@ version = "0.9.0" source = "git+https://github.com/integritee-network/env_logger-sgx#55745829b2ae8a77f0915af3671ec8a9a00cace9" dependencies = [ "humantime", - "log", + "log 0.4.17", "regex 1.3.1", "sgx_tstd", "termcolor", @@ -879,12 +928,6 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48c92028aaa870e83d51c64e5d4e0b6981b360c522198c23959f219a4e1b15b" -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - [[package]] name = "ethbloom" version = "0.13.0" @@ -942,7 +985,7 @@ dependencies = [ "evm-core", "evm-gasometer", "evm-runtime", - "log", + "log 0.4.28", "parity-scale-codec", "primitive-types", "rlp", @@ -1066,7 +1109,7 @@ source = "git+https://github.com/integritee-network/frontier.git?branch=bar/polk dependencies = [ "hex", "libsecp256k1", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-core", @@ -1128,7 +1171,7 @@ dependencies = [ "frame-support-procedural", "impl-trait-for-tuples", "k256", - "log", + "log 0.4.28", "parity-scale-codec", "paste", "scale-info", @@ -1191,7 +1234,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-core", @@ -1476,12 +1519,6 @@ dependencies = [ "ahash 0.8.3", ] -[[package]] -name = "hashbrown" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" - [[package]] name = "hashbrown_tstd" version = "0.12.0" @@ -1524,7 +1561,7 @@ name = "http_req" version = "0.8.1" source = "git+https://github.com/integritee-network/http_req#3723e88235f2b29bc1a31835853b072ffd0455fd" dependencies = [ - "log", + "log 0.4.28", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx)", "sgx_tstd", "unicase", @@ -1614,16 +1651,6 @@ dependencies = [ "sgx_tstd", ] -[[package]] -name = "indexmap" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" -dependencies = [ - "equivalent", - "hashbrown 0.14.0", -] - [[package]] name = "integer-sqrt" version = "0.1.5" @@ -1646,9 +1673,9 @@ name = "ipfs-unixfs" version = "0.0.1" source = "git+https://github.com/whalelephant/rust-ipfs?branch=w-nstd#52f84dceea7065bb4ee2c24da53b3bedf162241a" dependencies = [ - "cid", + "cid 0.5.1", "either", - "multihash", + "multihash 0.11.4", "quick-protobuf", "sha2 0.9.9", ] @@ -1674,12 +1701,12 @@ dependencies = [ "itp-enclave-metrics", "itp-ocall-api", "lazy_static", - "log", + "log 0.4.28", "parity-scale-codec", "serde 1.0.192", "sgx_tstd", "substrate-fixed", - "thiserror", + "thiserror 1.0.9", "url", ] @@ -1699,7 +1726,7 @@ dependencies = [ "itp-stf-primitives", "itp-types", "itp-utils", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -1714,7 +1741,7 @@ version = "0.1.0" dependencies = [ "hex-literal", "itp-types", - "log", + "log 0.4.28", ] [[package]] @@ -1754,14 +1781,17 @@ version = "0.9.0" dependencies = [ "frame-support", "frame-system", + "hex", "ita-assets-map", "ita-parentchain-specs", "ita-sgx-runtime", "itp-hashing", + "itp-ipfs-cid", "itp-node-api", "itp-node-api-metadata", "itp-pallet-storage", "itp-randomness", + "itp-sgx-crypto", "itp-sgx-externalities", "itp-sgx-runtime-primitives", "itp-stf-interface", @@ -1769,7 +1799,7 @@ dependencies = [ "itp-storage", "itp-types", "itp-utils", - "log", + "log 0.4.28", "pallet-assets", "pallet-balances", "pallet-notes", @@ -1796,12 +1826,12 @@ dependencies = [ "itp-types", "itp-utils", "jsonrpc-core", - "log", + "log 0.4.28", "parity-scale-codec", "serde_json 1.0.108", "sgx_tstd", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -1816,11 +1846,11 @@ dependencies = [ "itp-stf-state-handler", "itp-top-pool-author", "itp-types", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -1842,10 +1872,10 @@ version = "0.9.0" dependencies = [ "itc-parentchain-block-importer", "itp-import-queue", - "log", + "log 0.4.28", "sgx_tstd", "sgx_types", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -1859,12 +1889,12 @@ dependencies = [ "itp-stf-executor", "itp-stf-interface", "itp-types", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -1883,13 +1913,13 @@ dependencies = [ "itp-test", "itp-top-pool-author", "itp-types", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -1904,13 +1934,13 @@ dependencies = [ "itp-storage", "itp-test", "itp-types", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", "sp-consensus-grandpa", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -1928,11 +1958,11 @@ dependencies = [ "base64 0.13.1", "http", "http_req", - "log", + "log 0.4.28", "serde 1.0.192", "serde_json 1.0.108", "sgx_tstd", - "thiserror", + "thiserror 1.0.9", "url", ] @@ -1942,14 +1972,14 @@ version = "0.9.0" dependencies = [ "bit-vec", "chrono 0.4.26", - "log", + "log 0.4.28", "mio", "mio-extras", "rcgen", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx)", "sgx_tstd", "sp-core", - "thiserror", + "thiserror 1.0.9", "tungstenite", "webpki", "yasna", @@ -2012,7 +2042,7 @@ dependencies = [ "itp-sgx-crypto", "itp-sgx-io", "itp-time-utils", - "log", + "log 0.4.28", "num-bigint", "parity-scale-codec", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?rev=sgx_1.1.3)", @@ -2023,7 +2053,7 @@ dependencies = [ "sgx_tstd", "sgx_types", "sp-core", - "thiserror", + "thiserror 1.0.9", "webpki", "webpki-roots 0.21.0 (git+https://github.com/mesalock-linux/webpki-roots?branch=mesalock_sgx)", "yasna", @@ -2034,7 +2064,7 @@ name = "itp-component-container" version = "0.8.0" dependencies = [ "sgx_tstd", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2054,14 +2084,14 @@ dependencies = [ "itp-node-api", "itp-nonce-cache", "itp-types", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", "sp-core", "sp-runtime", "substrate-api-client", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2077,7 +2107,22 @@ version = "0.8.0" dependencies = [ "sgx_tstd", "sgx_types", - "thiserror", + "thiserror 1.0.9", +] + +[[package]] +name = "itp-ipfs-cid" +version = "0.1.0" +dependencies = [ + "cid 0.10.1", + "hex", + "log 0.4.28", + "multibase 0.9.1", + "multihash 0.18.1", + "parity-scale-codec", + "sgx_tcrypto", + "sgx_tstd", + "sgx_types", ] [[package]] @@ -2106,7 +2151,7 @@ version = "0.9.0" dependencies = [ "itp-node-api-metadata", "sgx_tstd", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2114,7 +2159,7 @@ name = "itp-nonce-cache" version = "0.8.0" dependencies = [ "sgx_tstd", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2149,7 +2194,7 @@ version = "0.9.0" dependencies = [ "lazy_static", "sgx_tstd", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2182,7 +2227,7 @@ dependencies = [ "derive_more", "itp-sgx-io", "itp-sgx-temp-dir", - "log", + "log 0.4.28", "ofb", "parity-scale-codec", "serde_json 1.0.60 (git+https://github.com/mesalock-linux/serde-json-sgx?tag=sgx_1.1.3)", @@ -2200,7 +2245,7 @@ dependencies = [ "derive_more", "environmental 1.1.3", "itp-hashing", - "log", + "log 0.4.28", "parity-scale-codec", "postcard", "serde 1.0.192", @@ -2254,13 +2299,13 @@ dependencies = [ "itp-time-utils", "itp-top-pool-author", "itp-types", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2300,13 +2345,13 @@ dependencies = [ "itp-stf-state-observer", "itp-time-utils", "itp-types", - "log", + "log 0.4.28", "parity-scale-codec", "rust-base58", "sgx_tstd", "sgx_types", "sp-core", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2314,9 +2359,9 @@ name = "itp-stf-state-observer" version = "0.9.0" dependencies = [ "itp-types", - "log", + "log 0.4.28", "sgx_tstd", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2334,7 +2379,7 @@ dependencies = [ "sp-runtime", "sp-std", "sp-trie", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2354,7 +2399,7 @@ dependencies = [ "itp-time-utils", "itp-types", "jsonrpc-core", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_crypto_helper", "sgx_tstd", @@ -2384,7 +2429,7 @@ dependencies = [ "its-primitives", "jsonrpc-core", "linked-hash-map", - "log", + "log 0.4.28", "parity-scale-codec", "serde 1.0.192", "sgx_tstd", @@ -2407,7 +2452,7 @@ dependencies = [ "itp-top-pool", "itp-types", "jsonrpc-core", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2441,8 +2486,13 @@ dependencies = [ name = "itp-utils" version = "0.9.0" dependencies = [ + "cid 0.10.1", "hex", + "log 0.4.28", + "multibase 0.9.1", + "multihash 0.18.1", "parity-scale-codec", + "sha2 0.10.9", ] [[package]] @@ -2460,13 +2510,13 @@ dependencies = [ "itp-types", "its-primitives", "its-state", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2475,7 +2525,7 @@ version = "0.1.0" dependencies = [ "its-primitives", "sgx_tstd", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2486,12 +2536,12 @@ dependencies = [ "itp-types", "itp-utils", "its-primitives", - "log", + "log 0.4.28", "sgx_tstd", "sp-consensus-slots", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2521,7 +2571,7 @@ dependencies = [ "its-primitives", "its-state", "its-validateer-fetch", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2548,12 +2598,12 @@ dependencies = [ "its-block-verification", "its-primitives", "its-state", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sgx_types", "sp-runtime", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2568,7 +2618,7 @@ dependencies = [ "its-consensus-common", "its-primitives", "lazy_static", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-consensus-slots", @@ -2602,7 +2652,7 @@ dependencies = [ "itp-utils", "its-primitives", "jsonrpc-core", - "log", + "log 0.4.28", "parity-scale-codec", "rust-base58", "sgx_tstd", @@ -2631,12 +2681,12 @@ dependencies = [ "itp-sgx-externalities", "itp-storage", "its-primitives", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", "sp-io", - "thiserror", + "thiserror 1.0.9", ] [[package]] @@ -2648,7 +2698,7 @@ dependencies = [ "itp-pallet-storage", "itp-types", "its-primitives", - "log", + "log 0.4.28", "parity-scale-codec", "sp-core", "sp-runtime", @@ -2661,7 +2711,7 @@ version = "18.0.0" source = "git+https://github.com/scs/jsonrpc?branch=no_std_v18#0faf53c491c3222b96242a973d902dd06e9b6674" dependencies = [ "futures 0.3.8", - "log", + "log 0.4.17", "serde 1.0.118", "serde_derive 1.0.118", "serde_json 1.0.60 (git+https://github.com/mesalock-linux/serde-json-sgx)", @@ -2676,7 +2726,7 @@ dependencies = [ "cfg-if 1.0.0", "ecdsa", "elliptic-curve", - "sha2 0.10.7", + "sha2 0.10.9", ] [[package]] @@ -2771,6 +2821,12 @@ dependencies = [ "sgx_tstd", ] +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + [[package]] name = "matches" version = "0.1.8" @@ -2830,7 +2886,7 @@ version = "0.6.21" source = "git+https://github.com/mesalock-linux/mio-sgx?tag=sgx_1.1.3#5b0e56a3066231c7a8d1876c7be3a19b08ffdfd5" dependencies = [ "iovec", - "log", + "log 0.4.17", "net2", "sgx_libc", "sgx_trts", @@ -2844,7 +2900,7 @@ version = "2.0.6" source = "git+https://github.com/integritee-network/mio-extras-sgx?rev=963234b#963234bf55e44f9efff921938255126c48deef3a" dependencies = [ "lazycell", - "log", + "log 0.4.28", "mio", "sgx_tstd", "sgx_types", @@ -2856,11 +2912,22 @@ name = "multibase" version = "0.8.0" source = "git+https://github.com/whalelephant/rust-multibase?branch=nstd#df67fb30e86998f7c10d4eea16a1cd480d2448c0" dependencies = [ - "base-x", + "base-x 0.2.6", "data-encoding", "lazy_static", ] +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x 0.2.11", + "data-encoding", + "data-encoding-macro", +] + [[package]] name = "multihash" version = "0.11.4" @@ -2872,7 +2939,34 @@ dependencies = [ "sha-1", "sha2 0.9.9", "sha3 0.9.1", - "unsigned-varint", + "unsigned-varint 0.5.1", +] + +[[package]] +name = "multihash" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfd8a792c1694c6da4f68db0a9d707c72bd260994da179e6030a5dcee00bb815" +dependencies = [ + "core2", + "digest 0.10.7", + "multihash-derive", + "sha2 0.10.9", + "unsigned-varint 0.7.2", +] + +[[package]] +name = "multihash-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" +dependencies = [ + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote 1.0.40", + "syn 1.0.109", + "synstructure", ] [[package]] @@ -3025,7 +3119,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "frame-support", "frame-system", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-runtime", @@ -3039,7 +3133,7 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -3062,7 +3156,7 @@ dependencies = [ "frame-system", "hex", "impl-trait-for-tuples", - "log", + "log 0.4.28", "parity-scale-codec", "rlp", "scale-info", @@ -3079,7 +3173,7 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -3097,7 +3191,7 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -3114,7 +3208,7 @@ version = "0.11.0" dependencies = [ "frame-support", "frame-system", - "log", + "log 0.4.28", "pallet-balances", "parity-scale-codec", "scale-info", @@ -3131,7 +3225,7 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log", + "log 0.4.28", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -3149,7 +3243,7 @@ dependencies = [ "enclave-bridge-primitives", "frame-support", "frame-system", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-core", @@ -3177,7 +3271,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "frame-support", "frame-system", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-inherents", @@ -3299,12 +3393,12 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell 1.18.0", - "toml_edit", + "thiserror 1.0.69", + "toml", ] [[package]] @@ -3603,7 +3697,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?tag=sgx_1.1.3#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log", + "log 0.4.17", "ring", "sct", "sgx_tstd", @@ -3616,7 +3710,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log", + "log 0.4.17", "ring", "sct", "sgx_tstd", @@ -3629,7 +3723,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?rev=sgx_1.1.3#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log", + "log 0.4.17", "ring", "sct", "sgx_tstd", @@ -3858,7 +3952,7 @@ name = "serde_json" version = "1.0.60" source = "git+https://github.com/mesalock-linux/serde-json-sgx?tag=sgx_1.1.3#380893814ad2a057758d825bab798aa117f7362a" dependencies = [ - "indexmap 1.6.1", + "indexmap", "itoa 0.4.5", "ryu", "serde 1.0.118", @@ -4108,9 +4202,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if 1.0.0", "cpufeatures", @@ -4199,7 +4293,7 @@ name = "sp-api" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-api-proc-macro", @@ -4255,7 +4349,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "finality-grandpa", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "sp-api", @@ -4289,7 +4383,7 @@ dependencies = [ "hash-db 0.16.0", "hash256-std-hasher", "libsecp256k1", - "log", + "log 0.4.28", "merlin", "parity-scale-codec", "paste", @@ -4315,7 +4409,7 @@ dependencies = [ "blake2b_simd 1.0.1", "byteorder 1.4.3", "digest 0.10.7", - "sha2 0.10.7", + "sha2 0.10.9", "sha3 0.10.8", "sp-std", "twox-hash", @@ -4371,7 +4465,7 @@ version = "7.0.0" dependencies = [ "itp-sgx-externalities", "libsecp256k1", - "log", + "log 0.4.28", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -4396,7 +4490,7 @@ dependencies = [ "either", "hash256-std-hasher", "impl-trait-for-tuples", - "log", + "log 0.4.28", "parity-scale-codec", "paste", "scale-info", @@ -4595,7 +4689,7 @@ dependencies = [ "derive_more", "frame-metadata", "hex", - "log", + "log 0.4.28", "maybe-async", "parity-scale-codec", "serde 1.0.192", @@ -4663,6 +4757,18 @@ dependencies = [ "unicode-xid 0.0.4", ] +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote 1.0.40", + "syn 1.0.109", + "unicode-xid 0.2.4", +] + [[package]] name = "tap" version = "1.0.1" @@ -4686,7 +4792,7 @@ source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13 dependencies = [ "common-primitives", "derive_more", - "log", + "log 0.4.28", "parity-scale-codec", "scale-info", "serde 1.0.192", @@ -4709,7 +4815,16 @@ version = "1.0.9" source = "git+https://github.com/mesalock-linux/thiserror-sgx?tag=sgx_1.1.3#c2f806b88616e06aab0af770366a76885d974fdc" dependencies = [ "sgx_tstd", - "thiserror-impl", + "thiserror-impl 1.0.9", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", ] [[package]] @@ -4722,6 +4837,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote 1.0.40", + "syn 2.0.106", +] + [[package]] name = "thread_local" version = "1.0.0" @@ -4741,20 +4867,12 @@ dependencies = [ ] [[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" - -[[package]] -name = "toml_edit" -version = "0.19.14" +name = "toml" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ - "indexmap 2.0.0", - "toml_datetime", - "winnow", + "serde 1.0.192", ] [[package]] @@ -4782,7 +4900,7 @@ checksum = "767abe6ffed88a1889671a102c2861ae742726f52e0a5a425b92c9fbfa7e9c85" dependencies = [ "hash-db 0.16.0", "hashbrown 0.13.2", - "log", + "log 0.4.28", "smallvec 1.11.0", ] @@ -4821,12 +4939,12 @@ dependencies = [ "bytes 1.0.1", "http", "httparse", - "log", + "log 0.4.17", "rand 0.7.3", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?tag=sgx_1.1.3)", "sgx_tstd", "sha1", - "thiserror", + "thiserror 1.0.9", "url", "utf-8", "webpki", @@ -4839,7 +4957,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "digest 0.10.7", "static_assertions", ] @@ -4921,6 +5039,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fdeedbf205afadfe39ae559b75c3240f24e257d0ca27e85f85cb82aa19ac35" +[[package]] +name = "unsigned-varint" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" + [[package]] name = "untrusted" version = "0.7.1" @@ -4986,15 +5110,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "winnow" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25b5872fa2e10bd067ae946f927e726d7d603eaeb6e02fa6a350e0722d2b8c11" -dependencies = [ - "memchr 2.5.0", -] - [[package]] name = "wyz" version = "0.5.1" diff --git a/enclave-runtime/Cargo.toml b/enclave-runtime/Cargo.toml index b781cf5bdd..444bb8bbe0 100644 --- a/enclave-runtime/Cargo.toml +++ b/enclave-runtime/Cargo.toml @@ -108,6 +108,7 @@ itp-component-container = { path = "../core-primitives/component-container", def itp-enclave-metrics = { path = "../core-primitives/enclave-metrics", default-features = false, features = ["sgx"] } itp-extrinsics-factory = { path = "../core-primitives/extrinsics-factory", default-features = false, features = ["sgx"] } itp-import-queue = { path = "../core-primitives/import-queue", default-features = false, features = ["sgx"] } +itp-ipfs-cid = { path = "../core-primitives/ipfs-cid", default-features = false, features = ["sgx"] } itp-node-api = { path = "../core-primitives/node-api", default-features = false, features = ["sgx"] } itp-node-api-metadata = { path = "../core-primitives/node-api/metadata", default-features = false } itp-nonce-cache = { path = "../core-primitives/nonce-cache", default-features = false, features = ["sgx"] } diff --git a/enclave-runtime/Enclave.config.xml b/enclave-runtime/Enclave.config.xml index b853d045a2..70626333ae 100644 --- a/enclave-runtime/Enclave.config.xml +++ b/enclave-runtime/Enclave.config.xml @@ -1,12 +1,12 @@ - 0 - 0 - 0x40000 - 0x20000000 - 8 - 0 - 0 - 0 - 0xFFFFFFFF + 0 + 0 + 0x40000 + 0x20000000 + 8 + 0 + 0 + 0 + 0xFFFFFFFF diff --git a/enclave-runtime/Enclave.edl b/enclave-runtime/Enclave.edl index dc77b85c1c..5c7ee044fb 100644 --- a/enclave-runtime/Enclave.edl +++ b/enclave-runtime/Enclave.edl @@ -225,13 +225,8 @@ enclave { [out] sgx_update_info_bit_t * update_info ); - sgx_status_t ocall_read_ipfs( - [in, size = cid_size] uint8_t * cid, uint32_t cid_size - ); - sgx_status_t ocall_write_ipfs( - [in, size = state_size] uint8_t * enc_state, uint32_t state_size, - [out, size = cid_size] uint8_t * cid, uint32_t cid_size + [in, size = content_size] uint8_t * content, uint32_t content_size ); sgx_status_t ocall_worker_request( diff --git a/enclave-runtime/src/ipfs.rs b/enclave-runtime/src/ipfs.rs deleted file mode 100644 index 7b90f062c1..0000000000 --- a/enclave-runtime/src/ipfs.rs +++ /dev/null @@ -1,99 +0,0 @@ -use cid::{Cid, Result as CidResult}; -use ipfs_unixfs::file::adder::FileAdder; -use log::*; -use multibase::Base; -use std::{convert::TryFrom, vec::Vec}; - -pub struct IpfsContent { - pub cid: CidResult, - pub file_content: Vec, - pub stats: Stats, -} -#[derive(Debug, PartialEq)] -pub enum IpfsError { - InputCidInvalid, - FinalCidMissing, - Verification, -} - -impl IpfsContent { - pub fn new(_cid: &str, _content: Vec) -> IpfsContent { - IpfsContent { cid: Cid::try_from(_cid), file_content: _content, stats: Stats::default() } - } - - pub fn verify(&mut self) -> Result<(), IpfsError> { - let mut adder: FileAdder = FileAdder::default(); - let mut total: usize = 0; - while total < self.file_content.len() { - let (blocks, consumed) = adder.push(&self.file_content[total..]); - total += consumed; - self.stats.process(blocks); - } - let blocks = adder.finish(); - self.stats.process(blocks); - - if let Some(last_cid) = self.stats.last.as_ref() { - let cid_str = Base::Base58Btc.encode(last_cid.hash().as_bytes()); - info!( - "new cid: {} generated from {} blocks, total of {} bytes", - cid_str, self.stats.blocks, self.stats.block_bytes - ); - match self.cid.as_ref() { - Ok(initial_cid) => - if last_cid.hash().eq(&initial_cid.hash()) { - Ok(()) - } else { - Err(IpfsError::Verification) - }, - Err(_) => Err(IpfsError::InputCidInvalid), - } - } else { - Err(IpfsError::FinalCidMissing) - } - } -} -#[derive(Default)] -pub struct Stats { - pub blocks: usize, - pub block_bytes: u64, - pub last: Option, -} - -impl Stats { - fn process)>>(&mut self, new_blocks: I) { - for (cid, block) in new_blocks { - self.last = Some(cid); - self.blocks += 1; - self.block_bytes += block.len() as u64; - } - } -} - -#[allow(unused)] -pub fn test_creates_ipfs_content_struct_works() { - let cid = "QmSaFjwJ2QtS3rZDKzC98XEzv2bqT4TfpWLCpphPPwyQTr"; - let content: Vec = vec![20; 512 * 1024]; - let ipfs_content = IpfsContent::new(cid, content.clone()); - - let cid_str = Base::Base58Btc.encode(ipfs_content.cid.as_ref().unwrap().hash().as_bytes()); - assert_eq!(cid_str, cid); - assert_eq!(ipfs_content.file_content, content); -} - -#[allow(unused)] -pub fn test_verification_ok_for_correct_content() { - let cid = "QmSaFjwJ2QtS3rZDKzC98XEzv2bqT4TfpWLCpphPPwyQTr"; - let content: Vec = vec![20; 512 * 1024]; - let mut ipfs_content = IpfsContent::new(cid, content); - let verification = ipfs_content.verify(); - assert!(verification.is_ok()); -} - -#[allow(unused)] -pub fn test_verification_fails_for_incorrect_content() { - let cid = "QmSaFjwJ2QtS3rZDKzC98XEzv2bqT4TfpWLCpphPPwyQTr"; - let content: Vec = vec![10; 512 * 1024]; - let mut ipfs_content = IpfsContent::new(cid, content); - let verification = ipfs_content.verify(); - assert_eq!(verification.unwrap_err(), IpfsError::Verification); -} diff --git a/enclave-runtime/src/lib.rs b/enclave-runtime/src/lib.rs index ae65a4ae48..4a4a29a6eb 100644 --- a/enclave-runtime/src/lib.rs +++ b/enclave-runtime/src/lib.rs @@ -73,7 +73,6 @@ use std::{ mod attestation; mod empty_impls; mod initialization; -mod ipfs; mod ocall; mod shard_config; mod shard_creation_info; diff --git a/enclave-runtime/src/ocall/ffi.rs b/enclave-runtime/src/ocall/ffi.rs index 64f47cc516..9e75be3cd0 100644 --- a/enclave-runtime/src/ocall/ffi.rs +++ b/enclave-runtime/src/ocall/ffi.rs @@ -116,17 +116,9 @@ extern "C" { await_each_inclusion: c_int, ) -> sgx_status_t; - pub fn ocall_read_ipfs( - ret_val: *mut sgx_status_t, - cid: *const u8, - cid_size: u32, - ) -> sgx_status_t; - pub fn ocall_write_ipfs( ret_val: *mut sgx_status_t, - enc_state: *const u8, - enc_state_size: u32, - cid: *mut u8, - cid_size: u32, + content: *const u8, + content_size: u32, ) -> sgx_status_t; } diff --git a/enclave-runtime/src/ocall/ipfs_ocall.rs b/enclave-runtime/src/ocall/ipfs_ocall.rs index d1a5530856..f17a74c821 100644 --- a/enclave-runtime/src/ocall/ipfs_ocall.rs +++ b/enclave-runtime/src/ocall/ipfs_ocall.rs @@ -15,43 +15,28 @@ limitations under the License. */ - use crate::ocall::{ffi, OcallApi}; +use alloc::vec::Vec; use frame_support::ensure; -use itp_ocall_api::{EnclaveIpfsOCallApi, IpfsCid}; +use itp_ocall_api::EnclaveIpfsOCallApi; +use log::*; use sgx_types::{sgx_status_t, SgxResult}; impl EnclaveIpfsOCallApi for OcallApi { - fn write_ipfs(&self, encoded_state: &[u8]) -> SgxResult { + fn write_ipfs(&self, content: Vec) -> SgxResult<()> { let mut rt: sgx_status_t = sgx_status_t::SGX_ERROR_UNEXPECTED; - let mut cid_buf = IpfsCid([0u8; 46]); - + trace!("calling OCallApi::write_ipfs with {} bytes", content.len()); + let payload = content; let res = unsafe { ffi::ocall_write_ipfs( &mut rt as *mut sgx_status_t, - encoded_state.as_ptr(), - encoded_state.len() as u32, - cid_buf.0.as_mut_ptr(), - cid_buf.0.len() as u32, + payload.as_ptr(), + payload.len() as u32, ) }; - - ensure!(rt == sgx_status_t::SGX_SUCCESS, rt); - ensure!(res == sgx_status_t::SGX_SUCCESS, res); - - Ok(cid_buf) - } - - fn read_ipfs(&self, cid: &IpfsCid) -> SgxResult<()> { - let mut rt: sgx_status_t = sgx_status_t::SGX_ERROR_UNEXPECTED; - - let res = unsafe { - ffi::ocall_read_ipfs(&mut rt as *mut sgx_status_t, cid.0.as_ptr(), cid.0.len() as u32) - }; - ensure!(rt == sgx_status_t::SGX_SUCCESS, rt); ensure!(res == sgx_status_t::SGX_SUCCESS, res); - + trace!("completed OCallApi::write_ipfs"); Ok(()) } } diff --git a/enclave-runtime/src/test/evm_pallet_tests.rs b/enclave-runtime/src/test/evm_pallet_tests.rs index a42376b117..c1fffdee8c 100644 --- a/enclave-runtime/src/test/evm_pallet_tests.rs +++ b/enclave-runtime/src/test/evm_pallet_tests.rs @@ -29,7 +29,7 @@ use itp_node_api::metadata::{metadata_mocks::NodeMetadataMock, provider::NodeMet use itp_sgx_externalities::SgxExternalitiesTrait; use itp_stf_interface::StateCallInterface; use itp_stf_primitives::{traits::TrustedCallSigning, types::KeyPair}; -use itp_types::{parentchain::ParentchainCall, AccountId, ShardIdentifier}; +use itp_types::{AccountId, ShardIdentifier, TrustedCallSideEffect}; use primitive_types::H256; use sp_core::{crypto::Pair, H160, U256}; use std::{sync::Arc, vec::Vec}; @@ -37,7 +37,7 @@ use std::{sync::Arc, vec::Vec}; pub fn test_evm_call() { // given let (_, mut state, shard, mrenclave, ..) = test_setup(); - let mut parentchain_calls = Vec::new(); + let mut side_effects = Vec::new(); // Create the sender account. let sender = funded_pair(); @@ -82,7 +82,7 @@ pub fn test_evm_call() { &mut state, &ShardIdentifier::default(), trusted_call, - &mut parentchain_calls, + &mut side_effects, repo, ) .unwrap(); @@ -97,7 +97,7 @@ pub fn test_evm_call() { pub fn test_evm_counter() { // given let (_, mut state, shard, mrenclave, ..) = test_setup(); - let mut parentchain_calls = Vec::new(); + let mut side_effects = Vec::new(); // Create the sender account. let sender = funded_pair(); @@ -134,7 +134,7 @@ pub fn test_evm_counter() { &mut state, &ShardIdentifier::default(), trusted_call, - &mut parentchain_calls, + &mut side_effects, repo, ) .unwrap(); @@ -173,7 +173,7 @@ pub fn test_evm_counter() { &mrenclave, &shard, &mut state, - &mut parentchain_calls, + &mut side_effects, 2, ); @@ -189,7 +189,7 @@ pub fn test_evm_counter() { &mrenclave, &shard, &mut state, - &mut parentchain_calls, + &mut side_effects, 5, ); @@ -206,7 +206,7 @@ pub fn test_evm_counter() { &mrenclave, &shard, &mut state, - &mut parentchain_calls, + &mut side_effects, 6, ); @@ -229,7 +229,7 @@ pub fn test_evm_counter() { &mrenclave, &shard, &mut state, - &mut parentchain_calls, + &mut side_effects, 8, ); } @@ -246,7 +246,7 @@ fn execute_and_verify_evm_call( mrenclave: &[u8; 32], shard: &ShardIdentifier, state: &mut State, - calls: &mut Vec, + calls: &mut Vec, counter_expected: u64, ) { let inc_call = TrustedCall::evm_call( @@ -274,7 +274,7 @@ fn execute_and_verify_evm_call( pub fn test_evm_create() { // given let (_, mut state, shard, mrenclave, ..) = test_setup(); - let mut parentchain_calls = Vec::new(); + let mut side_effects = Vec::new(); // Create the sender account. let sender = funded_pair(); @@ -313,7 +313,7 @@ pub fn test_evm_create() { &mut state, &ShardIdentifier::default(), trusted_call, - &mut parentchain_calls, + &mut side_effects, repo, ) .unwrap(); @@ -335,7 +335,7 @@ pub fn test_evm_create() { pub fn test_evm_create2() { // given let (_, mut state, shard, mrenclave, ..) = test_setup(); - let mut parentchain_calls = Vec::new(); + let mut side_effects = Vec::new(); // Create the sender account. let sender = funded_pair(); @@ -375,7 +375,7 @@ pub fn test_evm_create2() { &mut state, &ShardIdentifier::default(), trusted_call, - &mut parentchain_calls, + &mut side_effects, repo, ) .unwrap(); diff --git a/enclave-runtime/src/test/ipfs_tests.rs b/enclave-runtime/src/test/ipfs_tests.rs index f1f94d3696..1af760a5c2 100644 --- a/enclave-runtime/src/test/ipfs_tests.rs +++ b/enclave-runtime/src/test/ipfs_tests.rs @@ -16,27 +16,60 @@ */ -use crate::{ipfs::IpfsContent, ocall::OcallApi}; +#[cfg(all(not(feature = "std"), feature = "sgx"))] +extern crate sgx_tstd as std; + +use crate::ocall::OcallApi; +use itp_ipfs_cid::IpfsCid; use itp_ocall_api::EnclaveIpfsOCallApi; use log::*; -use std::{fs::File, io::Read, vec::Vec}; - -#[allow(unused)] -fn test_ocall_read_write_ipfs() { - info!("testing IPFS read/write. Hopefully ipfs daemon is running..."); - let enc_state: Vec = vec![20; 4 * 512 * 1024]; - - let cid = OcallApi.write_ipfs(enc_state.as_slice()).unwrap(); +use std::{ + fs, + io::Read, + path::{Path, PathBuf}, + string::{String, ToString}, + vec::Vec, +}; - OcallApi.read_ipfs(&cid).unwrap(); - - let cid_str = std::str::from_utf8(&cid.0).unwrap(); - let mut f = File::open(cid_str).unwrap(); +pub fn test_ocall_write_ipfs_fallback() { + let payload_size = 100; // in kB + info!("testing IPFS write of {}kB if api is unreachable. Expected to fallback to dump local file...", payload_size); + let enc_state: Vec = vec![20; payload_size * 1024]; + let res_expected_cid = IpfsCid::from_chunk(&enc_state); + let result = OcallApi.write_ipfs(enc_state); + debug!("write_ipfs ocall result : {:?}", result); + debug!("expected cid details: {:?}", res_expected_cid); + assert!(res_expected_cid.is_ok()); + let expected_cid = res_expected_cid.expect("known to be ok"); + info!("expected cid: {}", expected_cid); + let dumpfile = + find_first_matching_file(expected_cid.to_string()).expect("dumped file not found"); + info!("found dumped file: {:?}", dumpfile); + let mut f = fs::File::open(dumpfile).unwrap(); let mut content_buf = Vec::new(); f.read_to_end(&mut content_buf).unwrap(); - info!("reading file {:?} of size {} bytes", f, &content_buf.len()); + debug!("reading file {:?} of size {} bytes", f, &content_buf.len()); + let res_file_cid = IpfsCid::from_chunk(&content_buf); + debug!("file cid details: {:?}", res_file_cid); + assert!(res_file_cid.is_ok()); + let file_cid = res_file_cid.expect("known to be ok"); + debug!("file cid: {}", file_cid); + assert_eq!(expected_cid, file_cid); +} + +fn find_first_matching_file(cid_str: String) -> Option { + let dir = Path::new("log-ipfs-failing-add"); + let prefix = "ipfs-"; + let suffix = format!("-{}.bin", cid_str); - let mut ipfs_content = IpfsContent::new(cid_str, content_buf); - let verification = ipfs_content.verify(); - assert!(verification.is_ok()); + for entry in fs::read_dir(dir).ok()? { + let entry = entry.ok()?; + let file_name = entry.file_name(); + debug!("Checking file: {:?}", file_name); + let file_name = file_name.to_string_lossy(); + if file_name.starts_with(prefix) && file_name.ends_with(suffix.as_str()) { + return Some(entry.path()) + } + } + None } diff --git a/enclave-runtime/src/test/mocks/propose_to_import_call_mock.rs b/enclave-runtime/src/test/mocks/propose_to_import_call_mock.rs index f6b04e922a..2627131e95 100644 --- a/enclave-runtime/src/test/mocks/propose_to_import_call_mock.rs +++ b/enclave-runtime/src/test/mocks/propose_to_import_call_mock.rs @@ -19,7 +19,9 @@ use crate::test::mocks::types::TestBlockImporter; use codec::{Decode, Encode}; use itc_parentchain::primitives::ParentchainId; -use itp_ocall_api::{EnclaveOnChainOCallApi, EnclaveSidechainOCallApi, Result}; +use itp_ocall_api::{ + EnclaveIpfsOCallApi, EnclaveOnChainOCallApi, EnclaveSidechainOCallApi, Result, +}; use itp_types::{ storage::StorageEntryVerified, BlockHash, Header as ParentchainHeader, ShardIdentifier, WorkerRequest, WorkerResponse, H256, @@ -122,3 +124,9 @@ impl EnclaveSidechainOCallApi for ProposeToImportOCallApi { Ok(Vec::new()) } } + +impl EnclaveIpfsOCallApi for ProposeToImportOCallApi { + fn write_ipfs(&self, _encoded_state: Vec) -> SgxResult<()> { + Ok(()) + } +} diff --git a/enclave-runtime/src/test/sidechain_aura_tests.rs b/enclave-runtime/src/test/sidechain_aura_tests.rs index 08f7bca82b..f93e4d3193 100644 --- a/enclave-runtime/src/test/sidechain_aura_tests.rs +++ b/enclave-runtime/src/test/sidechain_aura_tests.rs @@ -27,7 +27,7 @@ use crate::{ }, mocks::{propose_to_import_call_mock::ProposeToImportOCallApi, types::*}, }, - top_pool_execution::{exec_aura_on_slot, send_blocks_and_extrinsics}, + top_pool_execution::{exec_aura_on_slot, send_blocks_and_execute_side_effects}, }; use codec::Decode; use ita_stf::{ @@ -167,7 +167,7 @@ pub fn produce_sidechain_block_and_import_it() { let state_hash_before_block_production = get_state_hash(state_handler.as_ref(), &shard_id); info!("Executing AURA on slot.."); - let (blocks, opaque_calls) = + let (blocks, side_effects) = exec_aura_on_slot::<_, ParentchainBlock, SignedSidechainBlock, _, _, _, _, _>( slot_info, signer, @@ -201,9 +201,9 @@ pub fn produce_sidechain_block_and_import_it() { let propose_to_block_import_ocall_api = Arc::new(ProposeToImportOCallApi::new(parentchain_header, block_importer)); - send_blocks_and_extrinsics::( + send_blocks_and_execute_side_effects::( blocks, - opaque_calls, + side_effects, propose_to_block_import_ocall_api, ) .unwrap(); diff --git a/enclave-runtime/src/test/sidechain_event_tests.rs b/enclave-runtime/src/test/sidechain_event_tests.rs index fcc1e5432a..82ae7eb3a6 100644 --- a/enclave-runtime/src/test/sidechain_event_tests.rs +++ b/enclave-runtime/src/test/sidechain_event_tests.rs @@ -25,7 +25,7 @@ use crate::{ }, mocks::{propose_to_import_call_mock::ProposeToImportOCallApi, types::*}, }, - top_pool_execution::{exec_aura_on_slot, send_blocks_and_extrinsics}, + top_pool_execution::{exec_aura_on_slot, send_blocks_and_execute_side_effects}, }; use ita_sgx_runtime::Runtime; use ita_stf::{helpers::set_block_number, Getter, TrustedCallSigned}; @@ -139,7 +139,7 @@ pub fn ensure_events_get_reset_upon_block_proposal() { ); info!("Executing AURA on slot.."); - let (blocks, opaque_calls) = + let (blocks, side_effects) = exec_aura_on_slot::<_, ParentchainBlock, SignedSidechainBlock, _, _, _, _, _>( slot_info, signer, @@ -156,9 +156,9 @@ pub fn ensure_events_get_reset_upon_block_proposal() { let propose_to_block_import_ocall_api = Arc::new(ProposeToImportOCallApi::new(parentchain_header, block_importer)); - send_blocks_and_extrinsics::( + send_blocks_and_execute_side_effects::( blocks, - opaque_calls, + side_effects, propose_to_block_import_ocall_api, ) .unwrap(); diff --git a/enclave-runtime/src/test/tests_main.rs b/enclave-runtime/src/test/tests_main.rs index 8f8881176b..6ae06ab4ba 100644 --- a/enclave-runtime/src/test/tests_main.rs +++ b/enclave-runtime/src/test/tests_main.rs @@ -162,11 +162,8 @@ pub extern "C" fn test_main_entrance() -> size_t { itc_parentchain::light_client::io::sgx_tests::init_parachain_light_client_works, itc_parentchain::light_client::io::sgx_tests::sealing_creates_backup, - // these unit test (?) need an ipfs node running.. - // ipfs::test_creates_ipfs_content_struct_works, - // ipfs::test_verification_ok_for_correct_content, - // ipfs::test_verification_fails_for_incorrect_content, - // test_ocall_read_write_ipfs, + // IPFS tests + crate::test::ipfs_tests::test_ocall_write_ipfs_fallback, // Teeracle tests run_teeracle_tests, diff --git a/enclave-runtime/src/top_pool_execution.rs b/enclave-runtime/src/top_pool_execution.rs index fbff20f779..0b7e999b1d 100644 --- a/enclave-runtime/src/top_pool_execution.rs +++ b/enclave-runtime/src/top_pool_execution.rs @@ -49,15 +49,17 @@ use itc_parentchain::{ use itp_component_container::ComponentGetter; use itp_enclave_metrics::EnclaveMetric; use itp_extrinsics_factory::CreateExtrinsics; -use itp_ocall_api::{EnclaveMetricsOCallApi, EnclaveOnChainOCallApi, EnclaveSidechainOCallApi}; +use itp_ocall_api::{ + EnclaveIpfsOCallApi, EnclaveMetricsOCallApi, EnclaveOnChainOCallApi, EnclaveSidechainOCallApi, +}; use itp_pallet_storage::{SidechainPalletStorage, SidechainPalletStorageKeys}; use itp_settings::sidechain::SLOT_DURATION; use itp_sgx_crypto::key_repository::AccessKey; use itp_stf_state_handler::query_shard_state::QueryShardState; use itp_time_utils::duration_now; use itp_types::{ - parentchain::{GenericMortality, ParentchainCall, ParentchainId, SidechainBlockConfirmation}, - Block, OpaqueCall, H256, + parentchain::{GenericMortality, ParentchainId, SidechainBlockConfirmation}, + Block, OpaqueCall, TrustedCallSideEffect, H256, }; use its_primitives::{ traits::{ @@ -233,7 +235,7 @@ fn execute_top_pool_trusted_calls_internal() -> Result<()> { block_composer, ); - let (blocks, parentchain_calls) = + let (blocks, side_effects) = exec_aura_on_slot::<_, _, SignedSidechainBlock, _, _, _, _, _>( slot.clone(), authority, @@ -252,7 +254,7 @@ fn execute_top_pool_trusted_calls_internal() -> Result<()> { log_remaining_slot_duration(&slot, SlotStage::AfterAura); - send_blocks_and_extrinsics::(blocks, parentchain_calls, ocall_api)?; + send_blocks_and_execute_side_effects::(blocks, side_effects, ocall_api)?; log_remaining_slot_duration(&slot, SlotStage::AfterBroadcastAndExtrinsics); }, @@ -286,7 +288,7 @@ pub(crate) fn exec_aura_on_slot< maybe_target_b_block_import_trigger: Option>, proposer_environment: PEnvironment, shards: Vec>, -) -> Result<(Vec, Vec)> +) -> Result<(Vec, Vec)> where ParentchainBlock: BlockTrait, SignedSidechainBlock: @@ -321,33 +323,41 @@ where ) .with_claim_strategy(SlotClaimStrategy::RoundRobin); - let (blocks, pxts): (Vec<_>, Vec<_>) = + let (blocks, side_effects): (Vec<_>, Vec<_>) = PerShardSlotWorkerScheduler::on_slot(&mut aura, slot, shards) .into_iter() - .map(|r| (r.block, r.parentchain_effects)) + .map(|r| (r.block, r.side_effects)) .unzip(); - let opaque_calls: Vec = pxts.into_iter().flatten().collect(); + let opaque_calls: Vec = side_effects.into_iter().flatten().collect(); Ok((blocks, opaque_calls)) } /// Broadcasts sidechain blocks to fellow peers and sends opaque calls as extrinsic to the parentchain. -pub(crate) fn send_blocks_and_extrinsics( +pub(crate) fn send_blocks_and_execute_side_effects< + ParentchainBlock, + SignedSidechainBlock, + OCallApi, +>( blocks: Vec, - parentchain_calls: Vec, + side_effects: Vec, ocall_api: Arc, ) -> Result<()> where ParentchainBlock: BlockTrait, SignedSidechainBlock: SignedBlock + 'static, - OCallApi: EnclaveSidechainOCallApi, + OCallApi: EnclaveSidechainOCallApi + EnclaveIpfsOCallApi, NumberFor: BlockNumberOps, { debug!("Proposing {} sidechain block(s) (broadcasting to peers)", blocks.len()); ocall_api.propose_sidechain_blocks(blocks)?; - let calls: Vec<(OpaqueCall, GenericMortality)> = parentchain_calls + let calls: Vec<(OpaqueCall, GenericMortality)> = side_effects .iter() + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::ParentchainCall(call) => Some(call.clone()), + _ => None, + }) .filter_map(|parentchain_call| parentchain_call.as_integritee()) .collect(); debug!("Enclave wants to send {} extrinsics to Integritee Parentchain", calls.len()); @@ -357,8 +367,12 @@ where let validator_access = get_validator_accessor_from_integritee_solo_or_parachain()?; validator_access.execute_mut_on_validator(|v| v.send_extrinsics(xts))?; } - let calls: Vec<(OpaqueCall, GenericMortality)> = parentchain_calls + let calls: Vec<(OpaqueCall, GenericMortality)> = side_effects .iter() + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::ParentchainCall(call) => Some(call.clone()), + _ => None, + }) .filter_map(|parentchain_call| parentchain_call.as_target_a()) .collect(); debug!("Enclave wants to send {} extrinsics to TargetA Parentchain", calls.len()); @@ -368,8 +382,12 @@ where let validator_access = get_validator_accessor_from_target_a_solo_or_parachain()?; validator_access.execute_mut_on_validator(|v| v.send_extrinsics(xts))?; } - let calls: Vec<(OpaqueCall, GenericMortality)> = parentchain_calls + let calls: Vec<(OpaqueCall, GenericMortality)> = side_effects .iter() + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::ParentchainCall(call) => Some(call.clone()), + _ => None, + }) .filter_map(|parentchain_call| parentchain_call.as_target_b()) .collect(); debug!("Enclave wants to send {} extrinsics to TargetB Parentchain", calls.len()); @@ -379,7 +397,22 @@ where let validator_access = get_validator_accessor_from_target_b_solo_or_parachain()?; validator_access.execute_mut_on_validator(|v| v.send_extrinsics(xts))?; } - + let ipfs_blobs_to_add: Vec> = side_effects + .iter() + .filter_map(|side_effect| match side_effect { + TrustedCallSideEffect::IpfsAdd(blob) => Some(blob.clone()), + _ => None, + }) + .collect(); + if !ipfs_blobs_to_add.is_empty() { + debug!("Enclave wants to store {} blob(s) on IPFS", ipfs_blobs_to_add.len()); + ipfs_blobs_to_add.iter().for_each(|blob| { + trace!("Storing blob of size {}B on IPFS", blob.len()); + // ignore errors here. ipfs is optimistic and a fallback is implemented. + // Moreover, we can't handle failures anyway + let _ = ocall_api.write_ipfs(blob.clone()); + }); + } Ok(()) } diff --git a/service/Cargo.toml b/service/Cargo.toml index 4e6ef0d524..f1b9da744c 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -31,7 +31,7 @@ url = "2.5.0" warp = "0.3" # ipfs -ipfs-api = "0.11.0" +ipfs-api-backend-hyper = { version = "0.6.0", features = ["with-hyper-tls", "with-builder"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } primitive-types = { version = "0.12.1", default-features = false, features = ["codec"] } @@ -48,6 +48,7 @@ itc-rpc-server = { path = "../core/rpc-server" } itp-api-client-types = { path = "../core-primitives/node-api/api-client-types" } itp-enclave-api = { path = "../core-primitives/enclave-api" } itp-enclave-metrics = { path = "../core-primitives/enclave-metrics" } +itp-ipfs-cid = { path = "../core-primitives/ipfs-cid" } itp-node-api = { path = "../core-primitives/node-api" } itp-settings = { path = "../core-primitives/settings" } itp-stf-interface = { path = "../core-primitives/stf-interface" } diff --git a/service/src/cli.yml b/service/src/cli.yml index b97f6907ab..d14b972e64 100644 --- a/service/src/cli.yml +++ b/service/src/cli.yml @@ -107,6 +107,18 @@ args: long: clean-reset short: c help: Cleans and purges any previous state and key files and generates them anew before starting. + - ipfs-api-url: + long: ipfs-api-url + takes_value: true + required: false + help: + Set the IPFS API endpoint to connect to a local or remote IPFS node. Use http(s) without api path. + - ipfs-api-auth: + long: ipfs-api-auth + takes_value: true + required: false + help: + Set the IPFS API basic auth credentials in the form username:password. subcommands: - run: diff --git a/service/src/config.rs b/service/src/config.rs index 65bf4c0423..0be35003ba 100644 --- a/service/src/config.rs +++ b/service/src/config.rs @@ -63,6 +63,10 @@ pub struct Config { metrics_server_port: String, /// Port for the untrusted HTTP server (e.g. for `is_initialized`) untrusted_http_port: String, + /// IPFS API endpoint + ipfs_api_url: Option, + /// IPFS API authentication + ipfs_api_auth: Option, /// Data directory used by all the services. data_dir: PathBuf, /// Config of the 'run' subcommand @@ -88,6 +92,8 @@ impl Config { enable_metrics_server: bool, metrics_server_port: String, untrusted_http_port: String, + ipfs_api_url: Option, + ipfs_api_auth: Option, data_dir: PathBuf, run_config: Option, ) -> Self { @@ -108,6 +114,8 @@ impl Config { enable_metrics_server, metrics_server_port, untrusted_http_port, + ipfs_api_url, + ipfs_api_auth, data_dir, run_config, } @@ -204,6 +212,14 @@ impl Config { self.untrusted_http_port.parse::().ok() } + pub fn ipfs_api_url(&self) -> Option { + self.ipfs_api_url.clone() + } + + pub fn ipfs_api_auth(&self) -> Option { + self.ipfs_api_auth.clone() + } + pub fn with_test_data_dir(&self) -> Self { let mut new = self.clone(); new.data_dir.push("test"); @@ -220,6 +236,8 @@ impl From<&ArgMatches<'_>> for Config { let metrics_server_port = m.value_of("metrics-port").unwrap_or(DEFAULT_METRICS_PORT); let untrusted_http_port = m.value_of("untrusted-http-port").unwrap_or(DEFAULT_UNTRUSTED_HTTP_PORT); + let ipfs_api_url = m.value_of("ipfs-api-url"); + let ipfs_api_auth = m.value_of("ipfs-api-auth"); let data_dir = match m.value_of("data-dir") { Some(d) => { @@ -261,6 +279,8 @@ impl From<&ArgMatches<'_>> for Config { is_metrics_server_enabled, metrics_server_port.to_string(), untrusted_http_port.to_string(), + ipfs_api_url.map(str::to_string), + ipfs_api_auth.map(str::to_string), data_dir, run_config, ) diff --git a/service/src/main_impl.rs b/service/src/main_impl.rs index e8242873d4..00fd0d2e74 100644 --- a/service/src/main_impl.rs +++ b/service/src/main_impl.rs @@ -31,6 +31,7 @@ use crate::{ use base58::ToBase58; use clap::{load_yaml, App, ArgMatches}; use codec::{Decode, Encode}; +use ipfs_api_backend_hyper::{IpfsApi, TryFromUri}; use ita_parentchain_interface::integritee::{Hash, Header}; use itp_enclave_api::{ enclave_base::EnclaveBase, @@ -189,7 +190,7 @@ pub(crate) fn main() { config.integritee_rpc_endpoint(), AccountKeyring::Alice.pair(), )); - let enclave = Arc::new(enclave_init(&config).unwrap()); + let enclave = Arc::new(enclave_init(&config).expect("Failed to initialize enclave")); let initialization_handler = Arc::new(InitializationHandler::default()); let worker = Arc::new(EnclaveWorker::new( config.clone(), @@ -222,6 +223,8 @@ pub(crate) fn main() { )) }); + let maybe_ipfs_url_and_auth = (config.ipfs_api_url(), config.ipfs_api_auth()); + // initialize o-call bridge with a concrete factory implementation OCallBridge::initialize(Arc::new(OCallBridgeComponentFactory::new( node_api_factory.clone(), @@ -234,6 +237,7 @@ pub(crate) fn main() { peer_sidechain_block_fetcher, tokio_handle.clone(), enclave_metrics_receiver, + maybe_ipfs_url_and_auth, config.data_dir().into(), ))); diff --git a/service/src/ocall_bridge/bridge_api.rs b/service/src/ocall_bridge/bridge_api.rs index 6e8f67c666..b86a561cf2 100644 --- a/service/src/ocall_bridge/bridge_api.rs +++ b/service/src/ocall_bridge/bridge_api.rs @@ -17,6 +17,7 @@ */ use itp_enclave_api::remote_attestation::QveReport; +use itp_ipfs_cid::IpfsCid; use lazy_static::lazy_static; use log::*; use parking_lot::RwLock; @@ -240,15 +241,10 @@ pub trait SidechainBridge { ) -> OCallBridgeResult>; } -/// type for IPFS -pub type Cid = [u8; 46]; - /// Trait for all the OCalls related to IPFS #[cfg_attr(test, automock)] pub trait IpfsBridge { - fn write_to_ipfs(&self, data: &'static [u8]) -> OCallBridgeResult; - - fn read_from_ipfs(&self, cid: Cid) -> OCallBridgeResult<()>; + fn write_to_ipfs(&self, data: Vec) -> OCallBridgeResult<()>; } /// Trait for the direct invocation OCalls diff --git a/service/src/ocall_bridge/component_factory.rs b/service/src/ocall_bridge/component_factory.rs index 6d36702e06..758e03b086 100644 --- a/service/src/ocall_bridge/component_factory.rs +++ b/service/src/ocall_bridge/component_factory.rs @@ -32,6 +32,7 @@ use crate::{ sync_block_broadcaster::BroadcastBlocks, worker_peers_updater::UpdateWorkerPeers, }; +use ipfs_api_backend_hyper::IpfsClient; use itp_api_client_types::{Config, Request}; use itp_enclave_api::remote_attestation::RemoteAttestationCallBacks; use itp_node_api::node_api_factory::{CreateNodeApi, NodeApiFactory}; @@ -69,6 +70,7 @@ pub struct OCallBridgeComponentFactory< peer_block_fetcher: Arc, tokio_handle: Arc, metrics_receiver: Arc, + maybe_ipfs_url_and_auth: (Option, Option), log_dir: Arc, } @@ -115,6 +117,7 @@ impl< peer_block_fetcher: Arc, tokio_handle: Arc, metrics_receiver: Arc, + maybe_ipfs_url_and_auth: (Option, Option), log_dir: Arc, ) -> Self { OCallBridgeComponentFactory { @@ -128,6 +131,7 @@ impl< peer_block_fetcher, tokio_handle, metrics_receiver, + maybe_ipfs_url_and_auth, log_dir, } } @@ -196,7 +200,11 @@ impl< } fn get_ipfs_api(&self) -> Arc { - Arc::new(IpfsOCall {}) + Arc::new(IpfsOCall::new( + self.maybe_ipfs_url_and_auth.0.clone(), + self.maybe_ipfs_url_and_auth.1.clone(), + self.log_dir.clone(), + )) } fn get_metrics_api(&self) -> Arc { diff --git a/service/src/ocall_bridge/ffi/ipfs.rs b/service/src/ocall_bridge/ffi/ipfs.rs index e264b49db2..043b1103b3 100644 --- a/service/src/ocall_bridge/ffi/ipfs.rs +++ b/service/src/ocall_bridge/ffi/ipfs.rs @@ -16,7 +16,9 @@ */ -use crate::ocall_bridge::bridge_api::{Bridge, Cid, IpfsBridge}; +use crate::ocall_bridge::bridge_api::{Bridge, IpfsBridge}; +use codec::{Decode, Encode}; +use itp_ipfs_cid::IpfsCid; use log::*; use sgx_types::sgx_status_t; use std::{slice, sync::Arc}; @@ -24,53 +26,11 @@ use std::{slice, sync::Arc}; /// C-API exposed for o-call from enclave #[no_mangle] pub unsafe extern "C" fn ocall_write_ipfs( - enc_state: *const u8, - enc_state_size: u32, - cid: *mut u8, - cid_size: u32, + content_ptr: *const u8, + content_size: u32, ) -> sgx_status_t { - write_ipfs(enc_state, enc_state_size, cid, cid_size, Bridge::get_ipfs_api()) -} - -/// C-API exposed for o-call from enclave -#[no_mangle] -pub unsafe extern "C" fn ocall_read_ipfs(cid: *const u8, cid_size: u32) -> sgx_status_t { - read_ipfs(cid, cid_size, Bridge::get_ipfs_api()) -} - -fn write_ipfs( - enc_state: *const u8, - enc_state_size: u32, - cid: *mut u8, - cid_size: u32, - ipfs_api: Arc, -) -> sgx_status_t { - let state = unsafe { slice::from_raw_parts(enc_state, enc_state_size as usize) }; - let cid = unsafe { slice::from_raw_parts_mut(cid, cid_size as usize) }; - - return match ipfs_api.write_to_ipfs(state) { - Ok(r) => { - cid.clone_from_slice(&r); - sgx_status_t::SGX_SUCCESS - }, - Err(e) => { - error!("OCall to write_ipfs failed: {:?}", e); - sgx_status_t::SGX_ERROR_UNEXPECTED - }, - } -} - -fn read_ipfs(cid: *const u8, cid_size: u32, ipfs_api: Arc) -> sgx_status_t { - let _cid = unsafe { slice::from_raw_parts(cid, cid_size as usize) }; - - let mut cid: Cid = [0; 46]; - cid.clone_from_slice(_cid); - - match ipfs_api.read_from_ipfs(cid) { - Ok(_) => sgx_status_t::SGX_SUCCESS, - Err(e) => { - error!("OCall to read_ipfs failed: {:?}", e); - sgx_status_t::SGX_ERROR_UNEXPECTED - }, - } + let content: Vec = + unsafe { Vec::from(slice::from_raw_parts(content_ptr, content_size as usize)) }; + let _ = Bridge::get_ipfs_api().write_to_ipfs(content); + sgx_status_t::SGX_SUCCESS } diff --git a/service/src/ocall_bridge/ipfs_ocall.rs b/service/src/ocall_bridge/ipfs_ocall.rs index 8cc25f85d7..6d870b8529 100644 --- a/service/src/ocall_bridge/ipfs_ocall.rs +++ b/service/src/ocall_bridge/ipfs_ocall.rs @@ -16,87 +16,92 @@ */ -use crate::ocall_bridge::bridge_api::{Cid, IpfsBridge, OCallBridgeError, OCallBridgeResult}; -use futures::TryStreamExt; -use ipfs_api::IpfsClient; +use crate::ocall_bridge::bridge_api::{IpfsBridge, OCallBridgeError, OCallBridgeResult}; +use chrono::Local; +use ipfs_api_backend_hyper::{IpfsApi, IpfsClient, TryFromUri}; +use itp_ipfs_cid::IpfsCid; use log::*; use std::{ - fs::File, - io::{Cursor, Write}, + fmt::Display, + fs::{create_dir_all, File}, + io::{self, Cursor, Write}, + path::{Path, PathBuf}, str, - sync::mpsc::channel, + sync::Arc, }; +use tokio::runtime::Runtime; -pub struct IpfsOCall; - -impl IpfsBridge for IpfsOCall { - fn write_to_ipfs(&self, data: &'static [u8]) -> OCallBridgeResult { - debug!(" Entering ocall_write_ipfs"); - Ok(write_to_ipfs(data)) - } - - fn read_from_ipfs(&self, cid: Cid) -> OCallBridgeResult<()> { - debug!("Entering ocall_read_ipfs"); - - let result = read_from_ipfs(cid); - match result { - Ok(res) => { - let filename = str::from_utf8(&cid).unwrap(); - create_file(filename, &res).map_err(OCallBridgeError::IpfsError) - }, - Err(_) => Err(OCallBridgeError::IpfsError("failed to read from IPFS".to_string())), - } - } +pub struct IpfsOCall { + client: Option>, + log_dir: Arc, } -fn create_file(filename: &str, result: &[u8]) -> Result<(), String> { - match File::create(filename) { - Ok(mut f) => f - .write_all(result) - .map_or_else(|e| Err(format!("failed writing to file: {}", e)), |_| Ok(())), - Err(e) => Err(format!("failed to create file: {}", e)), +impl IpfsOCall { + pub fn new(maybe_url: Option, maybe_auth: Option, log_dir: Arc) -> Self { + if let Some(url) = maybe_url { + let client = ipfs_api_backend_hyper::IpfsClient::from_str(&url).unwrap(); + let client = if let Some((user, pwd)) = maybe_auth + .and_then(|s| s.split_once(':').map(|(u, p)| (u.to_string(), p.to_string()))) + { + info!("Using IPFS node at {} with credentials ******", url); + client.with_credentials(user, pwd) + } else { + info!("Using IPFS node at {}", url); + client + }; + let version = tokio::runtime::Runtime::new().unwrap().block_on(client.version()); + match version { + Ok(v) => info!("Connected to IPFS node version: {}", v.version), + Err(e) => error!("Error getting IPFS node version: {}", e), + } + Self { client: Some(Arc::new(client)), log_dir } + } else { + info!("No IPFS URL provided, disabling IPFS."); + Self { client: None, log_dir } + } } } -#[tokio::main] -async fn write_to_ipfs(data: &'static [u8]) -> Cid { - // Creates an `IpfsClient` connected to the endpoint specified in ~/.ipfs/api. - // If not found, tries to connect to `localhost:5001`. - let client = IpfsClient::default(); - - match client.version().await { - Ok(version) => info!("version: {:?}", version.version), - Err(e) => eprintln!("error getting version: {}", e), - } - - let datac = Cursor::new(data); - let (tx, rx) = channel(); - - match client.add(datac).await { - Ok(res) => { - info!("Result Hash {}", res.hash); - tx.send(res.hash.into_bytes()).unwrap(); - }, - Err(e) => eprintln!("error adding file: {}", e), +impl IpfsBridge for IpfsOCall { + fn write_to_ipfs(&self, data: Vec) -> OCallBridgeResult<()> { + trace!(" Entering ocall_write_ipfs to write {}B", data.len()); + if let Some(ref client) = self.client { + let datac = Cursor::new(data.clone()); + let add_options = ipfs_api_backend_hyper::request::Add::builder() + .raw_leaves(true) + .cid_version(1) + .build(); + let rt = Runtime::new().unwrap(); + match rt.block_on(client.add_with_options(datac, add_options)) { + Ok(res) => { + debug!("ocall result IpfsCid {}", res.hash); + }, + Err(e) => { + let dumpfile = log_failing_blob_to_file(data, self.log_dir.clone()) + .unwrap_or_else(|e| e.to_string().into()); + warn!(" write to ipfs failed late, wrote to file {}", dumpfile.display()); + }, + }; + } else { + warn!("IPFS client not configured, writing to local file"); + let dumpfile = log_failing_blob_to_file(data, self.log_dir.clone()) + .unwrap_or_else(|e| e.to_string().into()); + }; + Ok(()) } - let mut cid: Cid = [0; 46]; - cid.clone_from_slice(&rx.recv().unwrap()); - cid } -#[tokio::main] -pub async fn read_from_ipfs(cid: Cid) -> Result, String> { - // Creates an `IpfsClient` connected to the endpoint specified in ~/.ipfs/api. - // If not found, tries to connect to `localhost:5001`. - let client = IpfsClient::default(); - let h = str::from_utf8(&cid).unwrap(); - - info!("Fetching content from: {}", h); - - client - .cat(h) - .map_ok(|chunk| chunk.to_vec()) - .map_err(|e| e.to_string()) - .try_concat() - .await +fn log_failing_blob_to_file(blob: Vec, log_dir: Arc) -> io::Result { + let log_dir = log_dir.join("log-ipfs-failing-add"); + create_dir_all(&log_dir)?; + let timestamp = Local::now().format("%Y%m%d-%H%M%S-%3f").to_string(); + let cid_str = IpfsCid::from_chunk(&blob) + .map(|cid| format!("{}", cid)) + .unwrap_or_else(|_| "invalid-cid".to_string()); + let file_name = format!("ipfs-{}-{}.bin", timestamp, cid_str); + let file_path = log_dir.join(file_name); + let mut file = File::create(file_path.clone())?; + file.write_all(&blob)?; + warn!(" write to ipfs failed early, wrote to file {}", file_path.display()); + Ok(file_path) } diff --git a/service/src/tests/commons.rs b/service/src/tests/commons.rs index f87020168b..7028182469 100644 --- a/service/src/tests/commons.rs +++ b/service/src/tests/commons.rs @@ -54,6 +54,8 @@ pub fn local_worker_config( false, "8787".to_string(), "4545".to_string(), + None, + None, crate::config::pwd(), None, ) diff --git a/service/src/tests/mock.rs b/service/src/tests/mock.rs index 7c7528fa6c..3a9f98d6d6 100644 --- a/service/src/tests/mock.rs +++ b/service/src/tests/mock.rs @@ -17,6 +17,7 @@ use codec::Encode; use enclave_bridge_primitives::ShardSignerStatus; +use itp_ipfs_cid::IpfsCid; use itp_node_api::api_client::{ApiResult, PalletTeerexApi}; use itp_types::{ parentchain::BlockNumber, AccountId, MultiEnclave, SgxBuildMode, SgxEnclave, SgxReportData, @@ -93,7 +94,7 @@ impl PalletTeerexApi for TestNodeApi { &self, _: &ShardIdentifier, _at_block: Option, - ) -> ApiResult> { + ) -> ApiResult> { unreachable!() } } diff --git a/sidechain/consensus/aura/src/slot_proposer.rs b/sidechain/consensus/aura/src/slot_proposer.rs index 617cb22ecd..667f5ddc8a 100644 --- a/sidechain/consensus/aura/src/slot_proposer.rs +++ b/sidechain/consensus/aura/src/slot_proposer.rs @@ -116,7 +116,7 @@ where ) .map_err(|e| ConsensusError::Other(e.to_string().into()))?; - let parentchain_extrinsics = batch_execution_result.get_extrinsic_callbacks(); + let side_effects = batch_execution_result.get_extrinsic_callbacks(); let executed_operation_hashes: Vec<_> = batch_execution_result.get_executed_operation_hashes().to_vec(); @@ -157,6 +157,6 @@ where max_duration.as_millis(), ); - Ok(Proposal { block: sidechain_block, parentchain_effects: parentchain_extrinsics }) + Ok(Proposal { block: sidechain_block, side_effects }) } } diff --git a/sidechain/consensus/aura/src/test/mocks/proposer_mock.rs b/sidechain/consensus/aura/src/test/mocks/proposer_mock.rs index 574083aaf9..03d99a9d0c 100644 --- a/sidechain/consensus/aura/src/test/mocks/proposer_mock.rs +++ b/sidechain/consensus/aura/src/test/mocks/proposer_mock.rs @@ -42,7 +42,7 @@ impl Proposer for ProposerMock { SidechainBlockBuilder::random().with_block_data(block_data).build_signed() }, - parentchain_effects: Default::default(), + side_effects: Default::default(), }) } } diff --git a/sidechain/consensus/common/src/lib.rs b/sidechain/consensus/common/src/lib.rs index 64391c1bf1..c7861d5c1d 100644 --- a/sidechain/consensus/common/src/lib.rs +++ b/sidechain/consensus/common/src/lib.rs @@ -50,7 +50,7 @@ pub use block_import::*; pub use block_import_confirmation_handler::*; pub use block_import_queue_worker::*; pub use error::*; -use itp_types::parentchain::ParentchainCall; +use itp_types::TrustedCallSideEffect; pub use peer_block_sync::*; pub trait Verifier: Send + Sync @@ -107,9 +107,10 @@ pub trait Proposer< pub struct Proposal { /// The sidechain block that was build. pub block: SignedSidechainBlock, - /// Parentchain state transitions triggered by sidechain state transitions. + /// Side effects of the trusted calls included in the block. + /// e.g. Parentchain state transitions triggered by sidechain state transitions. /// /// Any sidechain stf that invokes a parentchain stf must not commit its state change /// before the parentchain effect has been finalized. - pub parentchain_effects: Vec, + pub side_effects: Vec, } diff --git a/sidechain/consensus/slots/src/lib.rs b/sidechain/consensus/slots/src/lib.rs index 47fd911bc6..7a897c87d0 100644 --- a/sidechain/consensus/slots/src/lib.rs +++ b/sidechain/consensus/slots/src/lib.rs @@ -55,7 +55,7 @@ mod mocks; #[cfg(test)] mod per_shard_slot_worker_tests; -use itp_types::parentchain::ParentchainCall; +use itp_types::TrustedCallSideEffect; #[cfg(feature = "std")] pub use slot_stream::*; pub use slots::*; @@ -65,11 +65,12 @@ pub use slots::*; pub struct SlotResult { /// The result of a slot operation. pub block: SignedSidechainBlock, - /// Parentchain state transitions triggered by sidechain state transitions. + /// Side effects of the trusted calls included in the block. + /// e.g. Parentchain state transitions triggered by sidechain state transitions. /// /// Any sidechain stf that invokes a parentchain stf must not commit its state change /// before the parentchain effect has been finalized. - pub parentchain_effects: Vec, + pub side_effects: Vec, } /// A worker that should be invoked at every new slot for a specific shard. @@ -387,10 +388,7 @@ pub trait SimpleSlotWorker { latest_integritee_parentchain_header.number(), latest_integritee_parentchain_header.hash() ); - Some(SlotResult { - block: proposing.block, - parentchain_effects: proposing.parentchain_effects, - }) + Some(SlotResult { block: proposing.block, side_effects: proposing.side_effects }) } } diff --git a/sidechain/rpc-handler/src/constants.rs b/sidechain/rpc-handler/src/constants.rs index b3b5659b82..a75e4b6e0c 100644 --- a/sidechain/rpc-handler/src/constants.rs +++ b/sidechain/rpc-handler/src/constants.rs @@ -20,3 +20,4 @@ // RPC method names. pub const RPC_METHOD_NAME_IMPORT_BLOCKS: &str = "sidechain_importBlock"; pub const RPC_METHOD_NAME_FETCH_BLOCKS_FROM_PEER: &str = "sidechain_fetchBlocksFromPeer"; +pub const MAX_TOP_SIZE_TO_ENTER_POOL: usize = 102_400; // 100 KB diff --git a/sidechain/rpc-handler/src/direct_top_pool_api.rs b/sidechain/rpc-handler/src/direct_top_pool_api.rs index 820a52d8ed..e30eaf7f6c 100644 --- a/sidechain/rpc-handler/src/direct_top_pool_api.rs +++ b/sidechain/rpc-handler/src/direct_top_pool_api.rs @@ -25,6 +25,7 @@ use rust_base58::base58::FromBase58; #[cfg(feature = "sgx")] use base58::FromBase58; +use crate::constants::MAX_TOP_SIZE_TO_ENTER_POOL; use codec::{Decode, Encode}; use itp_enclave_metrics::EnclaveMetric; use itp_ocall_api::EnclaveMetricsOCallApi; @@ -154,7 +155,6 @@ where G: PartialEq + Encode + Decode + Debug + Send + Sync + 'static, { debug!("Author submit and watch trusted operation.."); - let hex_encoded_params = params.parse::>().map_err(|e| format!("{:?}", e))?; let request = @@ -162,6 +162,17 @@ where let shard: ShardIdentifier = request.shard; let encrypted_trusted_call: Vec = request.cyphertext; + trace!( + "Submitting trusted operation to TOP pool for shard: {:?}, with encrypted call size: {} bytes", + shard, + encrypted_trusted_call.len() + ); + if encrypted_trusted_call.len() > MAX_TOP_SIZE_TO_ENTER_POOL { + let error_msg = "Trusted operation too large"; + error!("{}", error_msg); + return Err(error_msg.into()) + } + let result = async { author.watch_top(encrypted_trusted_call, shard).await }; let response: Result = executor::block_on(result);