diff --git a/enclave/Cargo.lock b/enclave/Cargo.lock index abb58e4452..46f09c191a 100644 --- a/enclave/Cargo.lock +++ b/enclave/Cargo.lock @@ -91,6 +91,11 @@ name = "autocfg" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "base-x" +version = "0.2.6" +source = "git+https://github.com/whalelephant/base-x-rs?branch=no_std#906c9ac59282ff5a2eec86efd25d50ad9927b147" + [[package]] name = "base64" version = "0.10.1" @@ -118,6 +123,40 @@ dependencies = [ "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "blake2b_simd" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "blake2s_simd" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "blake3" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-mac 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block-buffer" version = "0.7.3" @@ -129,6 +168,15 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-padding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block-cipher-trait" version = "0.6.2" @@ -145,6 +193,11 @@ dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byte-slice-cast" version = "0.3.5" @@ -202,6 +255,16 @@ dependencies = [ "sgx_tstd 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", ] +[[package]] +name = "cid" +version = "0.5.1" +source = "git+https://github.com/whalelephant/rust-cid?branch=nstd#cca87467c46106c801ca3727500477258b0f13b0" +dependencies = [ + "multibase 0.8.0 (git+https://github.com/whalelephant/rust-multibase?branch=nstd)", + "multihash 0.11.2 (git+https://github.com/whalelephant/rust-multihash?branch=nstd)", + "unsigned-varint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clear_on_drop" version = "0.2.3" @@ -233,6 +296,11 @@ name = "constant_time_eq" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "crunchy" version = "0.2.2" @@ -247,6 +315,15 @@ dependencies = [ "subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "curve25519-dalek" version = "2.0.0" @@ -259,6 +336,11 @@ dependencies = [ "zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "data-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "derive_more" version = "0.99.5" @@ -277,6 +359,14 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ed25519-dalek" version = "1.0.0-pre.3" @@ -533,6 +623,15 @@ dependencies = [ "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "getrandom" version = "0.1.14" @@ -568,7 +667,7 @@ dependencies = [ [[package]] name = "hashbrown_tstd" version = "0.7.1" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -634,6 +733,18 @@ name = "integer-sqrt" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ipfs-unixfs" +version = "0.0.1" +source = "git+https://github.com/whalelephant/rust-ipfs?branch=w-nstd#52f84dceea7065bb4ee2c24da53b3bedf162241a" +dependencies = [ + "cid 0.5.1 (git+https://github.com/whalelephant/rust-cid?branch=nstd)", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "multihash 0.11.2 (git+https://github.com/whalelephant/rust-multihash?branch=nstd)", + "quick-protobuf 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itertools" version = "0.8.2" @@ -745,6 +856,31 @@ dependencies = [ "zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "multibase" +version = "0.8.0" +source = "git+https://github.com/whalelephant/rust-multibase?branch=nstd#df67fb30e86998f7c10d4eea16a1cd480d2448c0" +dependencies = [ + "base-x 0.2.6 (git+https://github.com/whalelephant/base-x-rs?branch=no_std)", + "data-encoding 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "multihash" +version = "0.11.2" +source = "git+https://github.com/whalelephant/rust-multihash?branch=nstd#bcb2a319bc5920f89b9b1f024c43c1d3543e13c7" +dependencies = [ + "blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2s_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "blake3 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unsigned-varint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "nodrop" version = "0.1.14" @@ -852,6 +988,11 @@ name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pallet-aura" version = "2.0.0-alpha.7" @@ -1170,6 +1311,14 @@ name = "quick-error" version = "1.2.2" source = "git+https://github.com/mesalock-linux/quick-error-sgx#c77b8867336fff708f5567c7e051227af07139ea" +[[package]] +name = "quick-protobuf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "0.3.15" @@ -1490,12 +1639,12 @@ dependencies = [ [[package]] name = "sgx_alloc" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" [[package]] name = "sgx_backtrace_sys" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", "sgx_build_helper 0.1.3 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", @@ -1505,7 +1654,7 @@ dependencies = [ [[package]] name = "sgx_build_helper" version = "0.1.3" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" [[package]] name = "sgx_crypto_helper" @@ -1524,12 +1673,12 @@ dependencies = [ [[package]] name = "sgx_demangle" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" [[package]] name = "sgx_libc" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "sgx_types 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", ] @@ -1547,7 +1696,7 @@ dependencies = [ [[package]] name = "sgx_serialize" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "sgx_tstd 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", ] @@ -1589,7 +1738,7 @@ dependencies = [ [[package]] name = "sgx_tprotected_fs" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "sgx_trts 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", "sgx_types 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", @@ -1598,7 +1747,7 @@ dependencies = [ [[package]] name = "sgx_trts" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "sgx_libc 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", "sgx_types 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", @@ -1626,7 +1775,7 @@ dependencies = [ [[package]] name = "sgx_tstd" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "hashbrown_tstd 0.7.1 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", "sgx_alloc 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", @@ -1650,16 +1799,28 @@ dependencies = [ [[package]] name = "sgx_types" version = "1.1.2" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" [[package]] name = "sgx_unwind" version = "0.1.1" -source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#253b3ac982b2d09d32f5fa5a2011e3c36bcbed1e" +source = "git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2#8f065be7a442157bf16dc7106feb795ea1c578eb" dependencies = [ "sgx_build_helper 0.1.3 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)", ] +[[package]] +name = "sha-1" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cpuid-bool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha2" version = "0.8.1" @@ -1671,6 +1832,29 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sha2" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cpuid-bool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "slab" version = "0.4.2" @@ -2104,11 +2288,14 @@ dependencies = [ "bit-vec 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "chain-relay 0.6.5-sub2.0.0-alpha.7", "chrono 0.4.11 (git+https://github.com/mesalock-linux/chrono-sgx)", + "cid 0.5.1 (git+https://github.com/whalelephant/rust-cid?branch=nstd)", "env_logger 0.7.1 (git+https://github.com/mesalock-linux/env_logger-sgx)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ipfs-unixfs 0.0.1 (git+https://github.com/whalelephant/rust-ipfs?branch=w-nstd)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (git+https://github.com/mesalock-linux/log-sgx)", + "multibase 0.8.0 (git+https://github.com/whalelephant/rust-multibase?branch=nstd)", "num-bigint 0.2.5 (git+https://github.com/mesalock-linux/num-bigint-sgx)", "ofb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2301,11 +2488,21 @@ name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unsigned-varint" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "untrusted" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -2392,28 +2589,39 @@ dependencies = [ "checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +"checksum base-x 0.2.6 (git+https://github.com/whalelephant/base-x-rs?branch=no_std)" = "" "checksum base64 0.10.1 (git+https://github.com/mesalock-linux/rust-base64-sgx)" = "" "checksum bit-vec 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" "checksum bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5da9b3d9f6f585199287a473f4f8dfab6566cf827d15c00c219f53c645687ead" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" +"checksum blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" +"checksum blake2s_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab9e07352b829279624ceb7c64adb4f585dacdb81d35cafae81139ccd617cf44" +"checksum blake3 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ce4f9586c9a3151c4b49b19e82ba163dd073614dd057e53c969e1a4db5b52720" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +"checksum block-buffer 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +"checksum block-padding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" "checksum byte-slice-cast 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" "checksum cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chrono 0.4.11 (git+https://github.com/mesalock-linux/chrono-sgx)" = "" +"checksum cid 0.5.1 (git+https://github.com/whalelephant/rust-cid?branch=nstd)" = "" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum const-random 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "2f1af9ac737b2dd2d577701e59fd09ba34822f6f2ebdb30a7647405d9e55e16a" "checksum const-random-macro 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "25e4c606eb459dd29f7c57b2e0879f2b6f14ee130918c2b78ccb58a9624e6c7a" "checksum constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +"checksum cpuid-bool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" "checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +"checksum crypto-mac 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" "checksum curve25519-dalek 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26778518a7f6cffa1d25a44b602b62b979bd88adb9e99ffec546998cf3404839" +"checksum data-encoding 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d0e2d24e5ee3b23a01de38eefdcd978907890701f08ffffd4cb457ca4ee8d6" "checksum derive_more 0.99.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e2323f3f47db9a0e77ce7a300605d8d2098597fc451ed1a97bb1f6411bb550a7" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +"checksum digest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" "checksum ed25519-dalek 1.0.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)" = "978710b352437433c97b2bff193f2fb1dfd58a093f863dd95e225a19baa599a2" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum env_logger 0.7.1 (git+https://github.com/mesalock-linux/env_logger-sgx)" = "" @@ -2440,6 +2648,7 @@ dependencies = [ "checksum futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" "checksum futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +"checksum generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" "checksum hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d23bd4e7b5eda0d0f3a307e8b381fdc8ba9000f26fbe912250c0a4cc3956364a" "checksum hash256-std-hasher 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "92c171d55b98633f4ed3860808f004099b36c1cc29c42cfc53aa8591b21efcf2" @@ -2453,6 +2662,7 @@ dependencies = [ "checksum impl-codec 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1be51a921b067b0eaca2fad532d9400041561aa922221cc65f95a85641c6bf53" "checksum impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ef5550a42e3740a0e71f909d4c861056a284060af885ae7aa6242820f920d9d" "checksum integer-sqrt 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f65877bf7d44897a473350b1046277941cee20b263397e90869c50b6e766088b" +"checksum ipfs-unixfs 0.0.1 (git+https://github.com/whalelephant/rust-ipfs?branch=w-nstd)" = "" "checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" "checksum itoa 0.4.5 (git+https://github.com/mesalock-linux/itoa-sgx.git)" = "" @@ -2466,6 +2676,8 @@ dependencies = [ "checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" "checksum memory-db 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be512cb2ccb4ecbdca937fdd4a62ea5f09f8e7195466a85e4632b3d5bcce82e6" "checksum merlin 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c6feca46f4fa3443a01769d768727f10c10a20fdb65e52dc16a81f0c8269bb78" +"checksum multibase 0.8.0 (git+https://github.com/whalelephant/rust-multibase?branch=nstd)" = "" +"checksum multihash 0.11.2 (git+https://github.com/whalelephant/rust-multihash?branch=nstd)" = "" "checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" "checksum num 0.2.0 (git+https://github.com/mesalock-linux/num-sgx)" = "" "checksum num-bigint 0.2.5 (git+https://github.com/mesalock-linux/num-bigint-sgx)" = "" @@ -2478,6 +2690,7 @@ dependencies = [ "checksum ofb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a877c7cc0b1801e45e3a71a799f50d8e4707ffb36faa06998f0a479b54bb894" "checksum once_cell 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +"checksum opaque-debug 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" "checksum pallet-aura 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)" = "84bfe377cb99f04a51ef30521bd3236acdf57ae76187d6ae8f0b1896fae1ba1d" "checksum pallet-balances 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5933eed290294f48ae9c6ca9b83c48f73c0e50eb2d86532a388d2076806f9d37" "checksum pallet-finality-tracker 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)" = "99b6aaf467788f82d9f18c940f57b6773e6114988120c63630ec1a30ef6af73d" @@ -2508,6 +2721,7 @@ dependencies = [ "checksum prometheus 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0575e258dab62268e7236d7307caa38848acbda7ec7ab87bd9093791e999d20" "checksum protobuf 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e86d370532557ae7573551a1ec8235a0f8d6cb276c7c9e6aa490b511c447485" "checksum quick-error 1.2.2 (git+https://github.com/mesalock-linux/quick-error-sgx)" = "" +"checksum quick-protobuf 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e489d4a83c17ea69b0291630229b5d4c92a94a3bf0165f7f72f506e94cda8b4b" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "42934bc9c8ab0d3b273a16d8551c8f0fcff46be73276ca083ec2414c15c4ba5e" "checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" @@ -2561,7 +2775,10 @@ dependencies = [ "checksum sgx_tunittest 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)" = "" "checksum sgx_types 1.1.2 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)" = "" "checksum sgx_unwind 0.1.1 (git+https://github.com/apache/teaclave-sgx-sdk.git?rev=v1.1.2)" = "" +"checksum sha-1 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" "checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" +"checksum sha2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2933378ddfeda7ea26f48c555bdad8bb446bf8a3d17832dc83e380d444cfb8c1" +"checksum sha3 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" "checksum sp-api 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4e34c770de3ada5729a094ed0e594a94fe03f4d6bfffd5d27f40e00778d20998" @@ -2617,7 +2834,9 @@ dependencies = [ "checksum uint 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "173cd16430c206dc1a430af8a89a0e9c076cf15cb42b4aedb10e8cc8fee73681" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum unsigned-varint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a98e44fc6af1e18c3a06666d829b4fd8d2714fb2dbffe8ab99d5dc7ea6baa628" "checksum untrusted 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +"checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" "checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" "checksum webpki 0.21.2 (git+https://github.com/mesalock-linux/webpki?branch=mesalock_sgx)" = "" "checksum webpki-roots 0.19.0 (git+https://github.com/mesalock-linux/webpki-roots?branch=mesalock_sgx)" = "" diff --git a/enclave/Cargo.toml b/enclave/Cargo.toml index b97af1ccc1..be651c87eb 100644 --- a/enclave/Cargo.toml +++ b/enclave/Cargo.toml @@ -50,6 +50,10 @@ itertools = { version = "0.8", default-features = false, features = []} bit-vec = { version = "0.6", default-features = false } base58 = { rev = "sgx_1.1.2", package="rust-base58", git = "https://github.com/mesalock-linux/rust-base58-sgx", default-features = false, features=["mesalock_sgx"] } +cid = { git = "https://github.com/whalelephant/rust-cid", branch = "nstd", default-features = false } +multibase = { git = "https://github.com/whalelephant/rust-multibase", branch = "nstd", default-features = false } + + [dependencies.webpki] git = "https://github.com/mesalock-linux/webpki" branch = "mesalock_sgx" @@ -125,3 +129,10 @@ features = ["sgx"] [patch.crates-io] sp-io = { git = "https://github.com/scs/sgx-runtime", default-features = false, features = ["disable_oom", "disable_panic_handler", "disable_allocator", "sgx"]} + +[dependencies.ipfs-unixfs] +git = "https://github.com/whalelephant/rust-ipfs" +branch = "w-nstd" +default-features = false + + diff --git a/enclave/Enclave.edl b/enclave/Enclave.edl index cf6a0b227e..246034eaf6 100644 --- a/enclave/Enclave.edl +++ b/enclave/Enclave.edl @@ -98,7 +98,6 @@ enclave { ); sgx_status_t ocall_read_ipfs( - [out, size = state_size] uint8_t * enc_state, uint32_t state_size, [in, size = cid_size] uint8_t * cid, uint32_t cid_size ); diff --git a/enclave/src/ipfs.rs b/enclave/src/ipfs.rs new file mode 100644 index 0000000000..0df5758f0b --- /dev/null +++ b/enclave/src/ipfs.rs @@ -0,0 +1,104 @@ +use cid::{Cid, Result as CidResult}; +use ipfs_unixfs::file::adder::FileAdder; +use log::*; +use multibase::Base; +use std::convert::TryFrom; +use std::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; + } + } +} + +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); +} + +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_eq!(verification.is_ok(), true); +} + +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/src/lib.rs b/enclave/src/lib.rs index 9de341cd8d..af854cf4d0 100644 --- a/enclave/src/lib.rs +++ b/enclave/src/lib.rs @@ -50,7 +50,10 @@ use std::slice; use std::string::String; use std::vec::Vec; +use ipfs::IpfsContent; use std::collections::HashMap; +use std::fs::File; +use std::io::Read; use utils::write_slice_and_whitespace_pad; use crate::constants::{CALL_WORKER, SHIELD_FUNDS}; @@ -62,13 +65,14 @@ use chain_relay::{ use sp_runtime::OpaqueExtrinsic; use sp_runtime::{generic::SignedBlock, traits::Header as HeaderT}; use substrate_api_client::extrinsic::xt_primitives::UncheckedExtrinsicV4; -use substratee_stf::sgx::{OpaqueCall, shards_key_hash, storage_hashes_to_update_per_shard}; +use substratee_stf::sgx::{shards_key_hash, storage_hashes_to_update_per_shard, OpaqueCall}; mod aes; mod attestation; mod constants; mod ed25519; mod io; +mod ipfs; mod rsa3072; mod state; mod utils; @@ -227,7 +231,7 @@ pub unsafe extern "C" fn get_state( let mut state = match state::load(&shard) { Ok(s) => s, - Err(status) => return status + Err(status) => return status, }; let validator = match io::light_validation::unseal() { @@ -363,7 +367,6 @@ pub unsafe extern "C" fn sync_chain_relay( Ok(c) => calls.extend(c.into_iter()), Err(_) => error!("Error executing relevant extrinsics"), }; - } if let Err(_e) = stf_post_actions(validator, calls, xt_slice, *nonce) { @@ -391,7 +394,8 @@ pub fn update_states(header: Header) -> SgxResult<()> { if let Some(maybe_shards) = update_map.get(&shards_key_hash()) { match maybe_shards { Some(shards) => { - let shards: Vec = Decode::decode(&mut shards.as_slice()).sgx_error_with_log("error decoding shards")?; + let shards: Vec = Decode::decode(&mut shards.as_slice()) + .sgx_error_with_log("error decoding shards")?; for s in shards { if !state::exists(&s) { info!("Initialized new shard that was found on chain: {:?}", s); @@ -403,7 +407,8 @@ pub fn update_states(header: Header) -> SgxResult<()> { .map(|key| WorkerRequest::ChainStorage(key, Some(header.hash()))) .collect(); - let responses: Vec>> = worker_request(per_shard_request)?; + let responses: Vec>> = + worker_request(per_shard_request)?; let per_shard_update_map = verify_worker_responses(responses, header.clone())?; let mut state = state::load(&s)?; @@ -412,7 +417,7 @@ pub fn update_states(header: Header) -> SgxResult<()> { state::write(state, &s)?; } } - None => info!("No shards are on the chain yet") + None => info!("No shards are on the chain yet"), }; }; Ok(()) @@ -596,8 +601,6 @@ fn verify_worker_responses( extern "C" { pub fn ocall_read_ipfs( ret_val: *mut sgx_status_t, - enc_state: *mut u8, - enc_state_size: u32, cid: *const u8, cid_size: u32, ) -> sgx_status_t; @@ -629,6 +632,9 @@ extern "C" { pub extern "C" fn test_main_entrance() -> size_t { rsgx_unit_tests!( state::test_encrypted_state_io_works, + 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, test_ocall_worker_request ) @@ -638,7 +644,7 @@ fn test_ocall_read_write_ipfs() { info!("testing IPFS read/write. Hopefully ipfs daemon is running..."); let mut rt: sgx_status_t = sgx_status_t::SGX_ERROR_UNEXPECTED; let mut cid_buf: Vec = vec![0; 46]; - let enc_state: Vec = vec![20; 36]; + let enc_state: Vec = vec![20; 4 * 512 * 1024]; let _res = unsafe { ocall_write_ipfs( @@ -650,18 +656,28 @@ fn test_ocall_read_write_ipfs() { ) }; - let mut ret_state = vec![0; 36]; - let _res = unsafe { + let res = unsafe { ocall_read_ipfs( &mut rt as *mut sgx_status_t, - ret_state.as_mut_ptr(), - ret_state.len() as u32, cid_buf.as_ptr(), cid_buf.len() as u32, ) }; - assert_eq!(enc_state, ret_state); + if res == sgx_status_t::SGX_SUCCESS { + let cid = std::str::from_utf8(&cid_buf).unwrap(); + let mut f = File::open(&cid).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()); + + let mut ipfs_content = IpfsContent::new(cid, content_buf); + let verification = ipfs_content.verify(); + assert_eq!(verification.is_ok(), true); + } else { + error!("was not able to write to file"); + assert!(false); + } } // TODO: this is redundantly defined in worker/src/main.rs diff --git a/enclave/src/state.rs b/enclave/src/state.rs index 1321da3826..03ff6089c0 100644 --- a/enclave/src/state.rs +++ b/enclave/src/state.rs @@ -16,8 +16,8 @@ */ use std::fs; -use std::vec::Vec; use std::io::Write; +use std::vec::Vec; use log::*; use sgx_tcrypto::rsgx_sha256_slice; diff --git a/stf/src/sgx.rs b/stf/src/sgx.rs index 5d8e30f7ac..6c8593039e 100644 --- a/stf/src/sgx.rs +++ b/stf/src/sgx.rs @@ -12,8 +12,8 @@ use sp_io::SgxExternalitiesTrait; use sp_runtime::traits::Dispatchable; use crate::{ - AccountId, State, Stf, TrustedCall, TrustedCallSigned, TrustedGetter, TrustedGetterSigned, - ShardIdentifier, SUBSRATEE_REGISTRY_MODULE, UNSHIELD, + AccountId, ShardIdentifier, State, Stf, TrustedCall, TrustedCallSigned, TrustedGetter, + TrustedGetterSigned, SUBSRATEE_REGISTRY_MODULE, UNSHIELD, }; use sp_core::blake2_256; @@ -71,14 +71,12 @@ impl Stf { pub fn update_storage(ext: &mut State, map_update: &HashMap, Option>>) { ext.execute_with(|| { - map_update - .iter() - .for_each(|(k, v)| { - match v { - Some(value) => sp_io::storage::set(k, value), - None => sp_io::storage::clear(k) - }; - }); + map_update.iter().for_each(|(k, v)| { + match v { + Some(value) => sp_io::storage::set(k, value), + None => sp_io::storage::clear(k), + }; + }); }); } @@ -210,7 +208,10 @@ impl Stf { } pub fn get_storage_hashes_to_update_for_getter(getter: &TrustedGetterSigned) -> Vec> { - info!("No specific storage updates needed for getter. Returning those for on block: {:?}", getter.getter); + info!( + "No specific storage updates needed for getter. Returning those for on block: {:?}", + getter.getter + ); Self::storage_hashes_to_update_on_block() } diff --git a/worker/src/ipfs.rs b/worker/src/ipfs.rs index 585ad22baf..52daf52db0 100644 --- a/worker/src/ipfs.rs +++ b/worker/src/ipfs.rs @@ -15,7 +15,8 @@ */ -use std::io::Cursor; +use std::fs::File; +use std::io::{Cursor, Write}; use std::slice; use std::str; use std::sync::mpsc::channel; @@ -46,8 +47,8 @@ async fn write_to_ipfs(data: &'static [u8]) -> Cid { Ok(res) => { info!("Result Hash {}", res.hash); tx.send(res.hash.into_bytes()).unwrap(); - }, - Err(e) => eprintln!("error adding file: {}", e) + } + Err(e) => eprintln!("error adding file: {}", e), } let mut cid: Cid = [0; 46]; cid.clone_from_slice(&rx.recv().unwrap()); @@ -55,7 +56,7 @@ async fn write_to_ipfs(data: &'static [u8]) -> Cid { } #[tokio::main] -pub async fn read_from_ipfs(cid: Cid) -> Vec { +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(); @@ -63,18 +64,12 @@ pub async fn read_from_ipfs(cid: Cid) -> Vec { info!("Fetching content from: {}", h); - let (tx, rx) = channel(); - - match client.cat(h) + client + .cat(h) .map_ok(|chunk| chunk.to_vec()) + .map_err(|e| e.to_string()) .try_concat() - .await - { - Ok(res) => { tx.send(res).unwrap(); }, - Err(e) => eprintln!("error reading file: {}", e) - } - - rx.recv().unwrap().to_vec() + .await } #[no_mangle] @@ -95,22 +90,32 @@ pub unsafe extern "C" fn ocall_write_ipfs( } #[no_mangle] -pub unsafe extern "C" fn ocall_read_ipfs( - enc_state: *mut u8, - enc_state_size: u32, - cid: *const u8, - cid_size: u32, -) -> sgx_status_t { +pub unsafe extern "C" fn ocall_read_ipfs(cid: *const u8, cid_size: u32) -> sgx_status_t { debug!("Entering ocall_read_ipfs"); - let state = slice::from_raw_parts_mut(enc_state, enc_state_size as usize); let _cid = slice::from_raw_parts(cid, cid_size as usize); let mut cid = [0; 46]; cid.clone_from_slice(_cid); - let res = read_from_ipfs(cid); - state.clone_from_slice(&res); - - sgx_status_t::SGX_SUCCESS + let result = read_from_ipfs(cid); + match result { + Ok(res) => { + let filename = str::from_utf8(&cid).unwrap(); + match File::create(filename) { + Ok(mut f) => f.write_all(&res).map_or_else( + |e| { + error!("ocall_read_ipfs failed writing to file. {}", e); + sgx_status_t::SGX_ERROR_UNEXPECTED + }, + |_| sgx_status_t::SGX_SUCCESS, + ), + Err(e) => { + error!("ocall_read_ipfs failed at creating file. {}", e); + sgx_status_t::SGX_ERROR_UNEXPECTED + } + } + } + Err(_) => sgx_status_t::SGX_ERROR_UNEXPECTED, + } } diff --git a/worker/src/main.rs b/worker/src/main.rs index fd1249e074..28e5658ec7 100644 --- a/worker/src/main.rs +++ b/worker/src/main.rs @@ -477,8 +477,14 @@ pub fn sync_chain_relay( let no_blocks_to_sync = head.block.header.number - last_synced_head.number; if no_blocks_to_sync > 1 { - println!("Chain Relay is synced until block: {:?}", last_synced_head.number); - println!("Last finalized block number: {:?}\n", head.block.header.number); + println!( + "Chain Relay is synced until block: {:?}", + last_synced_head.number + ); + println!( + "Last finalized block number: {:?}\n", + head.block.header.number + ); } while head.block.header.parent_hash != last_synced_head.hash() { @@ -488,7 +494,10 @@ pub fn sync_chain_relay( blocks_to_sync.push(head.clone()); if head.block.header.number % 100 == 0 { - println!("Remaining blocks to fetch until last synced header: {:?}", head.block.header.number - last_synced_head.number) + println!( + "Remaining blocks to fetch until last synced header: {:?}", + head.block.header.number - last_synced_head.number + ) } } blocks_to_sync.reverse(); @@ -514,7 +523,11 @@ pub fn sync_chain_relay( } i += chunk.len(); - println!("Synced {} blocks out of {} finalized blocks", i , blocks_to_sync[0].block.header.number as usize + blocks_to_sync.len()) + println!( + "Synced {} blocks out of {} finalized blocks", + i, + blocks_to_sync[0].block.header.number as usize + blocks_to_sync.len() + ) } curr_head.block.header diff --git a/worker/worker-api/src/lib.rs b/worker/worker-api/src/lib.rs index b622438f6a..92ec04a4d0 100644 --- a/worker/worker-api/src/lib.rs +++ b/worker/worker-api/src/lib.rs @@ -38,9 +38,7 @@ pub struct Api { impl Api { pub fn new(url: String) -> Api { - Api { - url, - } + Api { url } } pub fn get_mu_ra_port(&self) -> Result {