From 843bc0bebbc3ef2d8655a8282880ca0a66256fae Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:53:10 +0100 Subject: [PATCH 001/115] merge improved deposit contract with integration tests --- Cargo.toml | 5 +- contracts/Cargo.lock | 1650 +++++++++++++++++ contracts/Cargo.toml | 16 + contracts/README.md | 112 ++ contracts/contract-types/Cargo.toml | 8 + contracts/contract-types/src/lib.rs | 15 + contracts/deposit-contract-tests/.env | 1 + contracts/deposit-contract-tests/Cargo.toml | 21 + .../rust-toolchain.toml | 2 + .../src/integration_tests.rs | 70 + .../src/test_fixture.rs | 244 +++ .../src/test_fixture/utils.rs | 47 + contracts/deposit-contracts/Cargo.lock | 829 +++++++++ contracts/deposit-contracts/Cargo.toml | 15 + .../deposit-contracts/build-contracts.sh | 17 + .../contract/.cargo/config.toml | 2 + .../deposit-contracts/contract/Cargo.toml | 26 + .../contract/src/constants.rs | 15 + .../deposit-contracts/contract/src/detail.rs | 110 ++ .../contract/src/entry_points.rs | 69 + .../deposit-contracts/contract/src/error.rs | 21 + .../deposit-contracts/contract/src/main.rs | 216 +++ .../contract/src/security.rs | 80 + .../deposit-session/Cargo.toml | 19 + .../deposit-session/src/main.rs | 24 + .../malicious-reader/Cargo.toml | 17 + .../malicious-reader/src/main.rs | 12 + .../malicious-session/Cargo.toml | 17 + .../malicious-session/src/main.rs | 15 + contracts/deposit-contracts/readme.md | 0 .../deposit-contracts/rust-toolchain.toml | 2 + .../withdrawal-session/Cargo.toml | 17 + .../withdrawal-session/src/main.rs | 19 + 33 files changed, 3732 insertions(+), 1 deletion(-) create mode 100644 contracts/Cargo.lock create mode 100644 contracts/Cargo.toml create mode 100644 contracts/README.md create mode 100644 contracts/contract-types/Cargo.toml create mode 100644 contracts/contract-types/src/lib.rs create mode 100644 contracts/deposit-contract-tests/.env create mode 100644 contracts/deposit-contract-tests/Cargo.toml create mode 100644 contracts/deposit-contract-tests/rust-toolchain.toml create mode 100644 contracts/deposit-contract-tests/src/integration_tests.rs create mode 100644 contracts/deposit-contract-tests/src/test_fixture.rs create mode 100644 contracts/deposit-contract-tests/src/test_fixture/utils.rs create mode 100644 contracts/deposit-contracts/Cargo.lock create mode 100644 contracts/deposit-contracts/Cargo.toml create mode 100755 contracts/deposit-contracts/build-contracts.sh create mode 100644 contracts/deposit-contracts/contract/.cargo/config.toml create mode 100644 contracts/deposit-contracts/contract/Cargo.toml create mode 100644 contracts/deposit-contracts/contract/src/constants.rs create mode 100644 contracts/deposit-contracts/contract/src/detail.rs create mode 100644 contracts/deposit-contracts/contract/src/entry_points.rs create mode 100644 contracts/deposit-contracts/contract/src/error.rs create mode 100644 contracts/deposit-contracts/contract/src/main.rs create mode 100644 contracts/deposit-contracts/contract/src/security.rs create mode 100644 contracts/deposit-contracts/deposit-session/Cargo.toml create mode 100644 contracts/deposit-contracts/deposit-session/src/main.rs create mode 100644 contracts/deposit-contracts/malicious-reader/Cargo.toml create mode 100644 contracts/deposit-contracts/malicious-reader/src/main.rs create mode 100644 contracts/deposit-contracts/malicious-session/Cargo.toml create mode 100644 contracts/deposit-contracts/malicious-session/src/main.rs create mode 100644 contracts/deposit-contracts/readme.md create mode 100644 contracts/deposit-contracts/rust-toolchain.toml create mode 100644 contracts/deposit-contracts/withdrawal-session/Cargo.toml create mode 100644 contracts/deposit-contracts/withdrawal-session/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index c0942185..1edeb3d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,12 @@ members = [ "kairos-tx", ] +exclude = [ + "contracts" +] + [workspace.package] name = "kairos" version = "0.1.0" edition = "2021" license = "MIT OR Apache-2.0" - diff --git a/contracts/Cargo.lock b/contracts/Cargo.lock new file mode 100644 index 00000000..f278185f --- /dev/null +++ b/contracts/Cargo.lock @@ -0,0 +1,1650 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base16" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27c3610c36aee21ce8ac510e6224498de4228ad772a171ed65643a24693a5a8" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "blake2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +dependencies = [ + "crypto-mac", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "casper-contract" +version = "4.0.0" +source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +dependencies = [ + "casper-types", + "hex_fmt", +] + +[[package]] +name = "casper-engine-test-support" +version = "7.0.1" +source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +dependencies = [ + "casper-execution-engine", + "casper-hashing", + "casper-types", + "filesize", + "humantime", + "lmdb-rkv", + "log", + "num-rational", + "num-traits", + "once_cell", + "rand", + "serde", + "tempfile", + "toml", +] + +[[package]] +name = "casper-execution-engine" +version = "7.0.1" +source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +dependencies = [ + "anyhow", + "base16", + "bincode", + "casper-hashing", + "casper-types", + "casper-wasm", + "casper-wasm-utils", + "casper-wasmi", + "datasize", + "either", + "hex-buffer-serde 0.2.2", + "hex_fmt", + "hostname", + "humantime", + "itertools", + "libc", + "linked-hash-map", + "lmdb-rkv", + "log", + "num", + "num-derive", + "num-rational", + "num-traits", + "num_cpus", + "once_cell", + "proptest", + "rand", + "rand_chacha", + "schemars", + "serde", + "serde_bytes", + "serde_json", + "strum", + "thiserror", + "tracing", + "uint", + "uuid", +] + +[[package]] +name = "casper-hashing" +version = "3.0.0" +source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +dependencies = [ + "base16", + "blake2", + "casper-types", + "datasize", + "hex", + "hex-buffer-serde 0.3.0", + "hex_fmt", + "itertools", + "once_cell", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "casper-types" +version = "4.0.1" +source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +dependencies = [ + "base16", + "base64 0.13.1", + "bitflags 1.3.2", + "blake2", + "datasize", + "derp", + "ed25519-dalek", + "getrandom", + "hex", + "hex_fmt", + "humantime", + "k256", + "num", + "num-derive", + "num-integer", + "num-rational", + "num-traits", + "once_cell", + "pem", + "proptest", + "proptest-derive", + "rand", + "rand_pcg", + "schemars", + "serde", + "serde_bytes", + "serde_json", + "strum", + "thiserror", + "uint", + "untrusted", +] + +[[package]] +name = "casper-wasm" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f53c4e789fbff66ead0ea44030b1af2fc3c465201973483528e479a9155f98" + +[[package]] +name = "casper-wasm-utils" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15d9f1a2269d52961812862f67d209ef29742d06b47634e2982a96e80d0fe2b4" +dependencies = [ + "byteorder", + "casper-wasm", + "log", +] + +[[package]] +name = "casper-wasmi" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8357f19a7fd98073d8fe8df60f1bef1e677b7c623c1e6e2e07d2f8e59ceb87fc" +dependencies = [ + "casper-wasm", + "casper-wasmi-core", + "casper-wasmi-validation", +] + +[[package]] +name = "casper-wasmi-core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60089625560924f184cf91d59b0731373d5114b81224f1201c6a39ccc1d8388c" +dependencies = [ + "downcast-rs", + "libm", + "memory_units", + "num-rational", + "num-traits", +] + +[[package]] +name = "casper-wasmi-validation" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f669d385132ce321a57fdf453588d69c01654e75991bee3d22392a3aaaad80bb" +dependencies = [ + "casper-wasm", +] + +[[package]] +name = "cc" +version = "1.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "contract-types" +version = "0.1.0" +dependencies = [ + "casper-types", + "serde", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 2.0.55", +] + +[[package]] +name = "datasize" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e65c07d59e45d77a8bda53458c24a828893a99ac6cdd9c84111e09176ab739a2" +dependencies = [ + "datasize_derive", +] + +[[package]] +name = "datasize_derive" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613e4ee15899913285b7612004bbd490abd605be7b11d35afada5902fb6b91d5" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 1.0.109", +] + +[[package]] +name = "deposit-contract-tests" +version = "0.1.0" +dependencies = [ + "base64 0.21.7", + "casper-contract", + "casper-engine-test-support", + "casper-execution-engine", + "casper-types", + "dotenv", + "lazy_static", +] + +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derp" +version = "0.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9b84cfd9b6fa437e498215e5625e9e3ae3bf9bb54d623028a181c40820db169" +dependencies = [ + "untrusted", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek", + "ed25519", + "serde", + "sha2", + "subtle", + "zeroize", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" + +[[package]] +name = "filesize" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43" +dependencies = [ + "winapi", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] + +[[package]] +name = "hex-buffer-serde" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310e9578ff64e65a3a18e0624609f6833ee4a20503ef38eebb48430cf8ac3ab8" +dependencies = [ + "hex", + "serde", +] + +[[package]] +name = "hex-buffer-serde" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f52012c160668b4494727f3588045aa00429849fcae51de70d68fa98228039" +dependencies = [ + "hex", + "serde", +] + +[[package]] +name = "hex_fmt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "lmdb-rkv" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "libc", + "lmdb-rkv-sys", +] + +[[package]] +name = "lmdb-rkv-sys" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61b9ce6b3be08acefa3003c57b7565377432a89ec24476bbe72e11d101f852fe" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "serde", + "value-bag", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 1.0.109", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "pem" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" +dependencies = [ + "base64 0.13.1", + "once_cell", + "regex", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "platforms" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags 2.5.0", + "lazy_static", + "num-traits", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "proptest-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90b46295382dc76166cb7cf2bb4a97952464e4b7ed5a43e6cd34e1fec3349ddc" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2 1.0.79", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "schemars" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b82485a532ef0af18878ad4281f73e58161cdba1db7918176e9294f0ca5498a5" +dependencies = [ + "dyn-clone", + "indexmap 1.9.3", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791c2c848cff1abaeae34fef7e70da5f93171d9eea81ce0fe969a1df627a61a8" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "serde_derive_internals", + "syn 1.0.109", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 2.0.55", +] + +[[package]] +name = "serde_derive_internals" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +dependencies = [ + "indexmap 2.2.6", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2 1.0.79", + "quote 1.0.35", + "rustversion", + "syn 1.0.109", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 2.0.55", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 2.0.55", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + +[[package]] +name = "value-bag" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml new file mode 100644 index 00000000..e2c59ea9 --- /dev/null +++ b/contracts/Cargo.toml @@ -0,0 +1,16 @@ +[workspace] +resolver = "2" + +members = [ + "deposit-contract-tests", + "contract-types" +] + +exclude = [ + "deposit-contracts" +] + +[workspace.package] +name = "kairos-contract" +version = "0.1.0" +edition = "2021" diff --git a/contracts/README.md b/contracts/README.md new file mode 100644 index 00000000..9b9b67b8 --- /dev/null +++ b/contracts/README.md @@ -0,0 +1,112 @@ +# Kairos deposit contract +A deposit contract for the Kairos L2, targeting Casper Node v2.0 and VM v1.0 + +# Entry Points +Documentation of all contract entry points + +## Update Admin - ADMIN +Updates the admin account. Admin account is permitted to re-create the contract purse and to execute withdrawals. + +Arguments: + +- new_admin: Key + +Return: + +() + +## Create Purse - ADMIN +Create a new contract purse => overrides the value under the corresponding contract purse named_key + +Arguments: + +None + +Return: + +() + +## Get Purse +Retrieve a reference to the deposit purse with "ADD" permission + +Arguments: + +None + +Return: + +URef + +## Deposit +Execute a deposit on the L1. + +Arguments: + +- temp_purse: URef +- amount: U512 + +Return: + +() + +## Withdrawal - ADMIN +Withdrawal from the contract purse, can only be called by the admin. + +Arguments: + +- destination_purse: URef +- amount: U512 + +Return: + +() + +## Increment most recent Deposit Counter - ADMIN +This entry point is called by the L2 whenever a deposit request is routed through the L2 (not created through a native L1 call). This method updates the counter of the total deposits submitted through both L1 and L2. + +Arguments: + +None + +Return: + +() + +# User + + -> main_purse + + -> temp_purse + +1. Call the session code to transfer N tokens from main_purse to the freshly created temp_purse. + +2. The session code will then call the deposit entry point of the deposit contract and pass the temp_purse as a reference. + +3. All funds from the temp_purse will be transferred to the contract_purse that is managed by the ADMIN. + + +## Building and testing +Currently the paths in build-macos-darwin.sh are configured for Macos, nixifying this makes sense. Paths must be discoverable by utils.rs in the test engine. + +For now, on Macos: + +`./build-macos-darwin-feat-2.0.sh` + +or, on Ubuntu/Debian: + +`./build-ubuntu-feat-2.0.sh` + +next, set the environment variable that points to the compiled .wasm binaries (contracts and sessions): + +```bash +chef@chef:~/Kairos/kairos-cctl-env/kairos$ export PATH_TO_WASM_BINARIES="/home/chef/Kairos/kairos-cctl-env/kairos/kairos-deposit-contract/target/wasm32-unknown-unknown/release" +``` + +then: + +```bash +# navigate to the root +cd kairos +# run the contract-specific tests +cargo test -p kairos-deposit-contract-tests +``` diff --git a/contracts/contract-types/Cargo.toml b/contracts/contract-types/Cargo.toml new file mode 100644 index 00000000..e2464651 --- /dev/null +++ b/contracts/contract-types/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "contract-types" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = "1.0.197" +casper-types = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} \ No newline at end of file diff --git a/contracts/contract-types/src/lib.rs b/contracts/contract-types/src/lib.rs new file mode 100644 index 00000000..6fc50b1f --- /dev/null +++ b/contracts/contract-types/src/lib.rs @@ -0,0 +1,15 @@ +/* + The deposit contract requires a Casper-typed Deposit struct. + We can either keep this contract-types crate or move the deposit struct elsewhere. +*/ + +use casper_types::{Key, U512}; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +pub struct Deposit { + pub account: Key, + pub amount: U512, + pub timestamp: Option, + pub processed: bool, +} diff --git a/contracts/deposit-contract-tests/.env b/contracts/deposit-contract-tests/.env new file mode 100644 index 00000000..3151507b --- /dev/null +++ b/contracts/deposit-contract-tests/.env @@ -0,0 +1 @@ +PATH_TO_WASM_BINARIES="/Users/chef/Desktop/deposit/kairos/contracts/deposit-contracts/target/wasm32-unknown-unknown/release" diff --git a/contracts/deposit-contract-tests/Cargo.toml b/contracts/deposit-contract-tests/Cargo.toml new file mode 100644 index 00000000..7fe8d78e --- /dev/null +++ b/contracts/deposit-contract-tests/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "deposit-contract-tests" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dev-dependencies] +base64 = { version = "0.21.2", default-features = false, features = ["alloc"] } +casper-engine-test-support = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} +casper-execution-engine = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} +casper-contract = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} +casper-types = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} +dotenv = "0.15.0" + +[[test]] +name = "kairos_contract_tests" +path = "src/integration_tests.rs" + +[dependencies] +lazy_static = "1.4.0" diff --git a/contracts/deposit-contract-tests/rust-toolchain.toml b/contracts/deposit-contract-tests/rust-toolchain.toml new file mode 100644 index 00000000..292fe499 --- /dev/null +++ b/contracts/deposit-contract-tests/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "stable" diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/src/integration_tests.rs new file mode 100644 index 00000000..b04dd8e5 --- /dev/null +++ b/contracts/deposit-contract-tests/src/integration_tests.rs @@ -0,0 +1,70 @@ +mod test_fixture; +#[cfg(test)] +mod tests { + use crate::test_fixture::TestContext; + use casper_types::{account::AccountHash, U512}; + + #[test] + fn should_install() { + let mut fixture: TestContext = TestContext::new(); + fixture.install(fixture.account_1); + } + + fn setup() -> (TestContext, AccountHash) { + let fixture: TestContext = TestContext::new(); + let installer = fixture.account_1; + return (fixture, installer); + } + + #[test] + fn deposit_into_purse() { + let (mut fixture, installer) = setup(); + fixture.install(installer); + fixture.run_deposit_session(U512::from(100000000000u64), installer); + } + + #[test] + fn withdrawal_from_purse() { + let (mut fixture, installer) = setup(); + fixture.install(installer); + fixture.run_deposit_session(U512::from(100000000000u64), installer); + fixture.run_withdrawal_session(fixture.account_1, U512::from(100000000000u64), installer) + } + + // attack vector 1: session code attempts to empty purse + #[test] + fn run_malicious_session() { + let (mut fixture, installer) = setup(); + fixture.install(installer); + fixture.run_deposit_session(U512::from(100000000000u64), installer); + fixture.run_malicious_session(fixture.account_2, U512::from(100000000000u64), installer); + } + + // attack vector 2: smart contract access control + #[test] + fn run_malicious_contract() { + let (mut fixture, installer) = setup(); + fixture.install(installer); + fixture.run_deposit_session(U512::from(100000000000u64), installer); + fixture.run_malicious_withdrawal_session( + fixture.account_2, + U512::from(100000000000u64), + installer, + ); + } + + // attack vector 3: purse URef in contract named keys + #[test] + fn run_malicious_reader() { + let (mut fixture, installer) = setup(); + fixture.install(installer); + fixture.run_deposit_session(U512::from(100000000000u64), installer); + let deposit_purse_uref = fixture.get_contract_purse_uref(installer); + fixture.run_malicious_reader_session( + fixture.account_2, + U512::from(100000000000u64), + installer, + deposit_purse_uref, + ); + } +} diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs new file mode 100644 index 00000000..77d88f0c --- /dev/null +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -0,0 +1,244 @@ +mod utils; +use casper_engine_test_support::{ + ExecuteRequestBuilder, InMemoryWasmTestBuilder, DEFAULT_ACCOUNT_ADDR, + PRODUCTION_RUN_GENESIS_REQUEST, +}; +use casper_types::{ + account::AccountHash, contracts::NamedKeys, runtime_args, ContractHash, Key, RuntimeArgs, URef, + U512, +}; +use lazy_static::lazy_static; +use utils::create_funded_dummy_account; +extern crate dotenv; +use dotenv::dotenv; +use std::env; + +pub const ACCOUNT_USER_1: [u8; 32] = [1u8; 32]; +pub const ACCOUNT_USER_2: [u8; 32] = [2u8; 32]; +pub const ACCOUNT_USER_3: [u8; 32] = [3u8; 32]; + +// This defines a static variable for the path to WASM binaries +lazy_static! { + static ref PATH_TO_WASM_BINARIES: String = { + dotenv().ok(); // Load the .env file at runtime + env::var("PATH_TO_WASM_BINARIES").expect("Missing environment variable PATH_TO_WASM_BINARIES") + }; +} + +#[cfg(test)] +pub struct TestContext { + pub builder: InMemoryWasmTestBuilder, + pub account_1: AccountHash, + pub account_2: AccountHash, + pub account_3: AccountHash, +} + +impl TestContext { + pub fn new() -> TestContext { + let mut builder = InMemoryWasmTestBuilder::default(); + builder.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST); + let account_1 = create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_1)); + let account_2 = create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_2)); + let account_3 = create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_3)); + + TestContext { + builder, + account_1, + account_2, + account_3, + } + } + + pub fn named_keys(&self, account: AccountHash) -> NamedKeys { + self.builder + .get_expected_account(account) + .named_keys() + .clone() + } + + pub fn contract_named_keys( + &self, + contract_name: &str, + key_name: &str, + account: AccountHash, + ) -> Key { + let contract_hash = self.contract_hash_from_named_keys(contract_name, account); + *self + .builder + .get_contract(contract_hash) + .expect("should have contract") + .named_keys() + .get(key_name) + .unwrap() + } + + pub fn contract_hash_from_named_keys( + &self, + key_name: &str, + account: AccountHash, + ) -> ContractHash { + self.named_keys(account) + .get(key_name) + .expect("must have contract hash key as part of contract creation") + .into_hash() + .map(ContractHash::new) + .expect("must get contract hash") + } + + pub fn contract_hash(&self, name: &str, account: AccountHash) -> ContractHash { + self.builder + .get_expected_account(account) + .named_keys() + .get(name) + .expect("must have contract hash key as part of contract creation") + .into_hash() + .map(ContractHash::new) + .expect("must get contract hash") + } + + pub fn install(&mut self, admin: AccountHash) { + let session_args = runtime_args! {}; + let install_contract_request = ExecuteRequestBuilder::standard( + admin, + &format!( + "{}/{}", + *PATH_TO_WASM_BINARIES, "deposit-contract-optimized.wasm" + ), + session_args, + ) + .build(); + self.builder + .exec(install_contract_request) + .expect_success() + .commit(); + } + + pub fn get_contract_purse_uref(&self, account: AccountHash) -> URef { + let seed_uref: URef = *self + .contract_named_keys("kairos_deposit_contract", "kairos_deposit_purse", account) + .as_uref() + .unwrap(); + seed_uref + } + + #[allow(dead_code)] + pub fn get_contract_purse_balance(&self, account: AccountHash) -> U512 { + let seed_uref: URef = *self + .contract_named_keys("kairos_deposit_contract", "kairos_deposit_purse", account) + .as_uref() + .unwrap(); + let purse_balance = self.builder.get_purse_balance(seed_uref); + purse_balance + } + + pub fn run_deposit_session(&mut self, amount: U512, account: AccountHash) { + let session_args = runtime_args! { + "amount" => amount, + "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) + }; + let session_request = ExecuteRequestBuilder::standard( + *DEFAULT_ACCOUNT_ADDR, + &format!( + "{}/{}", + *PATH_TO_WASM_BINARIES, "deposit-session-optimized.wasm" + ), + session_args, + ) + .build(); + self.builder.exec(session_request).expect_success().commit(); + } + + pub fn run_malicious_session( + &mut self, + msg_sender: AccountHash, + amount: U512, + account: AccountHash, + ) { + /* + let contract_hash: AddressableEntityHash = + self.contract_hash("kairos_deposit_contract", account); + */ + let session_args = runtime_args! { + "amount" => amount, + "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) + }; + let session_request = ExecuteRequestBuilder::standard( + msg_sender, + &format!( + "{}/{}", + *PATH_TO_WASM_BINARIES, "malicious-session-optimized.wasm" + ), + session_args, + ) + .build(); + self.builder.exec(session_request).expect_failure().commit(); + } + + pub fn run_withdrawal_session( + &mut self, + msg_sender: AccountHash, + amount: U512, + account: AccountHash, + ) { + let session_args = runtime_args! { + "amount" => amount, + "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) + }; + let session_request = ExecuteRequestBuilder::standard( + msg_sender, + &format!( + "{}/{}", + *PATH_TO_WASM_BINARIES, "withdrawal-session-optimized.wasm" + ), + session_args, + ) + .build(); + self.builder.exec(session_request).expect_success().commit(); + } + + pub fn run_malicious_withdrawal_session( + &mut self, + msg_sender: AccountHash, + amount: U512, + account: AccountHash, + ) { + let session_args = runtime_args! { + "amount" => amount, + "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) + }; + let session_request = ExecuteRequestBuilder::standard( + msg_sender, + &format!( + "{}/{}", + *PATH_TO_WASM_BINARIES, "withdrawal-session-optimized.wasm" + ), + session_args, + ) + .build(); + self.builder.exec(session_request).expect_failure().commit(); + } + + pub fn run_malicious_reader_session( + &mut self, + msg_sender: AccountHash, + amount: U512, + account: AccountHash, + deposit_purse_uref: URef, + ) { + let session_args = runtime_args! { + "amount" => amount, + "deposit_contract" => self.contract_hash("kairos_deposit_contract", account), + "purse_uref" => deposit_purse_uref + }; + let session_request = ExecuteRequestBuilder::standard( + msg_sender, + &format!( + "{}/{}", + *PATH_TO_WASM_BINARIES, "malicious-reader-optimized.wasm" + ), + session_args, + ) + .build(); + self.builder.exec(session_request).expect_failure().commit(); + } +} diff --git a/contracts/deposit-contract-tests/src/test_fixture/utils.rs b/contracts/deposit-contract-tests/src/test_fixture/utils.rs new file mode 100644 index 00000000..c2467df9 --- /dev/null +++ b/contracts/deposit-contract-tests/src/test_fixture/utils.rs @@ -0,0 +1,47 @@ +use casper_engine_test_support::{ + ExecuteRequestBuilder, WasmTestBuilder, ARG_AMOUNT, DEFAULT_ACCOUNT_ADDR, + DEFAULT_ACCOUNT_INITIAL_BALANCE, +}; +use casper_execution_engine::storage::global_state::in_memory::InMemoryGlobalState; +use casper_types::{ + account::AccountHash, + runtime_args, + system::{handle_payment::ARG_TARGET, mint::ARG_ID}, + PublicKey, RuntimeArgs, SecretKey, +}; + +// Creates a dummy account and transfer funds to it +pub fn create_funded_dummy_account( + builder: &mut WasmTestBuilder, + account_string: Option<[u8; 32]>, +) -> AccountHash { + let (_, account_public_key) = + create_dummy_key_pair(if let Some(account_string) = account_string { + account_string + } else { + [7u8; 32] + }); + let account = account_public_key.to_account_hash(); + fund_account(builder, account); + account +} + +pub fn create_dummy_key_pair(account_string: [u8; 32]) -> (SecretKey, PublicKey) { + let secret_key = + SecretKey::ed25519_from_bytes(account_string).expect("failed to create secret key"); + let public_key = PublicKey::from(&secret_key); + (secret_key, public_key) +} + +pub fn fund_account(builder: &mut WasmTestBuilder, account: AccountHash) { + let transfer = ExecuteRequestBuilder::transfer( + *DEFAULT_ACCOUNT_ADDR, + runtime_args! { + ARG_AMOUNT => DEFAULT_ACCOUNT_INITIAL_BALANCE / 10_u64, + ARG_TARGET => account, + ARG_ID => Option::::None, + }, + ) + .build(); + builder.exec(transfer).expect_success().commit(); +} diff --git a/contracts/deposit-contracts/Cargo.lock b/contracts/deposit-contracts/Cargo.lock new file mode 100644 index 00000000..91e04d07 --- /dev/null +++ b/contracts/deposit-contracts/Cargo.lock @@ -0,0 +1,829 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base16" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27c3610c36aee21ce8ac510e6224498de4228ad772a171ed65643a24693a5a8" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "blake2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +dependencies = [ + "crypto-mac", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "casper-contract" +version = "4.0.0" +source = "git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0#441e517fb1ae0640e90a087ff275f9e599828556" +dependencies = [ + "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "hex_fmt", + "wee_alloc", +] + +[[package]] +name = "casper-contract" +version = "4.0.0" +source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +dependencies = [ + "casper-types 4.0.1 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", + "hex_fmt", + "wee_alloc", +] + +[[package]] +name = "casper-types" +version = "4.0.1" +source = "git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0#441e517fb1ae0640e90a087ff275f9e599828556" +dependencies = [ + "base16", + "base64 0.13.1", + "bitflags", + "blake2", + "ed25519-dalek", + "hex", + "hex_fmt", + "k256", + "num", + "num-derive", + "num-integer", + "num-rational", + "num-traits", + "rand", + "serde", + "serde_bytes", + "serde_json", + "uint", +] + +[[package]] +name = "casper-types" +version = "4.0.1" +source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +dependencies = [ + "base16", + "base64 0.13.1", + "bitflags", + "blake2", + "ed25519-dalek", + "hex", + "hex_fmt", + "k256", + "num", + "num-derive", + "num-integer", + "num-rational", + "num-traits", + "rand", + "serde", + "serde_bytes", + "serde_json", + "uint", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "contract" +version = "0.1.0" +dependencies = [ + "base64 0.20.0", + "bincode", + "casper-contract 4.0.0 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", + "casper-types 4.0.1 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", + "contract-types", +] + +[[package]] +name = "contract-types" +version = "0.1.0" +dependencies = [ + "casper-types 4.0.1 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", + "serde", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + +[[package]] +name = "deposit-session" +version = "0.1.0" +dependencies = [ + "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", +] + +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek", + "ed25519", + "serde", + "sha2", + "subtle", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex_fmt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if 1.0.0", + "ecdsa", + "elliptic-curve", + "sha2", +] + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "malicious-reader" +version = "0.1.0" +dependencies = [ + "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", +] + +[[package]] +name = "malicious-session" +version = "0.1.0" +dependencies = [ + "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", +] + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "platforms" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + +[[package]] +name = "serde_json" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "withdrawal-session" +version = "0.1.0" +dependencies = [ + "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", +] + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/contracts/deposit-contracts/Cargo.toml b/contracts/deposit-contracts/Cargo.toml new file mode 100644 index 00000000..bd2d0d4d --- /dev/null +++ b/contracts/deposit-contracts/Cargo.toml @@ -0,0 +1,15 @@ +[workspace] +resolver = "2" + +members = [ + "malicious-reader", + "malicious-session", + "withdrawal-session", + "deposit-session", + "contract" +] + +[workspace.package] +name = "deposit-contracts" +version = "0.1.0" +edition = "2021" \ No newline at end of file diff --git a/contracts/deposit-contracts/build-contracts.sh b/contracts/deposit-contracts/build-contracts.sh new file mode 100755 index 00000000..e0f003dd --- /dev/null +++ b/contracts/deposit-contracts/build-contracts.sh @@ -0,0 +1,17 @@ +#!/bin/bash +rustup target add wasm32-unknown-unknown + +cargo build -p contract --release --target wasm32-unknown-unknown +wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/deposit-contract.wasm -o ./target/wasm32-unknown-unknown/release/deposit-contract-optimized.wasm + +cargo build -p deposit-session --release --target wasm32-unknown-unknown +wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/deposit-session.wasm -o ./target/wasm32-unknown-unknown/release/deposit-session-optimized.wasm + +cargo build -p malicious-session --release --target wasm32-unknown-unknown +wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/malicious-session.wasm -o ./target/wasm32-unknown-unknown/release/malicious-session-optimized.wasm + +cargo build -p withdrawal-session --release --target wasm32-unknown-unknown +wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/withdrawal-session.wasm -o ./target/wasm32-unknown-unknown/release/withdrawal-session-optimized.wasm + +cargo build -p malicious-reader --release --target wasm32-unknown-unknown +wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/malicious-reader.wasm -o ./target/wasm32-unknown-unknown/release/malicious-reader-optimized.wasm diff --git a/contracts/deposit-contracts/contract/.cargo/config.toml b/contracts/deposit-contracts/contract/.cargo/config.toml new file mode 100644 index 00000000..f4e8c002 --- /dev/null +++ b/contracts/deposit-contracts/contract/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/contracts/deposit-contracts/contract/Cargo.toml b/contracts/deposit-contracts/contract/Cargo.toml new file mode 100644 index 00000000..843b084b --- /dev/null +++ b/contracts/deposit-contracts/contract/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "contract" +version = "0.1.0" +edition = "2021" + +[dependencies] +casper-contract = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", features=["std", "test-support"]} +casper-types = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} +base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } +contract-types = {path="../../contract-types"} +bincode = "1.3.3" + + +[build] +target = "wasm32-unknown-unknown" + +[[bin]] +name = "deposit-contract" +path = "src/main.rs" +bench = false +doctest = false +test = false + +[profile.release] +codegen-units = 1 +lto = true \ No newline at end of file diff --git a/contracts/deposit-contracts/contract/src/constants.rs b/contracts/deposit-contracts/contract/src/constants.rs new file mode 100644 index 00000000..5683a63e --- /dev/null +++ b/contracts/deposit-contracts/contract/src/constants.rs @@ -0,0 +1,15 @@ +pub const KAIROS_DEPOSIT_CONTRACT_NAME: &str = "kairos_deposit_contract"; +pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "deposit_contract_package"; +pub const KAIROS_DEPOSIT_CONTRACT: &str = "deposit_contract"; + +pub const KAIROS_DEPOSIT_EVENT_DICT: &str = "kairos_deposit_event_dict"; +pub const KAIROS_MOST_RECENT_DEPOSIT_COUNTER: &str = "most_recent_deposit_counter"; +pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_counter"; +pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; + +pub const RUNTIME_ARG_TEMP_PURSE: &str = "temp_purse"; +pub const RUNTIME_ARG_DEST_PURSE: &str = "destination_purse"; +pub const RUNTIME_ARG_AMOUNT: &str = "amount"; + +pub const SECURITY_BADGES: &str = "security_badges"; +pub const ADMIN_LIST: &str = "admin_list"; diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/contracts/deposit-contracts/contract/src/detail.rs new file mode 100644 index 00000000..00fa418b --- /dev/null +++ b/contracts/deposit-contracts/contract/src/detail.rs @@ -0,0 +1,110 @@ +/* + The utilities found in this file were scraped from other Casper contracts, + mainly cep-78 and cep-18. + This file is not necessarily due for review, unless breaking changes are suspected. +*/ + +use crate::error::DepositError; +use alloc::vec::Vec; +use casper_contract::{ + contract_api::{self, runtime}, + ext_ffi, + unwrap_or_revert::UnwrapOrRevert, +}; +use casper_types::{ + api_error, bytesrepr, bytesrepr::FromBytes, system::CallStackElement, ApiError, Key, URef, +}; +use core::convert::TryInto; + +fn call_stack_element_to_address(call_stack_element: CallStackElement) -> Key { + match call_stack_element { + CallStackElement::Session { account_hash } => Key::from(account_hash), + CallStackElement::StoredSession { account_hash, .. } => { + // Stored session code acts in account's context, so if stored session wants to interact + // with an CEP-18 token caller's address will be used. + Key::from(account_hash) + } + CallStackElement::StoredContract { + contract_package_hash, + .. + } => Key::from(contract_package_hash), + } +} + +/// Traverse the callstack +pub(crate) fn get_immediate_caller() -> Result { + let call_stack = runtime::get_call_stack(); + call_stack + .into_iter() + .rev() + .nth(1) + .map(call_stack_element_to_address) + .ok_or(DepositError::InvalidContext) +} + +/// Gets [`URef`] under a name. +pub(crate) fn get_uref(name: &str) -> URef { + let key = runtime::get_key(name) + .ok_or(ApiError::MissingKey) + .unwrap_or_revert(); + key.try_into().unwrap_or_revert() +} + +pub fn get_named_arg_size(name: &str) -> Option { + let mut arg_size: usize = 0; + let ret = unsafe { + ext_ffi::casper_get_named_arg_size( + name.as_bytes().as_ptr(), + name.len(), + &mut arg_size as *mut usize, + ) + }; + match api_error::result_from(ret) { + Ok(_) => Some(arg_size), + Err(ApiError::MissingArgument) => None, + Err(e) => runtime::revert(e), + } +} + +/// Optional named args are used for access control +pub fn get_optional_named_arg_with_user_errors( + name: &str, + invalid: DepositError, +) -> Option { + match get_named_arg_with_user_errors::(name, DepositError::Phantom, invalid) { + Ok(val) => Some(val), + Err(_) => None, + } +} + +/// Read optional arg and propagate errors +pub fn get_named_arg_with_user_errors( + name: &str, + missing: DepositError, + invalid: DepositError, +) -> Result { + let arg_size = get_named_arg_size(name).ok_or(missing)?; + let arg_bytes = if arg_size > 0 { + let res = { + let data_non_null_ptr = contract_api::alloc_bytes(arg_size); + let ret = unsafe { + ext_ffi::casper_get_named_arg( + name.as_bytes().as_ptr(), + name.len(), + data_non_null_ptr.as_ptr(), + arg_size, + ) + }; + let data = + unsafe { Vec::from_raw_parts(data_non_null_ptr.as_ptr(), arg_size, arg_size) }; + api_error::result_from(ret).map(|_| data) + }; + // Assumed to be safe as `get_named_arg_size` checks the argument already + res.unwrap_or_revert_with(DepositError::FailedToGetArgBytes) + } else { + // Avoids allocation with 0 bytes and a call to get_named_arg + Vec::new() + }; + + bytesrepr::deserialize(arg_bytes).map_err(|_| invalid) +} diff --git a/contracts/deposit-contracts/contract/src/entry_points.rs b/contracts/deposit-contracts/contract/src/entry_points.rs new file mode 100644 index 00000000..869b963f --- /dev/null +++ b/contracts/deposit-contracts/contract/src/entry_points.rs @@ -0,0 +1,69 @@ +use crate::constants::{RUNTIME_ARG_AMOUNT, RUNTIME_ARG_DEST_PURSE, RUNTIME_ARG_TEMP_PURSE}; +use alloc::vec; +use casper_types::{CLType, EntryPoint, EntryPointAccess, EntryPointType, Parameter}; + +pub fn init() -> EntryPoint { + EntryPoint::new( + "init", + vec![], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Contract, + ) +} + +pub fn get_purse() -> EntryPoint { + EntryPoint::new( + "get_purse", + vec![], + CLType::URef, + EntryPointAccess::Public, + EntryPointType::Contract, + ) +} + +pub fn deposit() -> EntryPoint { + EntryPoint::new( + "deposit", + vec![ + Parameter::new(RUNTIME_ARG_AMOUNT, CLType::U512), + Parameter::new(RUNTIME_ARG_TEMP_PURSE, CLType::URef), + ], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Contract, + ) +} + +pub fn withdrawal() -> EntryPoint { + EntryPoint::new( + "withdrawal", + vec![ + Parameter::new(RUNTIME_ARG_DEST_PURSE, CLType::URef), + Parameter::new(RUNTIME_ARG_AMOUNT, CLType::U512), + ], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Contract, + ) +} + +pub fn incr_last_processed_deposit_counter() -> EntryPoint { + EntryPoint::new( + "incr_last_processed_deposit_counter", + vec![], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Contract, + ) +} + +pub fn change_security() -> EntryPoint { + EntryPoint::new( + "change_security", + vec![], + CLType::Unit, + EntryPointAccess::Public, + EntryPointType::Contract, + ) +} diff --git a/contracts/deposit-contracts/contract/src/error.rs b/contracts/deposit-contracts/contract/src/error.rs new file mode 100644 index 00000000..992e5873 --- /dev/null +++ b/contracts/deposit-contracts/contract/src/error.rs @@ -0,0 +1,21 @@ +//! Error handling on the Casper platform. +use casper_types::ApiError; + +#[repr(u16)] +#[derive(Clone, Copy)] +pub enum DepositError { + InvalidContext = 0, + MissingKey = 1, + InvalidAdminList = 2, + InvalidNoneList = 3, + FailedToGetArgBytes = 4, + Phantom = 5, + InsufficientRights = 6, + AlreadyInitialized = 7, +} + +impl From for ApiError { + fn from(error: DepositError) -> Self { + ApiError::User(error as u16) + } +} diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs new file mode 100644 index 00000000..fd79a354 --- /dev/null +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -0,0 +1,216 @@ +#![no_std] +#![no_main] +extern crate alloc; +use alloc::{collections::BTreeMap, string::ToString, vec, vec::Vec}; +use casper_contract::{ + contract_api::{runtime, storage, system}, + unwrap_or_revert::UnwrapOrRevert, +}; +use casper_types::{ + bytesrepr::ToBytes, contracts::NamedKeys, runtime_args, AccessRights, ApiError, CLValue, + EntryPoints, Key, RuntimeArgs, URef, U512, +}; +mod constants; +use constants::{ + ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, + KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_EVENT_DICT, KAIROS_DEPOSIT_PURSE, + KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, KAIROS_MOST_RECENT_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, + RUNTIME_ARG_DEST_PURSE, RUNTIME_ARG_TEMP_PURSE, SECURITY_BADGES, +}; +mod detail; +use detail::{get_immediate_caller, get_optional_named_arg_with_user_errors}; +mod error; +use error::DepositError; +mod security; +use security::{sec_check, SecurityBadge}; +mod entry_points; + +use contract_types::Deposit; + +#[no_mangle] +pub extern "C" fn init() { + if runtime::get_key(KAIROS_DEPOSIT_PURSE).is_some() { + runtime::revert(DepositError::AlreadyInitialized); + } + let security_badges_dict = storage::new_dictionary(SECURITY_BADGES).unwrap_or_revert(); + storage::dictionary_put( + security_badges_dict, + &base64::encode( + Key::from(runtime::get_caller()) + .to_bytes() + .unwrap_or_revert(), + ), + SecurityBadge::Admin, + ); + let admin_list: Option> = + get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); + if let Some(admin_list) = admin_list { + for admin in admin_list { + storage::dictionary_put( + security_badges_dict, + &base64::encode(admin.to_bytes().unwrap_or_revert()), + SecurityBadge::Admin, + ); + } + }; + let new_deposit_purse: URef = system::create_purse(); + runtime::put_key(KAIROS_DEPOSIT_PURSE, new_deposit_purse.into()); +} + +#[no_mangle] +pub extern "C" fn get_purse() { + let deposit_purse: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) + .unwrap_or_revert_with(ApiError::MissingKey) + .into_uref() + .unwrap_or_revert(); + runtime::ret( + CLValue::from_t(deposit_purse.with_access_rights(AccessRights::ADD)).unwrap_or_revert(), + ); +} + +#[no_mangle] +pub extern "C" fn deposit() { + let temp_purse: URef = runtime::get_named_arg(RUNTIME_ARG_TEMP_PURSE); + let amount: U512 = runtime::get_named_arg(RUNTIME_ARG_AMOUNT); + let deposit_purse_uref: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) + .unwrap_or_revert_with(ApiError::MissingKey) + .into_uref() + .unwrap_or_revert_with(ApiError::UnexpectedKeyVariant); + system::transfer_from_purse_to_purse(temp_purse, deposit_purse_uref, amount, None) + .unwrap_or_revert(); + + let most_recent_deposit_counter_uref = runtime::get_key(KAIROS_MOST_RECENT_DEPOSIT_COUNTER) + .unwrap_or_revert_with(ApiError::MissingKey) + .into_uref() + .unwrap_or_revert(); + let mut most_recent_deposit_counter_value: u64 = + storage::read(most_recent_deposit_counter_uref) + .unwrap_or_revert() + .unwrap_or_revert(); + let new_deposit_record: Deposit = Deposit { + account: get_immediate_caller().unwrap_or_revert(), + amount, + timestamp: None, + processed: false, + }; + + let kairos_deposit_event_dict_uref = runtime::get_key(KAIROS_DEPOSIT_EVENT_DICT) + .unwrap_or_revert_with(ApiError::MissingKey) + .into_uref() + .unwrap_or_revert(); + storage::dictionary_put::>( + kairos_deposit_event_dict_uref, + &most_recent_deposit_counter_value.to_string(), + bincode::serialize(&new_deposit_record).unwrap(), + ); + + most_recent_deposit_counter_value += 1u64; + storage::write( + most_recent_deposit_counter_uref, + most_recent_deposit_counter_value, + ); +} + +#[no_mangle] +pub extern "C" fn incr_last_processed_deposit_counter() { + sec_check(vec![SecurityBadge::Admin]); + let last_processed_deposit_counter_uref = + runtime::get_key(KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER) + .unwrap_or_revert_with(ApiError::MissingKey) + .into_uref() + .unwrap_or_revert(); + let mut last_processed_deposit_counter_value: u64 = + storage::read(last_processed_deposit_counter_uref) + .unwrap_or_revert() + .unwrap_or_revert(); + last_processed_deposit_counter_value += 1u64; + storage::write( + last_processed_deposit_counter_uref, + last_processed_deposit_counter_value, + ); +} + +#[no_mangle] +pub extern "C" fn withdrawal() { + sec_check(vec![SecurityBadge::Admin]); + let destination_purse: URef = runtime::get_named_arg(RUNTIME_ARG_DEST_PURSE); + let amount: U512 = runtime::get_named_arg(RUNTIME_ARG_AMOUNT); + let deposit_purse: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) + .unwrap_or_revert_with(ApiError::MissingKey) + .into_uref() + .unwrap_or_revert() + .with_access_rights(AccessRights::READ_ADD_WRITE); + system::transfer_from_purse_to_purse(deposit_purse, destination_purse, amount, None) + .unwrap_or_revert(); +} + +#[no_mangle] +pub extern "C" fn change_security() { + sec_check(vec![SecurityBadge::Admin]); + let admin_list: Option> = + get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); + // construct a new admin list from runtime arg + let mut badge_map: BTreeMap = BTreeMap::new(); + if let Some(admin_list) = admin_list { + for account_key in admin_list { + badge_map.insert(account_key, SecurityBadge::Admin); + } + } + // remove the caller from the admin list + let caller = get_immediate_caller().unwrap_or_revert(); + badge_map.remove(&caller); + security::change_sec_badge(&badge_map); +} + +#[no_mangle] +pub extern "C" fn call() { + let caller = Key::from(runtime::get_caller()); + + let admin_list: Option> = + get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); + + let entry_points = { + let mut entry_points = EntryPoints::new(); + entry_points.add_entry_point(entry_points::init()); + entry_points.add_entry_point(entry_points::get_purse()); + entry_points.add_entry_point(entry_points::deposit()); + entry_points.add_entry_point(entry_points::withdrawal()); + entry_points.add_entry_point(entry_points::incr_last_processed_deposit_counter()); + entry_points.add_entry_point(entry_points::change_security()); + entry_points + }; + let mut named_keys = NamedKeys::new(); + let event_dict = storage::new_dictionary(KAIROS_DEPOSIT_EVENT_DICT).unwrap_or_revert(); + named_keys.insert(KAIROS_DEPOSIT_EVENT_DICT.to_string(), event_dict.into()); + let last_processed_deposit_counter = storage::new_uref(u64::from(0u8)); + + named_keys.insert( + KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER.to_string(), + last_processed_deposit_counter.into(), + ); + + let most_recent_deposit_counter = storage::new_uref(u64::from(0u8)); + named_keys.insert( + KAIROS_MOST_RECENT_DEPOSIT_COUNTER.to_string(), + most_recent_deposit_counter.into(), + ); + + let (contract_hash, _) = storage::new_contract( + entry_points, + Some(named_keys), + Some(KAIROS_DEPOSIT_CONTRACT.to_string()), + Some(KAIROS_DEPOSIT_CONTRACT_PACKAGE.to_string()), + ); + let contract_hash_key = Key::from(contract_hash); + runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); + + // runtime arguments for contract initialization + let mut init_args = runtime_args! {}; + if let Some(mut admin_list) = admin_list { + // for testing: add the caller to the admin list + admin_list.push(caller); + // prepare runtime arguments + init_args.insert(ADMIN_LIST, admin_list).unwrap_or_revert(); + } + runtime::call_contract::<()>(contract_hash, "init", init_args); +} diff --git a/contracts/deposit-contracts/contract/src/security.rs b/contracts/deposit-contracts/contract/src/security.rs new file mode 100644 index 00000000..e3b2f21e --- /dev/null +++ b/contracts/deposit-contracts/contract/src/security.rs @@ -0,0 +1,80 @@ +use alloc::{collections::BTreeMap, vec, vec::Vec}; + +use crate::{ + constants::SECURITY_BADGES, + detail::{get_immediate_caller, get_uref}, + error::DepositError, +}; +#[allow(unused_imports)] +use casper_contract::{ + contract_api::{ + self, + runtime::revert, + storage::{dictionary_get, dictionary_put}, + }, + ext_ffi, + unwrap_or_revert::UnwrapOrRevert, +}; +use casper_types::{ + bytesrepr::{self, FromBytes, ToBytes}, + CLTyped, Key, +}; + +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum SecurityBadge { + Admin = 0, +} + +impl CLTyped for SecurityBadge { + fn cl_type() -> casper_types::CLType { + casper_types::CLType::U8 + } +} + +impl ToBytes for SecurityBadge { + fn to_bytes(&self) -> Result, bytesrepr::Error> { + Ok(vec![*self as u8]) + } + + fn serialized_length(&self) -> usize { + 1 + } +} + +impl FromBytes for SecurityBadge { + fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> { + Ok(( + match bytes[0] { + 0 => SecurityBadge::Admin, + _ => return Err(bytesrepr::Error::LeftOverBytes), + }, + &[], + )) + } +} + +pub fn sec_check(allowed_badge_list: Vec) { + let caller = get_immediate_caller() + .unwrap_or_revert() + .to_bytes() + .unwrap_or_revert(); + if !allowed_badge_list.contains( + &dictionary_get::(get_uref(SECURITY_BADGES), &base64::encode(caller)) + .unwrap_or_revert() + .unwrap_or_revert_with(DepositError::InsufficientRights), + ) { + revert(DepositError::InsufficientRights) + } +} + +pub fn change_sec_badge(badge_map: &BTreeMap) { + let sec_uref = get_uref(SECURITY_BADGES); + for (&user, &badge) in badge_map { + dictionary_put( + sec_uref, + &base64::encode(user.to_bytes().unwrap_or_revert()), + badge, + ) + } +} diff --git a/contracts/deposit-contracts/deposit-session/Cargo.toml b/contracts/deposit-contracts/deposit-session/Cargo.toml new file mode 100644 index 00000000..4461a29f --- /dev/null +++ b/contracts/deposit-contracts/deposit-session/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "deposit-session" +version = "0.1.0" +edition = "2021" + +[dependencies] +casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0", features=["test-support"]} +casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} + +[[bin]] +name = "deposit-session" +path = "src/main.rs" +bench = false +doctest = false +test = false + +[profile.release] +codegen-units = 1 +lto = true \ No newline at end of file diff --git a/contracts/deposit-contracts/deposit-session/src/main.rs b/contracts/deposit-contracts/deposit-session/src/main.rs new file mode 100644 index 00000000..c74d1d68 --- /dev/null +++ b/contracts/deposit-contracts/deposit-session/src/main.rs @@ -0,0 +1,24 @@ +#![no_std] +#![no_main] +use casper_contract::contract_api::{account, runtime, system}; +use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; + +#[no_mangle] +pub extern "C" fn call() { + let contract_hash: ContractHash = runtime::get_named_arg("deposit_contract"); + let amount: U512 = runtime::get_named_arg("amount"); + let source: URef = account::get_main_purse(); + // create a temporary purse that can be passed to the deposit contract + let temp_purse: URef = system::create_purse(); + // fund the temporary purse + system::transfer_from_purse_to_purse(source, temp_purse, amount, None).unwrap(); + // call the deposit endpoint + runtime::call_contract::<()>( + contract_hash, + "deposit", + runtime_args! { + "temp_purse" => temp_purse, + "amount" => amount + }, + ); +} diff --git a/contracts/deposit-contracts/malicious-reader/Cargo.toml b/contracts/deposit-contracts/malicious-reader/Cargo.toml new file mode 100644 index 00000000..b2bff289 --- /dev/null +++ b/contracts/deposit-contracts/malicious-reader/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "malicious-reader" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} +casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} + +[[bin]] +name = "malicious-reader" +path = "src/main.rs" +bench = false +doctest = false +test = false \ No newline at end of file diff --git a/contracts/deposit-contracts/malicious-reader/src/main.rs b/contracts/deposit-contracts/malicious-reader/src/main.rs new file mode 100644 index 00000000..b9a22d72 --- /dev/null +++ b/contracts/deposit-contracts/malicious-reader/src/main.rs @@ -0,0 +1,12 @@ +#![no_std] +#![no_main] +use casper_contract::contract_api::{account, runtime, system}; +use casper_types::{RuntimeArgs, URef, U512}; + +#[no_mangle] +pub extern "C" fn call() { + let amount: U512 = runtime::get_named_arg("amount"); + let purse_uref: URef = runtime::get_named_arg("purse_uref"); + let destination_purse: URef = account::get_main_purse(); + system::transfer_from_purse_to_purse(purse_uref, destination_purse, amount, None).unwrap(); +} diff --git a/contracts/deposit-contracts/malicious-session/Cargo.toml b/contracts/deposit-contracts/malicious-session/Cargo.toml new file mode 100644 index 00000000..a96f6158 --- /dev/null +++ b/contracts/deposit-contracts/malicious-session/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "malicious-session" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} +casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} + +[[bin]] +name = "malicious-session" +path = "src/main.rs" +bench = false +doctest = false +test = false \ No newline at end of file diff --git a/contracts/deposit-contracts/malicious-session/src/main.rs b/contracts/deposit-contracts/malicious-session/src/main.rs new file mode 100644 index 00000000..38ba7146 --- /dev/null +++ b/contracts/deposit-contracts/malicious-session/src/main.rs @@ -0,0 +1,15 @@ +#![no_std] +#![no_main] +use casper_contract::contract_api::{account, runtime, system}; +use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; + +#[no_mangle] +pub extern "C" fn call() { + let contract_hash: ContractHash = runtime::get_named_arg("deposit_contract"); + let amount: U512 = runtime::get_named_arg("amount"); + let destination_purse: URef = account::get_main_purse(); + let borrowed_contract_purse: URef = + runtime::call_contract::(contract_hash, "get_purse", runtime_args! {}); + system::transfer_from_purse_to_purse(borrowed_contract_purse, destination_purse, amount, None) + .unwrap(); +} diff --git a/contracts/deposit-contracts/readme.md b/contracts/deposit-contracts/readme.md new file mode 100644 index 00000000..e69de29b diff --git a/contracts/deposit-contracts/rust-toolchain.toml b/contracts/deposit-contracts/rust-toolchain.toml new file mode 100644 index 00000000..860a7ce1 --- /dev/null +++ b/contracts/deposit-contracts/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2024-01-04" \ No newline at end of file diff --git a/contracts/deposit-contracts/withdrawal-session/Cargo.toml b/contracts/deposit-contracts/withdrawal-session/Cargo.toml new file mode 100644 index 00000000..8fb94f43 --- /dev/null +++ b/contracts/deposit-contracts/withdrawal-session/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "withdrawal-session" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} +casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} + +[[bin]] +name = "withdrawal-session" +path = "src/main.rs" +bench = false +doctest = false +test = false \ No newline at end of file diff --git a/contracts/deposit-contracts/withdrawal-session/src/main.rs b/contracts/deposit-contracts/withdrawal-session/src/main.rs new file mode 100644 index 00000000..a651d062 --- /dev/null +++ b/contracts/deposit-contracts/withdrawal-session/src/main.rs @@ -0,0 +1,19 @@ +#![no_std] +#![no_main] +use casper_contract::contract_api::{account, runtime}; +use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; + +#[no_mangle] +pub extern "C" fn call() { + let contract_hash: ContractHash = runtime::get_named_arg("deposit_contract"); + let amount: U512 = runtime::get_named_arg("amount"); + let destination_purse: URef = account::get_main_purse(); + runtime::call_contract::<()>( + contract_hash, + "withdrawal", + runtime_args! { + "destination_purse" => destination_purse, + "amount" => amount + }, + ); +} From 7e8625acc006b5c065e703400a25e3d79160a441 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:55:24 +0100 Subject: [PATCH 002/115] remove outdated readme, due for recreation --- contracts/README.md | 112 -------------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 contracts/README.md diff --git a/contracts/README.md b/contracts/README.md deleted file mode 100644 index 9b9b67b8..00000000 --- a/contracts/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# Kairos deposit contract -A deposit contract for the Kairos L2, targeting Casper Node v2.0 and VM v1.0 - -# Entry Points -Documentation of all contract entry points - -## Update Admin - ADMIN -Updates the admin account. Admin account is permitted to re-create the contract purse and to execute withdrawals. - -Arguments: - -- new_admin: Key - -Return: - -() - -## Create Purse - ADMIN -Create a new contract purse => overrides the value under the corresponding contract purse named_key - -Arguments: - -None - -Return: - -() - -## Get Purse -Retrieve a reference to the deposit purse with "ADD" permission - -Arguments: - -None - -Return: - -URef - -## Deposit -Execute a deposit on the L1. - -Arguments: - -- temp_purse: URef -- amount: U512 - -Return: - -() - -## Withdrawal - ADMIN -Withdrawal from the contract purse, can only be called by the admin. - -Arguments: - -- destination_purse: URef -- amount: U512 - -Return: - -() - -## Increment most recent Deposit Counter - ADMIN -This entry point is called by the L2 whenever a deposit request is routed through the L2 (not created through a native L1 call). This method updates the counter of the total deposits submitted through both L1 and L2. - -Arguments: - -None - -Return: - -() - -# User - - -> main_purse - - -> temp_purse - -1. Call the session code to transfer N tokens from main_purse to the freshly created temp_purse. - -2. The session code will then call the deposit entry point of the deposit contract and pass the temp_purse as a reference. - -3. All funds from the temp_purse will be transferred to the contract_purse that is managed by the ADMIN. - - -## Building and testing -Currently the paths in build-macos-darwin.sh are configured for Macos, nixifying this makes sense. Paths must be discoverable by utils.rs in the test engine. - -For now, on Macos: - -`./build-macos-darwin-feat-2.0.sh` - -or, on Ubuntu/Debian: - -`./build-ubuntu-feat-2.0.sh` - -next, set the environment variable that points to the compiled .wasm binaries (contracts and sessions): - -```bash -chef@chef:~/Kairos/kairos-cctl-env/kairos$ export PATH_TO_WASM_BINARIES="/home/chef/Kairos/kairos-cctl-env/kairos/kairos-deposit-contract/target/wasm32-unknown-unknown/release" -``` - -then: - -```bash -# navigate to the root -cd kairos -# run the contract-specific tests -cargo test -p kairos-deposit-contract-tests -``` From 533758283d1ffbf7fe1d3482180b727e1eec1e0a Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:04:09 +0100 Subject: [PATCH 003/115] bugfix: do not add the caller to the admin list --- contracts/deposit-contracts/contract/src/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs index fd79a354..d0d7f4c8 100644 --- a/contracts/deposit-contracts/contract/src/main.rs +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -207,8 +207,6 @@ pub extern "C" fn call() { // runtime arguments for contract initialization let mut init_args = runtime_args! {}; if let Some(mut admin_list) = admin_list { - // for testing: add the caller to the admin list - admin_list.push(caller); // prepare runtime arguments init_args.insert(ADMIN_LIST, admin_list).unwrap_or_revert(); } From c4530246ae29fbd6ca8fbb615df453c0d29a3073 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:21:42 +0100 Subject: [PATCH 004/115] dotenv -> dotenvy --- contracts/Cargo.lock | 8 ++++---- contracts/deposit-contract-tests/.env | 2 +- contracts/deposit-contract-tests/Cargo.toml | 2 +- contracts/deposit-contract-tests/src/test_fixture.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/Cargo.lock b/contracts/Cargo.lock index f278185f..d01d9df9 100644 --- a/contracts/Cargo.lock +++ b/contracts/Cargo.lock @@ -426,7 +426,7 @@ dependencies = [ "casper-engine-test-support", "casper-execution-engine", "casper-types", - "dotenv", + "dotenvy", "lazy_static", ] @@ -471,10 +471,10 @@ dependencies = [ ] [[package]] -name = "dotenv" -version = "0.15.0" +name = "dotenvy" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" [[package]] name = "downcast-rs" diff --git a/contracts/deposit-contract-tests/.env b/contracts/deposit-contract-tests/.env index 3151507b..c6e799ac 100644 --- a/contracts/deposit-contract-tests/.env +++ b/contracts/deposit-contract-tests/.env @@ -1 +1 @@ -PATH_TO_WASM_BINARIES="/Users/chef/Desktop/deposit/kairos/contracts/deposit-contracts/target/wasm32-unknown-unknown/release" +PATH_TO_WASM_BINARIES="/Users/chef/Desktop/kairos/contracts/deposit-contracts/target/wasm32-unknown-unknown/release" diff --git a/contracts/deposit-contract-tests/Cargo.toml b/contracts/deposit-contract-tests/Cargo.toml index 7fe8d78e..aee50159 100644 --- a/contracts/deposit-contract-tests/Cargo.toml +++ b/contracts/deposit-contract-tests/Cargo.toml @@ -11,7 +11,7 @@ casper-engine-test-support = {git = "https://github.com/casper-network/casper-no casper-execution-engine = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} casper-contract = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} casper-types = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} -dotenv = "0.15.0" +dotenvy = "0.15.7" [[test]] name = "kairos_contract_tests" diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index 77d88f0c..00aeb408 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -9,8 +9,8 @@ use casper_types::{ }; use lazy_static::lazy_static; use utils::create_funded_dummy_account; -extern crate dotenv; -use dotenv::dotenv; +extern crate dotenvy; +use dotenvy::dotenv; use std::env; pub const ACCOUNT_USER_1: [u8; 32] = [1u8; 32]; From 59d2d41f127145e75a8c7640aa90046d7672501f Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:51:03 +0100 Subject: [PATCH 005/115] casper deps from crates.io --- contracts/Cargo.lock | 15 +++-- contracts/Cargo.toml | 1 + contracts/contract-types/Cargo.toml | 2 +- contracts/deposit-contract-tests/Cargo.toml | 10 +-- contracts/deposit-contracts/Cargo.lock | 65 +++++-------------- .../deposit-contracts/contract/Cargo.toml | 4 +- .../deposit-session/Cargo.toml | 4 +- .../malicious-reader/Cargo.toml | 4 +- .../malicious-session/Cargo.toml | 4 +- .../withdrawal-session/Cargo.toml | 4 +- 10 files changed, 43 insertions(+), 70 deletions(-) diff --git a/contracts/Cargo.lock b/contracts/Cargo.lock index d01d9df9..1968bf6b 100644 --- a/contracts/Cargo.lock +++ b/contracts/Cargo.lock @@ -118,7 +118,8 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "casper-contract" version = "4.0.0" -source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" dependencies = [ "casper-types", "hex_fmt", @@ -127,7 +128,8 @@ dependencies = [ [[package]] name = "casper-engine-test-support" version = "7.0.1" -source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7967f1032f17243fbc9df3e4a8591dba169676adb3262b53dab4bb98f37d3c01" dependencies = [ "casper-execution-engine", "casper-hashing", @@ -148,7 +150,8 @@ dependencies = [ [[package]] name = "casper-execution-engine" version = "7.0.1" -source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e4b48df024b3424cc994c60403472f66ca0961bffb25800f66318bb66c80611" dependencies = [ "anyhow", "base16", @@ -192,7 +195,8 @@ dependencies = [ [[package]] name = "casper-hashing" version = "3.0.0" -source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c29b63e179d67da0c6b32c1b84bad5480f5f4bfd1b2d7f88390c85f92e87ae0" dependencies = [ "base16", "blake2", @@ -211,7 +215,8 @@ dependencies = [ [[package]] name = "casper-types" version = "4.0.1" -source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" dependencies = [ "base16", "base64 0.13.1", diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index e2c59ea9..e61863d1 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -14,3 +14,4 @@ exclude = [ name = "kairos-contract" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" \ No newline at end of file diff --git a/contracts/contract-types/Cargo.toml b/contracts/contract-types/Cargo.toml index e2464651..f64dd361 100644 --- a/contracts/contract-types/Cargo.toml +++ b/contracts/contract-types/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" [dependencies] serde = "1.0.197" -casper-types = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} \ No newline at end of file +casper-types = {version="4.0.0", default-features=false} \ No newline at end of file diff --git a/contracts/deposit-contract-tests/Cargo.toml b/contracts/deposit-contract-tests/Cargo.toml index aee50159..4e049281 100644 --- a/contracts/deposit-contract-tests/Cargo.toml +++ b/contracts/deposit-contract-tests/Cargo.toml @@ -6,11 +6,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dev-dependencies] -base64 = { version = "0.21.2", default-features = false, features = ["alloc"] } -casper-engine-test-support = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} -casper-execution-engine = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} -casper-contract = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} -casper-types = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} +base64 = {version = "0.21.2", default-features = false, features = ["alloc"] } +casper-engine-test-support = {version="7.0.0", default-features=false} +casper-execution-engine = {version="7.0.0", default-features=false} +casper-contract = {version="4.0.0", default-features=false} +casper-types = {version="4.0.0", default-features=false} dotenvy = "0.15.7" [[test]] diff --git a/contracts/deposit-contracts/Cargo.lock b/contracts/deposit-contracts/Cargo.lock index 91e04d07..1052829b 100644 --- a/contracts/deposit-contracts/Cargo.lock +++ b/contracts/deposit-contracts/Cargo.lock @@ -82,19 +82,10 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "casper-contract" version = "4.0.0" -source = "git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0#441e517fb1ae0640e90a087ff275f9e599828556" -dependencies = [ - "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", - "hex_fmt", - "wee_alloc", -] - -[[package]] -name = "casper-contract" -version = "4.0.0" -source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" dependencies = [ - "casper-types 4.0.1 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", + "casper-types", "hex_fmt", "wee_alloc", ] @@ -102,32 +93,8 @@ dependencies = [ [[package]] name = "casper-types" version = "4.0.1" -source = "git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0#441e517fb1ae0640e90a087ff275f9e599828556" -dependencies = [ - "base16", - "base64 0.13.1", - "bitflags", - "blake2", - "ed25519-dalek", - "hex", - "hex_fmt", - "k256", - "num", - "num-derive", - "num-integer", - "num-rational", - "num-traits", - "rand", - "serde", - "serde_bytes", - "serde_json", - "uint", -] - -[[package]] -name = "casper-types" -version = "4.0.1" -source = "git+https://github.com/casper-network/casper-node?branch=release-1.5.6#9f3995853204a18f17de9c022233d22aa14b9c37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" dependencies = [ "base16", "base64 0.13.1", @@ -173,8 +140,8 @@ version = "0.1.0" dependencies = [ "base64 0.20.0", "bincode", - "casper-contract 4.0.0 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", - "casper-types 4.0.1 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", + "casper-contract", + "casper-types", "contract-types", ] @@ -182,7 +149,7 @@ dependencies = [ name = "contract-types" version = "0.1.0" dependencies = [ - "casper-types 4.0.1 (git+https://github.com/casper-network/casper-node?branch=release-1.5.6)", + "casper-types", "serde", ] @@ -265,8 +232,8 @@ dependencies = [ name = "deposit-session" version = "0.1.0" dependencies = [ - "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", - "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-contract", + "casper-types", ] [[package]] @@ -442,16 +409,16 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" name = "malicious-reader" version = "0.1.0" dependencies = [ - "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", - "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-contract", + "casper-types", ] [[package]] name = "malicious-session" version = "0.1.0" dependencies = [ - "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", - "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-contract", + "casper-types", ] [[package]] @@ -818,8 +785,8 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" name = "withdrawal-session" version = "0.1.0" dependencies = [ - "casper-contract 4.0.0 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", - "casper-types 4.0.1 (git+https://github.com/jonas089/casper-node?branch=kairos-1.5.6-risc0)", + "casper-contract", + "casper-types", ] [[package]] diff --git a/contracts/deposit-contracts/contract/Cargo.toml b/contracts/deposit-contracts/contract/Cargo.toml index 843b084b..51fb1eaf 100644 --- a/contracts/deposit-contracts/contract/Cargo.toml +++ b/contracts/deposit-contracts/contract/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -casper-contract = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", features=["std", "test-support"]} -casper-types = {git = "https://github.com/casper-network/casper-node", branch="release-1.5.6", default-features=false} +casper-contract = {version="4.0.0", features=["std", "test-support"]} +casper-types = {version="4.0.0", default-features=false} base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } contract-types = {path="../../contract-types"} bincode = "1.3.3" diff --git a/contracts/deposit-contracts/deposit-session/Cargo.toml b/contracts/deposit-contracts/deposit-session/Cargo.toml index 4461a29f..fd01df4f 100644 --- a/contracts/deposit-contracts/deposit-session/Cargo.toml +++ b/contracts/deposit-contracts/deposit-session/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0", features=["test-support"]} -casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} +casper-contract = {version="4.0.0", features=["test-support"]} +casper-types = "4.0.0" [[bin]] name = "deposit-session" diff --git a/contracts/deposit-contracts/malicious-reader/Cargo.toml b/contracts/deposit-contracts/malicious-reader/Cargo.toml index b2bff289..d35c4a84 100644 --- a/contracts/deposit-contracts/malicious-reader/Cargo.toml +++ b/contracts/deposit-contracts/malicious-reader/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} -casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} +casper-contract = "4.0.0" +casper-types = "4.0.0" [[bin]] name = "malicious-reader" diff --git a/contracts/deposit-contracts/malicious-session/Cargo.toml b/contracts/deposit-contracts/malicious-session/Cargo.toml index a96f6158..0c9836b6 100644 --- a/contracts/deposit-contracts/malicious-session/Cargo.toml +++ b/contracts/deposit-contracts/malicious-session/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} -casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} +casper-contract = "4.0.0" +casper-types = "4.0.0" [[bin]] name = "malicious-session" diff --git a/contracts/deposit-contracts/withdrawal-session/Cargo.toml b/contracts/deposit-contracts/withdrawal-session/Cargo.toml index 8fb94f43..9e4291a6 100644 --- a/contracts/deposit-contracts/withdrawal-session/Cargo.toml +++ b/contracts/deposit-contracts/withdrawal-session/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -casper-contract = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} -casper-types = {git = "https://github.com/jonas089/casper-node", branch="kairos-1.5.6-risc0"} +casper-contract = "4.0.0" +casper-types = "4.0.0" [[bin]] name = "withdrawal-session" From b625d1aa3a5fd993295aff5b7212e49ffc74dadf Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:52:41 +0100 Subject: [PATCH 006/115] Update contracts/deposit-contracts/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contracts/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/deposit-contracts/Cargo.toml b/contracts/deposit-contracts/Cargo.toml index bd2d0d4d..56400f99 100644 --- a/contracts/deposit-contracts/Cargo.toml +++ b/contracts/deposit-contracts/Cargo.toml @@ -12,4 +12,5 @@ members = [ [workspace.package] name = "deposit-contracts" version = "0.1.0" -edition = "2021" \ No newline at end of file +edition = "2021" +license = "MIT OR Apache-2.0" \ No newline at end of file From 7cd75596471a201a3ab9179d51700f3518639b7f Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:53:38 +0100 Subject: [PATCH 007/115] Update contracts/contract-types/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/contract-types/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/contract-types/Cargo.toml b/contracts/contract-types/Cargo.toml index f64dd361..27a159e6 100644 --- a/contracts/contract-types/Cargo.toml +++ b/contracts/contract-types/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -serde = "1.0.197" +serde = "1" casper-types = {version="4.0.0", default-features=false} \ No newline at end of file From ce530f62bf39cce31f24571e167c7a7fcd61d619 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:19:21 +0100 Subject: [PATCH 008/115] Update contracts/deposit-contracts/malicious-reader/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contracts/malicious-reader/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/deposit-contracts/malicious-reader/Cargo.toml b/contracts/deposit-contracts/malicious-reader/Cargo.toml index d35c4a84..1b5afcd5 100644 --- a/contracts/deposit-contracts/malicious-reader/Cargo.toml +++ b/contracts/deposit-contracts/malicious-reader/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "malicious-reader" -version = "0.1.0" -edition = "2021" +workspace.version = true +workspace.edition = true +workspace.license = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 1c83c185a6c071c9c38ec27225da7bea002ec344 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:19:48 +0100 Subject: [PATCH 009/115] Update contracts/deposit-contracts/withdrawal-session/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contracts/withdrawal-session/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/deposit-contracts/withdrawal-session/Cargo.toml b/contracts/deposit-contracts/withdrawal-session/Cargo.toml index 9e4291a6..b5a44ed1 100644 --- a/contracts/deposit-contracts/withdrawal-session/Cargo.toml +++ b/contracts/deposit-contracts/withdrawal-session/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "withdrawal-session" -version = "0.1.0" -edition = "2021" +workspace.version = true +workspace.edition = true +workspace.license = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 2acfaafad38594b47f3e407b289588619196be56 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:22:28 +0100 Subject: [PATCH 010/115] Update contracts/deposit-contracts/malicious-session/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contracts/malicious-session/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/deposit-contracts/malicious-session/Cargo.toml b/contracts/deposit-contracts/malicious-session/Cargo.toml index 0c9836b6..ebb6e387 100644 --- a/contracts/deposit-contracts/malicious-session/Cargo.toml +++ b/contracts/deposit-contracts/malicious-session/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "malicious-session" -version = "0.1.0" -edition = "2021" +workspace.version = true +workspace.edition = true +workspace.license = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From aeea7edcd8b821bfe8d0ec4b061142521dcef38c Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:23:36 +0100 Subject: [PATCH 011/115] Update contracts/deposit-contracts/deposit-session/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contracts/deposit-session/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/deposit-contracts/deposit-session/Cargo.toml b/contracts/deposit-contracts/deposit-session/Cargo.toml index fd01df4f..382793d4 100644 --- a/contracts/deposit-contracts/deposit-session/Cargo.toml +++ b/contracts/deposit-contracts/deposit-session/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "deposit-session" -version = "0.1.0" -edition = "2021" +workspace.version = true +workspace.edition = true +workspace.license = true [dependencies] casper-contract = {version="4.0.0", features=["test-support"]} From 13b946f24973e59739144a5ca564f076958b6c13 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:29:46 +0100 Subject: [PATCH 012/115] Update contracts/contract-types/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/contract-types/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/contract-types/Cargo.toml b/contracts/contract-types/Cargo.toml index 27a159e6..895da2bd 100644 --- a/contracts/contract-types/Cargo.toml +++ b/contracts/contract-types/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "contract-types" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true +license.workspace = true [dependencies] serde = "1" From 3e2423ce860042ecc2266ae8b371b5a1b09720ca Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:41:38 +0100 Subject: [PATCH 013/115] Update contracts/deposit-contract-tests/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contract-tests/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/deposit-contract-tests/Cargo.toml b/contracts/deposit-contract-tests/Cargo.toml index 4e049281..2aa3df63 100644 --- a/contracts/deposit-contract-tests/Cargo.toml +++ b/contracts/deposit-contract-tests/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "deposit-contract-tests" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true +license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 90a8c066cb2fe58cb9869600cd033fd90fc62264 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:43:30 +0100 Subject: [PATCH 014/115] Update contracts/deposit-contracts/contract/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contracts/contract/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/deposit-contracts/contract/Cargo.toml b/contracts/deposit-contracts/contract/Cargo.toml index 51fb1eaf..4b02cea2 100644 --- a/contracts/deposit-contracts/contract/Cargo.toml +++ b/contracts/deposit-contracts/contract/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "contract" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true +license.workspace = true [dependencies] casper-contract = {version="4.0.0", features=["std", "test-support"]} From a10d11e8372a6f73e3c689b02ba7a46547dd19b2 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:43:45 +0100 Subject: [PATCH 015/115] Update contracts/deposit-contract-tests/src/test_fixture.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contract-tests/src/test_fixture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index 00aeb408..de7ec090 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -69,7 +69,7 @@ impl TestContext { .expect("should have contract") .named_keys() .get(key_name) - .unwrap() + .expect("Key not found") } pub fn contract_hash_from_named_keys( From 50d36df95e90417d29b571fa718f0374fd5b6b3a Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:44:02 +0100 Subject: [PATCH 016/115] Update contracts/deposit-contract-tests/src/test_fixture.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contract-tests/src/test_fixture.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index de7ec090..2f2a04d4 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -154,10 +154,6 @@ impl TestContext { amount: U512, account: AccountHash, ) { - /* - let contract_hash: AddressableEntityHash = - self.contract_hash("kairos_deposit_contract", account); - */ let session_args = runtime_args! { "amount" => amount, "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) From 6e9a17b5e158b4d6f601d389978412692ecad488 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:44:49 +0100 Subject: [PATCH 017/115] Update contracts/deposit-contract-tests/src/test_fixture/utils.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marijan Petričević --- contracts/deposit-contract-tests/src/test_fixture/utils.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/contracts/deposit-contract-tests/src/test_fixture/utils.rs b/contracts/deposit-contract-tests/src/test_fixture/utils.rs index c2467df9..7f975152 100644 --- a/contracts/deposit-contract-tests/src/test_fixture/utils.rs +++ b/contracts/deposit-contract-tests/src/test_fixture/utils.rs @@ -16,11 +16,7 @@ pub fn create_funded_dummy_account( account_string: Option<[u8; 32]>, ) -> AccountHash { let (_, account_public_key) = - create_dummy_key_pair(if let Some(account_string) = account_string { - account_string - } else { - [7u8; 32] - }); + create_dummy_key_pair(account_string.unwrap_or([7u8; 32])) let account = account_public_key.to_account_hash(); fund_account(builder, account); account From 1899d7a714bfbfdab75bc96aa68889abfee6c89b Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:10:34 +0100 Subject: [PATCH 018/115] remove the withdrawal EP, add comments, explain malicious session code, explain security and change function names --- .../src/integration_tests.rs | 25 +-------- .../src/test_fixture.rs | 48 +--------------- contracts/deposit-contracts/Cargo.lock | 8 --- contracts/deposit-contracts/Cargo.toml | 1 - .../deposit-contracts/build-contracts.sh | 3 - .../deposit-contracts/contract/src/detail.rs | 17 +++++- .../contract/src/entry_points.rs | 13 ----- .../deposit-contracts/contract/src/main.rs | 55 +++++++++++-------- .../contract/src/security.rs | 6 +- .../deposit-session/Cargo.toml | 6 +- .../malicious-reader/Cargo.toml | 6 +- .../malicious-reader/src/main.rs | 6 ++ .../malicious-session/Cargo.toml | 6 +- .../malicious-session/src/main.rs | 6 ++ contracts/deposit-contracts/readme.md | 0 .../withdrawal-session/Cargo.toml | 18 ------ .../withdrawal-session/src/main.rs | 19 ------- 17 files changed, 74 insertions(+), 169 deletions(-) delete mode 100644 contracts/deposit-contracts/readme.md delete mode 100644 contracts/deposit-contracts/withdrawal-session/Cargo.toml delete mode 100644 contracts/deposit-contracts/withdrawal-session/src/main.rs diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/src/integration_tests.rs index b04dd8e5..d7b699a9 100644 --- a/contracts/deposit-contract-tests/src/integration_tests.rs +++ b/contracts/deposit-contract-tests/src/integration_tests.rs @@ -23,15 +23,7 @@ mod tests { fixture.run_deposit_session(U512::from(100000000000u64), installer); } - #[test] - fn withdrawal_from_purse() { - let (mut fixture, installer) = setup(); - fixture.install(installer); - fixture.run_deposit_session(U512::from(100000000000u64), installer); - fixture.run_withdrawal_session(fixture.account_1, U512::from(100000000000u64), installer) - } - - // attack vector 1: session code attempts to empty purse + // see malicious-session #[test] fn run_malicious_session() { let (mut fixture, installer) = setup(); @@ -40,20 +32,7 @@ mod tests { fixture.run_malicious_session(fixture.account_2, U512::from(100000000000u64), installer); } - // attack vector 2: smart contract access control - #[test] - fn run_malicious_contract() { - let (mut fixture, installer) = setup(); - fixture.install(installer); - fixture.run_deposit_session(U512::from(100000000000u64), installer); - fixture.run_malicious_withdrawal_session( - fixture.account_2, - U512::from(100000000000u64), - installer, - ); - } - - // attack vector 3: purse URef in contract named keys + // see malicious-reader #[test] fn run_malicious_reader() { let (mut fixture, installer) = setup(); diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index 2f2a04d4..f3b25932 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -20,7 +20,7 @@ pub const ACCOUNT_USER_3: [u8; 32] = [3u8; 32]; // This defines a static variable for the path to WASM binaries lazy_static! { static ref PATH_TO_WASM_BINARIES: String = { - dotenv().ok(); // Load the .env file at runtime + dotenv().ok(); env::var("PATH_TO_WASM_BINARIES").expect("Missing environment variable PATH_TO_WASM_BINARIES") }; } @@ -148,6 +148,7 @@ impl TestContext { self.builder.exec(session_request).expect_success().commit(); } + // see malicious-session pub fn run_malicious_session( &mut self, msg_sender: AccountHash, @@ -170,50 +171,7 @@ impl TestContext { self.builder.exec(session_request).expect_failure().commit(); } - pub fn run_withdrawal_session( - &mut self, - msg_sender: AccountHash, - amount: U512, - account: AccountHash, - ) { - let session_args = runtime_args! { - "amount" => amount, - "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) - }; - let session_request = ExecuteRequestBuilder::standard( - msg_sender, - &format!( - "{}/{}", - *PATH_TO_WASM_BINARIES, "withdrawal-session-optimized.wasm" - ), - session_args, - ) - .build(); - self.builder.exec(session_request).expect_success().commit(); - } - - pub fn run_malicious_withdrawal_session( - &mut self, - msg_sender: AccountHash, - amount: U512, - account: AccountHash, - ) { - let session_args = runtime_args! { - "amount" => amount, - "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) - }; - let session_request = ExecuteRequestBuilder::standard( - msg_sender, - &format!( - "{}/{}", - *PATH_TO_WASM_BINARIES, "withdrawal-session-optimized.wasm" - ), - session_args, - ) - .build(); - self.builder.exec(session_request).expect_failure().commit(); - } - + // see malicious-reader pub fn run_malicious_reader_session( &mut self, msg_sender: AccountHash, diff --git a/contracts/deposit-contracts/Cargo.lock b/contracts/deposit-contracts/Cargo.lock index 1052829b..2297b6aa 100644 --- a/contracts/deposit-contracts/Cargo.lock +++ b/contracts/deposit-contracts/Cargo.lock @@ -781,14 +781,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "withdrawal-session" -version = "0.1.0" -dependencies = [ - "casper-contract", - "casper-types", -] - [[package]] name = "zeroize" version = "1.7.0" diff --git a/contracts/deposit-contracts/Cargo.toml b/contracts/deposit-contracts/Cargo.toml index 56400f99..782e523e 100644 --- a/contracts/deposit-contracts/Cargo.toml +++ b/contracts/deposit-contracts/Cargo.toml @@ -4,7 +4,6 @@ resolver = "2" members = [ "malicious-reader", "malicious-session", - "withdrawal-session", "deposit-session", "contract" ] diff --git a/contracts/deposit-contracts/build-contracts.sh b/contracts/deposit-contracts/build-contracts.sh index e0f003dd..c73c4f95 100755 --- a/contracts/deposit-contracts/build-contracts.sh +++ b/contracts/deposit-contracts/build-contracts.sh @@ -10,8 +10,5 @@ wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/releas cargo build -p malicious-session --release --target wasm32-unknown-unknown wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/malicious-session.wasm -o ./target/wasm32-unknown-unknown/release/malicious-session-optimized.wasm -cargo build -p withdrawal-session --release --target wasm32-unknown-unknown -wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/withdrawal-session.wasm -o ./target/wasm32-unknown-unknown/release/withdrawal-session-optimized.wasm - cargo build -p malicious-reader --release --target wasm32-unknown-unknown wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/malicious-reader.wasm -o ./target/wasm32-unknown-unknown/release/malicious-reader-optimized.wasm diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/contracts/deposit-contracts/contract/src/detail.rs index 00fa418b..d84a4234 100644 --- a/contracts/deposit-contracts/contract/src/detail.rs +++ b/contracts/deposit-contracts/contract/src/detail.rs @@ -16,6 +16,7 @@ use casper_types::{ }; use core::convert::TryInto; +/// Wrap the immediate caller as a Key and return it fn call_stack_element_to_address(call_stack_element: CallStackElement) -> Key { match call_stack_element { CallStackElement::Session { account_hash } => Key::from(account_hash), @@ -31,7 +32,7 @@ fn call_stack_element_to_address(call_stack_element: CallStackElement) -> Key { } } -/// Traverse the callstack +/// Traverse the callstack to retrieve the n - 1 th element of the callstack pub(crate) fn get_immediate_caller() -> Result { let call_stack = runtime::get_call_stack(); call_stack @@ -77,7 +78,18 @@ pub fn get_optional_named_arg_with_user_errors( } } -/// Read optional arg and propagate errors +/// Read optional arg and propagate errors. +/// This is required because it should be possible to +/// install the deposit contract without passing a list of +/// admins. In such a case the default admin will be the installing +/// account. +/// +/// This function checks if the runtime argument size is greater than 0 +/// and if that is the case it gets parsed and returned. Should the parsing +/// fail or should the user not supply the argument at all, then an error is propagated. +/// +/// To install the contract without an admin list, one still needs to pass an empty admins +/// list as a runtime argument. Otherwise the missing error will be propagated. pub fn get_named_arg_with_user_errors( name: &str, missing: DepositError, @@ -105,6 +117,5 @@ pub fn get_named_arg_with_user_errors( // Avoids allocation with 0 bytes and a call to get_named_arg Vec::new() }; - bytesrepr::deserialize(arg_bytes).map_err(|_| invalid) } diff --git a/contracts/deposit-contracts/contract/src/entry_points.rs b/contracts/deposit-contracts/contract/src/entry_points.rs index 869b963f..ee23c1b7 100644 --- a/contracts/deposit-contracts/contract/src/entry_points.rs +++ b/contracts/deposit-contracts/contract/src/entry_points.rs @@ -35,19 +35,6 @@ pub fn deposit() -> EntryPoint { ) } -pub fn withdrawal() -> EntryPoint { - EntryPoint::new( - "withdrawal", - vec![ - Parameter::new(RUNTIME_ARG_DEST_PURSE, CLType::URef), - Parameter::new(RUNTIME_ARG_AMOUNT, CLType::U512), - ], - CLType::Unit, - EntryPointAccess::Public, - EntryPointType::Contract, - ) -} - pub fn incr_last_processed_deposit_counter() -> EntryPoint { EntryPoint::new( "incr_last_processed_deposit_counter", diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs index d0d7f4c8..12d2705b 100644 --- a/contracts/deposit-contracts/contract/src/main.rs +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -22,21 +22,30 @@ use detail::{get_immediate_caller, get_optional_named_arg_with_user_errors}; mod error; use error::DepositError; mod security; -use security::{sec_check, SecurityBadge}; +use security::{access_control_check, SecurityBadge}; mod entry_points; use contract_types::Deposit; +// This entry point is called once when the contract is installed +// and sets up the security badges with the installer as an admin or the +// optional list of admins that was passed to the installation session as a runtime argument. +// The contract purse will be created in contract context so that it is "owned" by the contract +// instead of the installing account. #[no_mangle] pub extern "C" fn init() { if runtime::get_key(KAIROS_DEPOSIT_PURSE).is_some() { runtime::revert(DepositError::AlreadyInitialized); } let security_badges_dict = storage::new_dictionary(SECURITY_BADGES).unwrap_or_revert(); + let installing_entity = runtime::get_caller(); + // Assign the admin role to the installer, regardless of the list of admins that was + // passed to the installation session. The installer is by default an admin and + // this admin access needs to be revoked after the initialization if it is not wanted. storage::dictionary_put( security_badges_dict, &base64::encode( - Key::from(runtime::get_caller()) + Key::from(installing_entity) .to_bytes() .unwrap_or_revert(), ), @@ -46,9 +55,10 @@ pub extern "C" fn init() { get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); if let Some(admin_list) = admin_list { for admin in admin_list { + let account_dictionary_key = admin.to_bytes().unwrap_or_revert(); storage::dictionary_put( security_badges_dict, - &base64::encode(admin.to_bytes().unwrap_or_revert()), + &base64::encode(account_dictionary_key), SecurityBadge::Admin, ); } @@ -63,11 +73,16 @@ pub extern "C" fn get_purse() { .unwrap_or_revert_with(ApiError::MissingKey) .into_uref() .unwrap_or_revert(); + let reference_to_deposit_purse_with_restricted_access = deposit_purse.with_access_rights(AccessRights::ADD); runtime::ret( - CLValue::from_t(deposit_purse.with_access_rights(AccessRights::ADD)).unwrap_or_revert(), + CLValue::from_t(reference_to_deposit_purse_with_restricted_access).unwrap_or_revert(), ); } +// Entry point called by a user through session code to deposit funds. +// Due to Casper < 2.0 purse management and access control, it is necessary that +// a temporary purse is funded and passed to the deposit contract since this is +// the only secure method of making a payment to a contract purse. #[no_mangle] pub extern "C" fn deposit() { let temp_purse: URef = runtime::get_named_arg(RUNTIME_ARG_TEMP_PURSE); @@ -111,9 +126,12 @@ pub extern "C" fn deposit() { ); } +// The centralized Kairos service, or a sequencer, +// will update the counter to keep track +// of the last processed deposit index on-chain. #[no_mangle] pub extern "C" fn incr_last_processed_deposit_counter() { - sec_check(vec![SecurityBadge::Admin]); + access_control_check(vec![SecurityBadge::Admin]); let last_processed_deposit_counter_uref = runtime::get_key(KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER) .unwrap_or_revert_with(ApiError::MissingKey) @@ -130,23 +148,12 @@ pub extern "C" fn incr_last_processed_deposit_counter() { ); } -#[no_mangle] -pub extern "C" fn withdrawal() { - sec_check(vec![SecurityBadge::Admin]); - let destination_purse: URef = runtime::get_named_arg(RUNTIME_ARG_DEST_PURSE); - let amount: U512 = runtime::get_named_arg(RUNTIME_ARG_AMOUNT); - let deposit_purse: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) - .unwrap_or_revert_with(ApiError::MissingKey) - .into_uref() - .unwrap_or_revert() - .with_access_rights(AccessRights::READ_ADD_WRITE); - system::transfer_from_purse_to_purse(deposit_purse, destination_purse, amount, None) - .unwrap_or_revert(); -} - +// Update the security badge for one or multiple accounts +// This entry point is used to assign and revoke rolse such +// as the "Admin" role. #[no_mangle] pub extern "C" fn change_security() { - sec_check(vec![SecurityBadge::Admin]); + access_control_check(vec![SecurityBadge::Admin]); let admin_list: Option> = get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); // construct a new admin list from runtime arg @@ -159,7 +166,7 @@ pub extern "C" fn change_security() { // remove the caller from the admin list let caller = get_immediate_caller().unwrap_or_revert(); badge_map.remove(&caller); - security::change_sec_badge(&badge_map); + security::update_security_badges(&badge_map); } #[no_mangle] @@ -174,7 +181,6 @@ pub extern "C" fn call() { entry_points.add_entry_point(entry_points::init()); entry_points.add_entry_point(entry_points::get_purse()); entry_points.add_entry_point(entry_points::deposit()); - entry_points.add_entry_point(entry_points::withdrawal()); entry_points.add_entry_point(entry_points::incr_last_processed_deposit_counter()); entry_points.add_entry_point(entry_points::change_security()); entry_points @@ -204,10 +210,11 @@ pub extern "C" fn call() { let contract_hash_key = Key::from(contract_hash); runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); - // runtime arguments for contract initialization + // prepare runtime arguments for contract initialization, + // propagating the list of admin accounts that was passed + // to the installation session let mut init_args = runtime_args! {}; if let Some(mut admin_list) = admin_list { - // prepare runtime arguments init_args.insert(ADMIN_LIST, admin_list).unwrap_or_revert(); } runtime::call_contract::<()>(contract_hash, "init", init_args); diff --git a/contracts/deposit-contracts/contract/src/security.rs b/contracts/deposit-contracts/contract/src/security.rs index e3b2f21e..1a4bca26 100644 --- a/contracts/deposit-contracts/contract/src/security.rs +++ b/contracts/deposit-contracts/contract/src/security.rs @@ -54,7 +54,7 @@ impl FromBytes for SecurityBadge { } } -pub fn sec_check(allowed_badge_list: Vec) { +pub fn access_control_check(allowed_badge_list: Vec) { let caller = get_immediate_caller() .unwrap_or_revert() .to_bytes() @@ -68,7 +68,7 @@ pub fn sec_check(allowed_badge_list: Vec) { } } -pub fn change_sec_badge(badge_map: &BTreeMap) { +pub fn update_security_badges(badge_map: &BTreeMap) { let sec_uref = get_uref(SECURITY_BADGES); for (&user, &badge) in badge_map { dictionary_put( @@ -77,4 +77,4 @@ pub fn change_sec_badge(badge_map: &BTreeMap) { badge, ) } -} +} \ No newline at end of file diff --git a/contracts/deposit-contracts/deposit-session/Cargo.toml b/contracts/deposit-contracts/deposit-session/Cargo.toml index 382793d4..ec36e204 100644 --- a/contracts/deposit-contracts/deposit-session/Cargo.toml +++ b/contracts/deposit-contracts/deposit-session/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "deposit-session" -workspace.version = true -workspace.edition = true -workspace.license = true +version.workspace = true +edition.workspace = true +license.workspace = true [dependencies] casper-contract = {version="4.0.0", features=["test-support"]} diff --git a/contracts/deposit-contracts/malicious-reader/Cargo.toml b/contracts/deposit-contracts/malicious-reader/Cargo.toml index 1b5afcd5..ef5ee9ae 100644 --- a/contracts/deposit-contracts/malicious-reader/Cargo.toml +++ b/contracts/deposit-contracts/malicious-reader/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "malicious-reader" -workspace.version = true -workspace.edition = true -workspace.license = true +version.workspace = true +edition.workspace = true +license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/contracts/deposit-contracts/malicious-reader/src/main.rs b/contracts/deposit-contracts/malicious-reader/src/main.rs index b9a22d72..e5a7b1a0 100644 --- a/contracts/deposit-contracts/malicious-reader/src/main.rs +++ b/contracts/deposit-contracts/malicious-reader/src/main.rs @@ -1,3 +1,9 @@ +/* + This session code emulates an attack where a user tries to transfer funds + out of the deposit contract's purse, by passing the deposit contract purse as a runtime argument + and calling transfer_from_purse_to_purse +*/ + #![no_std] #![no_main] use casper_contract::contract_api::{account, runtime, system}; diff --git a/contracts/deposit-contracts/malicious-session/Cargo.toml b/contracts/deposit-contracts/malicious-session/Cargo.toml index ebb6e387..e1f96116 100644 --- a/contracts/deposit-contracts/malicious-session/Cargo.toml +++ b/contracts/deposit-contracts/malicious-session/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "malicious-session" -workspace.version = true -workspace.edition = true -workspace.license = true +version.workspace = true +edition.workspace = true +license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/contracts/deposit-contracts/malicious-session/src/main.rs b/contracts/deposit-contracts/malicious-session/src/main.rs index 38ba7146..fdd1a461 100644 --- a/contracts/deposit-contracts/malicious-session/src/main.rs +++ b/contracts/deposit-contracts/malicious-session/src/main.rs @@ -1,3 +1,9 @@ +/* + This session code emulates an attack where a user tries to transfer funds + out of the deposit contract's purse, by querying the get_purse entry point + and calling transfer_from_purse_to_purse +*/ + #![no_std] #![no_main] use casper_contract::contract_api::{account, runtime, system}; diff --git a/contracts/deposit-contracts/readme.md b/contracts/deposit-contracts/readme.md deleted file mode 100644 index e69de29b..00000000 diff --git a/contracts/deposit-contracts/withdrawal-session/Cargo.toml b/contracts/deposit-contracts/withdrawal-session/Cargo.toml deleted file mode 100644 index b5a44ed1..00000000 --- a/contracts/deposit-contracts/withdrawal-session/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "withdrawal-session" -workspace.version = true -workspace.edition = true -workspace.license = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -casper-contract = "4.0.0" -casper-types = "4.0.0" - -[[bin]] -name = "withdrawal-session" -path = "src/main.rs" -bench = false -doctest = false -test = false \ No newline at end of file diff --git a/contracts/deposit-contracts/withdrawal-session/src/main.rs b/contracts/deposit-contracts/withdrawal-session/src/main.rs deleted file mode 100644 index a651d062..00000000 --- a/contracts/deposit-contracts/withdrawal-session/src/main.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![no_std] -#![no_main] -use casper_contract::contract_api::{account, runtime}; -use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; - -#[no_mangle] -pub extern "C" fn call() { - let contract_hash: ContractHash = runtime::get_named_arg("deposit_contract"); - let amount: U512 = runtime::get_named_arg("amount"); - let destination_purse: URef = account::get_main_purse(); - runtime::call_contract::<()>( - contract_hash, - "withdrawal", - runtime_args! { - "destination_purse" => destination_purse, - "amount" => amount - }, - ); -} From 3370111aeb6aad5dbbaec4cbdab257e68dfeea4a Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:40:09 +0100 Subject: [PATCH 019/115] add .env to gitignore for contract tests --- .gitignore | 1 + contracts/deposit-contract-tests/src/test_fixture/utils.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 37358052..30896c03 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ result target .tmp .nixos-test-history +contracts/deposit-contract-tests/.env \ No newline at end of file diff --git a/contracts/deposit-contract-tests/src/test_fixture/utils.rs b/contracts/deposit-contract-tests/src/test_fixture/utils.rs index 7f975152..bfe73866 100644 --- a/contracts/deposit-contract-tests/src/test_fixture/utils.rs +++ b/contracts/deposit-contract-tests/src/test_fixture/utils.rs @@ -16,7 +16,7 @@ pub fn create_funded_dummy_account( account_string: Option<[u8; 32]>, ) -> AccountHash { let (_, account_public_key) = - create_dummy_key_pair(account_string.unwrap_or([7u8; 32])) + create_dummy_key_pair(account_string.unwrap_or([7u8; 32])); let account = account_public_key.to_account_hash(); fund_account(builder, account); account From 14b709ca6fc50c7f345bbcf1ef94e724152421c3 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:40:45 +0100 Subject: [PATCH 020/115] remove .env --- contracts/deposit-contract-tests/.env | 1 - 1 file changed, 1 deletion(-) delete mode 100644 contracts/deposit-contract-tests/.env diff --git a/contracts/deposit-contract-tests/.env b/contracts/deposit-contract-tests/.env deleted file mode 100644 index c6e799ac..00000000 --- a/contracts/deposit-contract-tests/.env +++ /dev/null @@ -1 +0,0 @@ -PATH_TO_WASM_BINARIES="/Users/chef/Desktop/kairos/contracts/deposit-contracts/target/wasm32-unknown-unknown/release" From 4c90b4d0c50e71a105c1c5165e033c7ced6344b7 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:21:46 +0100 Subject: [PATCH 021/115] improved tests and expect rather than unwrap in session code --- .../src/integration_tests.rs | 31 ++++++++++++++----- .../src/test_fixture.rs | 17 ++++++---- .../src/test_fixture/utils.rs | 3 +- .../deposit-contracts/contract/src/detail.rs | 6 ++-- .../deposit-contracts/contract/src/main.rs | 17 +++++----- .../contract/src/security.rs | 2 +- .../deposit-session/src/main.rs | 8 +++-- .../malicious-reader/src/main.rs | 3 +- .../malicious-session/src/main.rs | 2 +- 9 files changed, 55 insertions(+), 34 deletions(-) diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/src/integration_tests.rs index d7b699a9..71b40f9f 100644 --- a/contracts/deposit-contract-tests/src/integration_tests.rs +++ b/contracts/deposit-contract-tests/src/integration_tests.rs @@ -10,34 +10,49 @@ mod tests { fixture.install(fixture.account_1); } - fn setup() -> (TestContext, AccountHash) { + fn setup() -> (TestContext, AccountHash, AccountHash) { let fixture: TestContext = TestContext::new(); let installer = fixture.account_1; - return (fixture, installer); + let user = fixture.account_2; + return (fixture, installer, user); } #[test] fn deposit_into_purse() { - let (mut fixture, installer) = setup(); + let DEPOSIT_AMOUNT: U512 = U512::from(100000000000u64); + let (mut fixture, installer, user) = setup(); fixture.install(installer); - fixture.run_deposit_session(U512::from(100000000000u64), installer); + + let user_purse_uref = fixture.get_account_purse_uref(user); + let user_balance_before = fixture.builder.get_purse_balance(user_purse_uref); + + let contract_balance_before = fixture.get_contract_purse_balance(installer); + assert_eq!(contract_balance_before, U512::zero()); + + fixture.run_deposit_session(DEPOSIT_AMOUNT, installer, user); + + let contract_balance_after = fixture.get_contract_purse_balance(installer); + assert_eq!(contract_balance_after, DEPOSIT_AMOUNT); + + let user_balance_after = fixture.builder.get_purse_balance(user_purse_uref); + assert_eq!(user_balance_after, U512::from(9999871666161540u64)); } // see malicious-session #[test] fn run_malicious_session() { - let (mut fixture, installer) = setup(); + let (mut fixture, installer, user) = setup(); fixture.install(installer); - fixture.run_deposit_session(U512::from(100000000000u64), installer); + fixture.run_deposit_session(U512::from(100000000000u64), installer, user); fixture.run_malicious_session(fixture.account_2, U512::from(100000000000u64), installer); } // see malicious-reader #[test] fn run_malicious_reader() { - let (mut fixture, installer) = setup(); + let (mut fixture, installer, user) = setup(); fixture.install(installer); - fixture.run_deposit_session(U512::from(100000000000u64), installer); + fixture.run_deposit_session(U512::from(100000000000u64), installer, user); let deposit_purse_uref = fixture.get_contract_purse_uref(installer); fixture.run_malicious_reader_session( fixture.account_2, diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index f3b25932..eccbbb78 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -21,7 +21,8 @@ pub const ACCOUNT_USER_3: [u8; 32] = [3u8; 32]; lazy_static! { static ref PATH_TO_WASM_BINARIES: String = { dotenv().ok(); - env::var("PATH_TO_WASM_BINARIES").expect("Missing environment variable PATH_TO_WASM_BINARIES") + env::var("PATH_TO_WASM_BINARIES") + .expect("Missing environment variable PATH_TO_WASM_BINARIES") }; } @@ -121,23 +122,27 @@ impl TestContext { seed_uref } + pub fn get_account_purse_uref(&self, account: AccountHash) -> URef { + self.builder.get_expected_account(account).main_purse() + } + #[allow(dead_code)] pub fn get_contract_purse_balance(&self, account: AccountHash) -> U512 { - let seed_uref: URef = *self + let contract_purse_uref: URef = *self .contract_named_keys("kairos_deposit_contract", "kairos_deposit_purse", account) .as_uref() .unwrap(); - let purse_balance = self.builder.get_purse_balance(seed_uref); + let purse_balance = self.builder.get_purse_balance(contract_purse_uref); purse_balance } - pub fn run_deposit_session(&mut self, amount: U512, account: AccountHash) { + pub fn run_deposit_session(&mut self, amount: U512, installer: AccountHash, user: AccountHash) { let session_args = runtime_args! { "amount" => amount, - "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) + "deposit_contract" => self.contract_hash("kairos_deposit_contract", installer) }; let session_request = ExecuteRequestBuilder::standard( - *DEFAULT_ACCOUNT_ADDR, + user, &format!( "{}/{}", *PATH_TO_WASM_BINARIES, "deposit-session-optimized.wasm" diff --git a/contracts/deposit-contract-tests/src/test_fixture/utils.rs b/contracts/deposit-contract-tests/src/test_fixture/utils.rs index bfe73866..fa24a3f4 100644 --- a/contracts/deposit-contract-tests/src/test_fixture/utils.rs +++ b/contracts/deposit-contract-tests/src/test_fixture/utils.rs @@ -15,8 +15,7 @@ pub fn create_funded_dummy_account( builder: &mut WasmTestBuilder, account_string: Option<[u8; 32]>, ) -> AccountHash { - let (_, account_public_key) = - create_dummy_key_pair(account_string.unwrap_or([7u8; 32])); + let (_, account_public_key) = create_dummy_key_pair(account_string.unwrap_or([7u8; 32])); let account = account_public_key.to_account_hash(); fund_account(builder, account); account diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/contracts/deposit-contracts/contract/src/detail.rs index d84a4234..d5c6bf3f 100644 --- a/contracts/deposit-contracts/contract/src/detail.rs +++ b/contracts/deposit-contracts/contract/src/detail.rs @@ -79,15 +79,15 @@ pub fn get_optional_named_arg_with_user_errors( } /// Read optional arg and propagate errors. -/// This is required because it should be possible to +/// This is required because it should be possible to /// install the deposit contract without passing a list of /// admins. In such a case the default admin will be the installing /// account. -/// +/// /// This function checks if the runtime argument size is greater than 0 /// and if that is the case it gets parsed and returned. Should the parsing /// fail or should the user not supply the argument at all, then an error is propagated. -/// +/// /// To install the contract without an admin list, one still needs to pass an empty admins /// list as a runtime argument. Otherwise the missing error will be propagated. pub fn get_named_arg_with_user_errors( diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs index 12d2705b..1322a3fe 100644 --- a/contracts/deposit-contracts/contract/src/main.rs +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -27,7 +27,7 @@ mod entry_points; use contract_types::Deposit; -// This entry point is called once when the contract is installed +// This entry point is called once when the contract is installed // and sets up the security badges with the installer as an admin or the // optional list of admins that was passed to the installation session as a runtime argument. // The contract purse will be created in contract context so that it is "owned" by the contract @@ -39,16 +39,12 @@ pub extern "C" fn init() { } let security_badges_dict = storage::new_dictionary(SECURITY_BADGES).unwrap_or_revert(); let installing_entity = runtime::get_caller(); - // Assign the admin role to the installer, regardless of the list of admins that was - // passed to the installation session. The installer is by default an admin and + // Assign the admin role to the installer, regardless of the list of admins that was + // passed to the installation session. The installer is by default an admin and // this admin access needs to be revoked after the initialization if it is not wanted. storage::dictionary_put( security_badges_dict, - &base64::encode( - Key::from(installing_entity) - .to_bytes() - .unwrap_or_revert(), - ), + &base64::encode(Key::from(installing_entity).to_bytes().unwrap_or_revert()), SecurityBadge::Admin, ); let admin_list: Option> = @@ -73,7 +69,8 @@ pub extern "C" fn get_purse() { .unwrap_or_revert_with(ApiError::MissingKey) .into_uref() .unwrap_or_revert(); - let reference_to_deposit_purse_with_restricted_access = deposit_purse.with_access_rights(AccessRights::ADD); + let reference_to_deposit_purse_with_restricted_access = + deposit_purse.with_access_rights(AccessRights::ADD); runtime::ret( CLValue::from_t(reference_to_deposit_purse_with_restricted_access).unwrap_or_revert(), ); @@ -127,7 +124,7 @@ pub extern "C" fn deposit() { } // The centralized Kairos service, or a sequencer, -// will update the counter to keep track +// will update the counter to keep track // of the last processed deposit index on-chain. #[no_mangle] pub extern "C" fn incr_last_processed_deposit_counter() { diff --git a/contracts/deposit-contracts/contract/src/security.rs b/contracts/deposit-contracts/contract/src/security.rs index 1a4bca26..88cd22a1 100644 --- a/contracts/deposit-contracts/contract/src/security.rs +++ b/contracts/deposit-contracts/contract/src/security.rs @@ -77,4 +77,4 @@ pub fn update_security_badges(badge_map: &BTreeMap) { badge, ) } -} \ No newline at end of file +} diff --git a/contracts/deposit-contracts/deposit-session/src/main.rs b/contracts/deposit-contracts/deposit-session/src/main.rs index c74d1d68..04140f74 100644 --- a/contracts/deposit-contracts/deposit-session/src/main.rs +++ b/contracts/deposit-contracts/deposit-session/src/main.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] use casper_contract::contract_api::{account, runtime, system}; -use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; +use casper_types::{runtime_args, ApiError, ContractHash, RuntimeArgs, URef, U512}; #[no_mangle] pub extern "C" fn call() { @@ -9,9 +9,13 @@ pub extern "C" fn call() { let amount: U512 = runtime::get_named_arg("amount"); let source: URef = account::get_main_purse(); // create a temporary purse that can be passed to the deposit contract + // this is required due to the access control model of the purse system used + // in casper_node 1.5.x + // this will likely be drastically changed in 2.0 let temp_purse: URef = system::create_purse(); // fund the temporary purse - system::transfer_from_purse_to_purse(source, temp_purse, amount, None).unwrap(); + system::transfer_from_purse_to_purse(source, temp_purse, amount, None) + .expect("Failed to transfer into temporary purse"); // call the deposit endpoint runtime::call_contract::<()>( contract_hash, diff --git a/contracts/deposit-contracts/malicious-reader/src/main.rs b/contracts/deposit-contracts/malicious-reader/src/main.rs index e5a7b1a0..4311c707 100644 --- a/contracts/deposit-contracts/malicious-reader/src/main.rs +++ b/contracts/deposit-contracts/malicious-reader/src/main.rs @@ -14,5 +14,6 @@ pub extern "C" fn call() { let amount: U512 = runtime::get_named_arg("amount"); let purse_uref: URef = runtime::get_named_arg("purse_uref"); let destination_purse: URef = account::get_main_purse(); - system::transfer_from_purse_to_purse(purse_uref, destination_purse, amount, None).unwrap(); + system::transfer_from_purse_to_purse(purse_uref, destination_purse, amount, None) + .expect("Failed to transfer from purse to purse"); } diff --git a/contracts/deposit-contracts/malicious-session/src/main.rs b/contracts/deposit-contracts/malicious-session/src/main.rs index fdd1a461..34e40fda 100644 --- a/contracts/deposit-contracts/malicious-session/src/main.rs +++ b/contracts/deposit-contracts/malicious-session/src/main.rs @@ -17,5 +17,5 @@ pub extern "C" fn call() { let borrowed_contract_purse: URef = runtime::call_contract::(contract_hash, "get_purse", runtime_args! {}); system::transfer_from_purse_to_purse(borrowed_contract_purse, destination_purse, amount, None) - .unwrap(); + .expect("Failed to transfer from purse to purse"); } From 7827f9e68bc28b5668a3bb5fa411ca375d943060 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:24:36 +0100 Subject: [PATCH 022/115] improve existing tests, add comments, add tests for access control / security badges, automatically remove the caller when updating the security badges -> this may change in the future --- Cargo.lock | 183 +++++++----------- .../src/integration_tests.rs | 18 +- .../src/test_fixture.rs | 47 +++++ .../deposit-contracts/contract/src/detail.rs | 3 +- .../contract/src/entry_points.rs | 2 +- .../deposit-contracts/contract/src/main.rs | 12 +- .../contract/src/security.rs | 14 +- .../deposit-session/src/main.rs | 8 + 8 files changed, 163 insertions(+), 124 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80351f91..145e452f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -103,13 +103,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.78" +version = "0.1.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "461abc97219de0eaaf81fe3ef974a540158f3d079c2ab200f891f1a2ef201e85" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] @@ -120,15 +120,15 @@ checksum = "3c1e7e457ea78e524f48639f551fd79703ac3f2237f5ecccdf4708f8a75ad373" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "axum" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" dependencies = [ "async-trait", "axum-core", @@ -150,7 +150,7 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 1.0.0", "tokio", "tower", "tower-layer", @@ -173,7 +173,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper", + "sync_wrapper 0.1.2", "tower-layer", "tower-service", "tracing", @@ -181,9 +181,9 @@ dependencies = [ [[package]] name = "axum-extra" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "895ff42f72016617773af68fb90da2a9677d89c62338ec09162d4909d86fdd8f" +checksum = "0be6ea09c9b96cb5076af0de2e383bd2bc0c18f827cf1967bdd353e0b910d733" dependencies = [ "axum", "axum-core", @@ -205,6 +205,7 @@ dependencies = [ "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -216,14 +217,14 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] name = "axum-test" -version = "14.4.0" +version = "14.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673f937bbc7eaadff359e2797c0de2c20e02c9db5bd6f2aed457c7ae93559b9b" +checksum = "feeac32f78598625ed66da8eb352354f1a959311a029fa418d6eed17551eb786" dependencies = [ "anyhow", "async-trait", @@ -250,9 +251,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -316,9 +317,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bitvec" @@ -381,9 +382,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "casper-types" @@ -432,18 +433,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.35" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" dependencies = [ "num-traits", ] [[package]] name = "clap" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -463,14 +464,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] @@ -499,9 +500,9 @@ checksum = "6051f239ecec86fde3410901ab7860d458d160371533842974fc61f96d15879b" [[package]] name = "cookie" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd91cf61412820176e137621345ee43b3f4423e589e7ae4e50d601d93e35ef8" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" dependencies = [ "time", "version_check", @@ -604,7 +605,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] @@ -759,9 +760,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "ff" @@ -775,9 +776,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" +checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" [[package]] name = "float-cmp" @@ -830,12 +831,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - [[package]] name = "futures-task" version = "0.3.30" @@ -896,25 +891,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "h2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ee2dd2e4f378392eeff5d51618cd9a63166a2513846bbc55f21cfacd9199d4" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 1.1.0", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "hashbrown" version = "0.14.3" @@ -1056,7 +1032,6 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2", "http 1.1.0", "http-body", "httparse", @@ -1100,9 +1075,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.5" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", @@ -1119,9 +1094,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jzon" @@ -1257,9 +1232,9 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mime" @@ -1516,7 +1491,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] @@ -1543,9 +1518,9 @@ dependencies = [ [[package]] name = "platforms" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] name = "powerfmt" @@ -1616,13 +1591,13 @@ checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.4.2", + "bitflags 2.5.0", "lazy_static", "num-traits", "rand", "rand_chacha", "rand_xorshift", - "regex-syntax 0.8.2", + "regex-syntax 0.8.3", "rusty-fork", "tempfile", "unarray", @@ -1728,9 +1703,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -1757,14 +1732,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", "regex-automata 0.4.6", - "regex-syntax 0.8.2", + "regex-syntax 0.8.3", ] [[package]] @@ -1784,7 +1759,7 @@ checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax 0.8.3", ] [[package]] @@ -1795,9 +1770,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "reserve-port" @@ -1852,11 +1827,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -1938,7 +1913,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] @@ -1956,9 +1931,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "indexmap", "itoa", @@ -2049,9 +2024,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "snafu" @@ -2127,9 +2102,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.53" +version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ "proc-macro2", "quote", @@ -2142,6 +2117,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384595c11a4e2969895cad5a8c4029115f5ab956a9e5ef4de79d11a426e5f20c" + [[package]] name = "tap" version = "1.0.1" @@ -2183,7 +2164,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] @@ -2270,21 +2251,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", -] - -[[package]] -name = "tokio-util" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", + "syn 2.0.55", ] [[package]] @@ -2335,7 +2302,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.55", ] [[package]] diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/src/integration_tests.rs index 71b40f9f..80d62b08 100644 --- a/contracts/deposit-contract-tests/src/integration_tests.rs +++ b/contracts/deposit-contract-tests/src/integration_tests.rs @@ -2,7 +2,7 @@ mod test_fixture; #[cfg(test)] mod tests { use crate::test_fixture::TestContext; - use casper_types::{account::AccountHash, U512}; + use casper_types::{account::AccountHash, Key, U512}; #[test] fn should_install() { @@ -35,7 +35,21 @@ mod tests { assert_eq!(contract_balance_after, DEPOSIT_AMOUNT); let user_balance_after = fixture.builder.get_purse_balance(user_purse_uref); - assert_eq!(user_balance_after, U512::from(9999871666161540u64)); + assert!(user_balance_after < user_balance_before); + } + + #[test] + fn update_security_badges() { + let (mut fixture, init_admin, new_admin) = setup(); + fixture.install(init_admin); + // try to update the admin list + let new_admin_list: Vec = vec![Key::from(new_admin)]; + fixture.update_security_badges(new_admin_list.clone(), init_admin, init_admin); + // update the admin list as the new_admin + fixture.update_security_badges(new_admin_list, new_admin, init_admin); + // now remove the admin role from the installer and expect failure. + let new_admin_list: Vec = vec![]; + fixture.unauthorized_update_security_badges(new_admin_list.clone(), init_admin, init_admin); } // see malicious-session diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index eccbbb78..419aa477 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -136,6 +136,53 @@ impl TestContext { purse_balance } + // try to update the access control / admin list of the deposit contract + pub fn update_security_badges( + &mut self, + admin_list: Vec, + caller: AccountHash, + installer: AccountHash, + ) { + let session_args = runtime_args! { + "admin_list" => admin_list, + }; + let update_security_request = ExecuteRequestBuilder::contract_call_by_hash( + caller, + self.contract_hash("kairos_deposit_contract", installer), + "update_security_badges", + session_args, + ) + .build(); + self.builder + .exec(update_security_request) + .expect_success() + .commit(); + } + + // an unauthorized attempt of changing the admin badges + pub fn unauthorized_update_security_badges( + &mut self, + admin_list: Vec, + caller: AccountHash, + installer: AccountHash, + ) { + let session_args = runtime_args! { + "admin_list" => admin_list, + }; + let update_security_request = ExecuteRequestBuilder::contract_call_by_hash( + caller, + self.contract_hash("kairos_deposit_contract", installer), + "update_security_badges", + session_args, + ) + .build(); + self.builder + .exec(update_security_request) + .expect_failure() + .commit(); + } + + // see deposit-session pub fn run_deposit_session(&mut self, amount: U512, installer: AccountHash, user: AccountHash) { let session_args = runtime_args! { "amount" => amount, diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/contracts/deposit-contracts/contract/src/detail.rs index d5c6bf3f..c1d21952 100644 --- a/contracts/deposit-contracts/contract/src/detail.rs +++ b/contracts/deposit-contracts/contract/src/detail.rs @@ -78,8 +78,7 @@ pub fn get_optional_named_arg_with_user_errors( } } -/// Read optional arg and propagate errors. -/// This is required because it should be possible to +/// Reading optional args is required because it should be possible to /// install the deposit contract without passing a list of /// admins. In such a case the default admin will be the installing /// account. diff --git a/contracts/deposit-contracts/contract/src/entry_points.rs b/contracts/deposit-contracts/contract/src/entry_points.rs index ee23c1b7..239619af 100644 --- a/contracts/deposit-contracts/contract/src/entry_points.rs +++ b/contracts/deposit-contracts/contract/src/entry_points.rs @@ -47,7 +47,7 @@ pub fn incr_last_processed_deposit_counter() -> EntryPoint { pub fn change_security() -> EntryPoint { EntryPoint::new( - "change_security", + "update_security_badges", vec![], CLType::Unit, EntryPointAccess::Public, diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs index 1322a3fe..204f6c16 100644 --- a/contracts/deposit-contracts/contract/src/main.rs +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -45,7 +45,7 @@ pub extern "C" fn init() { storage::dictionary_put( security_badges_dict, &base64::encode(Key::from(installing_entity).to_bytes().unwrap_or_revert()), - SecurityBadge::Admin, + Some(SecurityBadge::Admin), ); let admin_list: Option> = get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); @@ -55,7 +55,7 @@ pub extern "C" fn init() { storage::dictionary_put( security_badges_dict, &base64::encode(account_dictionary_key), - SecurityBadge::Admin, + Some(SecurityBadge::Admin), ); } }; @@ -149,20 +149,20 @@ pub extern "C" fn incr_last_processed_deposit_counter() { // This entry point is used to assign and revoke rolse such // as the "Admin" role. #[no_mangle] -pub extern "C" fn change_security() { +pub extern "C" fn update_security_badges() { access_control_check(vec![SecurityBadge::Admin]); let admin_list: Option> = get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); // construct a new admin list from runtime arg - let mut badge_map: BTreeMap = BTreeMap::new(); + let mut badge_map: BTreeMap> = BTreeMap::new(); if let Some(admin_list) = admin_list { for account_key in admin_list { - badge_map.insert(account_key, SecurityBadge::Admin); + badge_map.insert(account_key, Some(SecurityBadge::Admin)); } } // remove the caller from the admin list let caller = get_immediate_caller().unwrap_or_revert(); - badge_map.remove(&caller); + badge_map.insert(caller, None); security::update_security_badges(&badge_map); } diff --git a/contracts/deposit-contracts/contract/src/security.rs b/contracts/deposit-contracts/contract/src/security.rs index 88cd22a1..19af1096 100644 --- a/contracts/deposit-contracts/contract/src/security.rs +++ b/contracts/deposit-contracts/contract/src/security.rs @@ -10,7 +10,7 @@ use casper_contract::{ contract_api::{ self, runtime::revert, - storage::{dictionary_get, dictionary_put}, + storage::{dictionary_get, dictionary_put, new_dictionary}, }, ext_ffi, unwrap_or_revert::UnwrapOrRevert, @@ -60,15 +60,19 @@ pub fn access_control_check(allowed_badge_list: Vec) { .to_bytes() .unwrap_or_revert(); if !allowed_badge_list.contains( - &dictionary_get::(get_uref(SECURITY_BADGES), &base64::encode(caller)) - .unwrap_or_revert() - .unwrap_or_revert_with(DepositError::InsufficientRights), + &dictionary_get::>( + get_uref(SECURITY_BADGES), + &base64::encode(caller), + ) + .unwrap_or_revert() + .unwrap_or_revert() + .unwrap_or_revert_with(DepositError::InsufficientRights), ) { revert(DepositError::InsufficientRights) } } -pub fn update_security_badges(badge_map: &BTreeMap) { +pub fn update_security_badges(badge_map: &BTreeMap>) { let sec_uref = get_uref(SECURITY_BADGES); for (&user, &badge) in badge_map { dictionary_put( diff --git a/contracts/deposit-contracts/deposit-session/src/main.rs b/contracts/deposit-contracts/deposit-session/src/main.rs index 04140f74..60ff39cf 100644 --- a/contracts/deposit-contracts/deposit-session/src/main.rs +++ b/contracts/deposit-contracts/deposit-session/src/main.rs @@ -1,3 +1,11 @@ +/* + Transfer native Casper tokens from the caller to the deposit smart contract. + Due to the purse access control in Casper 1.5.x, a temporary purse is created and funded + by the user first, to then be passed to the deposit contract. + + Finally the temporary purse is emptied / all funds are transferred to the deposit contract's + purse. +*/ #![no_std] #![no_main] use casper_contract::contract_api::{account, runtime, system}; From 9666736e026f9d6b292f78c62bb4ae50d80fea95 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:52:19 +0100 Subject: [PATCH 023/115] improve deposit contract error handling by being more explicit and add comments --- .../src/integration_tests.rs | 2 +- .../deposit-contracts/contract/src/detail.rs | 3 +- .../deposit-contracts/contract/src/error.rs | 9 +++++- .../deposit-contracts/contract/src/main.rs | 28 ++++++++++++------- .../contract/src/security.rs | 6 ++++ 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/src/integration_tests.rs index 80d62b08..fd2669a5 100644 --- a/contracts/deposit-contract-tests/src/integration_tests.rs +++ b/contracts/deposit-contract-tests/src/integration_tests.rs @@ -5,7 +5,7 @@ mod tests { use casper_types::{account::AccountHash, Key, U512}; #[test] - fn should_install() { + fn should_install_deposit_contract() { let mut fixture: TestContext = TestContext::new(); fixture.install(fixture.account_1); } diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/contracts/deposit-contracts/contract/src/detail.rs index c1d21952..534d82a6 100644 --- a/contracts/deposit-contracts/contract/src/detail.rs +++ b/contracts/deposit-contracts/contract/src/detail.rs @@ -72,7 +72,8 @@ pub fn get_optional_named_arg_with_user_errors( name: &str, invalid: DepositError, ) -> Option { - match get_named_arg_with_user_errors::(name, DepositError::Phantom, invalid) { + match get_named_arg_with_user_errors::(name, DepositError::MissingOptionalArgument, invalid) + { Ok(val) => Some(val), Err(_) => None, } diff --git a/contracts/deposit-contracts/contract/src/error.rs b/contracts/deposit-contracts/contract/src/error.rs index 992e5873..1c13e00e 100644 --- a/contracts/deposit-contracts/contract/src/error.rs +++ b/contracts/deposit-contracts/contract/src/error.rs @@ -9,9 +9,16 @@ pub enum DepositError { InvalidAdminList = 2, InvalidNoneList = 3, FailedToGetArgBytes = 4, - Phantom = 5, + MissingOptionalArgument = 5, InsufficientRights = 6, AlreadyInitialized = 7, + MissingKeyDepositPurse = 8, + MissingKeyMostRecentDepositCounter = 9, + MissingKeyLastProcessedDepositCounter = 10, + MissingKeyDepositEventDict = 11, + FailedToCreateSecurityBadgesDict = 12, + FailedToCreateDepositDict = 13, + FailedToReturnContractPurseAsReference = 14, } impl From for ApiError { diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs index 204f6c16..677fbb86 100644 --- a/contracts/deposit-contracts/contract/src/main.rs +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -37,7 +37,8 @@ pub extern "C" fn init() { if runtime::get_key(KAIROS_DEPOSIT_PURSE).is_some() { runtime::revert(DepositError::AlreadyInitialized); } - let security_badges_dict = storage::new_dictionary(SECURITY_BADGES).unwrap_or_revert(); + let security_badges_dict = storage::new_dictionary(SECURITY_BADGES) + .unwrap_or_revert_with(DepositError::FailedToCreateSecurityBadgesDict); let installing_entity = runtime::get_caller(); // Assign the admin role to the installer, regardless of the list of admins that was // passed to the installation session. The installer is by default an admin and @@ -66,13 +67,14 @@ pub extern "C" fn init() { #[no_mangle] pub extern "C" fn get_purse() { let deposit_purse: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) - .unwrap_or_revert_with(ApiError::MissingKey) + .unwrap_or_revert_with(DepositError::MissingKeyDepositPurse) .into_uref() .unwrap_or_revert(); let reference_to_deposit_purse_with_restricted_access = deposit_purse.with_access_rights(AccessRights::ADD); runtime::ret( - CLValue::from_t(reference_to_deposit_purse_with_restricted_access).unwrap_or_revert(), + CLValue::from_t(reference_to_deposit_purse_with_restricted_access) + .unwrap_or_revert_with(DepositError::FailedToReturnContractPurseAsReference), ); } @@ -85,14 +87,14 @@ pub extern "C" fn deposit() { let temp_purse: URef = runtime::get_named_arg(RUNTIME_ARG_TEMP_PURSE); let amount: U512 = runtime::get_named_arg(RUNTIME_ARG_AMOUNT); let deposit_purse_uref: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) - .unwrap_or_revert_with(ApiError::MissingKey) + .unwrap_or_revert_with(DepositError::MissingKeyDepositPurse) .into_uref() .unwrap_or_revert_with(ApiError::UnexpectedKeyVariant); system::transfer_from_purse_to_purse(temp_purse, deposit_purse_uref, amount, None) .unwrap_or_revert(); let most_recent_deposit_counter_uref = runtime::get_key(KAIROS_MOST_RECENT_DEPOSIT_COUNTER) - .unwrap_or_revert_with(ApiError::MissingKey) + .unwrap_or_revert_with(DepositError::MissingKeyMostRecentDepositCounter) .into_uref() .unwrap_or_revert(); let mut most_recent_deposit_counter_value: u64 = @@ -106,13 +108,15 @@ pub extern "C" fn deposit() { processed: false, }; + let deposit_event_dict_key: &str = &most_recent_deposit_counter_value.to_string(); + let kairos_deposit_event_dict_uref = runtime::get_key(KAIROS_DEPOSIT_EVENT_DICT) - .unwrap_or_revert_with(ApiError::MissingKey) + .unwrap_or_revert_with(DepositError::MissingKeyDepositEventDict) .into_uref() .unwrap_or_revert(); storage::dictionary_put::>( kairos_deposit_event_dict_uref, - &most_recent_deposit_counter_value.to_string(), + deposit_event_dict_key, bincode::serialize(&new_deposit_record).unwrap(), ); @@ -131,7 +135,7 @@ pub extern "C" fn incr_last_processed_deposit_counter() { access_control_check(vec![SecurityBadge::Admin]); let last_processed_deposit_counter_uref = runtime::get_key(KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER) - .unwrap_or_revert_with(ApiError::MissingKey) + .unwrap_or_revert_with(DepositError::MissingKeyLastProcessedDepositCounter) .into_uref() .unwrap_or_revert(); let mut last_processed_deposit_counter_value: u64 = @@ -160,7 +164,10 @@ pub extern "C" fn update_security_badges() { badge_map.insert(account_key, Some(SecurityBadge::Admin)); } } - // remove the caller from the admin list + // remove the caller from the admin list, + // by inserting None as the security badge + // accounts with no security badge will not be considered part of a badge group + // and therefore loose the ability to call EPs that call `access_control_check(vec![SecurityBadge::Admin]);` o.e. let caller = get_immediate_caller().unwrap_or_revert(); badge_map.insert(caller, None); security::update_security_badges(&badge_map); @@ -183,7 +190,8 @@ pub extern "C" fn call() { entry_points }; let mut named_keys = NamedKeys::new(); - let event_dict = storage::new_dictionary(KAIROS_DEPOSIT_EVENT_DICT).unwrap_or_revert(); + let event_dict = storage::new_dictionary(KAIROS_DEPOSIT_EVENT_DICT) + .unwrap_or_revert_with(DepositError::FailedToCreateDepositDict); named_keys.insert(KAIROS_DEPOSIT_EVENT_DICT.to_string(), event_dict.into()); let last_processed_deposit_counter = storage::new_uref(u64::from(0u8)); diff --git a/contracts/deposit-contracts/contract/src/security.rs b/contracts/deposit-contracts/contract/src/security.rs index 19af1096..08562d16 100644 --- a/contracts/deposit-contracts/contract/src/security.rs +++ b/contracts/deposit-contracts/contract/src/security.rs @@ -54,6 +54,9 @@ impl FromBytes for SecurityBadge { } } +// Check if a given account / Key is part of a Group / assigned a specific Badge. +// If the account doesn't hold the required badge, the runtime will revert and the +// execution of the contract is terminated. pub fn access_control_check(allowed_badge_list: Vec) { let caller = get_immediate_caller() .unwrap_or_revert() @@ -72,6 +75,9 @@ pub fn access_control_check(allowed_badge_list: Vec) { } } +// Insert the new and updated roles into the security badge dictionary. +// Accounts that are assigned "None" will not be considered members of a group / groupless. +// Groups (=Badges) are used for access control. pub fn update_security_badges(badge_map: &BTreeMap>) { let sec_uref = get_uref(SECURITY_BADGES); for (&user, &badge) in badge_map { From d0534389214556c5aeddd167b2bc5e74e95f2682 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:56:12 +0100 Subject: [PATCH 024/115] update function name for contract installation --- .../deposit-contract-tests/src/integration_tests.rs | 10 +++++----- contracts/deposit-contract-tests/src/test_fixture.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/src/integration_tests.rs index fd2669a5..450994dd 100644 --- a/contracts/deposit-contract-tests/src/integration_tests.rs +++ b/contracts/deposit-contract-tests/src/integration_tests.rs @@ -7,7 +7,7 @@ mod tests { #[test] fn should_install_deposit_contract() { let mut fixture: TestContext = TestContext::new(); - fixture.install(fixture.account_1); + fixture.install_deposit_contract(fixture.account_1); } fn setup() -> (TestContext, AccountHash, AccountHash) { @@ -21,7 +21,7 @@ mod tests { fn deposit_into_purse() { let DEPOSIT_AMOUNT: U512 = U512::from(100000000000u64); let (mut fixture, installer, user) = setup(); - fixture.install(installer); + fixture.install_deposit_contract(installer); let user_purse_uref = fixture.get_account_purse_uref(user); let user_balance_before = fixture.builder.get_purse_balance(user_purse_uref); @@ -41,7 +41,7 @@ mod tests { #[test] fn update_security_badges() { let (mut fixture, init_admin, new_admin) = setup(); - fixture.install(init_admin); + fixture.install_deposit_contract(init_admin); // try to update the admin list let new_admin_list: Vec = vec![Key::from(new_admin)]; fixture.update_security_badges(new_admin_list.clone(), init_admin, init_admin); @@ -56,7 +56,7 @@ mod tests { #[test] fn run_malicious_session() { let (mut fixture, installer, user) = setup(); - fixture.install(installer); + fixture.install_deposit_contract(installer); fixture.run_deposit_session(U512::from(100000000000u64), installer, user); fixture.run_malicious_session(fixture.account_2, U512::from(100000000000u64), installer); } @@ -65,7 +65,7 @@ mod tests { #[test] fn run_malicious_reader() { let (mut fixture, installer, user) = setup(); - fixture.install(installer); + fixture.install_deposit_contract(installer); fixture.run_deposit_session(U512::from(100000000000u64), installer, user); let deposit_purse_uref = fixture.get_contract_purse_uref(installer); fixture.run_malicious_reader_session( diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index 419aa477..bca33d16 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -97,7 +97,7 @@ impl TestContext { .expect("must get contract hash") } - pub fn install(&mut self, admin: AccountHash) { + pub fn install_deposit_contract(&mut self, admin: AccountHash) { let session_args = runtime_args! {}; let install_contract_request = ExecuteRequestBuilder::standard( admin, From 2c215a62cef73612e40def3951c0dfe0228494a8 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 19:11:20 +0100 Subject: [PATCH 025/115] add constants for EP names, minor cleanups --- .../src/test_fixture/utils.rs | 20 ++++++++----------- .../contract/src/constants.rs | 6 ++++++ .../deposit-contracts/contract/src/detail.rs | 7 +++---- .../contract/src/entry_points.rs | 16 +++++++++------ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/contracts/deposit-contract-tests/src/test_fixture/utils.rs b/contracts/deposit-contract-tests/src/test_fixture/utils.rs index fa24a3f4..dd1fa2cd 100644 --- a/contracts/deposit-contract-tests/src/test_fixture/utils.rs +++ b/contracts/deposit-contract-tests/src/test_fixture/utils.rs @@ -17,18 +17,6 @@ pub fn create_funded_dummy_account( ) -> AccountHash { let (_, account_public_key) = create_dummy_key_pair(account_string.unwrap_or([7u8; 32])); let account = account_public_key.to_account_hash(); - fund_account(builder, account); - account -} - -pub fn create_dummy_key_pair(account_string: [u8; 32]) -> (SecretKey, PublicKey) { - let secret_key = - SecretKey::ed25519_from_bytes(account_string).expect("failed to create secret key"); - let public_key = PublicKey::from(&secret_key); - (secret_key, public_key) -} - -pub fn fund_account(builder: &mut WasmTestBuilder, account: AccountHash) { let transfer = ExecuteRequestBuilder::transfer( *DEFAULT_ACCOUNT_ADDR, runtime_args! { @@ -39,4 +27,12 @@ pub fn fund_account(builder: &mut WasmTestBuilder, account: ) .build(); builder.exec(transfer).expect_success().commit(); + account +} + +pub fn create_dummy_key_pair(account_string: [u8; 32]) -> (SecretKey, PublicKey) { + let secret_key = + SecretKey::ed25519_from_bytes(account_string).expect("failed to create secret key"); + let public_key = PublicKey::from(&secret_key); + (secret_key, public_key) } diff --git a/contracts/deposit-contracts/contract/src/constants.rs b/contracts/deposit-contracts/contract/src/constants.rs index 5683a63e..d8fe779d 100644 --- a/contracts/deposit-contracts/contract/src/constants.rs +++ b/contracts/deposit-contracts/contract/src/constants.rs @@ -13,3 +13,9 @@ pub const RUNTIME_ARG_AMOUNT: &str = "amount"; pub const SECURITY_BADGES: &str = "security_badges"; pub const ADMIN_LIST: &str = "admin_list"; + +pub const EP_INIT_NAME: &str = "init"; +pub const EP_GET_PURSE_NAME: &str = "get_purse"; +pub const EP_DEPOSIT_NAME: &str = "deposit"; +pub const EP_INCR_LAST_PROCESSED_NAME: &str = "incr_last_processed_deposit_counter"; +pub const EP_UPDATE_SECURITY_BADGES_NAME: &str = "update_security_badges"; diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/contracts/deposit-contracts/contract/src/detail.rs index 534d82a6..8654516f 100644 --- a/contracts/deposit-contracts/contract/src/detail.rs +++ b/contracts/deposit-contracts/contract/src/detail.rs @@ -72,8 +72,8 @@ pub fn get_optional_named_arg_with_user_errors( name: &str, invalid: DepositError, ) -> Option { - match get_named_arg_with_user_errors::(name, DepositError::MissingOptionalArgument, invalid) - { + let maybe_named_arg_with_user_errors = get_named_arg_with_user_errors::(name, invalid); + match maybe_named_arg_with_user_errors { Ok(val) => Some(val), Err(_) => None, } @@ -92,10 +92,9 @@ pub fn get_optional_named_arg_with_user_errors( /// list as a runtime argument. Otherwise the missing error will be propagated. pub fn get_named_arg_with_user_errors( name: &str, - missing: DepositError, invalid: DepositError, ) -> Result { - let arg_size = get_named_arg_size(name).ok_or(missing)?; + let arg_size = get_named_arg_size(name).ok_or(DepositError::MissingOptionalArgument)?; let arg_bytes = if arg_size > 0 { let res = { let data_non_null_ptr = contract_api::alloc_bytes(arg_size); diff --git a/contracts/deposit-contracts/contract/src/entry_points.rs b/contracts/deposit-contracts/contract/src/entry_points.rs index 239619af..33ee936b 100644 --- a/contracts/deposit-contracts/contract/src/entry_points.rs +++ b/contracts/deposit-contracts/contract/src/entry_points.rs @@ -1,10 +1,14 @@ -use crate::constants::{RUNTIME_ARG_AMOUNT, RUNTIME_ARG_DEST_PURSE, RUNTIME_ARG_TEMP_PURSE}; +use crate::constants::{ + EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INCR_LAST_PROCESSED_NAME, EP_INIT_NAME, + EP_UPDATE_SECURITY_BADGES_NAME, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_DEST_PURSE, + RUNTIME_ARG_TEMP_PURSE, +}; use alloc::vec; use casper_types::{CLType, EntryPoint, EntryPointAccess, EntryPointType, Parameter}; pub fn init() -> EntryPoint { EntryPoint::new( - "init", + EP_INIT_NAME, vec![], CLType::Unit, EntryPointAccess::Public, @@ -14,7 +18,7 @@ pub fn init() -> EntryPoint { pub fn get_purse() -> EntryPoint { EntryPoint::new( - "get_purse", + EP_GET_PURSE_NAME, vec![], CLType::URef, EntryPointAccess::Public, @@ -24,7 +28,7 @@ pub fn get_purse() -> EntryPoint { pub fn deposit() -> EntryPoint { EntryPoint::new( - "deposit", + EP_DEPOSIT_NAME, vec![ Parameter::new(RUNTIME_ARG_AMOUNT, CLType::U512), Parameter::new(RUNTIME_ARG_TEMP_PURSE, CLType::URef), @@ -37,7 +41,7 @@ pub fn deposit() -> EntryPoint { pub fn incr_last_processed_deposit_counter() -> EntryPoint { EntryPoint::new( - "incr_last_processed_deposit_counter", + EP_INCR_LAST_PROCESSED_NAME, vec![], CLType::Unit, EntryPointAccess::Public, @@ -47,7 +51,7 @@ pub fn incr_last_processed_deposit_counter() -> EntryPoint { pub fn change_security() -> EntryPoint { EntryPoint::new( - "update_security_badges", + EP_UPDATE_SECURITY_BADGES_NAME, vec![], CLType::Unit, EntryPointAccess::Public, From 07326338cca821bb959814260d2456a7954420c3 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 28 Mar 2024 19:25:57 +0100 Subject: [PATCH 026/115] remove upgradability from deposit contract --- contracts/deposit-contracts/contract/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs index 677fbb86..29b5bb18 100644 --- a/contracts/deposit-contracts/contract/src/main.rs +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -210,7 +210,8 @@ pub extern "C" fn call() { entry_points, Some(named_keys), Some(KAIROS_DEPOSIT_CONTRACT.to_string()), - Some(KAIROS_DEPOSIT_CONTRACT_PACKAGE.to_string()), + // Some(key) if upgradable + None, ); let contract_hash_key = Key::from(contract_hash); runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); From 9af7c30b98014736b57501b903f4da18c78b268d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 11:29:48 -0500 Subject: [PATCH 027/115] kairos-contracts: package with nix --- Cargo.lock | 535 +++++++++- Cargo.toml | 6 +- contracts/Cargo.lock | 961 +----------------- contracts/Cargo.toml | 13 +- .../build-contracts.sh | 0 contracts/deposit-contracts/Cargo.lock | 788 -------------- contracts/deposit-contracts/Cargo.toml | 15 - .../rust-toolchain.toml | 0 flake.nix | 40 +- 9 files changed, 596 insertions(+), 1762 deletions(-) rename contracts/{deposit-contracts => }/build-contracts.sh (100%) delete mode 100644 contracts/deposit-contracts/Cargo.lock delete mode 100644 contracts/deposit-contracts/Cargo.toml rename contracts/{deposit-contracts => }/rust-toolchain.toml (100%) diff --git a/Cargo.lock b/Cargo.lock index 145e452f..9ecfb0c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,8 +107,8 @@ version = "0.1.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] @@ -215,8 +215,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00c055ee2d014ae5981ce1016374e8213682aa14d9bf40e48ab48b5f3ef20eaa" dependencies = [ "heck 0.4.1", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] @@ -294,6 +294,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -386,6 +395,103 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +[[package]] +name = "casper-contract" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" +dependencies = [ + "casper-types", + "hex_fmt", +] + +[[package]] +name = "casper-engine-test-support" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7967f1032f17243fbc9df3e4a8591dba169676adb3262b53dab4bb98f37d3c01" +dependencies = [ + "casper-execution-engine", + "casper-hashing", + "casper-types", + "filesize", + "humantime", + "lmdb-rkv", + "log", + "num-rational", + "num-traits", + "once_cell", + "rand", + "serde", + "tempfile", + "toml", +] + +[[package]] +name = "casper-execution-engine" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e4b48df024b3424cc994c60403472f66ca0961bffb25800f66318bb66c80611" +dependencies = [ + "anyhow", + "base16", + "bincode", + "casper-hashing", + "casper-types", + "casper-wasm", + "casper-wasm-utils", + "casper-wasmi", + "datasize", + "either", + "hex-buffer-serde 0.2.2", + "hex_fmt", + "hostname", + "humantime", + "itertools", + "libc", + "linked-hash-map", + "lmdb-rkv", + "log", + "num", + "num-derive", + "num-rational", + "num-traits", + "num_cpus", + "once_cell", + "proptest", + "rand", + "rand_chacha", + "schemars", + "serde", + "serde_bytes", + "serde_json", + "strum", + "thiserror", + "tracing", + "uint", + "uuid 0.8.2", +] + +[[package]] +name = "casper-hashing" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c29b63e179d67da0c6b32c1b84bad5480f5f4bfd1b2d7f88390c85f92e87ae0" +dependencies = [ + "base16", + "blake2", + "casper-types", + "datasize", + "hex", + "hex-buffer-serde 0.3.0", + "hex_fmt", + "itertools", + "once_cell", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "casper-types" version = "4.0.1" @@ -396,6 +502,7 @@ dependencies = [ "base64 0.13.1", "bitflags 1.3.2", "blake2", + "datasize", "derp", "ed25519-dalek", "getrandom", @@ -410,15 +517,70 @@ dependencies = [ "num-traits", "once_cell", "pem", + "proptest", + "proptest-derive", "rand", + "rand_pcg", + "schemars", "serde", "serde_bytes", "serde_json", + "strum", "thiserror", "uint", "untrusted", ] +[[package]] +name = "casper-wasm" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f53c4e789fbff66ead0ea44030b1af2fc3c465201973483528e479a9155f98" + +[[package]] +name = "casper-wasm-utils" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15d9f1a2269d52961812862f67d209ef29742d06b47634e2982a96e80d0fe2b4" +dependencies = [ + "byteorder", + "casper-wasm", + "log", +] + +[[package]] +name = "casper-wasmi" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8357f19a7fd98073d8fe8df60f1bef1e677b7c623c1e6e2e07d2f8e59ceb87fc" +dependencies = [ + "casper-wasm", + "casper-wasmi-core", + "casper-wasmi-validation", +] + +[[package]] +name = "casper-wasmi-core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60089625560924f184cf91d59b0731373d5114b81224f1201c6a39ccc1d8388c" +dependencies = [ + "downcast-rs", + "libm", + "memory_units", + "num-rational", + "num-traits", +] + +[[package]] +name = "casper-wasmi-validation" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f669d385132ce321a57fdf453588d69c01654e75991bee3d22392a3aaaad80bb" +dependencies = [ + "casper-wasm", +] + [[package]] name = "cc" version = "1.0.90" @@ -469,8 +631,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck 0.5.0", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] @@ -498,6 +660,14 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6051f239ecec86fde3410901ab7860d458d160371533842974fc61f96d15879b" +[[package]] +name = "contract-types" +version = "0.1.0" +dependencies = [ + "casper-types", + "serde", +] + [[package]] name = "cookie" version = "0.18.1" @@ -603,11 +773,44 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] +[[package]] +name = "datasize" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e65c07d59e45d77a8bda53458c24a828893a99ac6cdd9c84111e09176ab739a2" +dependencies = [ + "datasize_derive", +] + +[[package]] +name = "datasize_derive" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613e4ee15899913285b7612004bbd490abd605be7b11d35afada5902fb6b91d5" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 1.0.109", +] + +[[package]] +name = "deposit-contract-tests" +version = "0.1.0" +dependencies = [ + "base64 0.21.7", + "casper-contract", + "casper-engine-test-support", + "casper-execution-engine", + "casper-types", + "dotenvy", + "lazy_static", +] + [[package]] name = "der" version = "0.7.8" @@ -681,6 +884,18 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + [[package]] name = "ecdsa" version = "0.16.9" @@ -780,6 +995,15 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +[[package]] +name = "filesize" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43" +dependencies = [ + "winapi", +] + [[package]] name = "float-cmp" version = "0.9.0" @@ -891,6 +1115,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hashbrown" version = "0.14.3" @@ -944,6 +1174,29 @@ name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] + +[[package]] +name = "hex-buffer-serde" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310e9578ff64e65a3a18e0624609f6833ee4a20503ef38eebb48430cf8ac3ab8" +dependencies = [ + "hex", + "serde", +] + +[[package]] +name = "hex-buffer-serde" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f52012c160668b4494727f3588045aa00429849fcae51de70d68fa98228039" +dependencies = [ + "hex", + "serde", +] [[package]] name = "hex_fmt" @@ -960,6 +1213,17 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + [[package]] name = "http" version = "0.2.12" @@ -1073,6 +1337,17 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.2.6" @@ -1080,7 +1355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.3", ] [[package]] @@ -1193,12 +1468,41 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +[[package]] +name = "lmdb-rkv" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "libc", + "lmdb-rkv-sys", +] + +[[package]] +name = "lmdb-rkv-sys" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61b9ce6b3be08acefa3003c57b7565377432a89ec24476bbe72e11d101f852fe" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "lock_api" version = "0.4.11" @@ -1214,6 +1518,16 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "serde", + "value-bag", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" [[package]] name = "matchers" @@ -1236,6 +1550,12 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + [[package]] name = "mime" version = "0.3.17" @@ -1350,8 +1670,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] @@ -1385,6 +1705,7 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", + "serde", ] [[package]] @@ -1489,8 +1810,8 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] @@ -1516,6 +1837,12 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "platforms" version = "3.4.0" @@ -1574,6 +1901,15 @@ dependencies = [ "yansi", ] +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid", +] + [[package]] name = "proc-macro2" version = "1.0.79" @@ -1603,19 +1939,39 @@ dependencies = [ "unarray", ] +[[package]] +name = "proptest-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90b46295382dc76166cb7cf2bb4a97952464e4b7ed5a43e6cd34e1fec3349ddc" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + [[package]] name = "quick-error" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + [[package]] name = "quote" version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.79", ] [[package]] @@ -1654,6 +2010,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core", +] + [[package]] name = "rand_xorshift" version = "0.3.0" @@ -1694,11 +2059,11 @@ checksum = "cbaf7105cd254b632f4732fbcc243ce750cef87d8335826125ef6df5733b5a0c" dependencies = [ "either", "itertools", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "rayon", "syn 1.0.109", - "uuid", + "uuid 1.8.0", ] [[package]] @@ -1862,6 +2227,31 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +[[package]] +name = "schemars" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b82485a532ef0af18878ad4281f73e58161cdba1db7918176e9294f0ca5498a5" +dependencies = [ + "dyn-clone", + "indexmap 1.9.3", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791c2c848cff1abaeae34fef7e70da5f93171d9eea81ce0fe969a1df627a61a8" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "serde_derive_internals", + "syn 1.0.109", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1911,11 +2301,22 @@ version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] +[[package]] +name = "serde_derive_internals" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 1.0.109", +] + [[package]] name = "serde_html_form" version = "0.2.5" @@ -1923,7 +2324,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50437e6a58912eecc08865e35ea2e8d365fbb2db0debb1c8bb43bf1faf055f25" dependencies = [ "form_urlencoded", - "indexmap", + "indexmap 2.2.6", "itoa", "ryu", "serde", @@ -1935,7 +2336,7 @@ version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ - "indexmap", + "indexmap 2.2.6", "itoa", "ryu", "serde", @@ -2046,8 +2447,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "990079665f075b699031e9c08fd3ab99be5029b96f3b78dc0709e8f77e4efebf" dependencies = [ "heck 0.4.1", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] @@ -2083,20 +2484,53 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck 0.4.1", + "proc-macro2 1.0.79", + "quote 1.0.35", + "rustversion", + "syn 1.0.109", +] + [[package]] name = "subtle" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid", +] + [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "unicode-ident", ] @@ -2106,8 +2540,8 @@ version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "unicode-ident", ] @@ -2162,8 +2596,8 @@ version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] @@ -2225,9 +2659,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.36.0" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", "bytes", @@ -2249,11 +2683,20 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "tower" version = "0.4.13" @@ -2300,8 +2743,8 @@ version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.55", ] @@ -2419,6 +2862,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "untrusted" version = "0.7.1" @@ -2442,6 +2891,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "uuid" version = "1.8.0" @@ -2457,6 +2916,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 1edeb3d0..0115b707 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,8 @@ members = [ "kairos-cli", "kairos-server", "kairos-tx", -] - -exclude = [ - "contracts" + "contracts/contract-types", + "contracts/deposit-contract-tests", ] [workspace.package] diff --git a/contracts/Cargo.lock b/contracts/Cargo.lock index 1968bf6b..2297b6aa 100644 --- a/contracts/Cargo.lock +++ b/contracts/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "anyhow" -version = "1.0.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" - [[package]] name = "autocfg" version = "1.1.0" @@ -43,9 +28,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.7" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" [[package]] name = "base64ct" @@ -62,33 +47,12 @@ dependencies = [ "serde", ] -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - [[package]] name = "blake2" version = "0.9.2" @@ -123,93 +87,7 @@ checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" dependencies = [ "casper-types", "hex_fmt", -] - -[[package]] -name = "casper-engine-test-support" -version = "7.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7967f1032f17243fbc9df3e4a8591dba169676adb3262b53dab4bb98f37d3c01" -dependencies = [ - "casper-execution-engine", - "casper-hashing", - "casper-types", - "filesize", - "humantime", - "lmdb-rkv", - "log", - "num-rational", - "num-traits", - "once_cell", - "rand", - "serde", - "tempfile", - "toml", -] - -[[package]] -name = "casper-execution-engine" -version = "7.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e4b48df024b3424cc994c60403472f66ca0961bffb25800f66318bb66c80611" -dependencies = [ - "anyhow", - "base16", - "bincode", - "casper-hashing", - "casper-types", - "casper-wasm", - "casper-wasm-utils", - "casper-wasmi", - "datasize", - "either", - "hex-buffer-serde 0.2.2", - "hex_fmt", - "hostname", - "humantime", - "itertools", - "libc", - "linked-hash-map", - "lmdb-rkv", - "log", - "num", - "num-derive", - "num-rational", - "num-traits", - "num_cpus", - "once_cell", - "proptest", - "rand", - "rand_chacha", - "schemars", - "serde", - "serde_bytes", - "serde_json", - "strum", - "thiserror", - "tracing", - "uint", - "uuid", -] - -[[package]] -name = "casper-hashing" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c29b63e179d67da0c6b32c1b84bad5480f5f4bfd1b2d7f88390c85f92e87ae0" -dependencies = [ - "base16", - "blake2", - "casper-types", - "datasize", - "hex", - "hex-buffer-serde 0.3.0", - "hex_fmt", - "itertools", - "once_cell", - "schemars", - "serde", - "thiserror", + "wee_alloc", ] [[package]] @@ -220,92 +98,29 @@ checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" dependencies = [ "base16", "base64 0.13.1", - "bitflags 1.3.2", + "bitflags", "blake2", - "datasize", - "derp", "ed25519-dalek", - "getrandom", "hex", "hex_fmt", - "humantime", "k256", "num", "num-derive", "num-integer", "num-rational", "num-traits", - "once_cell", - "pem", - "proptest", - "proptest-derive", "rand", - "rand_pcg", - "schemars", "serde", "serde_bytes", "serde_json", - "strum", - "thiserror", "uint", - "untrusted", ] [[package]] -name = "casper-wasm" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f53c4e789fbff66ead0ea44030b1af2fc3c465201973483528e479a9155f98" - -[[package]] -name = "casper-wasm-utils" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d9f1a2269d52961812862f67d209ef29742d06b47634e2982a96e80d0fe2b4" -dependencies = [ - "byteorder", - "casper-wasm", - "log", -] - -[[package]] -name = "casper-wasmi" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8357f19a7fd98073d8fe8df60f1bef1e677b7c623c1e6e2e07d2f8e59ceb87fc" -dependencies = [ - "casper-wasm", - "casper-wasmi-core", - "casper-wasmi-validation", -] - -[[package]] -name = "casper-wasmi-core" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60089625560924f184cf91d59b0731373d5114b81224f1201c6a39ccc1d8388c" -dependencies = [ - "downcast-rs", - "libm", - "memory_units", - "num-rational", - "num-traits", -] - -[[package]] -name = "casper-wasmi-validation" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f669d385132ce321a57fdf453588d69c01654e75991bee3d22392a3aaaad80bb" -dependencies = [ - "casper-wasm", -] - -[[package]] -name = "cc" -version = "1.0.90" +name = "cfg-if" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" @@ -319,6 +134,17 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "contract" +version = "0.1.0" +dependencies = [ + "base64 0.20.0", + "bincode", + "casper-contract", + "casper-types", + "contract-types", +] + [[package]] name = "contract-types" version = "0.1.0" @@ -380,7 +206,7 @@ version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", @@ -397,42 +223,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", + "proc-macro2", + "quote", "syn 2.0.55", ] [[package]] -name = "datasize" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e65c07d59e45d77a8bda53458c24a828893a99ac6cdd9c84111e09176ab739a2" -dependencies = [ - "datasize_derive", -] - -[[package]] -name = "datasize_derive" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613e4ee15899913285b7612004bbd490abd605be7b11d35afada5902fb6b91d5" -dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", - "syn 1.0.109", -] - -[[package]] -name = "deposit-contract-tests" +name = "deposit-session" version = "0.1.0" dependencies = [ - "base64 0.21.7", "casper-contract", - "casper-engine-test-support", - "casper-execution-engine", "casper-types", - "dotenvy", - "lazy_static", ] [[package]] @@ -445,15 +246,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "derp" -version = "0.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9b84cfd9b6fa437e498215e5625e9e3ae3bf9bb54d623028a181c40820db169" -dependencies = [ - "untrusted", -] - [[package]] name = "digest" version = "0.9.0" @@ -475,24 +267,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - -[[package]] -name = "downcast-rs" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" - -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - [[package]] name = "ecdsa" version = "0.16.9" @@ -530,12 +304,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "either" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" - [[package]] name = "elliptic-curve" version = "0.13.8" @@ -554,28 +322,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "fastrand" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" - [[package]] name = "ff" version = "0.13.0" @@ -592,21 +338,6 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" -[[package]] -name = "filesize" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43" -dependencies = [ - "winapi", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "generic-array" version = "0.14.7" @@ -618,17 +349,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "group" version = "0.13.0" @@ -640,58 +360,11 @@ dependencies = [ "subtle", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -dependencies = [ - "serde", -] - -[[package]] -name = "hex-buffer-serde" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "310e9578ff64e65a3a18e0624609f6833ee4a20503ef38eebb48430cf8ac3ab8" -dependencies = [ - "hex", - "serde", -] - -[[package]] -name = "hex-buffer-serde" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f52012c160668b4494727f3588045aa00429849fcae51de70d68fa98228039" -dependencies = [ - "hex", - "serde", -] [[package]] name = "hex_fmt" @@ -708,53 +381,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "hostname" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" -dependencies = [ - "libc", - "match_cfg", - "winapi", -] - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", - "serde", -] - -[[package]] -name = "indexmap" -version = "2.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" -dependencies = [ - "equivalent", - "hashbrown 0.14.3", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.10" @@ -767,18 +393,12 @@ version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "ecdsa", "elliptic-curve", "sha2", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.153" @@ -786,68 +406,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - -[[package]] -name = "lmdb-rkv" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b" -dependencies = [ - "bitflags 1.3.2", - "byteorder", - "libc", - "lmdb-rkv-sys", -] - -[[package]] -name = "lmdb-rkv-sys" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b9ce6b3be08acefa3003c57b7565377432a89ec24476bbe72e11d101f852fe" +name = "malicious-reader" +version = "0.1.0" dependencies = [ - "cc", - "libc", - "pkg-config", + "casper-contract", + "casper-types", ] [[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +name = "malicious-session" +version = "0.1.0" dependencies = [ - "serde", - "value-bag", + "casper-contract", + "casper-types", ] -[[package]] -name = "match_cfg" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" - -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - [[package]] name = "memory_units" version = "0.4.0" @@ -894,8 +467,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -929,7 +502,6 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", - "serde", ] [[package]] @@ -939,48 +511,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", - "libm", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - [[package]] name = "opaque-debug" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "pem" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" -dependencies = [ - "base64 0.13.1", - "once_cell", - "regex", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - [[package]] name = "pkcs8" version = "0.10.2" @@ -991,33 +529,12 @@ dependencies = [ "spki", ] -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "platforms" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid", -] - [[package]] name = "proc-macro2" version = "1.0.79" @@ -1027,59 +544,13 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proptest" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" -dependencies = [ - "bit-set", - "bit-vec", - "bitflags 2.5.0", - "lazy_static", - "num-traits", - "rand", - "rand_chacha", - "rand_xorshift", - "regex-syntax", - "rusty-fork", - "tempfile", - "unarray", -] - -[[package]] -name = "proptest-derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90b46295382dc76166cb7cf2bb4a97952464e4b7ed5a43e6cd34e1fec3349ddc" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", -] - -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -dependencies = [ - "proc-macro2 0.4.30", -] - [[package]] name = "quote" version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ - "proc-macro2 1.0.79", + "proc-macro2", ] [[package]] @@ -1088,18 +559,6 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", "rand_core", ] @@ -1108,56 +567,6 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_pcg" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" -dependencies = [ - "rand_core", -] - -[[package]] -name = "rand_xorshift" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -dependencies = [ - "rand_core", -] - -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rfc6979" @@ -1178,68 +587,12 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "0.38.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - -[[package]] -name = "rusty-fork" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = [ - "fnv", - "quick-error", - "tempfile", - "wait-timeout", -] - [[package]] name = "ryu" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" -[[package]] -name = "schemars" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b82485a532ef0af18878ad4281f73e58161cdba1db7918176e9294f0ca5498a5" -dependencies = [ - "dyn-clone", - "indexmap 1.9.3", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791c2c848cff1abaeae34fef7e70da5f93171d9eea81ce0fe969a1df627a61a8" -dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", - "serde_derive_internals", - "syn 1.0.109", -] - [[package]] name = "sec1" version = "0.7.3" @@ -1283,29 +636,17 @@ version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", + "proc-macro2", + "quote", "syn 2.0.55", ] -[[package]] -name = "serde_derive_internals" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" -dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", - "syn 1.0.109", -] - [[package]] name = "serde_json" version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ - "indexmap 2.2.6", "itoa", "ryu", "serde", @@ -1317,7 +658,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest 0.10.7", ] @@ -1348,53 +689,20 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2 1.0.79", - "quote 1.0.35", - "rustversion", - "syn 1.0.109", -] - [[package]] name = "subtle" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "syn" -version = "0.15.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "unicode-xid", -] - [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", + "proc-macro2", + "quote", "unicode-ident", ] @@ -1404,83 +712,11 @@ version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", + "proc-macro2", + "quote", "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys", -] - -[[package]] -name = "thiserror" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" -dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", - "syn 2.0.55", -] - -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", - "syn 2.0.55", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", -] - [[package]] name = "typenum" version = "1.17.0" @@ -1499,46 +735,12 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "unarray" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom", - "serde", -] - -[[package]] -name = "value-bag" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" - [[package]] name = "version_check" version = "0.9.4" @@ -1546,20 +748,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "wait-timeout" -version = "0.2.0" +name = "wee_alloc" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" dependencies = [ + "cfg-if 0.1.10", "libc", + "memory_units", + "winapi", ] -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "winapi" version = "0.3.9" @@ -1582,72 +781,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" - [[package]] name = "zeroize" version = "1.7.0" diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index e61863d1..4fa50687 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -2,16 +2,19 @@ resolver = "2" members = [ - "deposit-contract-tests", - "contract-types" + "deposit-contracts/malicious-reader", + "deposit-contracts/malicious-session", + "deposit-contracts/deposit-session", + "deposit-contracts/contract", + "contract-types", ] exclude = [ - "deposit-contracts" + "deposit-contracts" ] [workspace.package] -name = "kairos-contract" +name = "contracts" version = "0.1.0" edition = "2021" -license = "MIT OR Apache-2.0" \ No newline at end of file +license = "MIT OR Apache-2.0" diff --git a/contracts/deposit-contracts/build-contracts.sh b/contracts/build-contracts.sh similarity index 100% rename from contracts/deposit-contracts/build-contracts.sh rename to contracts/build-contracts.sh diff --git a/contracts/deposit-contracts/Cargo.lock b/contracts/deposit-contracts/Cargo.lock deleted file mode 100644 index 2297b6aa..00000000 --- a/contracts/deposit-contracts/Cargo.lock +++ /dev/null @@ -1,788 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "base16" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d27c3610c36aee21ce8ac510e6224498de4228ad772a171ed65643a24693a5a8" - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - -[[package]] -name = "base64" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "blake2" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" -dependencies = [ - "crypto-mac", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "casper-contract" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" -dependencies = [ - "casper-types", - "hex_fmt", - "wee_alloc", -] - -[[package]] -name = "casper-types" -version = "4.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" -dependencies = [ - "base16", - "base64 0.13.1", - "bitflags", - "blake2", - "ed25519-dalek", - "hex", - "hex_fmt", - "k256", - "num", - "num-derive", - "num-integer", - "num-rational", - "num-traits", - "rand", - "serde", - "serde_bytes", - "serde_json", - "uint", -] - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "contract" -version = "0.1.0" -dependencies = [ - "base64 0.20.0", - "bincode", - "casper-contract", - "casper-types", - "contract-types", -] - -[[package]] -name = "contract-types" -version = "0.1.0" -dependencies = [ - "casper-types", - "serde", -] - -[[package]] -name = "cpufeatures" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" -dependencies = [ - "libc", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "curve25519-dalek" -version = "4.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "curve25519-dalek-derive", - "digest 0.10.7", - "fiat-crypto", - "platforms", - "rustc_version", - "subtle", - "zeroize", -] - -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.55", -] - -[[package]] -name = "deposit-session" -version = "0.1.0" -dependencies = [ - "casper-contract", - "casper-types", -] - -[[package]] -name = "der" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", -] - -[[package]] -name = "ed25519" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" -dependencies = [ - "pkcs8", - "signature", -] - -[[package]] -name = "ed25519-dalek" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" -dependencies = [ - "curve25519-dalek", - "ed25519", - "serde", - "sha2", - "subtle", - "zeroize", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "rand_core", - "sec1", - "subtle", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "rand_core", - "subtle", -] - -[[package]] -name = "fiat-crypto" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hex_fmt" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "itoa" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" - -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if 1.0.0", - "ecdsa", - "elliptic-curve", - "sha2", -] - -[[package]] -name = "libc" -version = "0.2.153" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "malicious-reader" -version = "0.1.0" -dependencies = [ - "casper-contract", - "casper-types", -] - -[[package]] -name = "malicious-session" -version = "0.1.0" -dependencies = [ - "casper-contract", - "casper-types", -] - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "num" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-complex" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" -dependencies = [ - "autocfg", - "num-bigint", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "platforms" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" - -[[package]] -name = "proc-macro2" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - -[[package]] -name = "ryu" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "subtle", - "zeroize", -] - -[[package]] -name = "semver" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" - -[[package]] -name = "serde" -version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_bytes" -version = "0.11.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.55", -] - -[[package]] -name = "serde_json" -version = "1.0.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest 0.10.7", - "rand_core", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "uint" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/contracts/deposit-contracts/Cargo.toml b/contracts/deposit-contracts/Cargo.toml deleted file mode 100644 index 782e523e..00000000 --- a/contracts/deposit-contracts/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[workspace] -resolver = "2" - -members = [ - "malicious-reader", - "malicious-session", - "deposit-session", - "contract" -] - -[workspace.package] -name = "deposit-contracts" -version = "0.1.0" -edition = "2021" -license = "MIT OR Apache-2.0" \ No newline at end of file diff --git a/contracts/deposit-contracts/rust-toolchain.toml b/contracts/rust-toolchain.toml similarity index 100% rename from contracts/deposit-contracts/rust-toolchain.toml rename to contracts/rust-toolchain.toml diff --git a/flake.nix b/flake.nix index 0974826d..af192bc7 100644 --- a/flake.nix +++ b/flake.nix @@ -39,9 +39,36 @@ ]; perSystem = { config, self', inputs', system, pkgs, lib, ... }: let - rustToolchain = inputs'.fenix.packages.stable.toolchain; + rustToolchain = with inputs'.fenix.packages; combine [ + complete.toolchain + targets.wasm32-unknown-unknown.latest.rust-std + ]; craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolchain; + kairosContractsAttrs = { + src = lib.cleanSourceWith { + src = craneLib.path ./contracts; + filter = path: type: craneLib.filterCargoSources path type; + }; + cargoExtraArgs = "--target wasm32-unknown-unknown"; + nativeBuildInputs = [ pkgs.binaryen ]; + doCheck = false; + # Append "-optimized" to wasm files, to make the tests pass + postInstall = '' + directory="$out/bin/" + for file in "$directory"*.wasm; do + if [ -e "$file" ]; then + # Extract the file name without extension + filename=$(basename "$file" .wasm) + # Append "-optimized" to the filename and add back the .wasm extension + new_filename="$directory$filename-optimized.wasm" + wasm-opt --strip-debug --signext-lowering "$file" -o "$new_filename" + #mv "$file" "$new_filename" + fi + done + ''; + }; + kairosNodeAttrs = { src = lib.cleanSourceWith { src = craneLib.path ./.; @@ -59,6 +86,9 @@ ] ++ lib.optionals stdenv.isDarwin [ libiconv ]; + + PATH_TO_WASM_BINARIES = "${self'.packages.kairos-contracts}/bin"; + meta.mainProgram = "kairos-server"; }; in @@ -83,6 +113,14 @@ kairos-docs = craneLib.cargoDoc (kairosNodeAttrs // { cargoArtifacts = self'.packages.kairos-deps; }); + + kairos-contracts-deps = craneLib.buildPackage (kairosContractsAttrs // { + pname = "kairos-contracts"; + }); + + kairos-contracts = craneLib.buildPackage (kairosContractsAttrs // { + cargoArtifacts = self'.packages.kairos-contracts-deps; + }); }; checks = { From 9b1bc57f70f20204bdc4eff6874f9311767a9a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 11:32:13 -0500 Subject: [PATCH 028/115] ci: build kairos-contracts --- .github/workflows/check.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 93722e0a..3bac6c18 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -40,6 +40,18 @@ jobs: - name: coverage if: matrix.os == 'ubuntu-latest' run: nix build -L --no-link --show-trace .#checks.x86_64-linux.coverage-report + + - name: kairos-contracts x86_64-linux + if: matrix.os == 'ubuntu-latest' + run: nix build -L --no-link --show-trace .#packages.x86_64-linux.kairos-contracts + + - name: kairos-contracts x86_64-darwin + if: matrix.os == 'macos-latest' + run: nix build -L --no-link --show-trace .#packages.x86_64-darwin.kairos-contracts + + - name: kairos-contracts aarch64-darwin + if: matrix.os == 'macos-14' + run: nix build -L --no-link --show-trace .#packages.aarch64-darwin.kairos-contracts - name: kairos x86_64-linux if: matrix.os == 'ubuntu-latest' From c7a69601e458682b28f8c562d89c7c6640eb76e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 11:36:51 -0500 Subject: [PATCH 029/115] ci: run on any pull request --- .github/workflows/check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3bac6c18..a93448cb 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,7 +1,6 @@ name: check on: pull_request: - branches: [main] push: branches: [main] From eec3780943fd6d73a9a8725e17052dc03db69207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 11:57:30 -0500 Subject: [PATCH 030/115] flake/kairos-contracts: add darwin targets --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index af192bc7..667e79f3 100644 --- a/flake.nix +++ b/flake.nix @@ -42,6 +42,8 @@ rustToolchain = with inputs'.fenix.packages; combine [ complete.toolchain targets.wasm32-unknown-unknown.latest.rust-std + targets.aarch64-apple-darwin.complete.rust-std + targets.x86_64-apple-darwin.complete.rust-std ]; craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolchain; From 8bdae6cb1449d81d95cdcd31f04c720a3231bc7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 11:57:53 -0500 Subject: [PATCH 031/115] flake/checks: add kairos-contract check outputs --- flake.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/flake.nix b/flake.nix index 667e79f3..4200ce8f 100644 --- a/flake.nix +++ b/flake.nix @@ -139,6 +139,16 @@ inherit (kairosNodeAttrs) src; advisory-db = inputs.advisory-db; }; + + kairos-contracts-lint = craneLib.cargoClippy (kairosContractsAttrs // { + cargoArtifacts = self'.packages.kairos-contracts-deps; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + kairos-contracts-audit = craneLib.cargoAudit { + inherit (kairosContractsAttrs) src; + advisory-db = inputs.advisory-db; + }; }; treefmt = { From 9e27d1344442273a6938dd24804c593e1b3082d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 12:13:28 -0500 Subject: [PATCH 032/115] deposit-contracts-tests: fix linter warnings --- .../deposit-contract-tests/src/integration_tests.rs | 10 +++++----- contracts/deposit-contract-tests/src/test_fixture.rs | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/src/integration_tests.rs index 450994dd..735a5418 100644 --- a/contracts/deposit-contract-tests/src/integration_tests.rs +++ b/contracts/deposit-contract-tests/src/integration_tests.rs @@ -14,12 +14,12 @@ mod tests { let fixture: TestContext = TestContext::new(); let installer = fixture.account_1; let user = fixture.account_2; - return (fixture, installer, user); + (fixture, installer, user) } #[test] fn deposit_into_purse() { - let DEPOSIT_AMOUNT: U512 = U512::from(100000000000u64); + let deposit_amount: U512 = U512::from(100000000000u64); let (mut fixture, installer, user) = setup(); fixture.install_deposit_contract(installer); @@ -29,13 +29,13 @@ mod tests { let contract_balance_before = fixture.get_contract_purse_balance(installer); assert_eq!(contract_balance_before, U512::zero()); - fixture.run_deposit_session(DEPOSIT_AMOUNT, installer, user); + fixture.run_deposit_session(deposit_amount, installer, user); let contract_balance_after = fixture.get_contract_purse_balance(installer); - assert_eq!(contract_balance_after, DEPOSIT_AMOUNT); + assert_eq!(contract_balance_after, deposit_amount); let user_balance_after = fixture.builder.get_purse_balance(user_purse_uref); - assert!(user_balance_after < user_balance_before); + assert!(user_balance_after <= user_balance_before - deposit_amount); } #[test] diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/src/test_fixture.rs index bca33d16..e4f2da28 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/src/test_fixture.rs @@ -1,7 +1,6 @@ mod utils; use casper_engine_test_support::{ - ExecuteRequestBuilder, InMemoryWasmTestBuilder, DEFAULT_ACCOUNT_ADDR, - PRODUCTION_RUN_GENESIS_REQUEST, + ExecuteRequestBuilder, InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST, }; use casper_types::{ account::AccountHash, contracts::NamedKeys, runtime_args, ContractHash, Key, RuntimeArgs, URef, @@ -132,8 +131,7 @@ impl TestContext { .contract_named_keys("kairos_deposit_contract", "kairos_deposit_purse", account) .as_uref() .unwrap(); - let purse_balance = self.builder.get_purse_balance(contract_purse_uref); - purse_balance + self.builder.get_purse_balance(contract_purse_uref) } // try to update the access control / admin list of the deposit contract From 52b9016fc8434b6296b45b3eef291c0480120f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 14:06:57 -0500 Subject: [PATCH 033/115] flake/kairos: ignore contracts --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 4200ce8f..faa20eb7 100644 --- a/flake.nix +++ b/flake.nix @@ -77,6 +77,8 @@ filter = path: type: # Allow static files. (lib.hasInfix "/fixtures/" path) || + # ignore the contracts directory + !(lib.hasInfix "contracts/" path) || # Default filter (from crane) for .rs files. (craneLib.filterCargoSources path type) ; From cbb1a5260a25f0688558d85d437be0eb7dd34778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 14:07:26 -0500 Subject: [PATCH 034/115] flake/kairos-contracts: remove unused mv comment --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index faa20eb7..35e33468 100644 --- a/flake.nix +++ b/flake.nix @@ -65,7 +65,6 @@ # Append "-optimized" to the filename and add back the .wasm extension new_filename="$directory$filename-optimized.wasm" wasm-opt --strip-debug --signext-lowering "$file" -o "$new_filename" - #mv "$file" "$new_filename" fi done ''; From 62f6ec664dd43594c55c62a0b83a6b0c47171c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 14:07:43 -0500 Subject: [PATCH 035/115] flake/kairos-contracts: remove darwin targets --- flake.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/flake.nix b/flake.nix index 35e33468..7bde1466 100644 --- a/flake.nix +++ b/flake.nix @@ -42,8 +42,6 @@ rustToolchain = with inputs'.fenix.packages; combine [ complete.toolchain targets.wasm32-unknown-unknown.latest.rust-std - targets.aarch64-apple-darwin.complete.rust-std - targets.x86_64-apple-darwin.complete.rust-std ]; craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolchain; From 54985389c8f2ed8ccafb53b034078b3952063e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 14:08:33 -0500 Subject: [PATCH 036/115] kairos-contracts-test: refactor to test only crate --- contracts/deposit-contract-tests/Cargo.toml | 6 ------ .../{src => tests}/integration_tests.rs | 0 contracts/deposit-contract-tests/tests/lib.rs | 3 +++ .../{src/test_fixture.rs => tests/test_fixture/mod.rs} | 2 +- .../utils.rs => tests/test_fixture/utils/mod.rs} | 0 5 files changed, 4 insertions(+), 7 deletions(-) rename contracts/deposit-contract-tests/{src => tests}/integration_tests.rs (100%) create mode 100644 contracts/deposit-contract-tests/tests/lib.rs rename contracts/deposit-contract-tests/{src/test_fixture.rs => tests/test_fixture/mod.rs} (99%) rename contracts/deposit-contract-tests/{src/test_fixture/utils.rs => tests/test_fixture/utils/mod.rs} (100%) diff --git a/contracts/deposit-contract-tests/Cargo.toml b/contracts/deposit-contract-tests/Cargo.toml index 2aa3df63..489e739a 100644 --- a/contracts/deposit-contract-tests/Cargo.toml +++ b/contracts/deposit-contract-tests/Cargo.toml @@ -13,10 +13,4 @@ casper-execution-engine = {version="7.0.0", default-features=false} casper-contract = {version="4.0.0", default-features=false} casper-types = {version="4.0.0", default-features=false} dotenvy = "0.15.7" - -[[test]] -name = "kairos_contract_tests" -path = "src/integration_tests.rs" - -[dependencies] lazy_static = "1.4.0" diff --git a/contracts/deposit-contract-tests/src/integration_tests.rs b/contracts/deposit-contract-tests/tests/integration_tests.rs similarity index 100% rename from contracts/deposit-contract-tests/src/integration_tests.rs rename to contracts/deposit-contract-tests/tests/integration_tests.rs diff --git a/contracts/deposit-contract-tests/tests/lib.rs b/contracts/deposit-contract-tests/tests/lib.rs new file mode 100644 index 00000000..66d4fc53 --- /dev/null +++ b/contracts/deposit-contract-tests/tests/lib.rs @@ -0,0 +1,3 @@ +pub mod test_fixture { + pub mod utils; +} diff --git a/contracts/deposit-contract-tests/src/test_fixture.rs b/contracts/deposit-contract-tests/tests/test_fixture/mod.rs similarity index 99% rename from contracts/deposit-contract-tests/src/test_fixture.rs rename to contracts/deposit-contract-tests/tests/test_fixture/mod.rs index e4f2da28..bbfa5b20 100644 --- a/contracts/deposit-contract-tests/src/test_fixture.rs +++ b/contracts/deposit-contract-tests/tests/test_fixture/mod.rs @@ -25,11 +25,11 @@ lazy_static! { }; } -#[cfg(test)] pub struct TestContext { pub builder: InMemoryWasmTestBuilder, pub account_1: AccountHash, pub account_2: AccountHash, + #[allow(dead_code)] pub account_3: AccountHash, } diff --git a/contracts/deposit-contract-tests/src/test_fixture/utils.rs b/contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs similarity index 100% rename from contracts/deposit-contract-tests/src/test_fixture/utils.rs rename to contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs From f9c63f453a4347e80dfe576130340f72e31c9647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 15:29:19 -0500 Subject: [PATCH 037/115] kairos-contracts: dont exclude deposit-contracts --- contracts/Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index 4fa50687..0e65d0f9 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -9,10 +9,6 @@ members = [ "contract-types", ] -exclude = [ - "deposit-contracts" -] - [workspace.package] name = "contracts" version = "0.1.0" From d322a57bb6bcf2255de9565c1ed00483d84e2bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 16:15:15 -0500 Subject: [PATCH 038/115] flake/coverage-report: fix issue with rust-nightly and tarpaulin --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 7bde1466..777b6bbb 100644 --- a/flake.nix +++ b/flake.nix @@ -132,6 +132,8 @@ coverage-report = craneLib.cargoTarpaulin (kairosNodeAttrs // { cargoArtifacts = self'.packages.kairos-deps; + # FIXME fix weird issue with rust-nightly and tarpaulin https://github.com/xd009642/tarpaulin/issues/1499 + RUSTFLAGS = "-Cstrip=none"; }); audit = craneLib.cargoAudit { From a06b8dcd80e8faa9e62eb55e2839d87de694bda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 16:24:30 -0500 Subject: [PATCH 039/115] kairos-contracts: fix linter issues --- .../deposit-contracts/contract/src/constants.rs | 4 ++++ contracts/deposit-contracts/contract/src/detail.rs | 1 - .../deposit-contracts/contract/src/entry_points.rs | 3 +-- contracts/deposit-contracts/contract/src/main.rs | 13 +++++++------ .../deposit-contracts/deposit-session/src/main.rs | 2 +- .../deposit-contracts/malicious-reader/src/main.rs | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/contracts/deposit-contracts/contract/src/constants.rs b/contracts/deposit-contracts/contract/src/constants.rs index d8fe779d..19d64b92 100644 --- a/contracts/deposit-contracts/contract/src/constants.rs +++ b/contracts/deposit-contracts/contract/src/constants.rs @@ -1,4 +1,6 @@ pub const KAIROS_DEPOSIT_CONTRACT_NAME: &str = "kairos_deposit_contract"; +// TODO why is this unused? +#[allow(dead_code)] pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "deposit_contract_package"; pub const KAIROS_DEPOSIT_CONTRACT: &str = "deposit_contract"; @@ -8,6 +10,8 @@ pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_ pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; pub const RUNTIME_ARG_TEMP_PURSE: &str = "temp_purse"; +// TODO why is this unused? +#[allow(dead_code)] pub const RUNTIME_ARG_DEST_PURSE: &str = "destination_purse"; pub const RUNTIME_ARG_AMOUNT: &str = "amount"; diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/contracts/deposit-contracts/contract/src/detail.rs index 8654516f..78539d4e 100644 --- a/contracts/deposit-contracts/contract/src/detail.rs +++ b/contracts/deposit-contracts/contract/src/detail.rs @@ -14,7 +14,6 @@ use casper_contract::{ use casper_types::{ api_error, bytesrepr, bytesrepr::FromBytes, system::CallStackElement, ApiError, Key, URef, }; -use core::convert::TryInto; /// Wrap the immediate caller as a Key and return it fn call_stack_element_to_address(call_stack_element: CallStackElement) -> Key { diff --git a/contracts/deposit-contracts/contract/src/entry_points.rs b/contracts/deposit-contracts/contract/src/entry_points.rs index 33ee936b..98dbdeb4 100644 --- a/contracts/deposit-contracts/contract/src/entry_points.rs +++ b/contracts/deposit-contracts/contract/src/entry_points.rs @@ -1,7 +1,6 @@ use crate::constants::{ EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INCR_LAST_PROCESSED_NAME, EP_INIT_NAME, - EP_UPDATE_SECURITY_BADGES_NAME, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_DEST_PURSE, - RUNTIME_ARG_TEMP_PURSE, + EP_UPDATE_SECURITY_BADGES_NAME, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, }; use alloc::vec; use casper_types::{CLType, EntryPoint, EntryPointAccess, EntryPointType, Parameter}; diff --git a/contracts/deposit-contracts/contract/src/main.rs b/contracts/deposit-contracts/contract/src/main.rs index 29b5bb18..75ee066c 100644 --- a/contracts/deposit-contracts/contract/src/main.rs +++ b/contracts/deposit-contracts/contract/src/main.rs @@ -12,10 +12,10 @@ use casper_types::{ }; mod constants; use constants::{ - ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, - KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_EVENT_DICT, KAIROS_DEPOSIT_PURSE, - KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, KAIROS_MOST_RECENT_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, - RUNTIME_ARG_DEST_PURSE, RUNTIME_ARG_TEMP_PURSE, SECURITY_BADGES, + ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_EVENT_DICT, + KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, + KAIROS_MOST_RECENT_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, + SECURITY_BADGES, }; mod detail; use detail::{get_immediate_caller, get_optional_named_arg_with_user_errors}; @@ -175,7 +175,8 @@ pub extern "C" fn update_security_badges() { #[no_mangle] pub extern "C" fn call() { - let caller = Key::from(runtime::get_caller()); + // TODO why is this unused? + let _caller = Key::from(runtime::get_caller()); let admin_list: Option> = get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); @@ -220,7 +221,7 @@ pub extern "C" fn call() { // propagating the list of admin accounts that was passed // to the installation session let mut init_args = runtime_args! {}; - if let Some(mut admin_list) = admin_list { + if let Some(admin_list) = admin_list { init_args.insert(ADMIN_LIST, admin_list).unwrap_or_revert(); } runtime::call_contract::<()>(contract_hash, "init", init_args); diff --git a/contracts/deposit-contracts/deposit-session/src/main.rs b/contracts/deposit-contracts/deposit-session/src/main.rs index 60ff39cf..3052548c 100644 --- a/contracts/deposit-contracts/deposit-session/src/main.rs +++ b/contracts/deposit-contracts/deposit-session/src/main.rs @@ -9,7 +9,7 @@ #![no_std] #![no_main] use casper_contract::contract_api::{account, runtime, system}; -use casper_types::{runtime_args, ApiError, ContractHash, RuntimeArgs, URef, U512}; +use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; #[no_mangle] pub extern "C" fn call() { diff --git a/contracts/deposit-contracts/malicious-reader/src/main.rs b/contracts/deposit-contracts/malicious-reader/src/main.rs index 4311c707..dee773d1 100644 --- a/contracts/deposit-contracts/malicious-reader/src/main.rs +++ b/contracts/deposit-contracts/malicious-reader/src/main.rs @@ -7,7 +7,7 @@ #![no_std] #![no_main] use casper_contract::contract_api::{account, runtime, system}; -use casper_types::{RuntimeArgs, URef, U512}; +use casper_types::{URef, U512}; #[no_mangle] pub extern "C" fn call() { From c512fc24d7e4203e27fcd3467933c76ffeb46768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 28 Mar 2024 16:40:44 -0500 Subject: [PATCH 040/115] kairos-contracts: rename workspace name --- contracts/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index 0e65d0f9..4fdbd815 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -10,7 +10,7 @@ members = [ ] [workspace.package] -name = "contracts" +name = "kairos-contracts" version = "0.1.0" edition = "2021" license = "MIT OR Apache-2.0" From 23d0db28c9ac29674963984bb5021bda7ba00bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Fri, 29 Mar 2024 10:04:40 -0500 Subject: [PATCH 041/115] flake/rust: use latest toolchain --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 777b6bbb..59854660 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,7 @@ perSystem = { config, self', inputs', system, pkgs, lib, ... }: let rustToolchain = with inputs'.fenix.packages; combine [ - complete.toolchain + latest.toolchain targets.wasm32-unknown-unknown.latest.rust-std ]; craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolchain; From 39a0535fcfa33c79cbbd7726beee87a3f7473624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Fri, 29 Mar 2024 11:31:15 -0500 Subject: [PATCH 042/115] rename contracts -> kairos-contracts --- Cargo.toml | 4 ++-- flake.nix | 6 +++--- {contracts => kairos-contracts}/Cargo.lock | 0 {contracts => kairos-contracts}/Cargo.toml | 0 {contracts => kairos-contracts}/build-contracts.sh | 0 {contracts => kairos-contracts}/contract-types/Cargo.toml | 0 {contracts => kairos-contracts}/contract-types/src/lib.rs | 0 .../deposit-contract-tests/Cargo.toml | 0 .../deposit-contract-tests/rust-toolchain.toml | 0 .../deposit-contract-tests/tests/integration_tests.rs | 0 .../deposit-contract-tests/tests/lib.rs | 0 .../deposit-contract-tests/tests/test_fixture/mod.rs | 0 .../deposit-contract-tests/tests/test_fixture/utils/mod.rs | 0 .../deposit-contracts/contract/.cargo/config.toml | 0 .../deposit-contracts/contract/Cargo.toml | 0 .../deposit-contracts/contract/src/constants.rs | 0 .../deposit-contracts/contract/src/detail.rs | 0 .../deposit-contracts/contract/src/entry_points.rs | 0 .../deposit-contracts/contract/src/error.rs | 0 .../deposit-contracts/contract/src/main.rs | 0 .../deposit-contracts/contract/src/security.rs | 0 .../deposit-contracts/deposit-session/Cargo.toml | 0 .../deposit-contracts/deposit-session/src/main.rs | 0 .../deposit-contracts/malicious-reader/Cargo.toml | 0 .../deposit-contracts/malicious-reader/src/main.rs | 0 .../deposit-contracts/malicious-session/Cargo.toml | 0 .../deposit-contracts/malicious-session/src/main.rs | 0 {contracts => kairos-contracts}/rust-toolchain.toml | 0 28 files changed, 5 insertions(+), 5 deletions(-) rename {contracts => kairos-contracts}/Cargo.lock (100%) rename {contracts => kairos-contracts}/Cargo.toml (100%) rename {contracts => kairos-contracts}/build-contracts.sh (100%) rename {contracts => kairos-contracts}/contract-types/Cargo.toml (100%) rename {contracts => kairos-contracts}/contract-types/src/lib.rs (100%) rename {contracts => kairos-contracts}/deposit-contract-tests/Cargo.toml (100%) rename {contracts => kairos-contracts}/deposit-contract-tests/rust-toolchain.toml (100%) rename {contracts => kairos-contracts}/deposit-contract-tests/tests/integration_tests.rs (100%) rename {contracts => kairos-contracts}/deposit-contract-tests/tests/lib.rs (100%) rename {contracts => kairos-contracts}/deposit-contract-tests/tests/test_fixture/mod.rs (100%) rename {contracts => kairos-contracts}/deposit-contract-tests/tests/test_fixture/utils/mod.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/.cargo/config.toml (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/Cargo.toml (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/src/constants.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/src/detail.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/src/entry_points.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/src/error.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/src/main.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/contract/src/security.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/deposit-session/Cargo.toml (100%) rename {contracts => kairos-contracts}/deposit-contracts/deposit-session/src/main.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/malicious-reader/Cargo.toml (100%) rename {contracts => kairos-contracts}/deposit-contracts/malicious-reader/src/main.rs (100%) rename {contracts => kairos-contracts}/deposit-contracts/malicious-session/Cargo.toml (100%) rename {contracts => kairos-contracts}/deposit-contracts/malicious-session/src/main.rs (100%) rename {contracts => kairos-contracts}/rust-toolchain.toml (100%) diff --git a/Cargo.toml b/Cargo.toml index f66b3a12..c123dd75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ members = [ "kairos-server", "kairos-tx", "kairos-test-utils", - "contracts/contract-types", - "contracts/deposit-contract-tests", + "kairos-contracts/contract-types", + "kairos-contracts/deposit-contract-tests", ] [workspace.package] diff --git a/flake.nix b/flake.nix index 4212eeb5..bcd5bde1 100644 --- a/flake.nix +++ b/flake.nix @@ -49,7 +49,7 @@ kairosContractsAttrs = { src = lib.cleanSourceWith { - src = craneLib.path ./contracts; + src = craneLib.path ./kairos-contracts; filter = path: type: craneLib.filterCargoSources path type; }; cargoExtraArgs = "--target wasm32-unknown-unknown"; @@ -76,8 +76,8 @@ filter = path: type: # Allow static files. (lib.hasInfix "/fixtures/" path) || - # ignore the contracts directory - !(lib.hasInfix "contracts/" path) || + # ignore the kairos-contracts directory + !(lib.hasInfix "kairos-contracts/" path) || # Default filter (from crane) for .rs files. (craneLib.filterCargoSources path type) ; diff --git a/contracts/Cargo.lock b/kairos-contracts/Cargo.lock similarity index 100% rename from contracts/Cargo.lock rename to kairos-contracts/Cargo.lock diff --git a/contracts/Cargo.toml b/kairos-contracts/Cargo.toml similarity index 100% rename from contracts/Cargo.toml rename to kairos-contracts/Cargo.toml diff --git a/contracts/build-contracts.sh b/kairos-contracts/build-contracts.sh similarity index 100% rename from contracts/build-contracts.sh rename to kairos-contracts/build-contracts.sh diff --git a/contracts/contract-types/Cargo.toml b/kairos-contracts/contract-types/Cargo.toml similarity index 100% rename from contracts/contract-types/Cargo.toml rename to kairos-contracts/contract-types/Cargo.toml diff --git a/contracts/contract-types/src/lib.rs b/kairos-contracts/contract-types/src/lib.rs similarity index 100% rename from contracts/contract-types/src/lib.rs rename to kairos-contracts/contract-types/src/lib.rs diff --git a/contracts/deposit-contract-tests/Cargo.toml b/kairos-contracts/deposit-contract-tests/Cargo.toml similarity index 100% rename from contracts/deposit-contract-tests/Cargo.toml rename to kairos-contracts/deposit-contract-tests/Cargo.toml diff --git a/contracts/deposit-contract-tests/rust-toolchain.toml b/kairos-contracts/deposit-contract-tests/rust-toolchain.toml similarity index 100% rename from contracts/deposit-contract-tests/rust-toolchain.toml rename to kairos-contracts/deposit-contract-tests/rust-toolchain.toml diff --git a/contracts/deposit-contract-tests/tests/integration_tests.rs b/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs similarity index 100% rename from contracts/deposit-contract-tests/tests/integration_tests.rs rename to kairos-contracts/deposit-contract-tests/tests/integration_tests.rs diff --git a/contracts/deposit-contract-tests/tests/lib.rs b/kairos-contracts/deposit-contract-tests/tests/lib.rs similarity index 100% rename from contracts/deposit-contract-tests/tests/lib.rs rename to kairos-contracts/deposit-contract-tests/tests/lib.rs diff --git a/contracts/deposit-contract-tests/tests/test_fixture/mod.rs b/kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs similarity index 100% rename from contracts/deposit-contract-tests/tests/test_fixture/mod.rs rename to kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs diff --git a/contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs b/kairos-contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs similarity index 100% rename from contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs rename to kairos-contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs diff --git a/contracts/deposit-contracts/contract/.cargo/config.toml b/kairos-contracts/deposit-contracts/contract/.cargo/config.toml similarity index 100% rename from contracts/deposit-contracts/contract/.cargo/config.toml rename to kairos-contracts/deposit-contracts/contract/.cargo/config.toml diff --git a/contracts/deposit-contracts/contract/Cargo.toml b/kairos-contracts/deposit-contracts/contract/Cargo.toml similarity index 100% rename from contracts/deposit-contracts/contract/Cargo.toml rename to kairos-contracts/deposit-contracts/contract/Cargo.toml diff --git a/contracts/deposit-contracts/contract/src/constants.rs b/kairos-contracts/deposit-contracts/contract/src/constants.rs similarity index 100% rename from contracts/deposit-contracts/contract/src/constants.rs rename to kairos-contracts/deposit-contracts/contract/src/constants.rs diff --git a/contracts/deposit-contracts/contract/src/detail.rs b/kairos-contracts/deposit-contracts/contract/src/detail.rs similarity index 100% rename from contracts/deposit-contracts/contract/src/detail.rs rename to kairos-contracts/deposit-contracts/contract/src/detail.rs diff --git a/contracts/deposit-contracts/contract/src/entry_points.rs b/kairos-contracts/deposit-contracts/contract/src/entry_points.rs similarity index 100% rename from contracts/deposit-contracts/contract/src/entry_points.rs rename to kairos-contracts/deposit-contracts/contract/src/entry_points.rs diff --git a/contracts/deposit-contracts/contract/src/error.rs b/kairos-contracts/deposit-contracts/contract/src/error.rs similarity index 100% rename from contracts/deposit-contracts/contract/src/error.rs rename to kairos-contracts/deposit-contracts/contract/src/error.rs diff --git a/contracts/deposit-contracts/contract/src/main.rs b/kairos-contracts/deposit-contracts/contract/src/main.rs similarity index 100% rename from contracts/deposit-contracts/contract/src/main.rs rename to kairos-contracts/deposit-contracts/contract/src/main.rs diff --git a/contracts/deposit-contracts/contract/src/security.rs b/kairos-contracts/deposit-contracts/contract/src/security.rs similarity index 100% rename from contracts/deposit-contracts/contract/src/security.rs rename to kairos-contracts/deposit-contracts/contract/src/security.rs diff --git a/contracts/deposit-contracts/deposit-session/Cargo.toml b/kairos-contracts/deposit-contracts/deposit-session/Cargo.toml similarity index 100% rename from contracts/deposit-contracts/deposit-session/Cargo.toml rename to kairos-contracts/deposit-contracts/deposit-session/Cargo.toml diff --git a/contracts/deposit-contracts/deposit-session/src/main.rs b/kairos-contracts/deposit-contracts/deposit-session/src/main.rs similarity index 100% rename from contracts/deposit-contracts/deposit-session/src/main.rs rename to kairos-contracts/deposit-contracts/deposit-session/src/main.rs diff --git a/contracts/deposit-contracts/malicious-reader/Cargo.toml b/kairos-contracts/deposit-contracts/malicious-reader/Cargo.toml similarity index 100% rename from contracts/deposit-contracts/malicious-reader/Cargo.toml rename to kairos-contracts/deposit-contracts/malicious-reader/Cargo.toml diff --git a/contracts/deposit-contracts/malicious-reader/src/main.rs b/kairos-contracts/deposit-contracts/malicious-reader/src/main.rs similarity index 100% rename from contracts/deposit-contracts/malicious-reader/src/main.rs rename to kairos-contracts/deposit-contracts/malicious-reader/src/main.rs diff --git a/contracts/deposit-contracts/malicious-session/Cargo.toml b/kairos-contracts/deposit-contracts/malicious-session/Cargo.toml similarity index 100% rename from contracts/deposit-contracts/malicious-session/Cargo.toml rename to kairos-contracts/deposit-contracts/malicious-session/Cargo.toml diff --git a/contracts/deposit-contracts/malicious-session/src/main.rs b/kairos-contracts/deposit-contracts/malicious-session/src/main.rs similarity index 100% rename from contracts/deposit-contracts/malicious-session/src/main.rs rename to kairos-contracts/deposit-contracts/malicious-session/src/main.rs diff --git a/contracts/rust-toolchain.toml b/kairos-contracts/rust-toolchain.toml similarity index 100% rename from contracts/rust-toolchain.toml rename to kairos-contracts/rust-toolchain.toml From 83032479455e44883bdcfc748b09dd5798bd91c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Fri, 29 Mar 2024 11:40:38 -0500 Subject: [PATCH 043/115] kairos-test-utils: fix lint error --- kairos-test-utils/src/cctl.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kairos-test-utils/src/cctl.rs b/kairos-test-utils/src/cctl.rs index 1a821e59..fe0b36e2 100644 --- a/kairos-test-utils/src/cctl.rs +++ b/kairos-test-utils/src/cctl.rs @@ -1,6 +1,6 @@ pub mod parsers; use anyhow::anyhow; -use backoff::{self, backoff::Constant, future::retry}; +use backoff::{backoff::Constant, future::retry}; use casper_client::{get_node_status, rpcs::results::ReactorState, Error, JsonRpcId, Verbosity}; use std::io::{self, Write}; use std::path::PathBuf; @@ -133,7 +133,6 @@ impl Drop for CCTLNetwork { #[cfg(test)] mod tests { use super::*; - use casper_client::{get_node_status, rpcs::results::ReactorState, JsonRpcId, Verbosity}; #[tokio::test] async fn test_cctl_network_starts_and_terminates() { let network = CCTLNetwork::run().await.unwrap(); From ac334b06394ce42542e9bda2329539d7fa4745c9 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Mon, 1 Apr 2024 00:10:48 +0200 Subject: [PATCH 044/115] propagate optional argument errors in utils.rs --- .gitignore | 2 +- kairos-contracts/deposit-contracts/contract/src/main.rs | 4 ++-- kairos-contracts/deposit-contracts/contract/src/security.rs | 2 +- .../deposit-contracts/contract/src/{detail.rs => utils.rs} | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) rename kairos-contracts/deposit-contracts/contract/src/{detail.rs => utils.rs} (96%) diff --git a/.gitignore b/.gitignore index 30896c03..e4383a5f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ result target .tmp .nixos-test-history -contracts/deposit-contract-tests/.env \ No newline at end of file +.env diff --git a/kairos-contracts/deposit-contracts/contract/src/main.rs b/kairos-contracts/deposit-contracts/contract/src/main.rs index 75ee066c..d8f18b1f 100644 --- a/kairos-contracts/deposit-contracts/contract/src/main.rs +++ b/kairos-contracts/deposit-contracts/contract/src/main.rs @@ -17,8 +17,8 @@ use constants::{ KAIROS_MOST_RECENT_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, SECURITY_BADGES, }; -mod detail; -use detail::{get_immediate_caller, get_optional_named_arg_with_user_errors}; +mod utils; +use utils::{get_immediate_caller, get_optional_named_arg_with_user_errors}; mod error; use error::DepositError; mod security; diff --git a/kairos-contracts/deposit-contracts/contract/src/security.rs b/kairos-contracts/deposit-contracts/contract/src/security.rs index 08562d16..b99b5eee 100644 --- a/kairos-contracts/deposit-contracts/contract/src/security.rs +++ b/kairos-contracts/deposit-contracts/contract/src/security.rs @@ -2,8 +2,8 @@ use alloc::{collections::BTreeMap, vec, vec::Vec}; use crate::{ constants::SECURITY_BADGES, - detail::{get_immediate_caller, get_uref}, error::DepositError, + utils::{get_immediate_caller, get_uref}, }; #[allow(unused_imports)] use casper_contract::{ diff --git a/kairos-contracts/deposit-contracts/contract/src/detail.rs b/kairos-contracts/deposit-contracts/contract/src/utils.rs similarity index 96% rename from kairos-contracts/deposit-contracts/contract/src/detail.rs rename to kairos-contracts/deposit-contracts/contract/src/utils.rs index 78539d4e..02370555 100644 --- a/kairos-contracts/deposit-contracts/contract/src/detail.rs +++ b/kairos-contracts/deposit-contracts/contract/src/utils.rs @@ -74,7 +74,10 @@ pub fn get_optional_named_arg_with_user_errors( let maybe_named_arg_with_user_errors = get_named_arg_with_user_errors::(name, invalid); match maybe_named_arg_with_user_errors { Ok(val) => Some(val), - Err(_) => None, + Err(err) => match err { + DepositError::MissingOptionalArgument => None, + _ => runtime::revert(err), + }, } } From d8c908d69927d795fe6e67675a0d115f9fd70bc1 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Mon, 1 Apr 2024 00:20:10 +0200 Subject: [PATCH 045/115] improve comments in main.rs & remove unused variable --- .../deposit-contracts/contract/src/main.rs | 33 ++++++++++--------- .../deposit-contracts/contract/src/utils.rs | 2 -- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/kairos-contracts/deposit-contracts/contract/src/main.rs b/kairos-contracts/deposit-contracts/contract/src/main.rs index d8f18b1f..4f0e3c79 100644 --- a/kairos-contracts/deposit-contracts/contract/src/main.rs +++ b/kairos-contracts/deposit-contracts/contract/src/main.rs @@ -29,9 +29,10 @@ use contract_types::Deposit; // This entry point is called once when the contract is installed // and sets up the security badges with the installer as an admin or the -// optional list of admins that was passed to the installation session as a runtime argument. +// optional list of admins. +// The optional list of admins is passed to the installation session as a runtime argument. // The contract purse will be created in contract context so that it is "owned" by the contract -// instead of the installing account. +// rather than the installing account. #[no_mangle] pub extern "C" fn init() { if runtime::get_key(KAIROS_DEPOSIT_PURSE).is_some() { @@ -40,9 +41,11 @@ pub extern "C" fn init() { let security_badges_dict = storage::new_dictionary(SECURITY_BADGES) .unwrap_or_revert_with(DepositError::FailedToCreateSecurityBadgesDict); let installing_entity = runtime::get_caller(); + // Assign the admin role to the installer, regardless of the list of admins that was - // passed to the installation session. The installer is by default an admin and - // this admin access needs to be revoked after the initialization if it is not wanted. + // passed to the installation session. + // The installer is by default an admin and the installer's admin role + // needs to be revoked after the initialization if it is not wanted. storage::dictionary_put( security_badges_dict, &base64::encode(Key::from(installing_entity).to_bytes().unwrap_or_revert()), @@ -80,7 +83,7 @@ pub extern "C" fn get_purse() { // Entry point called by a user through session code to deposit funds. // Due to Casper < 2.0 purse management and access control, it is necessary that -// a temporary purse is funded and passed to the deposit contract since this is +// a temporary purse is funded and passed to the deposit contract, since this is // the only secure method of making a payment to a contract purse. #[no_mangle] pub extern "C" fn deposit() { @@ -150,7 +153,7 @@ pub extern "C" fn incr_last_processed_deposit_counter() { } // Update the security badge for one or multiple accounts -// This entry point is used to assign and revoke rolse such +// This entry point is used to assign and revoke roles such // as the "Admin" role. #[no_mangle] pub extern "C" fn update_security_badges() { @@ -164,10 +167,11 @@ pub extern "C" fn update_security_badges() { badge_map.insert(account_key, Some(SecurityBadge::Admin)); } } - // remove the caller from the admin list, - // by inserting None as the security badge - // accounts with no security badge will not be considered part of a badge group - // and therefore loose the ability to call EPs that call `access_control_check(vec![SecurityBadge::Admin]);` o.e. + // Remove the caller from the admin list, + // by inserting None as the security badge. + // Accounts with no security badge will not be considered part of a badge group + // and therefore loose the ability to call EPs that contain + // `access_control_check(vec![SecurityBadge::Admin]);` o.e. let caller = get_immediate_caller().unwrap_or_revert(); badge_map.insert(caller, None); security::update_security_badges(&badge_map); @@ -175,9 +179,6 @@ pub extern "C" fn update_security_badges() { #[no_mangle] pub extern "C" fn call() { - // TODO why is this unused? - let _caller = Key::from(runtime::get_caller()); - let admin_list: Option> = get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); @@ -217,9 +218,9 @@ pub extern "C" fn call() { let contract_hash_key = Key::from(contract_hash); runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); - // prepare runtime arguments for contract initialization, - // propagating the list of admin accounts that was passed - // to the installation session + // Prepare runtime arguments for contract initialization, + // passing the list of admin accounts that was passed + // to the installation session. let mut init_args = runtime_args! {}; if let Some(admin_list) = admin_list { init_args.insert(ADMIN_LIST, admin_list).unwrap_or_revert(); diff --git a/kairos-contracts/deposit-contracts/contract/src/utils.rs b/kairos-contracts/deposit-contracts/contract/src/utils.rs index 02370555..b80ef455 100644 --- a/kairos-contracts/deposit-contracts/contract/src/utils.rs +++ b/kairos-contracts/deposit-contracts/contract/src/utils.rs @@ -85,11 +85,9 @@ pub fn get_optional_named_arg_with_user_errors( /// install the deposit contract without passing a list of /// admins. In such a case the default admin will be the installing /// account. -/// /// This function checks if the runtime argument size is greater than 0 /// and if that is the case it gets parsed and returned. Should the parsing /// fail or should the user not supply the argument at all, then an error is propagated. -/// /// To install the contract without an admin list, one still needs to pass an empty admins /// list as a runtime argument. Otherwise the missing error will be propagated. pub fn get_named_arg_with_user_errors( From b44b3ae3ec565072969448f2c6c8ef7b121e0f71 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:02:15 +0200 Subject: [PATCH 046/115] additional test cases, CES deposit event --- Cargo.lock | 8 --- Cargo.toml | 1 - kairos-contracts/Cargo.lock | 36 +++++++++---- kairos-contracts/Cargo.toml | 1 - kairos-contracts/contract-types/Cargo.toml | 9 ---- kairos-contracts/contract-types/src/lib.rs | 15 ------ .../tests/integration_tests.rs | 27 +++++++++- .../tests/test_fixture/mod.rs | 54 +++++++++++++++++-- .../deposit-contracts/contract/Cargo.toml | 4 +- .../contract/src/constants.rs | 2 - .../deposit-contracts/contract/src/events.rs | 11 ++++ .../deposit-contracts/contract/src/main.rs | 54 +++++-------------- 12 files changed, 125 insertions(+), 97 deletions(-) delete mode 100644 kairos-contracts/contract-types/Cargo.toml delete mode 100644 kairos-contracts/contract-types/src/lib.rs create mode 100644 kairos-contracts/deposit-contracts/contract/src/events.rs diff --git a/Cargo.lock b/Cargo.lock index 70f97a39..2b99d664 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -811,14 +811,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6051f239ecec86fde3410901ab7860d458d160371533842974fc61f96d15879b" -[[package]] -name = "contract-types" -version = "0.1.0" -dependencies = [ - "casper-types 4.0.1", - "serde", -] - [[package]] name = "cookie" version = "0.18.0" diff --git a/Cargo.toml b/Cargo.toml index c123dd75..22c6519c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ members = [ "kairos-server", "kairos-tx", "kairos-test-utils", - "kairos-contracts/contract-types", "kairos-contracts/deposit-contract-tests", ] diff --git a/kairos-contracts/Cargo.lock b/kairos-contracts/Cargo.lock index 2297b6aa..a6eb1a6d 100644 --- a/kairos-contracts/Cargo.lock +++ b/kairos-contracts/Cargo.lock @@ -90,6 +90,28 @@ dependencies = [ "wee_alloc", ] +[[package]] +name = "casper-event-standard" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3a1bdb142b4bfcdceec757422b2e292f446b72ce3613f881eb694f3925ef10" +dependencies = [ + "casper-contract", + "casper-event-standard-macro", + "casper-types", +] + +[[package]] +name = "casper-event-standard-macro" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "485810e6c8387863a92e9b81e4e66ce290e2c96c0ad8ec4352e95128aa88900e" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "casper-types" version = "4.0.1" @@ -141,16 +163,8 @@ dependencies = [ "base64 0.20.0", "bincode", "casper-contract", + "casper-event-standard", "casper-types", - "contract-types", -] - -[[package]] -name = "contract-types" -version = "0.1.0" -dependencies = [ - "casper-types", - "serde", ] [[package]] @@ -691,9 +705,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" diff --git a/kairos-contracts/Cargo.toml b/kairos-contracts/Cargo.toml index 4fdbd815..4250f8b8 100644 --- a/kairos-contracts/Cargo.toml +++ b/kairos-contracts/Cargo.toml @@ -6,7 +6,6 @@ members = [ "deposit-contracts/malicious-session", "deposit-contracts/deposit-session", "deposit-contracts/contract", - "contract-types", ] [workspace.package] diff --git a/kairos-contracts/contract-types/Cargo.toml b/kairos-contracts/contract-types/Cargo.toml deleted file mode 100644 index 895da2bd..00000000 --- a/kairos-contracts/contract-types/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "contract-types" -version.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -serde = "1" -casper-types = {version="4.0.0", default-features=false} \ No newline at end of file diff --git a/kairos-contracts/contract-types/src/lib.rs b/kairos-contracts/contract-types/src/lib.rs deleted file mode 100644 index 6fc50b1f..00000000 --- a/kairos-contracts/contract-types/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -/* - The deposit contract requires a Casper-typed Deposit struct. - We can either keep this contract-types crate or move the deposit struct elsewhere. -*/ - -use casper_types::{Key, U512}; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] -pub struct Deposit { - pub account: Key, - pub amount: U512, - pub timestamp: Option, - pub processed: bool, -} diff --git a/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs b/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs index 735a5418..f652a076 100644 --- a/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs +++ b/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs @@ -44,14 +44,37 @@ mod tests { fixture.install_deposit_contract(init_admin); // try to update the admin list let new_admin_list: Vec = vec![Key::from(new_admin)]; - fixture.update_security_badges(new_admin_list.clone(), init_admin, init_admin); + fixture.update_security_badges_as_admin(new_admin_list.clone(), init_admin, init_admin); // update the admin list as the new_admin - fixture.update_security_badges(new_admin_list, new_admin, init_admin); + fixture.update_security_badges_as_admin(new_admin_list, new_admin, init_admin); // now remove the admin role from the installer and expect failure. let new_admin_list: Vec = vec![]; fixture.unauthorized_update_security_badges(new_admin_list.clone(), init_admin, init_admin); } + #[test] + fn admin_should_increase_last_processed_counter() { + let (mut fixture, installer, user) = setup(); + fixture.install_deposit_contract(installer); + + let value_before: u64 = + fixture.read_counter_value(installer, "last_processed_deposit_counter"); + assert_eq!(value_before, 0u64); + + fixture.admin_increase_last_processed_counter(installer, installer); + let value_after: u64 = + fixture.read_counter_value(installer, "last_processed_deposit_counter"); + assert_eq!(value_after, 1u64); + } + + #[test] + fn unauthorized_should_not_increase_last_processed_counter() { + let (mut fixture, installer, unauthorized_user) = setup(); + fixture.install_deposit_contract(installer); + + fixture.unauthorized_increase_last_processed_counter(unauthorized_user, installer); + } + // see malicious-session #[test] fn run_malicious_session() { diff --git a/kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs b/kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs index bbfa5b20..fa876c57 100644 --- a/kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs +++ b/kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs @@ -56,7 +56,7 @@ impl TestContext { .clone() } - pub fn contract_named_keys( + pub fn get_contract_named_key( &self, contract_name: &str, key_name: &str, @@ -115,7 +115,7 @@ impl TestContext { pub fn get_contract_purse_uref(&self, account: AccountHash) -> URef { let seed_uref: URef = *self - .contract_named_keys("kairos_deposit_contract", "kairos_deposit_purse", account) + .get_contract_named_key("kairos_deposit_contract", "kairos_deposit_purse", account) .as_uref() .unwrap(); seed_uref @@ -128,14 +128,60 @@ impl TestContext { #[allow(dead_code)] pub fn get_contract_purse_balance(&self, account: AccountHash) -> U512 { let contract_purse_uref: URef = *self - .contract_named_keys("kairos_deposit_contract", "kairos_deposit_purse", account) + .get_contract_named_key("kairos_deposit_contract", "kairos_deposit_purse", account) .as_uref() .unwrap(); self.builder.get_purse_balance(contract_purse_uref) } + // read a u64 counter from the contract named keys e.g. "last_processed_deposit_counter" + pub fn read_counter_value(&mut self, account: AccountHash, name: &str) -> u64 { + let contract_hash = self.contract_hash("kairos_deposit_contract", account); + self.builder.get_value(contract_hash, name) + } + + // call the contract as admin to increase the last processed deposit counter value by 1 + pub fn admin_increase_last_processed_counter( + &mut self, + caller: AccountHash, + installer: AccountHash, + ) { + let session_args = runtime_args! {}; + let update_counter_request = ExecuteRequestBuilder::contract_call_by_hash( + caller, + self.contract_hash("kairos_deposit_contract", installer), + "incr_last_processed_deposit_counter", + session_args, + ) + .build(); + self.builder + .exec(update_counter_request) + .expect_success() + .commit(); + } + + // an unauthorized attempt of changing the last processed counter + pub fn unauthorized_increase_last_processed_counter( + &mut self, + caller: AccountHash, + installer: AccountHash, + ) { + let session_args = runtime_args! {}; + let update_counter_request = ExecuteRequestBuilder::contract_call_by_hash( + caller, + self.contract_hash("kairos_deposit_contract", installer), + "incr_last_processed_deposit_counter", + session_args, + ) + .build(); + self.builder + .exec(update_counter_request) + .expect_failure() + .commit(); + } + // try to update the access control / admin list of the deposit contract - pub fn update_security_badges( + pub fn update_security_badges_as_admin( &mut self, admin_list: Vec, caller: AccountHash, diff --git a/kairos-contracts/deposit-contracts/contract/Cargo.toml b/kairos-contracts/deposit-contracts/contract/Cargo.toml index 4b02cea2..2d7d7c19 100644 --- a/kairos-contracts/deposit-contracts/contract/Cargo.toml +++ b/kairos-contracts/deposit-contracts/contract/Cargo.toml @@ -7,8 +7,8 @@ license.workspace = true [dependencies] casper-contract = {version="4.0.0", features=["std", "test-support"]} casper-types = {version="4.0.0", default-features=false} +casper-event-standard="0.5.0" base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } -contract-types = {path="../../contract-types"} bincode = "1.3.3" @@ -24,4 +24,4 @@ test = false [profile.release] codegen-units = 1 -lto = true \ No newline at end of file +lto = true diff --git a/kairos-contracts/deposit-contracts/contract/src/constants.rs b/kairos-contracts/deposit-contracts/contract/src/constants.rs index 19d64b92..588523c3 100644 --- a/kairos-contracts/deposit-contracts/contract/src/constants.rs +++ b/kairos-contracts/deposit-contracts/contract/src/constants.rs @@ -4,8 +4,6 @@ pub const KAIROS_DEPOSIT_CONTRACT_NAME: &str = "kairos_deposit_contract"; pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "deposit_contract_package"; pub const KAIROS_DEPOSIT_CONTRACT: &str = "deposit_contract"; -pub const KAIROS_DEPOSIT_EVENT_DICT: &str = "kairos_deposit_event_dict"; -pub const KAIROS_MOST_RECENT_DEPOSIT_COUNTER: &str = "most_recent_deposit_counter"; pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_counter"; pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; diff --git a/kairos-contracts/deposit-contracts/contract/src/events.rs b/kairos-contracts/deposit-contracts/contract/src/events.rs new file mode 100644 index 00000000..4ce06cdc --- /dev/null +++ b/kairos-contracts/deposit-contracts/contract/src/events.rs @@ -0,0 +1,11 @@ +use casper_event_standard::Event; +extern crate alloc; +use alloc::{string::String, vec::Vec}; +use casper_types::{Key, U512}; + +#[derive(Event)] +pub struct Deposit { + pub account: Key, + pub amount: U512, + pub timestamp: Option, +} diff --git a/kairos-contracts/deposit-contracts/contract/src/main.rs b/kairos-contracts/deposit-contracts/contract/src/main.rs index 4f0e3c79..03e84ee8 100644 --- a/kairos-contracts/deposit-contracts/contract/src/main.rs +++ b/kairos-contracts/deposit-contracts/contract/src/main.rs @@ -12,9 +12,8 @@ use casper_types::{ }; mod constants; use constants::{ - ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_EVENT_DICT, - KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, - KAIROS_MOST_RECENT_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, + ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_PURSE, + KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, SECURITY_BADGES, }; mod utils; @@ -24,8 +23,10 @@ use error::DepositError; mod security; use security::{access_control_check, SecurityBadge}; mod entry_points; - -use contract_types::Deposit; +mod events; +use casper_event_standard; +use casper_event_standard::Schemas; +use events::Deposit; // This entry point is called once when the contract is installed // and sets up the security badges with the installer as an admin or the @@ -42,6 +43,10 @@ pub extern "C" fn init() { .unwrap_or_revert_with(DepositError::FailedToCreateSecurityBadgesDict); let installing_entity = runtime::get_caller(); + // initialize event schema + let schemas = Schemas::new().with::(); + casper_event_standard::init(schemas); + // Assign the admin role to the installer, regardless of the list of admins that was // passed to the installation session. // The installer is by default an admin and the installer's admin role @@ -96,38 +101,12 @@ pub extern "C" fn deposit() { system::transfer_from_purse_to_purse(temp_purse, deposit_purse_uref, amount, None) .unwrap_or_revert(); - let most_recent_deposit_counter_uref = runtime::get_key(KAIROS_MOST_RECENT_DEPOSIT_COUNTER) - .unwrap_or_revert_with(DepositError::MissingKeyMostRecentDepositCounter) - .into_uref() - .unwrap_or_revert(); - let mut most_recent_deposit_counter_value: u64 = - storage::read(most_recent_deposit_counter_uref) - .unwrap_or_revert() - .unwrap_or_revert(); let new_deposit_record: Deposit = Deposit { account: get_immediate_caller().unwrap_or_revert(), - amount, + amount: amount, timestamp: None, - processed: false, }; - - let deposit_event_dict_key: &str = &most_recent_deposit_counter_value.to_string(); - - let kairos_deposit_event_dict_uref = runtime::get_key(KAIROS_DEPOSIT_EVENT_DICT) - .unwrap_or_revert_with(DepositError::MissingKeyDepositEventDict) - .into_uref() - .unwrap_or_revert(); - storage::dictionary_put::>( - kairos_deposit_event_dict_uref, - deposit_event_dict_key, - bincode::serialize(&new_deposit_record).unwrap(), - ); - - most_recent_deposit_counter_value += 1u64; - storage::write( - most_recent_deposit_counter_uref, - most_recent_deposit_counter_value, - ); + casper_event_standard::emit(new_deposit_record); } // The centralized Kairos service, or a sequencer, @@ -192,9 +171,6 @@ pub extern "C" fn call() { entry_points }; let mut named_keys = NamedKeys::new(); - let event_dict = storage::new_dictionary(KAIROS_DEPOSIT_EVENT_DICT) - .unwrap_or_revert_with(DepositError::FailedToCreateDepositDict); - named_keys.insert(KAIROS_DEPOSIT_EVENT_DICT.to_string(), event_dict.into()); let last_processed_deposit_counter = storage::new_uref(u64::from(0u8)); named_keys.insert( @@ -202,12 +178,6 @@ pub extern "C" fn call() { last_processed_deposit_counter.into(), ); - let most_recent_deposit_counter = storage::new_uref(u64::from(0u8)); - named_keys.insert( - KAIROS_MOST_RECENT_DEPOSIT_COUNTER.to_string(), - most_recent_deposit_counter.into(), - ); - let (contract_hash, _) = storage::new_contract( entry_points, Some(named_keys), From 61471cc8073bc67028f742f158ae94a7fda3fd61 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:17:34 +0200 Subject: [PATCH 047/115] create a locked contract and store contract package in installer named keys --- .../deposit-contracts/contract/src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kairos-contracts/deposit-contracts/contract/src/main.rs b/kairos-contracts/deposit-contracts/contract/src/main.rs index 03e84ee8..6fbdaf93 100644 --- a/kairos-contracts/deposit-contracts/contract/src/main.rs +++ b/kairos-contracts/deposit-contracts/contract/src/main.rs @@ -12,9 +12,9 @@ use casper_types::{ }; mod constants; use constants::{ - ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_PURSE, - KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, - SECURITY_BADGES, + ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, + KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, + RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, SECURITY_BADGES, }; mod utils; use utils::{get_immediate_caller, get_optional_named_arg_with_user_errors}; @@ -178,12 +178,11 @@ pub extern "C" fn call() { last_processed_deposit_counter.into(), ); - let (contract_hash, _) = storage::new_contract( + let (contract_hash, _) = storage::new_locked_contract( entry_points, Some(named_keys), Some(KAIROS_DEPOSIT_CONTRACT.to_string()), - // Some(key) if upgradable - None, + Some(KAIROS_DEPOSIT_CONTRACT_PACKAGE.to_string()), ); let contract_hash_key = Key::from(contract_hash); runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); From 73fef22426767994c075d1c0478705a2d37ec419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Fri, 5 Apr 2024 10:57:30 -0500 Subject: [PATCH 048/115] fix linter warnings --- .../deposit-contract-tests/tests/integration_tests.rs | 2 +- kairos-contracts/deposit-contracts/contract/src/events.rs | 2 +- kairos-contracts/deposit-contracts/contract/src/main.rs | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs b/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs index f652a076..39d92e78 100644 --- a/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs +++ b/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs @@ -54,7 +54,7 @@ mod tests { #[test] fn admin_should_increase_last_processed_counter() { - let (mut fixture, installer, user) = setup(); + let (mut fixture, installer, _user) = setup(); fixture.install_deposit_contract(installer); let value_before: u64 = diff --git a/kairos-contracts/deposit-contracts/contract/src/events.rs b/kairos-contracts/deposit-contracts/contract/src/events.rs index 4ce06cdc..980b7b14 100644 --- a/kairos-contracts/deposit-contracts/contract/src/events.rs +++ b/kairos-contracts/deposit-contracts/contract/src/events.rs @@ -1,6 +1,6 @@ use casper_event_standard::Event; extern crate alloc; -use alloc::{string::String, vec::Vec}; +use alloc::string::String; use casper_types::{Key, U512}; #[derive(Event)] diff --git a/kairos-contracts/deposit-contracts/contract/src/main.rs b/kairos-contracts/deposit-contracts/contract/src/main.rs index 6fbdaf93..7375f0ac 100644 --- a/kairos-contracts/deposit-contracts/contract/src/main.rs +++ b/kairos-contracts/deposit-contracts/contract/src/main.rs @@ -24,7 +24,6 @@ mod security; use security::{access_control_check, SecurityBadge}; mod entry_points; mod events; -use casper_event_standard; use casper_event_standard::Schemas; use events::Deposit; @@ -103,7 +102,7 @@ pub extern "C" fn deposit() { let new_deposit_record: Deposit = Deposit { account: get_immediate_caller().unwrap_or_revert(), - amount: amount, + amount, timestamp: None, }; casper_event_standard::emit(new_deposit_record); From ba4e5806c5e9362b289b90537995ed95edd81ac4 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:09:50 +0200 Subject: [PATCH 049/115] remove access control -> self governance and mono contract design for demo --- Cargo.lock | 2 +- Cargo.toml | 2 +- flake.nix | 2 - kairos-contracts/Cargo.toml | 8 +- kairos-contracts/build-contracts.sh | 14 -- .../Cargo.toml | 2 +- .../rust-toolchain.toml | 0 .../tests/integration_tests.rs | 45 +--- .../tests/lib.rs | 0 .../tests/test_fixture/mod.rs | 106 +--------- .../tests/test_fixture/utils/mod.rs | 0 .../contract/.cargo/config.toml | 0 .../contract/Cargo.toml | 2 +- .../demo-contract/contract/src/constants.rs | 17 ++ .../contract/src/entry_points.rs | 23 +- .../demo-contract/contract/src/main.rs | 118 +++++++++++ .../demo-contract/contract/src/utils.rs | 38 ++++ .../contract/src/utils/errors.rs | 24 +++ .../contract/src/utils}/events.rs | 0 .../deposit-session/Cargo.toml | 0 .../deposit-session/src/main.rs | 2 +- .../malicious-reader/Cargo.toml | 0 .../malicious-reader/src/main.rs | 0 .../malicious-session/Cargo.toml | 0 .../malicious-session/src/main.rs | 2 +- .../contract/src/constants.rs | 23 -- .../deposit-contracts/contract/src/error.rs | 28 --- .../deposit-contracts/contract/src/main.rs | 197 ------------------ .../contract/src/security.rs | 90 -------- .../deposit-contracts/contract/src/utils.rs | 120 ----------- 30 files changed, 222 insertions(+), 643 deletions(-) delete mode 100755 kairos-contracts/build-contracts.sh rename kairos-contracts/{deposit-contract-tests => demo-contract-tests}/Cargo.toml (94%) rename kairos-contracts/{deposit-contract-tests => demo-contract-tests}/rust-toolchain.toml (100%) rename kairos-contracts/{deposit-contract-tests => demo-contract-tests}/tests/integration_tests.rs (53%) rename kairos-contracts/{deposit-contract-tests => demo-contract-tests}/tests/lib.rs (100%) rename kairos-contracts/{deposit-contract-tests => demo-contract-tests}/tests/test_fixture/mod.rs (62%) rename kairos-contracts/{deposit-contract-tests => demo-contract-tests}/tests/test_fixture/utils/mod.rs (100%) rename kairos-contracts/{deposit-contracts => demo-contract}/contract/.cargo/config.toml (100%) rename kairos-contracts/{deposit-contracts => demo-contract}/contract/Cargo.toml (95%) create mode 100644 kairos-contracts/demo-contract/contract/src/constants.rs rename kairos-contracts/{deposit-contracts => demo-contract}/contract/src/entry_points.rs (57%) create mode 100644 kairos-contracts/demo-contract/contract/src/main.rs create mode 100644 kairos-contracts/demo-contract/contract/src/utils.rs create mode 100644 kairos-contracts/demo-contract/contract/src/utils/errors.rs rename kairos-contracts/{deposit-contracts/contract/src => demo-contract/contract/src/utils}/events.rs (100%) rename kairos-contracts/{deposit-contracts => demo-contract}/deposit-session/Cargo.toml (100%) rename kairos-contracts/{deposit-contracts => demo-contract}/deposit-session/src/main.rs (98%) rename kairos-contracts/{deposit-contracts => demo-contract}/malicious-reader/Cargo.toml (100%) rename kairos-contracts/{deposit-contracts => demo-contract}/malicious-reader/src/main.rs (100%) rename kairos-contracts/{deposit-contracts => demo-contract}/malicious-session/Cargo.toml (100%) rename kairos-contracts/{deposit-contracts => demo-contract}/malicious-session/src/main.rs (97%) delete mode 100644 kairos-contracts/deposit-contracts/contract/src/constants.rs delete mode 100644 kairos-contracts/deposit-contracts/contract/src/error.rs delete mode 100644 kairos-contracts/deposit-contracts/contract/src/main.rs delete mode 100644 kairos-contracts/deposit-contracts/contract/src/security.rs delete mode 100644 kairos-contracts/deposit-contracts/contract/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 6224f1ca..6b3a95a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -981,7 +981,7 @@ dependencies = [ ] [[package]] -name = "deposit-contract-tests" +name = "demo-contract-tests" version = "0.1.0" dependencies = [ "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index 22c6519c..4152d5a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ "kairos-server", "kairos-tx", "kairos-test-utils", - "kairos-contracts/deposit-contract-tests", + "kairos-contracts/demo-contract-tests", ] [workspace.package] diff --git a/flake.nix b/flake.nix index d656003a..da8ca143 100644 --- a/flake.nix +++ b/flake.nix @@ -77,8 +77,6 @@ !(builtins.elem (builtins.baseNameOf path) [ "kairos-contracts" "nixos" "kairos-prover" ]) && # Allow static files. (lib.hasInfix "/fixtures/" path) || - # ignore the kairos-contracts directory - !(lib.hasInfix "kairos-contracts/" path) || # Default filter (from crane) for .rs files. (craneLib.filterCargoSources path type) ; diff --git a/kairos-contracts/Cargo.toml b/kairos-contracts/Cargo.toml index 4250f8b8..454c4ad9 100644 --- a/kairos-contracts/Cargo.toml +++ b/kairos-contracts/Cargo.toml @@ -2,10 +2,10 @@ resolver = "2" members = [ - "deposit-contracts/malicious-reader", - "deposit-contracts/malicious-session", - "deposit-contracts/deposit-session", - "deposit-contracts/contract", + "demo-contract/malicious-reader", + "demo-contract/malicious-session", + "demo-contract/deposit-session", + "demo-contract/contract", ] [workspace.package] diff --git a/kairos-contracts/build-contracts.sh b/kairos-contracts/build-contracts.sh deleted file mode 100755 index c73c4f95..00000000 --- a/kairos-contracts/build-contracts.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -rustup target add wasm32-unknown-unknown - -cargo build -p contract --release --target wasm32-unknown-unknown -wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/deposit-contract.wasm -o ./target/wasm32-unknown-unknown/release/deposit-contract-optimized.wasm - -cargo build -p deposit-session --release --target wasm32-unknown-unknown -wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/deposit-session.wasm -o ./target/wasm32-unknown-unknown/release/deposit-session-optimized.wasm - -cargo build -p malicious-session --release --target wasm32-unknown-unknown -wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/malicious-session.wasm -o ./target/wasm32-unknown-unknown/release/malicious-session-optimized.wasm - -cargo build -p malicious-reader --release --target wasm32-unknown-unknown -wasm-opt --strip-debug --signext-lowering ./target/wasm32-unknown-unknown/release/malicious-reader.wasm -o ./target/wasm32-unknown-unknown/release/malicious-reader-optimized.wasm diff --git a/kairos-contracts/deposit-contract-tests/Cargo.toml b/kairos-contracts/demo-contract-tests/Cargo.toml similarity index 94% rename from kairos-contracts/deposit-contract-tests/Cargo.toml rename to kairos-contracts/demo-contract-tests/Cargo.toml index 489e739a..53c84aaa 100644 --- a/kairos-contracts/deposit-contract-tests/Cargo.toml +++ b/kairos-contracts/demo-contract-tests/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "deposit-contract-tests" +name = "demo-contract-tests" version.workspace = true edition.workspace = true license.workspace = true diff --git a/kairos-contracts/deposit-contract-tests/rust-toolchain.toml b/kairos-contracts/demo-contract-tests/rust-toolchain.toml similarity index 100% rename from kairos-contracts/deposit-contract-tests/rust-toolchain.toml rename to kairos-contracts/demo-contract-tests/rust-toolchain.toml diff --git a/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs b/kairos-contracts/demo-contract-tests/tests/integration_tests.rs similarity index 53% rename from kairos-contracts/deposit-contract-tests/tests/integration_tests.rs rename to kairos-contracts/demo-contract-tests/tests/integration_tests.rs index 39d92e78..af54dc14 100644 --- a/kairos-contracts/deposit-contract-tests/tests/integration_tests.rs +++ b/kairos-contracts/demo-contract-tests/tests/integration_tests.rs @@ -7,7 +7,7 @@ mod tests { #[test] fn should_install_deposit_contract() { let mut fixture: TestContext = TestContext::new(); - fixture.install_deposit_contract(fixture.account_1); + fixture.install_demo_contract(fixture.account_1); } fn setup() -> (TestContext, AccountHash, AccountHash) { @@ -21,7 +21,7 @@ mod tests { fn deposit_into_purse() { let deposit_amount: U512 = U512::from(100000000000u64); let (mut fixture, installer, user) = setup(); - fixture.install_deposit_contract(installer); + fixture.install_demo_contract(installer); let user_purse_uref = fixture.get_account_purse_uref(user); let user_balance_before = fixture.builder.get_purse_balance(user_purse_uref); @@ -38,48 +38,11 @@ mod tests { assert!(user_balance_after <= user_balance_before - deposit_amount); } - #[test] - fn update_security_badges() { - let (mut fixture, init_admin, new_admin) = setup(); - fixture.install_deposit_contract(init_admin); - // try to update the admin list - let new_admin_list: Vec = vec![Key::from(new_admin)]; - fixture.update_security_badges_as_admin(new_admin_list.clone(), init_admin, init_admin); - // update the admin list as the new_admin - fixture.update_security_badges_as_admin(new_admin_list, new_admin, init_admin); - // now remove the admin role from the installer and expect failure. - let new_admin_list: Vec = vec![]; - fixture.unauthorized_update_security_badges(new_admin_list.clone(), init_admin, init_admin); - } - - #[test] - fn admin_should_increase_last_processed_counter() { - let (mut fixture, installer, _user) = setup(); - fixture.install_deposit_contract(installer); - - let value_before: u64 = - fixture.read_counter_value(installer, "last_processed_deposit_counter"); - assert_eq!(value_before, 0u64); - - fixture.admin_increase_last_processed_counter(installer, installer); - let value_after: u64 = - fixture.read_counter_value(installer, "last_processed_deposit_counter"); - assert_eq!(value_after, 1u64); - } - - #[test] - fn unauthorized_should_not_increase_last_processed_counter() { - let (mut fixture, installer, unauthorized_user) = setup(); - fixture.install_deposit_contract(installer); - - fixture.unauthorized_increase_last_processed_counter(unauthorized_user, installer); - } - // see malicious-session #[test] fn run_malicious_session() { let (mut fixture, installer, user) = setup(); - fixture.install_deposit_contract(installer); + fixture.install_demo_contract(installer); fixture.run_deposit_session(U512::from(100000000000u64), installer, user); fixture.run_malicious_session(fixture.account_2, U512::from(100000000000u64), installer); } @@ -88,7 +51,7 @@ mod tests { #[test] fn run_malicious_reader() { let (mut fixture, installer, user) = setup(); - fixture.install_deposit_contract(installer); + fixture.install_demo_contract(installer); fixture.run_deposit_session(U512::from(100000000000u64), installer, user); let deposit_purse_uref = fixture.get_contract_purse_uref(installer); fixture.run_malicious_reader_session( diff --git a/kairos-contracts/deposit-contract-tests/tests/lib.rs b/kairos-contracts/demo-contract-tests/tests/lib.rs similarity index 100% rename from kairos-contracts/deposit-contract-tests/tests/lib.rs rename to kairos-contracts/demo-contract-tests/tests/lib.rs diff --git a/kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs b/kairos-contracts/demo-contract-tests/tests/test_fixture/mod.rs similarity index 62% rename from kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs rename to kairos-contracts/demo-contract-tests/tests/test_fixture/mod.rs index fa876c57..d7c8549e 100644 --- a/kairos-contracts/deposit-contract-tests/tests/test_fixture/mod.rs +++ b/kairos-contracts/demo-contract-tests/tests/test_fixture/mod.rs @@ -96,13 +96,13 @@ impl TestContext { .expect("must get contract hash") } - pub fn install_deposit_contract(&mut self, admin: AccountHash) { + pub fn install_demo_contract(&mut self, admin: AccountHash) { let session_args = runtime_args! {}; let install_contract_request = ExecuteRequestBuilder::standard( admin, &format!( "{}/{}", - *PATH_TO_WASM_BINARIES, "deposit-contract-optimized.wasm" + *PATH_TO_WASM_BINARIES, "demo-contract-optimized.wasm" ), session_args, ) @@ -115,7 +115,7 @@ impl TestContext { pub fn get_contract_purse_uref(&self, account: AccountHash) -> URef { let seed_uref: URef = *self - .get_contract_named_key("kairos_deposit_contract", "kairos_deposit_purse", account) + .get_contract_named_key("kairos_demo_contract", "kairos_deposit_purse", account) .as_uref() .unwrap(); seed_uref @@ -128,109 +128,23 @@ impl TestContext { #[allow(dead_code)] pub fn get_contract_purse_balance(&self, account: AccountHash) -> U512 { let contract_purse_uref: URef = *self - .get_contract_named_key("kairos_deposit_contract", "kairos_deposit_purse", account) + .get_contract_named_key("kairos_demo_contract", "kairos_deposit_purse", account) .as_uref() .unwrap(); self.builder.get_purse_balance(contract_purse_uref) } - // read a u64 counter from the contract named keys e.g. "last_processed_deposit_counter" + /*// read a u64 counter from the contract named keys e.g. "last_processed_deposit_counter" pub fn read_counter_value(&mut self, account: AccountHash, name: &str) -> u64 { - let contract_hash = self.contract_hash("kairos_deposit_contract", account); + let contract_hash = self.contract_hash("kairos_demo_contract", account); self.builder.get_value(contract_hash, name) - } - - // call the contract as admin to increase the last processed deposit counter value by 1 - pub fn admin_increase_last_processed_counter( - &mut self, - caller: AccountHash, - installer: AccountHash, - ) { - let session_args = runtime_args! {}; - let update_counter_request = ExecuteRequestBuilder::contract_call_by_hash( - caller, - self.contract_hash("kairos_deposit_contract", installer), - "incr_last_processed_deposit_counter", - session_args, - ) - .build(); - self.builder - .exec(update_counter_request) - .expect_success() - .commit(); - } - - // an unauthorized attempt of changing the last processed counter - pub fn unauthorized_increase_last_processed_counter( - &mut self, - caller: AccountHash, - installer: AccountHash, - ) { - let session_args = runtime_args! {}; - let update_counter_request = ExecuteRequestBuilder::contract_call_by_hash( - caller, - self.contract_hash("kairos_deposit_contract", installer), - "incr_last_processed_deposit_counter", - session_args, - ) - .build(); - self.builder - .exec(update_counter_request) - .expect_failure() - .commit(); - } - - // try to update the access control / admin list of the deposit contract - pub fn update_security_badges_as_admin( - &mut self, - admin_list: Vec, - caller: AccountHash, - installer: AccountHash, - ) { - let session_args = runtime_args! { - "admin_list" => admin_list, - }; - let update_security_request = ExecuteRequestBuilder::contract_call_by_hash( - caller, - self.contract_hash("kairos_deposit_contract", installer), - "update_security_badges", - session_args, - ) - .build(); - self.builder - .exec(update_security_request) - .expect_success() - .commit(); - } - - // an unauthorized attempt of changing the admin badges - pub fn unauthorized_update_security_badges( - &mut self, - admin_list: Vec, - caller: AccountHash, - installer: AccountHash, - ) { - let session_args = runtime_args! { - "admin_list" => admin_list, - }; - let update_security_request = ExecuteRequestBuilder::contract_call_by_hash( - caller, - self.contract_hash("kairos_deposit_contract", installer), - "update_security_badges", - session_args, - ) - .build(); - self.builder - .exec(update_security_request) - .expect_failure() - .commit(); - } + }*/ // see deposit-session pub fn run_deposit_session(&mut self, amount: U512, installer: AccountHash, user: AccountHash) { let session_args = runtime_args! { "amount" => amount, - "deposit_contract" => self.contract_hash("kairos_deposit_contract", installer) + "demo_contract" => self.contract_hash("kairos_demo_contract", installer) }; let session_request = ExecuteRequestBuilder::standard( user, @@ -253,7 +167,7 @@ impl TestContext { ) { let session_args = runtime_args! { "amount" => amount, - "deposit_contract" => self.contract_hash("kairos_deposit_contract", account) + "demo_contract" => self.contract_hash("kairos_demo_contract", account) }; let session_request = ExecuteRequestBuilder::standard( msg_sender, @@ -277,7 +191,7 @@ impl TestContext { ) { let session_args = runtime_args! { "amount" => amount, - "deposit_contract" => self.contract_hash("kairos_deposit_contract", account), + "demo_contract" => self.contract_hash("kairos_demo_contract", account), "purse_uref" => deposit_purse_uref }; let session_request = ExecuteRequestBuilder::standard( diff --git a/kairos-contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs b/kairos-contracts/demo-contract-tests/tests/test_fixture/utils/mod.rs similarity index 100% rename from kairos-contracts/deposit-contract-tests/tests/test_fixture/utils/mod.rs rename to kairos-contracts/demo-contract-tests/tests/test_fixture/utils/mod.rs diff --git a/kairos-contracts/deposit-contracts/contract/.cargo/config.toml b/kairos-contracts/demo-contract/contract/.cargo/config.toml similarity index 100% rename from kairos-contracts/deposit-contracts/contract/.cargo/config.toml rename to kairos-contracts/demo-contract/contract/.cargo/config.toml diff --git a/kairos-contracts/deposit-contracts/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml similarity index 95% rename from kairos-contracts/deposit-contracts/contract/Cargo.toml rename to kairos-contracts/demo-contract/contract/Cargo.toml index 2d7d7c19..27e3f193 100644 --- a/kairos-contracts/deposit-contracts/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -16,7 +16,7 @@ bincode = "1.3.3" target = "wasm32-unknown-unknown" [[bin]] -name = "deposit-contract" +name = "demo-contract" path = "src/main.rs" bench = false doctest = false diff --git a/kairos-contracts/demo-contract/contract/src/constants.rs b/kairos-contracts/demo-contract/contract/src/constants.rs new file mode 100644 index 00000000..9f3540ef --- /dev/null +++ b/kairos-contracts/demo-contract/contract/src/constants.rs @@ -0,0 +1,17 @@ +pub const KAIROS_DEPOSIT_CONTRACT_NAME: &str = "kairos_demo_contract"; + +//#[allow(dead_code)] +pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "kairos_contract_package"; +pub const KAIROS_DEPOSIT_CONTRACT_UREF: &str = "demo_contract"; + +pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_counter"; +pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; + +pub const RUNTIME_ARG_TEMP_PURSE: &str = "temp_purse"; + +//#[allow(dead_code)] +pub const RUNTIME_ARG_AMOUNT: &str = "amount"; + +pub const EP_INIT_NAME: &str = "init"; +pub const EP_GET_PURSE_NAME: &str = "get_purse"; +pub const EP_DEPOSIT_NAME: &str = "deposit"; diff --git a/kairos-contracts/deposit-contracts/contract/src/entry_points.rs b/kairos-contracts/demo-contract/contract/src/entry_points.rs similarity index 57% rename from kairos-contracts/deposit-contracts/contract/src/entry_points.rs rename to kairos-contracts/demo-contract/contract/src/entry_points.rs index 98dbdeb4..ad6fc41e 100644 --- a/kairos-contracts/deposit-contracts/contract/src/entry_points.rs +++ b/kairos-contracts/demo-contract/contract/src/entry_points.rs @@ -1,6 +1,5 @@ use crate::constants::{ - EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INCR_LAST_PROCESSED_NAME, EP_INIT_NAME, - EP_UPDATE_SECURITY_BADGES_NAME, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, + EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INIT_NAME, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, }; use alloc::vec; use casper_types::{CLType, EntryPoint, EntryPointAccess, EntryPointType, Parameter}; @@ -37,23 +36,3 @@ pub fn deposit() -> EntryPoint { EntryPointType::Contract, ) } - -pub fn incr_last_processed_deposit_counter() -> EntryPoint { - EntryPoint::new( - EP_INCR_LAST_PROCESSED_NAME, - vec![], - CLType::Unit, - EntryPointAccess::Public, - EntryPointType::Contract, - ) -} - -pub fn change_security() -> EntryPoint { - EntryPoint::new( - EP_UPDATE_SECURITY_BADGES_NAME, - vec![], - CLType::Unit, - EntryPointAccess::Public, - EntryPointType::Contract, - ) -} diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs new file mode 100644 index 00000000..22140bc4 --- /dev/null +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -0,0 +1,118 @@ +#![no_std] +#![no_main] +extern crate alloc; +use alloc::string::ToString; +use casper_contract::{ + contract_api::{runtime, storage, system}, + unwrap_or_revert::UnwrapOrRevert, +}; +use casper_event_standard::Schemas; +use casper_types::{ + contracts::NamedKeys, runtime_args, AccessRights, ApiError, CLValue, EntryPoints, Key, + RuntimeArgs, URef, U512, +}; +mod constants; +use constants::{ + KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_CONTRACT_UREF, + KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, + RUNTIME_ARG_TEMP_PURSE, +}; +mod entry_points; +mod utils; +use utils::errors::DepositError; +use utils::events::Deposit; +use utils::get_immediate_caller; + +// This entry point is called once when the contract is installed +// and sets up the security badges with the installer as an admin or the +// optional list of admins. +// The optional list of admins is passed to the installation session as a runtime argument. +// The contract purse will be created in contract context so that it is "owned" by the contract +// rather than the installing account. +#[no_mangle] +pub extern "C" fn init() { + if runtime::get_key(KAIROS_DEPOSIT_PURSE).is_some() { + runtime::revert(DepositError::AlreadyInitialized); + } + + // initialize event schema + let schemas = Schemas::new().with::(); + casper_event_standard::init(schemas); + + let new_deposit_purse: URef = system::create_purse(); + runtime::put_key(KAIROS_DEPOSIT_PURSE, new_deposit_purse.into()); +} + +#[no_mangle] +pub extern "C" fn get_purse() { + let deposit_purse: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) + .unwrap_or_revert_with(DepositError::MissingKeyDepositPurse) + .into_uref() + .unwrap_or_revert(); + let reference_to_deposit_purse_with_restricted_access = + deposit_purse.with_access_rights(AccessRights::ADD); + runtime::ret( + CLValue::from_t(reference_to_deposit_purse_with_restricted_access) + .unwrap_or_revert_with(DepositError::FailedToReturnContractPurseAsReference), + ); +} + +// Entry point called by a user through session code to deposit funds. +// Due to Casper < 2.0 purse management and access control, it is necessary that +// a temporary purse is funded and passed to the deposit contract, since this is +// the only secure method of making a payment to a contract purse. +#[no_mangle] +pub extern "C" fn deposit() { + let temp_purse: URef = runtime::get_named_arg(RUNTIME_ARG_TEMP_PURSE); + let amount: U512 = runtime::get_named_arg(RUNTIME_ARG_AMOUNT); + let deposit_purse_uref: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) + .unwrap_or_revert_with(DepositError::MissingKeyDepositPurse) + .into_uref() + .unwrap_or_revert_with(ApiError::UnexpectedKeyVariant); + system::transfer_from_purse_to_purse(temp_purse, deposit_purse_uref, amount, None) + .unwrap_or_revert(); + + let new_deposit_record: Deposit = Deposit { + account: get_immediate_caller().unwrap_or_revert(), + amount, + timestamp: None, + }; + casper_event_standard::emit(new_deposit_record); +} + +#[no_mangle] +pub extern "C" fn call() { + let entry_points = { + let mut entry_points = EntryPoints::new(); + entry_points.add_entry_point(entry_points::init()); + entry_points.add_entry_point(entry_points::get_purse()); + entry_points.add_entry_point(entry_points::deposit()); + entry_points + }; + // this counter will be udpated by the entry point that processes / verifies batches + let mut named_keys = NamedKeys::new(); + let last_processed_deposit_counter = storage::new_uref(u64::from(0u8)); + + named_keys.insert( + KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER.to_string(), + last_processed_deposit_counter.into(), + ); + + let (contract_hash, _) = storage::new_locked_contract( + entry_points, + Some(named_keys), + Some(KAIROS_DEPOSIT_CONTRACT_UREF.to_string()), + Some(KAIROS_DEPOSIT_CONTRACT_PACKAGE.to_string()), + ); + let contract_hash_key = Key::from(contract_hash); + runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); + + /* + Initialize the contract, this will create the deposit purse. + Open questions: + - should this be revokable? + - should there be any governance at all? + */ + let init_args = runtime_args! {}; + runtime::call_contract::<()>(contract_hash, "init", init_args); +} diff --git a/kairos-contracts/demo-contract/contract/src/utils.rs b/kairos-contracts/demo-contract/contract/src/utils.rs new file mode 100644 index 00000000..bc162b82 --- /dev/null +++ b/kairos-contracts/demo-contract/contract/src/utils.rs @@ -0,0 +1,38 @@ +/* + The utilities found in this file were scraped from other Casper contracts, + mainly cep-78 and cep-18. + This file is not necessarily due for review, unless breaking changes are suspected. +*/ +use casper_contract::contract_api::runtime; +use casper_types::{system::CallStackElement, Key}; + +pub mod errors; +pub mod events; +use errors::DepositError; + +/// Wrap the immediate caller as a Key and return it +fn call_stack_element_to_address(call_stack_element: CallStackElement) -> Key { + match call_stack_element { + CallStackElement::Session { account_hash } => Key::from(account_hash), + CallStackElement::StoredSession { account_hash, .. } => { + // Stored session code acts in account's context, so if stored session wants to interact + // with an CEP-18 token caller's address will be used. + Key::from(account_hash) + } + CallStackElement::StoredContract { + contract_package_hash, + .. + } => Key::from(contract_package_hash), + } +} + +/// Traverse the callstack to retrieve the n - 1 th element of the callstack +pub(crate) fn get_immediate_caller() -> Result { + let call_stack = runtime::get_call_stack(); + call_stack + .into_iter() + .rev() + .nth(1) + .map(call_stack_element_to_address) + .ok_or(DepositError::InvalidContext) +} diff --git a/kairos-contracts/demo-contract/contract/src/utils/errors.rs b/kairos-contracts/demo-contract/contract/src/utils/errors.rs new file mode 100644 index 00000000..39603190 --- /dev/null +++ b/kairos-contracts/demo-contract/contract/src/utils/errors.rs @@ -0,0 +1,24 @@ +//! Error handling on the Casper platform. +use casper_types::ApiError; + +#[repr(u16)] +#[derive(Clone, Copy)] +pub enum DepositError { + InvalidContext = 0, + MissingKey = 1, + FailedToGetArgBytes = 2, + MissingOptionalArgument = 3, + AlreadyInitialized = 4, + MissingKeyDepositPurse = 5, + MissingKeyMostRecentDepositCounter = 6, + MissingKeyLastProcessedDepositCounter = 7, + MissingKeyDepositEventDict = 8, + FailedToCreateDepositDict = 9, + FailedToReturnContractPurseAsReference = 10, +} + +impl From for ApiError { + fn from(error: DepositError) -> Self { + ApiError::User(error as u16) + } +} diff --git a/kairos-contracts/deposit-contracts/contract/src/events.rs b/kairos-contracts/demo-contract/contract/src/utils/events.rs similarity index 100% rename from kairos-contracts/deposit-contracts/contract/src/events.rs rename to kairos-contracts/demo-contract/contract/src/utils/events.rs diff --git a/kairos-contracts/deposit-contracts/deposit-session/Cargo.toml b/kairos-contracts/demo-contract/deposit-session/Cargo.toml similarity index 100% rename from kairos-contracts/deposit-contracts/deposit-session/Cargo.toml rename to kairos-contracts/demo-contract/deposit-session/Cargo.toml diff --git a/kairos-contracts/deposit-contracts/deposit-session/src/main.rs b/kairos-contracts/demo-contract/deposit-session/src/main.rs similarity index 98% rename from kairos-contracts/deposit-contracts/deposit-session/src/main.rs rename to kairos-contracts/demo-contract/deposit-session/src/main.rs index 3052548c..3729e7c5 100644 --- a/kairos-contracts/deposit-contracts/deposit-session/src/main.rs +++ b/kairos-contracts/demo-contract/deposit-session/src/main.rs @@ -13,7 +13,7 @@ use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; #[no_mangle] pub extern "C" fn call() { - let contract_hash: ContractHash = runtime::get_named_arg("deposit_contract"); + let contract_hash: ContractHash = runtime::get_named_arg("demo_contract"); let amount: U512 = runtime::get_named_arg("amount"); let source: URef = account::get_main_purse(); // create a temporary purse that can be passed to the deposit contract diff --git a/kairos-contracts/deposit-contracts/malicious-reader/Cargo.toml b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml similarity index 100% rename from kairos-contracts/deposit-contracts/malicious-reader/Cargo.toml rename to kairos-contracts/demo-contract/malicious-reader/Cargo.toml diff --git a/kairos-contracts/deposit-contracts/malicious-reader/src/main.rs b/kairos-contracts/demo-contract/malicious-reader/src/main.rs similarity index 100% rename from kairos-contracts/deposit-contracts/malicious-reader/src/main.rs rename to kairos-contracts/demo-contract/malicious-reader/src/main.rs diff --git a/kairos-contracts/deposit-contracts/malicious-session/Cargo.toml b/kairos-contracts/demo-contract/malicious-session/Cargo.toml similarity index 100% rename from kairos-contracts/deposit-contracts/malicious-session/Cargo.toml rename to kairos-contracts/demo-contract/malicious-session/Cargo.toml diff --git a/kairos-contracts/deposit-contracts/malicious-session/src/main.rs b/kairos-contracts/demo-contract/malicious-session/src/main.rs similarity index 97% rename from kairos-contracts/deposit-contracts/malicious-session/src/main.rs rename to kairos-contracts/demo-contract/malicious-session/src/main.rs index 34e40fda..02294fa1 100644 --- a/kairos-contracts/deposit-contracts/malicious-session/src/main.rs +++ b/kairos-contracts/demo-contract/malicious-session/src/main.rs @@ -11,7 +11,7 @@ use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; #[no_mangle] pub extern "C" fn call() { - let contract_hash: ContractHash = runtime::get_named_arg("deposit_contract"); + let contract_hash: ContractHash = runtime::get_named_arg("demo_contract"); let amount: U512 = runtime::get_named_arg("amount"); let destination_purse: URef = account::get_main_purse(); let borrowed_contract_purse: URef = diff --git a/kairos-contracts/deposit-contracts/contract/src/constants.rs b/kairos-contracts/deposit-contracts/contract/src/constants.rs deleted file mode 100644 index 588523c3..00000000 --- a/kairos-contracts/deposit-contracts/contract/src/constants.rs +++ /dev/null @@ -1,23 +0,0 @@ -pub const KAIROS_DEPOSIT_CONTRACT_NAME: &str = "kairos_deposit_contract"; -// TODO why is this unused? -#[allow(dead_code)] -pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "deposit_contract_package"; -pub const KAIROS_DEPOSIT_CONTRACT: &str = "deposit_contract"; - -pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_counter"; -pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; - -pub const RUNTIME_ARG_TEMP_PURSE: &str = "temp_purse"; -// TODO why is this unused? -#[allow(dead_code)] -pub const RUNTIME_ARG_DEST_PURSE: &str = "destination_purse"; -pub const RUNTIME_ARG_AMOUNT: &str = "amount"; - -pub const SECURITY_BADGES: &str = "security_badges"; -pub const ADMIN_LIST: &str = "admin_list"; - -pub const EP_INIT_NAME: &str = "init"; -pub const EP_GET_PURSE_NAME: &str = "get_purse"; -pub const EP_DEPOSIT_NAME: &str = "deposit"; -pub const EP_INCR_LAST_PROCESSED_NAME: &str = "incr_last_processed_deposit_counter"; -pub const EP_UPDATE_SECURITY_BADGES_NAME: &str = "update_security_badges"; diff --git a/kairos-contracts/deposit-contracts/contract/src/error.rs b/kairos-contracts/deposit-contracts/contract/src/error.rs deleted file mode 100644 index 1c13e00e..00000000 --- a/kairos-contracts/deposit-contracts/contract/src/error.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Error handling on the Casper platform. -use casper_types::ApiError; - -#[repr(u16)] -#[derive(Clone, Copy)] -pub enum DepositError { - InvalidContext = 0, - MissingKey = 1, - InvalidAdminList = 2, - InvalidNoneList = 3, - FailedToGetArgBytes = 4, - MissingOptionalArgument = 5, - InsufficientRights = 6, - AlreadyInitialized = 7, - MissingKeyDepositPurse = 8, - MissingKeyMostRecentDepositCounter = 9, - MissingKeyLastProcessedDepositCounter = 10, - MissingKeyDepositEventDict = 11, - FailedToCreateSecurityBadgesDict = 12, - FailedToCreateDepositDict = 13, - FailedToReturnContractPurseAsReference = 14, -} - -impl From for ApiError { - fn from(error: DepositError) -> Self { - ApiError::User(error as u16) - } -} diff --git a/kairos-contracts/deposit-contracts/contract/src/main.rs b/kairos-contracts/deposit-contracts/contract/src/main.rs deleted file mode 100644 index 7375f0ac..00000000 --- a/kairos-contracts/deposit-contracts/contract/src/main.rs +++ /dev/null @@ -1,197 +0,0 @@ -#![no_std] -#![no_main] -extern crate alloc; -use alloc::{collections::BTreeMap, string::ToString, vec, vec::Vec}; -use casper_contract::{ - contract_api::{runtime, storage, system}, - unwrap_or_revert::UnwrapOrRevert, -}; -use casper_types::{ - bytesrepr::ToBytes, contracts::NamedKeys, runtime_args, AccessRights, ApiError, CLValue, - EntryPoints, Key, RuntimeArgs, URef, U512, -}; -mod constants; -use constants::{ - ADMIN_LIST, KAIROS_DEPOSIT_CONTRACT, KAIROS_DEPOSIT_CONTRACT_NAME, - KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, - RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, SECURITY_BADGES, -}; -mod utils; -use utils::{get_immediate_caller, get_optional_named_arg_with_user_errors}; -mod error; -use error::DepositError; -mod security; -use security::{access_control_check, SecurityBadge}; -mod entry_points; -mod events; -use casper_event_standard::Schemas; -use events::Deposit; - -// This entry point is called once when the contract is installed -// and sets up the security badges with the installer as an admin or the -// optional list of admins. -// The optional list of admins is passed to the installation session as a runtime argument. -// The contract purse will be created in contract context so that it is "owned" by the contract -// rather than the installing account. -#[no_mangle] -pub extern "C" fn init() { - if runtime::get_key(KAIROS_DEPOSIT_PURSE).is_some() { - runtime::revert(DepositError::AlreadyInitialized); - } - let security_badges_dict = storage::new_dictionary(SECURITY_BADGES) - .unwrap_or_revert_with(DepositError::FailedToCreateSecurityBadgesDict); - let installing_entity = runtime::get_caller(); - - // initialize event schema - let schemas = Schemas::new().with::(); - casper_event_standard::init(schemas); - - // Assign the admin role to the installer, regardless of the list of admins that was - // passed to the installation session. - // The installer is by default an admin and the installer's admin role - // needs to be revoked after the initialization if it is not wanted. - storage::dictionary_put( - security_badges_dict, - &base64::encode(Key::from(installing_entity).to_bytes().unwrap_or_revert()), - Some(SecurityBadge::Admin), - ); - let admin_list: Option> = - get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); - if let Some(admin_list) = admin_list { - for admin in admin_list { - let account_dictionary_key = admin.to_bytes().unwrap_or_revert(); - storage::dictionary_put( - security_badges_dict, - &base64::encode(account_dictionary_key), - Some(SecurityBadge::Admin), - ); - } - }; - let new_deposit_purse: URef = system::create_purse(); - runtime::put_key(KAIROS_DEPOSIT_PURSE, new_deposit_purse.into()); -} - -#[no_mangle] -pub extern "C" fn get_purse() { - let deposit_purse: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) - .unwrap_or_revert_with(DepositError::MissingKeyDepositPurse) - .into_uref() - .unwrap_or_revert(); - let reference_to_deposit_purse_with_restricted_access = - deposit_purse.with_access_rights(AccessRights::ADD); - runtime::ret( - CLValue::from_t(reference_to_deposit_purse_with_restricted_access) - .unwrap_or_revert_with(DepositError::FailedToReturnContractPurseAsReference), - ); -} - -// Entry point called by a user through session code to deposit funds. -// Due to Casper < 2.0 purse management and access control, it is necessary that -// a temporary purse is funded and passed to the deposit contract, since this is -// the only secure method of making a payment to a contract purse. -#[no_mangle] -pub extern "C" fn deposit() { - let temp_purse: URef = runtime::get_named_arg(RUNTIME_ARG_TEMP_PURSE); - let amount: U512 = runtime::get_named_arg(RUNTIME_ARG_AMOUNT); - let deposit_purse_uref: URef = runtime::get_key(KAIROS_DEPOSIT_PURSE) - .unwrap_or_revert_with(DepositError::MissingKeyDepositPurse) - .into_uref() - .unwrap_or_revert_with(ApiError::UnexpectedKeyVariant); - system::transfer_from_purse_to_purse(temp_purse, deposit_purse_uref, amount, None) - .unwrap_or_revert(); - - let new_deposit_record: Deposit = Deposit { - account: get_immediate_caller().unwrap_or_revert(), - amount, - timestamp: None, - }; - casper_event_standard::emit(new_deposit_record); -} - -// The centralized Kairos service, or a sequencer, -// will update the counter to keep track -// of the last processed deposit index on-chain. -#[no_mangle] -pub extern "C" fn incr_last_processed_deposit_counter() { - access_control_check(vec![SecurityBadge::Admin]); - let last_processed_deposit_counter_uref = - runtime::get_key(KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER) - .unwrap_or_revert_with(DepositError::MissingKeyLastProcessedDepositCounter) - .into_uref() - .unwrap_or_revert(); - let mut last_processed_deposit_counter_value: u64 = - storage::read(last_processed_deposit_counter_uref) - .unwrap_or_revert() - .unwrap_or_revert(); - last_processed_deposit_counter_value += 1u64; - storage::write( - last_processed_deposit_counter_uref, - last_processed_deposit_counter_value, - ); -} - -// Update the security badge for one or multiple accounts -// This entry point is used to assign and revoke roles such -// as the "Admin" role. -#[no_mangle] -pub extern "C" fn update_security_badges() { - access_control_check(vec![SecurityBadge::Admin]); - let admin_list: Option> = - get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); - // construct a new admin list from runtime arg - let mut badge_map: BTreeMap> = BTreeMap::new(); - if let Some(admin_list) = admin_list { - for account_key in admin_list { - badge_map.insert(account_key, Some(SecurityBadge::Admin)); - } - } - // Remove the caller from the admin list, - // by inserting None as the security badge. - // Accounts with no security badge will not be considered part of a badge group - // and therefore loose the ability to call EPs that contain - // `access_control_check(vec![SecurityBadge::Admin]);` o.e. - let caller = get_immediate_caller().unwrap_or_revert(); - badge_map.insert(caller, None); - security::update_security_badges(&badge_map); -} - -#[no_mangle] -pub extern "C" fn call() { - let admin_list: Option> = - get_optional_named_arg_with_user_errors(ADMIN_LIST, DepositError::InvalidAdminList); - - let entry_points = { - let mut entry_points = EntryPoints::new(); - entry_points.add_entry_point(entry_points::init()); - entry_points.add_entry_point(entry_points::get_purse()); - entry_points.add_entry_point(entry_points::deposit()); - entry_points.add_entry_point(entry_points::incr_last_processed_deposit_counter()); - entry_points.add_entry_point(entry_points::change_security()); - entry_points - }; - let mut named_keys = NamedKeys::new(); - let last_processed_deposit_counter = storage::new_uref(u64::from(0u8)); - - named_keys.insert( - KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER.to_string(), - last_processed_deposit_counter.into(), - ); - - let (contract_hash, _) = storage::new_locked_contract( - entry_points, - Some(named_keys), - Some(KAIROS_DEPOSIT_CONTRACT.to_string()), - Some(KAIROS_DEPOSIT_CONTRACT_PACKAGE.to_string()), - ); - let contract_hash_key = Key::from(contract_hash); - runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); - - // Prepare runtime arguments for contract initialization, - // passing the list of admin accounts that was passed - // to the installation session. - let mut init_args = runtime_args! {}; - if let Some(admin_list) = admin_list { - init_args.insert(ADMIN_LIST, admin_list).unwrap_or_revert(); - } - runtime::call_contract::<()>(contract_hash, "init", init_args); -} diff --git a/kairos-contracts/deposit-contracts/contract/src/security.rs b/kairos-contracts/deposit-contracts/contract/src/security.rs deleted file mode 100644 index b99b5eee..00000000 --- a/kairos-contracts/deposit-contracts/contract/src/security.rs +++ /dev/null @@ -1,90 +0,0 @@ -use alloc::{collections::BTreeMap, vec, vec::Vec}; - -use crate::{ - constants::SECURITY_BADGES, - error::DepositError, - utils::{get_immediate_caller, get_uref}, -}; -#[allow(unused_imports)] -use casper_contract::{ - contract_api::{ - self, - runtime::revert, - storage::{dictionary_get, dictionary_put, new_dictionary}, - }, - ext_ffi, - unwrap_or_revert::UnwrapOrRevert, -}; -use casper_types::{ - bytesrepr::{self, FromBytes, ToBytes}, - CLTyped, Key, -}; - -#[repr(u8)] -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum SecurityBadge { - Admin = 0, -} - -impl CLTyped for SecurityBadge { - fn cl_type() -> casper_types::CLType { - casper_types::CLType::U8 - } -} - -impl ToBytes for SecurityBadge { - fn to_bytes(&self) -> Result, bytesrepr::Error> { - Ok(vec![*self as u8]) - } - - fn serialized_length(&self) -> usize { - 1 - } -} - -impl FromBytes for SecurityBadge { - fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> { - Ok(( - match bytes[0] { - 0 => SecurityBadge::Admin, - _ => return Err(bytesrepr::Error::LeftOverBytes), - }, - &[], - )) - } -} - -// Check if a given account / Key is part of a Group / assigned a specific Badge. -// If the account doesn't hold the required badge, the runtime will revert and the -// execution of the contract is terminated. -pub fn access_control_check(allowed_badge_list: Vec) { - let caller = get_immediate_caller() - .unwrap_or_revert() - .to_bytes() - .unwrap_or_revert(); - if !allowed_badge_list.contains( - &dictionary_get::>( - get_uref(SECURITY_BADGES), - &base64::encode(caller), - ) - .unwrap_or_revert() - .unwrap_or_revert() - .unwrap_or_revert_with(DepositError::InsufficientRights), - ) { - revert(DepositError::InsufficientRights) - } -} - -// Insert the new and updated roles into the security badge dictionary. -// Accounts that are assigned "None" will not be considered members of a group / groupless. -// Groups (=Badges) are used for access control. -pub fn update_security_badges(badge_map: &BTreeMap>) { - let sec_uref = get_uref(SECURITY_BADGES); - for (&user, &badge) in badge_map { - dictionary_put( - sec_uref, - &base64::encode(user.to_bytes().unwrap_or_revert()), - badge, - ) - } -} diff --git a/kairos-contracts/deposit-contracts/contract/src/utils.rs b/kairos-contracts/deposit-contracts/contract/src/utils.rs deleted file mode 100644 index b80ef455..00000000 --- a/kairos-contracts/deposit-contracts/contract/src/utils.rs +++ /dev/null @@ -1,120 +0,0 @@ -/* - The utilities found in this file were scraped from other Casper contracts, - mainly cep-78 and cep-18. - This file is not necessarily due for review, unless breaking changes are suspected. -*/ - -use crate::error::DepositError; -use alloc::vec::Vec; -use casper_contract::{ - contract_api::{self, runtime}, - ext_ffi, - unwrap_or_revert::UnwrapOrRevert, -}; -use casper_types::{ - api_error, bytesrepr, bytesrepr::FromBytes, system::CallStackElement, ApiError, Key, URef, -}; - -/// Wrap the immediate caller as a Key and return it -fn call_stack_element_to_address(call_stack_element: CallStackElement) -> Key { - match call_stack_element { - CallStackElement::Session { account_hash } => Key::from(account_hash), - CallStackElement::StoredSession { account_hash, .. } => { - // Stored session code acts in account's context, so if stored session wants to interact - // with an CEP-18 token caller's address will be used. - Key::from(account_hash) - } - CallStackElement::StoredContract { - contract_package_hash, - .. - } => Key::from(contract_package_hash), - } -} - -/// Traverse the callstack to retrieve the n - 1 th element of the callstack -pub(crate) fn get_immediate_caller() -> Result { - let call_stack = runtime::get_call_stack(); - call_stack - .into_iter() - .rev() - .nth(1) - .map(call_stack_element_to_address) - .ok_or(DepositError::InvalidContext) -} - -/// Gets [`URef`] under a name. -pub(crate) fn get_uref(name: &str) -> URef { - let key = runtime::get_key(name) - .ok_or(ApiError::MissingKey) - .unwrap_or_revert(); - key.try_into().unwrap_or_revert() -} - -pub fn get_named_arg_size(name: &str) -> Option { - let mut arg_size: usize = 0; - let ret = unsafe { - ext_ffi::casper_get_named_arg_size( - name.as_bytes().as_ptr(), - name.len(), - &mut arg_size as *mut usize, - ) - }; - match api_error::result_from(ret) { - Ok(_) => Some(arg_size), - Err(ApiError::MissingArgument) => None, - Err(e) => runtime::revert(e), - } -} - -/// Optional named args are used for access control -pub fn get_optional_named_arg_with_user_errors( - name: &str, - invalid: DepositError, -) -> Option { - let maybe_named_arg_with_user_errors = get_named_arg_with_user_errors::(name, invalid); - match maybe_named_arg_with_user_errors { - Ok(val) => Some(val), - Err(err) => match err { - DepositError::MissingOptionalArgument => None, - _ => runtime::revert(err), - }, - } -} - -/// Reading optional args is required because it should be possible to -/// install the deposit contract without passing a list of -/// admins. In such a case the default admin will be the installing -/// account. -/// This function checks if the runtime argument size is greater than 0 -/// and if that is the case it gets parsed and returned. Should the parsing -/// fail or should the user not supply the argument at all, then an error is propagated. -/// To install the contract without an admin list, one still needs to pass an empty admins -/// list as a runtime argument. Otherwise the missing error will be propagated. -pub fn get_named_arg_with_user_errors( - name: &str, - invalid: DepositError, -) -> Result { - let arg_size = get_named_arg_size(name).ok_or(DepositError::MissingOptionalArgument)?; - let arg_bytes = if arg_size > 0 { - let res = { - let data_non_null_ptr = contract_api::alloc_bytes(arg_size); - let ret = unsafe { - ext_ffi::casper_get_named_arg( - name.as_bytes().as_ptr(), - name.len(), - data_non_null_ptr.as_ptr(), - arg_size, - ) - }; - let data = - unsafe { Vec::from_raw_parts(data_non_null_ptr.as_ptr(), arg_size, arg_size) }; - api_error::result_from(ret).map(|_| data) - }; - // Assumed to be safe as `get_named_arg_size` checks the argument already - res.unwrap_or_revert_with(DepositError::FailedToGetArgBytes) - } else { - // Avoids allocation with 0 bytes and a call to get_named_arg - Vec::new() - }; - bytesrepr::deserialize(arg_bytes).map_err(|_| invalid) -} From f81652d46f8d8ed6417aebc0baa888e01c8f732b Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:14:07 +0200 Subject: [PATCH 050/115] minor resturcturing of test_fixture crate for demo-contract --- .../tests/test_fixture/{utils/mod.rs => utils.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename kairos-contracts/demo-contract-tests/tests/test_fixture/{utils/mod.rs => utils.rs} (100%) diff --git a/kairos-contracts/demo-contract-tests/tests/test_fixture/utils/mod.rs b/kairos-contracts/demo-contract-tests/tests/test_fixture/utils.rs similarity index 100% rename from kairos-contracts/demo-contract-tests/tests/test_fixture/utils/mod.rs rename to kairos-contracts/demo-contract-tests/tests/test_fixture/utils.rs From 095a8e45279285e0edba47b09a2bbc55bf399a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 15 Apr 2024 09:37:54 -0500 Subject: [PATCH 051/115] flake/coverage: remove -Cstrip=none rust flag --- flake.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index da8ca143..9cb5034c 100644 --- a/flake.nix +++ b/flake.nix @@ -150,14 +150,11 @@ coverage-report = craneLib.cargoTarpaulin (kairosNodeAttrs // { cargoArtifacts = self'.packages.kairos-deps; - # FIXME fix weird issue with rust-nightly and tarpaulin https://github.com/xd009642/tarpaulin/issues/1499 - RUSTFLAGS = "-Cstrip=none"; - # Default values from https://crane.dev/API.html?highlight=tarpau#cranelibcargotarpaulin # --avoid-cfg-tarpaulin fixes nom/bitvec issue https://github.com/xd009642/tarpaulin/issues/756#issuecomment-838769320 cargoTarpaulinExtraArgs = "--skip-clean --out xml --output-dir $out --avoid-cfg-tarpaulin"; - # For some reason cargoTarpaulin runs the tests in the buildPhase + # For some reason cargoTarpaulin runs the tests in the buildPhase buildInputs = kairosNodeAttrs.buildInputs ++ [ inputs'.csprpkgs.packages.cctl ]; From 3e8ec276fec01ae7a5e0246e72c96edd51b2df5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 15 Apr 2024 10:59:51 -0500 Subject: [PATCH 052/115] flake: update nixpkgs --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 6bc0c0a1..bc7d32f3 100644 --- a/flake.lock +++ b/flake.lock @@ -117,11 +117,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710734606, - "narHash": "sha256-rFJl+WXfksu2NkWJWKGd5Km17ZGEjFg9hOQNwstsoU8=", + "lastModified": 1713128889, + "narHash": "sha256-aB90ZqzosyRDpBh+rILIcyP5lao8SKz8Sr2PSWvZrzk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "79bb4155141a5e68f2bdee2bf6af35b1d27d3a1d", + "rev": "2748d22b45a99fb2deafa5f11c7531c212b2cefa", "type": "github" }, "original": { From f9affdfcabf819976e1c5397a85ff00def1674e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 15 Apr 2024 12:34:42 -0500 Subject: [PATCH 053/115] flake/risc0pkgs: don't follow our nixpkgs revision --- flake.lock | 27 +++++++++++++++++++++------ flake.nix | 6 ++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index bc7d32f3..52ed4d09 100644 --- a/flake.lock +++ b/flake.lock @@ -149,23 +149,38 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1713013257, + "narHash": "sha256-ZEfGB3YCBVggvk0BQIqVY7J8XF/9jxQ68fCca6nib+8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "90055d5e616bd943795d38808c94dbf0dd35abe8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, "risc0pkgs": { "inputs": { - "nixpkgs": [ - "nixpkgs" - ] + "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1705057078, - "narHash": "sha256-IvTD2yh6vYFKgvBATOl793csHbu2Vki3D19MKCHp8sk=", + "lastModified": 1707207642, + "narHash": "sha256-EjzGyFHs+hpSuvOjNnVBx48V5h5whRIyAjIUgSOzqLk=", "owner": "cspr-rad", "repo": "risc0pkgs", - "rev": "144c9a42850a245f581db2586208cd18f98ff62b", + "rev": "7acff27ce7116777cc7f5a162efa9b599808ed97", "type": "github" }, "original": { "owner": "cspr-rad", "repo": "risc0pkgs", + "rev": "7acff27ce7116777cc7f5a162efa9b599808ed97", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 9cb5034c..affc2a9d 100644 --- a/flake.nix +++ b/flake.nix @@ -25,8 +25,10 @@ crane.inputs.nixpkgs.follows = "nixpkgs"; advisory-db.url = "github:rustsec/advisory-db"; advisory-db.flake = false; - risc0pkgs.url = "github:cspr-rad/risc0pkgs"; - risc0pkgs.inputs.nixpkgs.follows = "nixpkgs"; + # Pin to a revision with working risc0 build + risc0pkgs.url = "github:cspr-rad/risc0pkgs/7acff27ce7116777cc7f5a162efa9b599808ed97"; + # FIXME once we are able to build with upstream rustc we should uncomment this + #risc0pkgs.inputs.nixpkgs.follows = "nixpkgs"; csprpkgs.url = "github:cspr-rad/csprpkgs/add-cctl"; csprpkgs.inputs.nixpkgs.follows = "nixpkgs"; }; From d2c2c10c5d5dbe9826eb03a1b044c0af4acb5500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 15 Apr 2024 13:12:26 -0500 Subject: [PATCH 054/115] kairos-contracts/demo-contracts-test: remove unused import --- kairos-contracts/demo-contract-tests/tests/integration_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kairos-contracts/demo-contract-tests/tests/integration_tests.rs b/kairos-contracts/demo-contract-tests/tests/integration_tests.rs index af54dc14..45607079 100644 --- a/kairos-contracts/demo-contract-tests/tests/integration_tests.rs +++ b/kairos-contracts/demo-contract-tests/tests/integration_tests.rs @@ -2,7 +2,7 @@ mod test_fixture; #[cfg(test)] mod tests { use crate::test_fixture::TestContext; - use casper_types::{account::AccountHash, Key, U512}; + use casper_types::{account::AccountHash, U512}; #[test] fn should_install_deposit_contract() { From 42afe4c390a36b917054b162b1cf943164026ccc Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:33:11 +0200 Subject: [PATCH 055/115] improve function name for callstack element --- kairos-contracts/demo-contract/contract/src/utils.rs | 4 ++-- kairos-contracts/rust-toolchain.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/utils.rs b/kairos-contracts/demo-contract/contract/src/utils.rs index bc162b82..461d74c2 100644 --- a/kairos-contracts/demo-contract/contract/src/utils.rs +++ b/kairos-contracts/demo-contract/contract/src/utils.rs @@ -11,7 +11,7 @@ pub mod events; use errors::DepositError; /// Wrap the immediate caller as a Key and return it -fn call_stack_element_to_address(call_stack_element: CallStackElement) -> Key { +fn call_stack_element_to_key(call_stack_element: CallStackElement) -> Key { match call_stack_element { CallStackElement::Session { account_hash } => Key::from(account_hash), CallStackElement::StoredSession { account_hash, .. } => { @@ -33,6 +33,6 @@ pub(crate) fn get_immediate_caller() -> Result { .into_iter() .rev() .nth(1) - .map(call_stack_element_to_address) + .map(call_stack_element_to_key) .ok_or(DepositError::InvalidContext) } diff --git a/kairos-contracts/rust-toolchain.toml b/kairos-contracts/rust-toolchain.toml index 860a7ce1..a0f1a930 100644 --- a/kairos-contracts/rust-toolchain.toml +++ b/kairos-contracts/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2024-01-04" \ No newline at end of file +channel = "nightly-2024-01-04" From 0dca31e99c922776b40139aa6a004d717f2aa4b4 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:32:21 +0200 Subject: [PATCH 056/115] add abstract for submit_batch entry point --- .../demo-contract/contract/src/main.rs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 22140bc4..0f8c9224 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] extern crate alloc; -use alloc::string::ToString; +use alloc::{string::ToString, vec::Vec}; use casper_contract::{ contract_api::{runtime, storage, system}, unwrap_or_revert::UnwrapOrRevert, @@ -57,6 +57,24 @@ pub extern "C" fn get_purse() { ); } +// Batch submission with host verifier: Unimplemented +// This entry point will verify a batch proof and update the trie root +// TODO: Store the trie root under a URef in this deposit contract +// QUESTION: What is the initial root and state of the trie? +#[no_mangle] +pub extern "C" fn submit_batch() { + // receive some serialized proof + // the proof will include a public journal with the updated trie root + let _serialized_proof: Vec = runtime::get_named_arg("serialized_proof"); + + // TODO: VERIFY proof and UPDATE the trie root + // TODO: UPDATE last_processed_deposit_counter by `n`, where `n` is the amount of deposits processed in this batch. + + // OPEN QUESTIONS + // How are L1 deposits verified when proving? + // Are deposits and transfers private or public inputs to the circuit / guest? +} + // Entry point called by a user through session code to deposit funds. // Due to Casper < 2.0 purse management and access control, it is necessary that // a temporary purse is funded and passed to the deposit contract, since this is @@ -107,12 +125,6 @@ pub extern "C" fn call() { let contract_hash_key = Key::from(contract_hash); runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); - /* - Initialize the contract, this will create the deposit purse. - Open questions: - - should this be revokable? - - should there be any governance at all? - */ let init_args = runtime_args! {}; runtime::call_contract::<()>(contract_hash, "init", init_args); } From 3458cd05d4505ad8ce241d66b1df7a689dbb6fe4 Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:31:44 +0200 Subject: [PATCH 057/115] add counter query function for 1.5.x, using Casper Client as a library --- Cargo.lock | 49 ++++++++++++++++++++++++++++++++++- Cargo.toml | 4 +-- kairos-l1-query/Cargo.toml | 11 ++++++++ kairos-l1-query/src/lib.rs | 53 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 kairos-l1-query/Cargo.toml create mode 100644 kairos-l1-query/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 07ecaf67..541b1d95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -470,6 +470,43 @@ dependencies = [ "vergen", ] +[[package]] +name = "casper-client" +version = "2.0.0" +source = "git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0#438b660733d1f70890e143b3a9c8ccae22822b57" +dependencies = [ + "async-trait", + "base16", + "base64 0.13.1", + "casper-hashing", + "casper-types 3.0.0", + "clap", + "clap_complete", + "derp", + "ed25519-dalek 1.0.1", + "getrandom", + "hex-buffer-serde 0.4.0", + "humantime", + "itertools", + "jsonrpc-lite", + "k256 0.7.3", + "num-traits", + "once_cell", + "pem 1.1.1", + "rand 0.8.5", + "reqwest 0.11.27", + "schemars", + "serde", + "serde_json", + "signature 1.2.2", + "tempfile", + "thiserror", + "tokio", + "uint", + "untrusted 0.9.0", + "vergen", +] + [[package]] name = "casper-hashing" version = "2.0.0" @@ -1733,6 +1770,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "kairos-l1-query" +version = "0.1.0" +dependencies = [ + "casper-client 2.0.0 (git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0)", + "casper-hashing", + "casper-types 3.0.0", + "tokio", +] + [[package]] name = "kairos-server" version = "0.1.0" @@ -1758,7 +1805,7 @@ version = "0.1.0" dependencies = [ "anyhow", "backoff", - "casper-client", + "casper-client 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "nom", "reqwest 0.12.3", "sd-notify", diff --git a/Cargo.toml b/Cargo.toml index 9bdf86b6..99ed3e4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,8 @@ members = [ "kairos-crypto", "kairos-server", "kairos-tx", - "kairos-test-utils", + "kairos-test-utils", + "kairos-l1-query", ] [workspace.package] @@ -14,4 +15,3 @@ name = "kairos" version = "0.1.0" edition = "2021" license = "MIT OR Apache-2.0" - diff --git a/kairos-l1-query/Cargo.toml b/kairos-l1-query/Cargo.toml new file mode 100644 index 00000000..8fe4f0d6 --- /dev/null +++ b/kairos-l1-query/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "kairos-l1-query" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +casper-client = {git="https://github.com/casper-ecosystem/casper-client-rs", branch="release-2.0.0"} +casper-types = "3.0.0" +casper-hashing = "2.0.0" +tokio = {version="1.36.0", features=["full"]} diff --git a/kairos-l1-query/src/lib.rs b/kairos-l1-query/src/lib.rs new file mode 100644 index 00000000..24af1d5d --- /dev/null +++ b/kairos-l1-query/src/lib.rs @@ -0,0 +1,53 @@ +use casper_client::{ + get_dictionary_item, get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, + Verbosity, +}; +use casper_hashing::Digest; +use casper_types::{ + bytesrepr::{Bytes, ToBytes}, + CLValue, Key, URef, +}; + +pub async fn query_state_root_hash(node_address: &str, rpc_port: &str) -> Digest { + let srh = get_state_root_hash( + JsonRpcId::String(rpc_port.to_owned()), + node_address, + Verbosity::Low, + None, + ) + .await + .unwrap() + .result + .state_root_hash + .unwrap(); + srh +} + +pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &str) -> u64 { + let srh: Digest = query_state_root_hash(node_address, rpc_port).await; + let stored_value: StoredValue = query_global_state( + JsonRpcId::String(rpc_port.to_owned()), + node_address, + Verbosity::Low, + casper_client::rpcs::GlobalStateIdentifier::StateRootHash( + srh, + ), + casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), + Vec::new(), + ) + .await + .unwrap() + .result + .stored_value; + let value: u64 = match stored_value { + StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), + _ => panic!("Missing Value!"), + }; + value +} + +#[tokio::test] +async fn state_root_hash(){ + let srh = query_state_root_hash("http://127.0.0.1:11101/rpc", "11101").await; + println!("Srh: {:?}", &srh); +} From 559634b46715c48ee5aecf124104f58f5400b4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 22 Apr 2024 10:48:30 -0500 Subject: [PATCH 058/115] add missing newlines at end of file --- kairos-contracts/demo-contract/deposit-session/Cargo.toml | 2 +- kairos-contracts/demo-contract/malicious-reader/Cargo.toml | 2 +- kairos-contracts/demo-contract/malicious-session/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kairos-contracts/demo-contract/deposit-session/Cargo.toml b/kairos-contracts/demo-contract/deposit-session/Cargo.toml index ec36e204..8122eeec 100644 --- a/kairos-contracts/demo-contract/deposit-session/Cargo.toml +++ b/kairos-contracts/demo-contract/deposit-session/Cargo.toml @@ -17,4 +17,4 @@ test = false [profile.release] codegen-units = 1 -lto = true \ No newline at end of file +lto = true diff --git a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml index ef5ee9ae..659962ef 100644 --- a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml @@ -15,4 +15,4 @@ name = "malicious-reader" path = "src/main.rs" bench = false doctest = false -test = false \ No newline at end of file +test = false diff --git a/kairos-contracts/demo-contract/malicious-session/Cargo.toml b/kairos-contracts/demo-contract/malicious-session/Cargo.toml index e1f96116..f38620ec 100644 --- a/kairos-contracts/demo-contract/malicious-session/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-session/Cargo.toml @@ -15,4 +15,4 @@ name = "malicious-session" path = "src/main.rs" bench = false doctest = false -test = false \ No newline at end of file +test = false From 870dc975fc644660a9896e800e93034577617bae Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:18:19 +0200 Subject: [PATCH 059/115] add contract utils for installation and counter query --- Cargo.toml | 2 +- kairos-l1-query/src/lib.rs | 53 --------- .../Cargo.toml | 0 kairos-l1-utils/src/lib.rs | 112 ++++++++++++++++++ 4 files changed, 113 insertions(+), 54 deletions(-) delete mode 100644 kairos-l1-query/src/lib.rs rename {kairos-l1-query => kairos-l1-utils}/Cargo.toml (100%) create mode 100644 kairos-l1-utils/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 99ed3e4f..de810b4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ "kairos-server", "kairos-tx", "kairos-test-utils", - "kairos-l1-query", + "kairos-l1-utils", ] [workspace.package] diff --git a/kairos-l1-query/src/lib.rs b/kairos-l1-query/src/lib.rs deleted file mode 100644 index 24af1d5d..00000000 --- a/kairos-l1-query/src/lib.rs +++ /dev/null @@ -1,53 +0,0 @@ -use casper_client::{ - get_dictionary_item, get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, - Verbosity, -}; -use casper_hashing::Digest; -use casper_types::{ - bytesrepr::{Bytes, ToBytes}, - CLValue, Key, URef, -}; - -pub async fn query_state_root_hash(node_address: &str, rpc_port: &str) -> Digest { - let srh = get_state_root_hash( - JsonRpcId::String(rpc_port.to_owned()), - node_address, - Verbosity::Low, - None, - ) - .await - .unwrap() - .result - .state_root_hash - .unwrap(); - srh -} - -pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &str) -> u64 { - let srh: Digest = query_state_root_hash(node_address, rpc_port).await; - let stored_value: StoredValue = query_global_state( - JsonRpcId::String(rpc_port.to_owned()), - node_address, - Verbosity::Low, - casper_client::rpcs::GlobalStateIdentifier::StateRootHash( - srh, - ), - casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), - Vec::new(), - ) - .await - .unwrap() - .result - .stored_value; - let value: u64 = match stored_value { - StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), - _ => panic!("Missing Value!"), - }; - value -} - -#[tokio::test] -async fn state_root_hash(){ - let srh = query_state_root_hash("http://127.0.0.1:11101/rpc", "11101").await; - println!("Srh: {:?}", &srh); -} diff --git a/kairos-l1-query/Cargo.toml b/kairos-l1-utils/Cargo.toml similarity index 100% rename from kairos-l1-query/Cargo.toml rename to kairos-l1-utils/Cargo.toml diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs new file mode 100644 index 00000000..af056d4c --- /dev/null +++ b/kairos-l1-utils/src/lib.rs @@ -0,0 +1,112 @@ +use casper_client::{ + get_dictionary_item, get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, + Verbosity, +}; +use casper_hashing::Digest; +use casper_types::{ + bytesrepr::{Bytes, ToBytes}, + CLValue, Key, URef, +}; + +use casper_client::{ + rpcs::results::PutDeployResult, + types::{Deploy, DeployBuilder, ExecutableDeployItem, Timestamp}, + SuccessResponse, +}; +use casper_types::{crypto::SecretKey, runtime_args, ContractHash, RuntimeArgs}; +use std::{fs, io::Read, result}; + +pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1000_000_000_000; + +pub async fn install_wasm_bytecode( + node_address: &str, + rpc_port: &str, + chain_name: &str, + runtime_args: RuntimeArgs, + module_bytes: &[u8], + secret_key_path: &str, +) -> SuccessResponse { + let session: ExecutableDeployItem = + ExecutableDeployItem::new_module_bytes(module_bytes.into(), runtime_args); + let secret_key_bytes: Vec = fs::read(secret_key_path).unwrap(); + let secret_key: SecretKey = SecretKey::from_pem(secret_key_bytes.clone()).unwrap(); + + let deploy: Deploy = DeployBuilder::new(chain_name, session, &secret_key) + .with_timestamp(Timestamp::now()) + .with_standard_payment(DEFAULT_PAYMENT_AMOUNT) + .build() + .unwrap(); + + let result = casper_client::put_deploy( + JsonRpcId::String(rpc_port.to_string()), + node_address, + casper_client::Verbosity::Low, + deploy, + ) + .await + .unwrap(); + result +} + +pub async fn query_state_root_hash(node_address: &str, rpc_port: &str) -> Digest { + let srh = get_state_root_hash( + JsonRpcId::String(rpc_port.to_owned()), + node_address, + Verbosity::Low, + None, + ) + .await + .unwrap() + .result + .state_root_hash + .unwrap(); + srh +} + +pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &str) -> u64 { + let srh: Digest = query_state_root_hash(node_address, rpc_port).await; + let stored_value: StoredValue = query_global_state( + JsonRpcId::String(rpc_port.to_owned()), + node_address, + Verbosity::Low, + casper_client::rpcs::GlobalStateIdentifier::StateRootHash(srh), + casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), + Vec::new(), + ) + .await + .unwrap() + .result + .stored_value; + let value: u64 = match stored_value { + StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), + _ => panic!("Missing Value!"), + }; + value +} + +#[tokio::test] +async fn state_root_hash() { + let srh = query_state_root_hash("http://127.0.0.1:11101/rpc", "11101").await; + println!("Srh: {:?}", &srh); +} + +#[tokio::test] +async fn install_wasm() { + use std::fs::File; + let mut wasm_file: File = + File::open("/Users/chef/Desktop/demo-contract-optimized.wasm").unwrap(); + let mut wasm_bytes: Vec = Vec::new(); + wasm_file.read_to_end(&mut wasm_bytes).unwrap(); + let secret_key_path: &str = "/Users/chef/Desktop/secret_key.pem"; + let runtime_args: RuntimeArgs = runtime_args! {}; + let result: SuccessResponse = install_wasm_bytecode( + "http://127.0.0.1:11101/rpc", + "11101", + "cspr-dev-cctl", + runtime_args, + &wasm_bytes, + secret_key_path, + ) + .await; + println!("Deploy result: {:?}", &result); +} From ef1d2c31a2f78149d1b68f87a0cdc3061e2bd1df Mon Sep 17 00:00:00 2001 From: Jonas Pauli <49498646+jonas089@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:29:21 +0200 Subject: [PATCH 060/115] apply clippy suggestions --- Cargo.lock | 30 +++++++++---------- .../demo-contract/contract/src/main.rs | 20 +++++++++++-- kairos-l1-utils/src/lib.rs | 25 +++++++--------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 603615f7..be60a492 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,7 +109,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -217,7 +217,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -487,7 +487,7 @@ dependencies = [ "async-trait", "base16", "base64 0.13.1", - "casper-hashing", + "casper-hashing 2.0.0", "casper-types 3.0.0", "clap", "clap_complete", @@ -822,7 +822,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -1001,7 +1001,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -1269,7 +1269,7 @@ checksum = "03cdc46ec28bd728e67540c528013c6a10eb69a02eb31078a1bda695438cbfb8" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -1986,7 +1986,7 @@ name = "kairos-l1-query" version = "0.1.0" dependencies = [ "casper-client 2.0.0 (git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0)", - "casper-hashing", + "casper-hashing 2.0.0", "casper-types 3.0.0", "tokio", ] @@ -2417,7 +2417,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -2510,7 +2510,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -3221,7 +3221,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -3657,7 +3657,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -3741,7 +3741,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -3997,7 +3997,7 @@ dependencies = [ "once_cell", "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", "wasm-bindgen-shared", ] @@ -4031,7 +4031,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4264,5 +4264,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", - "syn 2.0.53", + "syn 2.0.58", ] diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 0f8c9224..94ee5ad3 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -57,7 +57,7 @@ pub extern "C" fn get_purse() { ); } -// Batch submission with host verifier: Unimplemented +// Batch submission EP with host verifier: Unimplemented // This entry point will verify a batch proof and update the trie root // TODO: Store the trie root under a URef in this deposit contract // QUESTION: What is the initial root and state of the trie? @@ -65,14 +65,25 @@ pub extern "C" fn get_purse() { pub extern "C" fn submit_batch() { // receive some serialized proof // the proof will include a public journal with the updated trie root + // public journal will include all deposits let _serialized_proof: Vec = runtime::get_named_arg("serialized_proof"); - - // TODO: VERIFY proof and UPDATE the trie root + // TODO: VERIFY proof and UPDATE the trie root // TODO: UPDATE last_processed_deposit_counter by `n`, where `n` is the amount of deposits processed in this batch. // OPEN QUESTIONS // How are L1 deposits verified when proving? // Are deposits and transfers private or public inputs to the circuit / guest? + // Do we want to only store the most recent root, or a history of roots? + // Option + + // Merkle proof for each state transition in the Trie + // If that matches the current root it'll be valid + // DA must store all transitions and those are verified against the root hash? + // Triestate is stored in the L2 + // The trie is updated inside the guest + + // Trie verifies Balance against L1 root -> not responsible for proving updates + // Update Trie inside Circuit } // Entry point called by a user through session code to deposit funds. @@ -95,6 +106,7 @@ pub extern "C" fn deposit() { amount, timestamp: None, }; + // this increases a counter automatically - we don't need to create one ourselves casper_event_standard::emit(new_deposit_record); } @@ -126,5 +138,7 @@ pub extern "C" fn call() { runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); let init_args = runtime_args! {}; + // Call the init entry point of the newly installed contract + // This will setup the deposit purse and initialize Event Schemas (CES) runtime::call_contract::<()>(contract_hash, "init", init_args); } diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index af056d4c..1d298f57 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -1,22 +1,19 @@ use casper_client::{ - get_dictionary_item, get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, + get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, }; use casper_hashing::Digest; -use casper_types::{ - bytesrepr::{Bytes, ToBytes}, - CLValue, Key, URef, -}; +use casper_types::URef; use casper_client::{ rpcs::results::PutDeployResult, types::{Deploy, DeployBuilder, ExecutableDeployItem, Timestamp}, SuccessResponse, }; -use casper_types::{crypto::SecretKey, runtime_args, ContractHash, RuntimeArgs}; -use std::{fs, io::Read, result}; +use casper_types::{crypto::SecretKey, RuntimeArgs}; +use std::fs; -pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1000_000_000_000; +pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; pub async fn install_wasm_bytecode( node_address: &str, @@ -37,19 +34,18 @@ pub async fn install_wasm_bytecode( .build() .unwrap(); - let result = casper_client::put_deploy( + casper_client::put_deploy( JsonRpcId::String(rpc_port.to_string()), node_address, casper_client::Verbosity::Low, deploy, ) .await - .unwrap(); - result + .unwrap() } pub async fn query_state_root_hash(node_address: &str, rpc_port: &str) -> Digest { - let srh = get_state_root_hash( + get_state_root_hash( JsonRpcId::String(rpc_port.to_owned()), node_address, Verbosity::Low, @@ -59,8 +55,7 @@ pub async fn query_state_root_hash(node_address: &str, rpc_port: &str) -> Digest .unwrap() .result .state_root_hash - .unwrap(); - srh + .unwrap() } pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &str) -> u64 { @@ -93,6 +88,8 @@ async fn state_root_hash() { #[tokio::test] async fn install_wasm() { use std::fs::File; + use std::io::Read; + use casper_types::{RuntimeArgs, runtime_args}; let mut wasm_file: File = File::open("/Users/chef/Desktop/demo-contract-optimized.wasm").unwrap(); let mut wasm_bytes: Vec = Vec::new(); From ade4d3cde19afcecb014b5b2fe5ccbfc947c68e6 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Fri, 26 Apr 2024 23:14:26 +0200 Subject: [PATCH 061/115] default arbitrary RPC id to 0 --- kairos-l1-utils/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 1d298f57..d1f37e80 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -17,7 +17,6 @@ pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; pub async fn install_wasm_bytecode( node_address: &str, - rpc_port: &str, chain_name: &str, runtime_args: RuntimeArgs, module_bytes: &[u8], @@ -35,7 +34,7 @@ pub async fn install_wasm_bytecode( .unwrap(); casper_client::put_deploy( - JsonRpcId::String(rpc_port.to_string()), + JsonRpcId::String(0.to_string()), node_address, casper_client::Verbosity::Low, deploy, @@ -44,9 +43,9 @@ pub async fn install_wasm_bytecode( .unwrap() } -pub async fn query_state_root_hash(node_address: &str, rpc_port: &str) -> Digest { +pub async fn query_state_root_hash(node_address: &str) -> Digest { get_state_root_hash( - JsonRpcId::String(rpc_port.to_owned()), + JsonRpcId::String(0.to_string()), node_address, Verbosity::Low, None, @@ -59,7 +58,7 @@ pub async fn query_state_root_hash(node_address: &str, rpc_port: &str) -> Digest } pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &str) -> u64 { - let srh: Digest = query_state_root_hash(node_address, rpc_port).await; + let srh: Digest = query_state_root_hash(node_address).await; let stored_value: StoredValue = query_global_state( JsonRpcId::String(rpc_port.to_owned()), node_address, @@ -81,7 +80,7 @@ pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &st #[tokio::test] async fn state_root_hash() { - let srh = query_state_root_hash("http://127.0.0.1:11101/rpc", "11101").await; + let srh = query_state_root_hash("http://127.0.0.1:11101/rpc").await; println!("Srh: {:?}", &srh); } @@ -98,7 +97,6 @@ async fn install_wasm() { let runtime_args: RuntimeArgs = runtime_args! {}; let result: SuccessResponse = install_wasm_bytecode( "http://127.0.0.1:11101/rpc", - "11101", "cspr-dev-cctl", runtime_args, &wasm_bytes, From 328c222f101de1474ed6ee3d9d1bcca3db90b029 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Mon, 29 Apr 2024 16:58:21 +0200 Subject: [PATCH 062/115] depend on casper node with risc0 verifier --- kairos-contracts/Cargo.lock | 68 +++++++++---------- .../demo-contract-tests/Cargo.toml | 2 +- .../demo-contract/contract/Cargo.toml | 6 +- .../demo-contract/contract/src/main.rs | 29 -------- .../demo-contract/deposit-session/Cargo.toml | 4 +- .../demo-contract/malicious-reader/Cargo.toml | 4 +- .../malicious-session/Cargo.toml | 4 +- kairos-l1-utils/src/lib.rs | 5 +- 8 files changed, 44 insertions(+), 78 deletions(-) diff --git a/kairos-contracts/Cargo.lock b/kairos-contracts/Cargo.lock index a6eb1a6d..0654b265 100644 --- a/kairos-contracts/Cargo.lock +++ b/kairos-contracts/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "base16" @@ -82,8 +82,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "casper-contract" version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" +source = "git+https://github.com/cspr-rad/casper-node?branch=kairos-demo-1.5.6#35222130c58b3c9997a358d4248ddae603836496" dependencies = [ "casper-types", "hex_fmt", @@ -93,8 +92,7 @@ dependencies = [ [[package]] name = "casper-event-standard" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3a1bdb142b4bfcdceec757422b2e292f446b72ce3613f881eb694f3925ef10" +source = "git+https://github.com/cspr-rad/casper-event-standard?branch=kairos-demo-1.5.6#88b855da23d855d9680816a3dbb4b2e0c4f0ffa7" dependencies = [ "casper-contract", "casper-event-standard-macro", @@ -104,8 +102,7 @@ dependencies = [ [[package]] name = "casper-event-standard-macro" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "485810e6c8387863a92e9b81e4e66ce290e2c96c0ad8ec4352e95128aa88900e" +source = "git+https://github.com/cspr-rad/casper-event-standard?branch=kairos-demo-1.5.6#88b855da23d855d9680816a3dbb4b2e0c4f0ffa7" dependencies = [ "proc-macro2", "quote", @@ -115,8 +112,7 @@ dependencies = [ [[package]] name = "casper-types" version = "4.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" +source = "git+https://github.com/cspr-rad/casper-node?branch=kairos-demo-1.5.6#35222130c58b3c9997a358d4248ddae603836496" dependencies = [ "base16", "base64 0.13.1", @@ -239,7 +235,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.60", ] [[package]] @@ -252,9 +248,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -348,9 +344,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +checksum = "38793c55593b33412e3ae40c2c9781ffaa6f438f6f8c10f24e71846fbd7ae01e" [[package]] name = "generic-array" @@ -397,9 +393,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "k256" @@ -443,9 +439,9 @@ checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] name = "num" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" dependencies = [ "num-bigint", "num-complex", @@ -545,24 +541,24 @@ dependencies = [ [[package]] name = "platforms" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -628,9 +624,9 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] @@ -646,20 +642,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.60", ] [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -705,9 +701,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" @@ -722,9 +718,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.55" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", diff --git a/kairos-contracts/demo-contract-tests/Cargo.toml b/kairos-contracts/demo-contract-tests/Cargo.toml index 53c84aaa..b90227be 100644 --- a/kairos-contracts/demo-contract-tests/Cargo.toml +++ b/kairos-contracts/demo-contract-tests/Cargo.toml @@ -11,6 +11,6 @@ base64 = {version = "0.21.2", default-features = false, features = ["alloc"] } casper-engine-test-support = {version="7.0.0", default-features=false} casper-execution-engine = {version="7.0.0", default-features=false} casper-contract = {version="4.0.0", default-features=false} -casper-types = {version="4.0.0", default-features=false} +casper-types = {version="4.0.1", default-features=false} dotenvy = "0.15.7" lazy_static = "1.4.0" diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index 27e3f193..ec55cdef 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -5,9 +5,9 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = {version="4.0.0", features=["std", "test-support"]} -casper-types = {version="4.0.0", default-features=false} -casper-event-standard="0.5.0" +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["std", "test-support"]} +casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", default-features=false} +casper-event-standard= {git="https://github.com/cspr-rad/casper-event-standard", branch="kairos-demo-1.5.6", default-features=false} base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } bincode = "1.3.3" diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 94ee5ad3..4d010818 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -57,35 +57,6 @@ pub extern "C" fn get_purse() { ); } -// Batch submission EP with host verifier: Unimplemented -// This entry point will verify a batch proof and update the trie root -// TODO: Store the trie root under a URef in this deposit contract -// QUESTION: What is the initial root and state of the trie? -#[no_mangle] -pub extern "C" fn submit_batch() { - // receive some serialized proof - // the proof will include a public journal with the updated trie root - // public journal will include all deposits - let _serialized_proof: Vec = runtime::get_named_arg("serialized_proof"); - // TODO: VERIFY proof and UPDATE the trie root - // TODO: UPDATE last_processed_deposit_counter by `n`, where `n` is the amount of deposits processed in this batch. - - // OPEN QUESTIONS - // How are L1 deposits verified when proving? - // Are deposits and transfers private or public inputs to the circuit / guest? - // Do we want to only store the most recent root, or a history of roots? - // Option - - // Merkle proof for each state transition in the Trie - // If that matches the current root it'll be valid - // DA must store all transitions and those are verified against the root hash? - // Triestate is stored in the L2 - // The trie is updated inside the guest - - // Trie verifies Balance against L1 root -> not responsible for proving updates - // Update Trie inside Circuit -} - // Entry point called by a user through session code to deposit funds. // Due to Casper < 2.0 purse management and access control, it is necessary that // a temporary purse is funded and passed to the deposit contract, since this is diff --git a/kairos-contracts/demo-contract/deposit-session/Cargo.toml b/kairos-contracts/demo-contract/deposit-session/Cargo.toml index 8122eeec..d8abdfd0 100644 --- a/kairos-contracts/demo-contract/deposit-session/Cargo.toml +++ b/kairos-contracts/demo-contract/deposit-session/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = {version="4.0.0", features=["test-support"]} -casper-types = "4.0.0" +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["test-support"]} +casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} [[bin]] name = "deposit-session" diff --git a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml index 659962ef..d139388f 100644 --- a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml @@ -7,8 +7,8 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -casper-contract = "4.0.0" -casper-types = "4.0.0" +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["test-support"]} +casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} [[bin]] name = "malicious-reader" diff --git a/kairos-contracts/demo-contract/malicious-session/Cargo.toml b/kairos-contracts/demo-contract/malicious-session/Cargo.toml index f38620ec..b8a599bf 100644 --- a/kairos-contracts/demo-contract/malicious-session/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-session/Cargo.toml @@ -7,8 +7,8 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -casper-contract = "4.0.0" -casper-types = "4.0.0" +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["test-support"]} +casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} [[bin]] name = "malicious-session" diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index d1f37e80..6397b05a 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -1,6 +1,5 @@ use casper_client::{ - get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, - Verbosity, + get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, }; use casper_hashing::Digest; use casper_types::URef; @@ -86,9 +85,9 @@ async fn state_root_hash() { #[tokio::test] async fn install_wasm() { + use casper_types::{runtime_args, RuntimeArgs}; use std::fs::File; use std::io::Read; - use casper_types::{RuntimeArgs, runtime_args}; let mut wasm_file: File = File::open("/Users/chef/Desktop/demo-contract-optimized.wasm").unwrap(); let mut wasm_bytes: Vec = Vec::new(); From 0cab3106688467a0f41f1d0760bd443403c7eaca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 29 Apr 2024 10:23:37 -0500 Subject: [PATCH 063/115] flake: update fenix --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 52ed4d09..377f026d 100644 --- a/flake.lock +++ b/flake.lock @@ -66,11 +66,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1710742993, - "narHash": "sha256-W0PQCe0bW3hKF5lHawXrKynBcdSP18Qa4sb8DcUfOqI=", + "lastModified": 1714285404, + "narHash": "sha256-MmoQIO+KRiH3UnH0myAp2Fgi84rmpROMfw9VIbqrjHA=", "owner": "nix-community", "repo": "fenix", - "rev": "6f2fec850f569d61562d3a47dc263f19e9c7d825", + "rev": "94be183087845937b0fd77281c37d0796572b899", "type": "github" }, "original": { @@ -199,11 +199,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1710708100, - "narHash": "sha256-Jd6pmXlwKk5uYcjyO/8BfbUVmx8g31Qfk7auI2IG66A=", + "lastModified": 1714217560, + "narHash": "sha256-zttBYGaoHpZfqWHQ8OI5f9OkGHCHb8tDBMySwsYNa2U=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "b6d1887bc4f9543b6c6bf098179a62446f34a6c3", + "rev": "f216be4a0746142c5f30835b254871256a7637b8", "type": "github" }, "original": { From 7c69acc90c0bc67b3195e625a1daf91eff17fdf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 29 Apr 2024 14:03:45 -0500 Subject: [PATCH 064/115] update Cargo.lock --- Cargo.lock | 599 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 538 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f55b2d2e..04ff3b5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "aliasable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" + [[package]] name = "anstream" version = "0.6.13" @@ -107,8 +113,8 @@ version = "0.1.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -215,8 +221,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00c055ee2d014ae5981ce1016374e8213682aa14d9bf40e48ab48b5f3ef20eaa" dependencies = [ "heck 0.4.1", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -314,6 +320,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -441,7 +456,44 @@ dependencies = [ "async-trait", "base16", "base64 0.13.1", - "casper-hashing", + "casper-hashing 2.0.0", + "casper-types 3.0.0", + "clap", + "clap_complete", + "derp", + "ed25519-dalek 1.0.1", + "getrandom", + "hex-buffer-serde 0.4.0", + "humantime", + "itertools 0.10.5", + "jsonrpc-lite", + "k256 0.7.3", + "num-traits", + "once_cell", + "pem 1.1.1", + "rand 0.8.5", + "reqwest 0.11.27", + "schemars", + "serde", + "serde_json", + "signature 1.2.2", + "tempfile", + "thiserror", + "tokio", + "uint", + "untrusted 0.9.0", + "vergen", +] + +[[package]] +name = "casper-client" +version = "2.0.0" +source = "git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0#438b660733d1f70890e143b3a9c8ccae22822b57" +dependencies = [ + "async-trait", + "base16", + "base64 0.13.1", + "casper-hashing 2.0.0", "casper-types 3.0.0", "clap", "clap_complete", @@ -450,7 +502,7 @@ dependencies = [ "getrandom", "hex-buffer-serde 0.4.0", "humantime", - "itertools", + "itertools 0.10.5", "jsonrpc-lite", "k256 0.7.3", "num-traits", @@ -470,6 +522,16 @@ dependencies = [ "vergen", ] +[[package]] +name = "casper-contract" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" +dependencies = [ + "casper-types 4.0.1", + "hex_fmt", +] + [[package]] name = "casper-deploy-notifier" version = "0.1.0" @@ -485,6 +547,73 @@ dependencies = [ "tokio", ] +[[package]] +name = "casper-engine-test-support" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7967f1032f17243fbc9df3e4a8591dba169676adb3262b53dab4bb98f37d3c01" +dependencies = [ + "casper-execution-engine", + "casper-hashing 3.0.0", + "casper-types 4.0.1", + "filesize", + "humantime", + "lmdb-rkv", + "log", + "num-rational", + "num-traits", + "once_cell", + "rand 0.8.5", + "serde", + "tempfile", + "toml", +] + +[[package]] +name = "casper-execution-engine" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e4b48df024b3424cc994c60403472f66ca0961bffb25800f66318bb66c80611" +dependencies = [ + "anyhow", + "base16", + "bincode", + "casper-hashing 3.0.0", + "casper-types 4.0.1", + "casper-wasm", + "casper-wasm-utils", + "casper-wasmi", + "datasize", + "either", + "hex-buffer-serde 0.2.2", + "hex_fmt", + "hostname", + "humantime", + "itertools 0.10.5", + "libc", + "linked-hash-map", + "lmdb-rkv", + "log", + "num", + "num-derive", + "num-rational", + "num-traits", + "num_cpus", + "once_cell", + "proptest", + "rand 0.8.5", + "rand_chacha 0.3.1", + "schemars", + "serde", + "serde_bytes", + "serde_json", + "strum", + "thiserror", + "tracing", + "uint", + "uuid 0.8.2", +] + [[package]] name = "casper-hashing" version = "2.0.0" @@ -498,7 +627,27 @@ dependencies = [ "hex", "hex-buffer-serde 0.3.0", "hex_fmt", - "itertools", + "itertools 0.10.5", + "once_cell", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "casper-hashing" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c29b63e179d67da0c6b32c1b84bad5480f5f4bfd1b2d7f88390c85f92e87ae0" +dependencies = [ + "base16", + "blake2", + "casper-types 4.0.1", + "datasize", + "hex", + "hex-buffer-serde 0.3.0", + "hex_fmt", + "itertools 0.10.5", "once_cell", "schemars", "serde", @@ -549,6 +698,7 @@ dependencies = [ "base64 0.13.1", "bitflags 1.3.2", "blake2", + "datasize", "derp", "ed25519-dalek 2.1.1", "getrandom", @@ -563,15 +713,70 @@ dependencies = [ "num-traits", "once_cell", "pem 0.8.3", + "proptest", + "proptest-derive", "rand 0.8.5", + "rand_pcg", + "schemars", "serde", "serde_bytes", "serde_json", + "strum", "thiserror", "uint", "untrusted 0.7.1", ] +[[package]] +name = "casper-wasm" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f53c4e789fbff66ead0ea44030b1af2fc3c465201973483528e479a9155f98" + +[[package]] +name = "casper-wasm-utils" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15d9f1a2269d52961812862f67d209ef29742d06b47634e2982a96e80d0fe2b4" +dependencies = [ + "byteorder", + "casper-wasm", + "log", +] + +[[package]] +name = "casper-wasmi" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8357f19a7fd98073d8fe8df60f1bef1e677b7c623c1e6e2e07d2f8e59ceb87fc" +dependencies = [ + "casper-wasm", + "casper-wasmi-core", + "casper-wasmi-validation", +] + +[[package]] +name = "casper-wasmi-core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60089625560924f184cf91d59b0731373d5114b81224f1201c6a39ccc1d8388c" +dependencies = [ + "downcast-rs", + "libm", + "memory_units", + "num-rational", + "num-traits", +] + +[[package]] +name = "casper-wasmi-validation" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f669d385132ce321a57fdf453588d69c01654e75991bee3d22392a3aaaad80bb" +dependencies = [ + "casper-wasm", +] + [[package]] name = "cc" version = "1.0.90" @@ -636,8 +841,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck 0.5.0", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -815,8 +1020,8 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -835,11 +1040,24 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613e4ee15899913285b7612004bbd490abd605be7b11d35afada5902fb6b91d5" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] +[[package]] +name = "demo-contract-tests" +version = "0.1.0" +dependencies = [ + "base64 0.21.7", + "casper-contract", + "casper-engine-test-support", + "casper-execution-engine", + "casper-types 4.0.1", + "dotenvy", + "lazy_static", +] + [[package]] name = "der" version = "0.1.0" @@ -922,6 +1140,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + [[package]] name = "dyn-clone" version = "1.0.17" @@ -1064,8 +1288,8 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03cdc46ec28bd728e67540c528013c6a10eb69a02eb31078a1bda695438cbfb8" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -1129,6 +1353,15 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +[[package]] +name = "filesize" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12d741e2415d4e2e5bd1c1d00409d1a8865a57892c2d689b504365655d237d43" +dependencies = [ + "winapi", +] + [[package]] name = "float-cmp" version = "0.9.0" @@ -1234,8 +1467,8 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -1298,8 +1531,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" dependencies = [ "proc-macro-error", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] @@ -1445,6 +1678,16 @@ dependencies = [ "serde", ] +[[package]] +name = "hex-buffer-serde" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310e9578ff64e65a3a18e0624609f6833ee4a20503ef38eebb48430cf8ac3ab8" +dependencies = [ + "hex", + "serde", +] + [[package]] name = "hex-buffer-serde" version = "0.3.0" @@ -1490,6 +1733,17 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + [[package]] name = "http" version = "0.2.12" @@ -1713,6 +1967,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -1800,6 +2063,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "kairos-l1-query" +version = "0.1.0" +dependencies = [ + "casper-client 2.0.0 (git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0)", + "casper-hashing 2.0.0", + "casper-types 3.0.0", + "tokio", +] + [[package]] name = "kairos-server" version = "0.1.0" @@ -1810,10 +2083,12 @@ dependencies = [ "axum-test", "dotenvy", "hex", + "kairos-trie", "kairos-tx", "proptest", "serde", "serde_json", + "sha2 0.10.8", "tokio", "tracing", "tracing-subscriber", @@ -1825,7 +2100,7 @@ version = "0.1.0" dependencies = [ "anyhow", "backoff", - "casper-client", + "casper-client 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "nom", "reqwest 0.12.3", "sd-notify", @@ -1834,6 +2109,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "kairos-trie" +version = "0.1.0" +source = "git+https://github.com/cspr-rad/kairos-trie#760a4b7a72334c737fe6b4a40f82ae0e1c35bcb3" +dependencies = [ + "bumpalo", + "digest 0.10.7", + "ouroboros", +] + [[package]] name = "kairos-tx" version = "0.1.0" @@ -1905,12 +2190,41 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +[[package]] +name = "lmdb-rkv" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "libc", + "lmdb-rkv-sys", +] + +[[package]] +name = "lmdb-rkv-sys" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61b9ce6b3be08acefa3003c57b7565377432a89ec24476bbe72e11d101f852fe" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "lock_api" version = "0.4.11" @@ -1926,6 +2240,16 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "serde", + "value-bag", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" [[package]] name = "matchers" @@ -1948,6 +2272,12 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + [[package]] name = "mime" version = "0.3.17" @@ -2080,8 +2410,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] @@ -2115,6 +2445,7 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", + "serde", ] [[package]] @@ -2179,8 +2510,8 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -2202,6 +2533,31 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ouroboros" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b7be5a8a3462b752f4be3ff2b2bf2f7f1d00834902e46be2a4d68b87b0573c" +dependencies = [ + "aliasable", + "ouroboros_macro", + "static_assertions", +] + +[[package]] +name = "ouroboros_macro" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b645dcde5f119c2c454a92d0dfa271a2a3b205da92e4292a68ead4bdbfde1f33" +dependencies = [ + "heck 0.4.1", + "itertools 0.12.1", + "proc-macro2 1.0.79", + "proc-macro2-diagnostics", + "quote 1.0.35", + "syn 2.0.58", +] + [[package]] name = "overload" version = "0.1.1" @@ -2272,8 +2628,8 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -2369,7 +2725,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" dependencies = [ "diff", - "yansi", + "yansi 0.5.1", ] [[package]] @@ -2379,8 +2735,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", "version_check", ] @@ -2391,11 +2747,20 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "version_check", ] +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid", +] + [[package]] name = "proc-macro2" version = "1.0.79" @@ -2405,6 +2770,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-macro2-diagnostics" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 2.0.58", + "version_check", + "yansi 1.0.1", +] + [[package]] name = "proptest" version = "1.4.0" @@ -2425,19 +2803,39 @@ dependencies = [ "unarray", ] +[[package]] +name = "proptest-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90b46295382dc76166cb7cf2bb4a97952464e4b7ed5a43e6cd34e1fec3349ddc" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + [[package]] name = "quick-error" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + [[package]] name = "quote" version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.79", ] [[package]] @@ -2518,6 +2916,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "rand_xorshift" version = "0.3.0" @@ -2557,12 +2964,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbaf7105cd254b632f4732fbcc243ce750cef87d8335826125ef6df5733b5a0c" dependencies = [ "either", - "itertools", - "proc-macro2", - "quote", + "itertools 0.10.5", + "proc-macro2 1.0.79", + "quote 1.0.35", "rayon", "syn 1.0.109", - "uuid", + "uuid 1.8.0", ] [[package]] @@ -2863,8 +3270,8 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "791c2c848cff1abaeae34fef7e70da5f93171d9eea81ce0fe969a1df627a61a8" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "serde_derive_internals", "syn 1.0.109", ] @@ -2947,8 +3354,8 @@ version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -2958,8 +3365,8 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] @@ -3116,8 +3523,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "990079665f075b699031e9c08fd3ab99be5029b96f3b78dc0709e8f77e4efebf" dependencies = [ "heck 0.4.1", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] @@ -3153,20 +3560,53 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck 0.4.1", + "proc-macro2 1.0.79", + "quote 1.0.35", + "rustversion", + "syn 1.0.109", +] + [[package]] name = "subtle" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid", +] + [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "unicode-ident", ] @@ -3176,8 +3616,8 @@ version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "unicode-ident", ] @@ -3263,8 +3703,8 @@ version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 1.0.109", ] @@ -3350,8 +3790,8 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -3379,6 +3819,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "tower" version = "0.4.13" @@ -3425,8 +3874,8 @@ version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] @@ -3544,6 +3993,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "untrusted" version = "0.7.1" @@ -3573,6 +4028,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "uuid" version = "1.8.0" @@ -3588,6 +4053,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" + [[package]] name = "vcpkg" version = "0.2.15" @@ -3659,8 +4130,8 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", "wasm-bindgen-shared", ] @@ -3683,7 +4154,7 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ - "quote", + "quote 1.0.35", "wasm-bindgen-macro-support", ] @@ -3693,8 +4164,8 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -3924,6 +4395,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "zeroize" version = "1.7.0" @@ -3939,7 +4416,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.79", + "quote 1.0.35", "syn 2.0.58", ] From 377cd699018704aad2f2f9f3423305dc63e8922b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 29 Apr 2024 16:20:40 -0500 Subject: [PATCH 065/115] kairos-l1-utils: fix integration test --- Cargo.lock | 5 ++- flake.nix | 1 + kairos-l1-utils/Cargo.toml | 6 ++- kairos-l1-utils/src/lib.rs | 76 ++++++++++++++++++++++++++++++++------ 4 files changed, 74 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04ff3b5d..edabafc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2064,12 +2064,15 @@ dependencies = [ ] [[package]] -name = "kairos-l1-query" +name = "kairos-l1-utils" version = "0.1.0" dependencies = [ + "anyhow", + "backoff", "casper-client 2.0.0 (git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0)", "casper-hashing 2.0.0", "casper-types 3.0.0", + "kairos-test-utils", "tokio", ] diff --git a/flake.nix b/flake.nix index 65cbfe46..97ecea62 100644 --- a/flake.nix +++ b/flake.nix @@ -115,6 +115,7 @@ devShells.default = pkgs.mkShell { # Rust Analyzer needs to be able to find the path to default crate RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + PATH_TO_WASM_BINARIES = "${self'.packages.kairos-contracts}/bin"; inputsFrom = [ self'.packages.kairos ]; }; diff --git a/kairos-l1-utils/Cargo.toml b/kairos-l1-utils/Cargo.toml index 8fe4f0d6..de60a213 100644 --- a/kairos-l1-utils/Cargo.toml +++ b/kairos-l1-utils/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kairos-l1-query" +name = "kairos-l1-utils" version.workspace = true edition.workspace = true license.workspace = true @@ -9,3 +9,7 @@ casper-client = {git="https://github.com/casper-ecosystem/casper-client-rs", bra casper-types = "3.0.0" casper-hashing = "2.0.0" tokio = {version="1.36.0", features=["full"]} +[dev-dependencies] +anyhow = "*" +kairos-test-utils = { path = "../kairos-test-utils" } +backoff = { version = "0.4", features = ["tokio", "futures"]} diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 6397b05a..1fcab4f6 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -23,6 +23,7 @@ pub async fn install_wasm_bytecode( ) -> SuccessResponse { let session: ExecutableDeployItem = ExecutableDeployItem::new_module_bytes(module_bytes.into(), runtime_args); + println!("{}", secret_key_path); let secret_key_bytes: Vec = fs::read(secret_key_path).unwrap(); let secret_key: SecretKey = SecretKey::from_pem(secret_key_bytes.clone()).unwrap(); @@ -77,30 +78,81 @@ pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &st value } -#[tokio::test] -async fn state_root_hash() { - let srh = query_state_root_hash("http://127.0.0.1:11101/rpc").await; - println!("Srh: {:?}", &srh); -} - +#[cfg_attr(not(feature = "cctl-tests"), ignore)] #[tokio::test] async fn install_wasm() { + use anyhow::anyhow; + use backoff::{backoff::Constant, future::retry}; + use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; use casper_types::{runtime_args, RuntimeArgs}; + use kairos_test_utils::cctl::CCTLNetwork; use std::fs::File; use std::io::Read; - let mut wasm_file: File = - File::open("/Users/chef/Desktop/demo-contract-optimized.wasm").unwrap(); + use std::path::Path; + + let network = CCTLNetwork::run().await.unwrap(); + let node = network + .nodes + .first() + .expect("Expected at least one node after successful network run"); + let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); + + let wasm_path = Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); + let mut wasm_file: File = File::open(wasm_path).unwrap(); let mut wasm_bytes: Vec = Vec::new(); wasm_file.read_to_end(&mut wasm_bytes).unwrap(); - let secret_key_path: &str = "/Users/chef/Desktop/secret_key.pem"; + let runtime_args: RuntimeArgs = runtime_args! {}; let result: SuccessResponse = install_wasm_bytecode( - "http://127.0.0.1:11101/rpc", + node_address, "cspr-dev-cctl", runtime_args, &wasm_bytes, - secret_key_path, + network + .assets_dir + .join("users/user-1/secret_key.pem") + .to_str() + .unwrap(), ) .await; - println!("Deploy result: {:?}", &result); + + // wait for successful processing of deploy + retry( + Constant::new(std::time::Duration::from_millis(100)), + || async { + get_deploy( + JsonRpcId::Number(1), + node_address, + Verbosity::High, + result.result.deploy_hash, + true, + ) + .await + .map_err(|err| match &err { + Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { + backoff::Error::transient(anyhow!(err)) + } + _ => backoff::Error::permanent(anyhow!(err)), + }) + .map(|success| { + if success + .result + .execution_results + .iter() + .all(|execution_result| match execution_result.result { + casper_types::ExecutionResult::Success { .. } => true, + casper_types::ExecutionResult::Failure { .. } => false, + }) + { + Ok(()) + } else { + Err(backoff::Error::transient(anyhow!( + "Deploy was not processed yet" + ))) + } + })? + }, + ) + .await + .unwrap() } From 07f623c9ee6e2a78078a6080730e2d147d3d8045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 29 Apr 2024 14:23:50 -0500 Subject: [PATCH 066/115] flake/kairos: don't filter kairos-contracts and kairos-l1-utils --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 97ecea62..37a6ea9a 100644 --- a/flake.nix +++ b/flake.nix @@ -82,6 +82,8 @@ "/kairos-crypto" "/kairos-server" "/kairos-test-utils" + "/kairos-l1-utils" + "/kairos-contracts" "/kairos-tx" "/Cargo.toml" "/Cargo.lock" From a54da4c1a9111402f09f66d4d2689850fadab149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 29 Apr 2024 14:28:22 -0500 Subject: [PATCH 067/115] kairos-contracts/demo-contract: remove unused import --- kairos-contracts/demo-contract/contract/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 4d010818..786f0b76 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] extern crate alloc; -use alloc::{string::ToString, vec::Vec}; +use alloc::string::ToString; use casper_contract::{ contract_api::{runtime, storage, system}, unwrap_or_revert::UnwrapOrRevert, From 3ccd97cc8a2f2ac89b5c33d7db47fa1edfbf8e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Tue, 30 Apr 2024 08:15:42 -0500 Subject: [PATCH 068/115] kairos-l1-utils: add all-tests feature and cctl-tests feature --- kairos-l1-utils/Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kairos-l1-utils/Cargo.toml b/kairos-l1-utils/Cargo.toml index de60a213..5df9f92f 100644 --- a/kairos-l1-utils/Cargo.toml +++ b/kairos-l1-utils/Cargo.toml @@ -9,6 +9,11 @@ casper-client = {git="https://github.com/casper-ecosystem/casper-client-rs", bra casper-types = "3.0.0" casper-hashing = "2.0.0" tokio = {version="1.36.0", features=["full"]} + +[features] +all-tests = ["cctl-tests"] +cctl-tests = [] + [dev-dependencies] anyhow = "*" kairos-test-utils = { path = "../kairos-test-utils" } From af1c00af9ef38468e603388769f291181f7845a0 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 15:59:06 +0200 Subject: [PATCH 069/115] add function to query contract urefs --- kairos-l1-utils/src/lib.rs | 47 ++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 1fcab4f6..9f9fff5a 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -1,15 +1,15 @@ use casper_client::{ - get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, + get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity }; use casper_hashing::Digest; -use casper_types::URef; +use casper_types::{ContractWasmHash, URef}; use casper_client::{ rpcs::results::PutDeployResult, types::{Deploy, DeployBuilder, ExecutableDeployItem, Timestamp}, SuccessResponse, }; -use casper_types::{crypto::SecretKey, RuntimeArgs}; +use casper_types::{crypto::SecretKey, RuntimeArgs, Key}; use std::fs; pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; @@ -57,25 +57,44 @@ pub async fn query_state_root_hash(node_address: &str) -> Digest { .unwrap() } -pub async fn query_counter(node_address: &str, rpc_port: &str, counter_uref: &str) -> u64 { +pub async fn query_contract_uref_from_installing_account(node_address: &str, srh: Digest, account: Key, contract_identifier: &str, contract_uref: &str) -> URef{ + let stored_value: StoredValue = query_stored_value(node_address, srh, account, vec![contract_identifier.to_owned()]).await; + let contract: ContractWasmHash = match stored_value{ + StoredValue::Contract(contract) => *contract.contract_wasm_hash(), + _ => panic!("Missing or invalid Value") + }; + let stored_value: StoredValue = query_stored_value(node_address, srh, contract.into(), vec![contract_uref.into()]).await; + let value: URef = match stored_value{ + StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), + _ => panic!("Missing or invalid Value") + }; + + value +} + +pub async fn query_counter(node_address: &str, counter_uref: &str) -> u64 { let srh: Digest = query_state_root_hash(node_address).await; - let stored_value: StoredValue = query_global_state( - JsonRpcId::String(rpc_port.to_owned()), + let stored_value: StoredValue = query_stored_value(node_address, srh, casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), Vec::new()).await; + let value: u64 = match stored_value { + StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), + _ => panic!("Missing Value!"), + }; + value +} + +async fn query_stored_value(node_address: &str, srh: Digest, key: Key, path: Vec) -> StoredValue{ + query_global_state( + JsonRpcId::String(0.to_string()), node_address, Verbosity::Low, casper_client::rpcs::GlobalStateIdentifier::StateRootHash(srh), - casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), - Vec::new(), + key, + path ) .await .unwrap() .result - .stored_value; - let value: u64 = match stored_value { - StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), - _ => panic!("Missing Value!"), - }; - value + .stored_value } #[cfg_attr(not(feature = "cctl-tests"), ignore)] From b428c69febbdeaa787b33f3c3baa1d9b2ad361d3 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 16:04:08 +0200 Subject: [PATCH 070/115] depend on casper-client from crates.io --- Cargo.lock | 41 ++--------------------------- kairos-l1-utils/Cargo.toml | 2 +- kairos-l1-utils/src/lib.rs | 53 +++++++++++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edabafc2..546f980c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,43 +485,6 @@ dependencies = [ "vergen", ] -[[package]] -name = "casper-client" -version = "2.0.0" -source = "git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0#438b660733d1f70890e143b3a9c8ccae22822b57" -dependencies = [ - "async-trait", - "base16", - "base64 0.13.1", - "casper-hashing 2.0.0", - "casper-types 3.0.0", - "clap", - "clap_complete", - "derp", - "ed25519-dalek 1.0.1", - "getrandom", - "hex-buffer-serde 0.4.0", - "humantime", - "itertools 0.10.5", - "jsonrpc-lite", - "k256 0.7.3", - "num-traits", - "once_cell", - "pem 1.1.1", - "rand 0.8.5", - "reqwest 0.11.27", - "schemars", - "serde", - "serde_json", - "signature 1.2.2", - "tempfile", - "thiserror", - "tokio", - "uint", - "untrusted 0.9.0", - "vergen", -] - [[package]] name = "casper-contract" version = "4.0.0" @@ -2069,7 +2032,7 @@ version = "0.1.0" dependencies = [ "anyhow", "backoff", - "casper-client 2.0.0 (git+https://github.com/casper-ecosystem/casper-client-rs?branch=release-2.0.0)", + "casper-client", "casper-hashing 2.0.0", "casper-types 3.0.0", "kairos-test-utils", @@ -2103,7 +2066,7 @@ version = "0.1.0" dependencies = [ "anyhow", "backoff", - "casper-client 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "casper-client", "nom", "reqwest 0.12.3", "sd-notify", diff --git a/kairos-l1-utils/Cargo.toml b/kairos-l1-utils/Cargo.toml index 5df9f92f..6d8ec299 100644 --- a/kairos-l1-utils/Cargo.toml +++ b/kairos-l1-utils/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true license.workspace = true [dependencies] -casper-client = {git="https://github.com/casper-ecosystem/casper-client-rs", branch="release-2.0.0"} +casper-client = "2.0.0" casper-types = "3.0.0" casper-hashing = "2.0.0" tokio = {version="1.36.0", features=["full"]} diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 9f9fff5a..1d9b7223 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -1,5 +1,5 @@ use casper_client::{ - get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity + get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, }; use casper_hashing::Digest; use casper_types::{ContractWasmHash, URef}; @@ -9,7 +9,7 @@ use casper_client::{ types::{Deploy, DeployBuilder, ExecutableDeployItem, Timestamp}, SuccessResponse, }; -use casper_types::{crypto::SecretKey, RuntimeArgs, Key}; +use casper_types::{crypto::SecretKey, Key, RuntimeArgs}; use std::fs; pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; @@ -57,16 +57,34 @@ pub async fn query_state_root_hash(node_address: &str) -> Digest { .unwrap() } -pub async fn query_contract_uref_from_installing_account(node_address: &str, srh: Digest, account: Key, contract_identifier: &str, contract_uref: &str) -> URef{ - let stored_value: StoredValue = query_stored_value(node_address, srh, account, vec![contract_identifier.to_owned()]).await; - let contract: ContractWasmHash = match stored_value{ +pub async fn query_contract_uref_from_installing_account( + node_address: &str, + srh: Digest, + account: Key, + contract_identifier: &str, + contract_uref: &str, +) -> URef { + let stored_value: StoredValue = query_stored_value( + node_address, + srh, + account, + vec![contract_identifier.to_owned()], + ) + .await; + let contract: ContractWasmHash = match stored_value { StoredValue::Contract(contract) => *contract.contract_wasm_hash(), - _ => panic!("Missing or invalid Value") + _ => panic!("Missing or invalid Value"), }; - let stored_value: StoredValue = query_stored_value(node_address, srh, contract.into(), vec![contract_uref.into()]).await; - let value: URef = match stored_value{ + let stored_value: StoredValue = query_stored_value( + node_address, + srh, + contract.into(), + vec![contract_uref.into()], + ) + .await; + let value: URef = match stored_value { StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), - _ => panic!("Missing or invalid Value") + _ => panic!("Missing or invalid Value"), }; value @@ -74,7 +92,13 @@ pub async fn query_contract_uref_from_installing_account(node_address: &str, srh pub async fn query_counter(node_address: &str, counter_uref: &str) -> u64 { let srh: Digest = query_state_root_hash(node_address).await; - let stored_value: StoredValue = query_stored_value(node_address, srh, casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), Vec::new()).await; + let stored_value: StoredValue = query_stored_value( + node_address, + srh, + casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), + Vec::new(), + ) + .await; let value: u64 = match stored_value { StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), _ => panic!("Missing Value!"), @@ -82,14 +106,19 @@ pub async fn query_counter(node_address: &str, counter_uref: &str) -> u64 { value } -async fn query_stored_value(node_address: &str, srh: Digest, key: Key, path: Vec) -> StoredValue{ +async fn query_stored_value( + node_address: &str, + srh: Digest, + key: Key, + path: Vec, +) -> StoredValue { query_global_state( JsonRpcId::String(0.to_string()), node_address, Verbosity::Low, casper_client::rpcs::GlobalStateIdentifier::StateRootHash(srh), key, - path + path, ) .await .unwrap() From f536bb1c640c51387e0a7af55f4b04acce2b0f30 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 16:49:08 +0200 Subject: [PATCH 071/115] typecheck for amount - u64 --- kairos-contracts/demo-contract/contract/Cargo.toml | 1 - kairos-contracts/demo-contract/contract/src/main.rs | 3 +++ kairos-contracts/demo-contract/contract/src/utils/events.rs | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index ec55cdef..8e102c8d 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -11,7 +11,6 @@ casper-event-standard= {git="https://github.com/cspr-rad/casper-event-standard", base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } bincode = "1.3.3" - [build] target = "wasm32-unknown-unknown" diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 786f0b76..34a65290 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -71,6 +71,9 @@ pub extern "C" fn deposit() { .unwrap_or_revert_with(ApiError::UnexpectedKeyVariant); system::transfer_from_purse_to_purse(temp_purse, deposit_purse_uref, amount, None) .unwrap_or_revert(); + + // kairos utilizes u64 so only amounts that can be converted are accepted. + let amount = u64::try_from(amount).unwrap_or_revert(); let new_deposit_record: Deposit = Deposit { account: get_immediate_caller().unwrap_or_revert(), diff --git a/kairos-contracts/demo-contract/contract/src/utils/events.rs b/kairos-contracts/demo-contract/contract/src/utils/events.rs index 980b7b14..6afe6559 100644 --- a/kairos-contracts/demo-contract/contract/src/utils/events.rs +++ b/kairos-contracts/demo-contract/contract/src/utils/events.rs @@ -1,11 +1,11 @@ use casper_event_standard::Event; extern crate alloc; use alloc::string::String; -use casper_types::{Key, U512}; +use casper_types::Key; #[derive(Event)] pub struct Deposit { pub account: Key, - pub amount: U512, + pub amount: u64, pub timestamp: Option, } From 9b7733e31209eb5d6035972c11857150166c3a46 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 16:58:27 +0200 Subject: [PATCH 072/115] remove unused code --- kairos-contracts/demo-contract/contract/src/constants.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/constants.rs b/kairos-contracts/demo-contract/contract/src/constants.rs index 9f3540ef..3fc43dad 100644 --- a/kairos-contracts/demo-contract/contract/src/constants.rs +++ b/kairos-contracts/demo-contract/contract/src/constants.rs @@ -1,6 +1,5 @@ pub const KAIROS_DEPOSIT_CONTRACT_NAME: &str = "kairos_demo_contract"; -//#[allow(dead_code)] pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "kairos_contract_package"; pub const KAIROS_DEPOSIT_CONTRACT_UREF: &str = "demo_contract"; @@ -9,7 +8,6 @@ pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; pub const RUNTIME_ARG_TEMP_PURSE: &str = "temp_purse"; -//#[allow(dead_code)] pub const RUNTIME_ARG_AMOUNT: &str = "amount"; pub const EP_INIT_NAME: &str = "init"; From 5f382848921597a1949187363d43a59b23a36d81 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 17:11:22 +0200 Subject: [PATCH 073/115] fix u64 unwrap error --- .DS_Store | Bin 0 -> 8196 bytes .../demo-contract/contract/src/main.rs | 5 +++-- .../demo-contract/contract/src/utils/errors.rs | 9 ++++----- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7e3c6778c16cac99a9d70a97f08340a319867c59 GIT binary patch literal 8196 zcmeHM(QeZ)6g?gTt(_P{NN6ue`GHm1A7ooAF^M5W`2f0hOw&SBHQB`8^3Ff(7x+G& z;M{9#ik%k33u5A0vQKK?bFXu*6VDj{cXT~F0QLZEu?p^PvsqDOTxzFmgq{~fM?O$u zfP(E5R~>8XFa=BjQ@|831x$f|K>_aBQnuFY`+n3~Q@|AXFBOpYL&hqY2W&j*tAmXm z0f?LI*1~I^1C)~m%mX$al}exf^xy*3g(HUZbdG0YPRs)~9z7k-)8Rs77fvWnqm!4Z zIb811T2sIj=qey*_dbp>!4enk^ZQ9rPS1++jN|f19kLF7XyH}Lsmc6|BH?^XI4}8K zV1fz@oHN=!X2gYlFSzBeIepZ)#3xpc$G+UF#8;no1-)I-_Wqkg!ugtTdJ$*NIA0RR z_k_`>{|W7uoLj{?P8stu=4@OfoZSwm2#^P-$fTzMHj z?ZjK+mbx-0NhHZfJJPd+S>S;8c&%9|(s^nI+Uzv$LRGq1kvqx5ub7o^u!<@9XfvND zGp@<3IN!Ci*6g%B^g14rH6ZzLJFR@|;0;drgpBYOW48OWc*lB-*BEsbj=0+$?kRnJ zh*_d+#Cpv2!nG-DF0rJNk!26>Iio`iaY`KU8Jr~yDi|@IP%ZzgpQDa#MXShGR#(O< zmy}x+9yaDPRixsRC|uI36C6rMvnH ww(Rm5>qk~8V%K<73Y+K;0sg-Khas;snhGZm*mz_Qi+u=C8LTk{{;C2$0l=akIRF3v literal 0 HcmV?d00001 diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 34a65290..780b46d4 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -71,9 +71,10 @@ pub extern "C" fn deposit() { .unwrap_or_revert_with(ApiError::UnexpectedKeyVariant); system::transfer_from_purse_to_purse(temp_purse, deposit_purse_uref, amount, None) .unwrap_or_revert(); - + // kairos utilizes u64 so only amounts that can be converted are accepted. - let amount = u64::try_from(amount).unwrap_or_revert(); + let amount = + u64::try_from(amount).unwrap_or_else(|_| runtime::revert(ApiError::InvalidArgument)); let new_deposit_record: Deposit = Deposit { account: get_immediate_caller().unwrap_or_revert(), diff --git a/kairos-contracts/demo-contract/contract/src/utils/errors.rs b/kairos-contracts/demo-contract/contract/src/utils/errors.rs index 39603190..69298ba9 100644 --- a/kairos-contracts/demo-contract/contract/src/utils/errors.rs +++ b/kairos-contracts/demo-contract/contract/src/utils/errors.rs @@ -10,11 +10,10 @@ pub enum DepositError { MissingOptionalArgument = 3, AlreadyInitialized = 4, MissingKeyDepositPurse = 5, - MissingKeyMostRecentDepositCounter = 6, - MissingKeyLastProcessedDepositCounter = 7, - MissingKeyDepositEventDict = 8, - FailedToCreateDepositDict = 9, - FailedToReturnContractPurseAsReference = 10, + MissingKeyLastProcessedDepositCounter = 6, + MissingKeyDepositEventDict = 7, + FailedToCreateDepositDict = 8, + FailedToReturnContractPurseAsReference = 9, } impl From for ApiError { From 11ed98d187c12edaaedd6a485b0ac561546f4a44 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 17:14:28 +0200 Subject: [PATCH 074/115] remove .DS_Store --- .DS_Store | Bin 8196 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7e3c6778c16cac99a9d70a97f08340a319867c59..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHM(QeZ)6g?gTt(_P{NN6ue`GHm1A7ooAF^M5W`2f0hOw&SBHQB`8^3Ff(7x+G& z;M{9#ik%k33u5A0vQKK?bFXu*6VDj{cXT~F0QLZEu?p^PvsqDOTxzFmgq{~fM?O$u zfP(E5R~>8XFa=BjQ@|831x$f|K>_aBQnuFY`+n3~Q@|AXFBOpYL&hqY2W&j*tAmXm z0f?LI*1~I^1C)~m%mX$al}exf^xy*3g(HUZbdG0YPRs)~9z7k-)8Rs77fvWnqm!4Z zIb811T2sIj=qey*_dbp>!4enk^ZQ9rPS1++jN|f19kLF7XyH}Lsmc6|BH?^XI4}8K zV1fz@oHN=!X2gYlFSzBeIepZ)#3xpc$G+UF#8;no1-)I-_Wqkg!ugtTdJ$*NIA0RR z_k_`>{|W7uoLj{?P8stu=4@OfoZSwm2#^P-$fTzMHj z?ZjK+mbx-0NhHZfJJPd+S>S;8c&%9|(s^nI+Uzv$LRGq1kvqx5ub7o^u!<@9XfvND zGp@<3IN!Ci*6g%B^g14rH6ZzLJFR@|;0;drgpBYOW48OWc*lB-*BEsbj=0+$?kRnJ zh*_d+#Cpv2!nG-DF0rJNk!26>Iio`iaY`KU8Jr~yDi|@IP%ZzgpQDa#MXShGR#(O< zmy}x+9yaDPRixsRC|uI36C6rMvnH ww(Rm5>qk~8V%K<73Y+K;0sg-Khas;snhGZm*mz_Qi+u=C8LTk{{;C2$0l=akIRF3v From 3a19d125adf493b9df319ba9b5bc44493903678a Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 17:21:47 +0200 Subject: [PATCH 075/115] use latest nightly --- .../demo-contract/contract/src/utils/errors.rs | 13 ++++++------- kairos-contracts/rust-toolchain.toml | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/utils/errors.rs b/kairos-contracts/demo-contract/contract/src/utils/errors.rs index 69298ba9..34a66273 100644 --- a/kairos-contracts/demo-contract/contract/src/utils/errors.rs +++ b/kairos-contracts/demo-contract/contract/src/utils/errors.rs @@ -7,13 +7,12 @@ pub enum DepositError { InvalidContext = 0, MissingKey = 1, FailedToGetArgBytes = 2, - MissingOptionalArgument = 3, - AlreadyInitialized = 4, - MissingKeyDepositPurse = 5, - MissingKeyLastProcessedDepositCounter = 6, - MissingKeyDepositEventDict = 7, - FailedToCreateDepositDict = 8, - FailedToReturnContractPurseAsReference = 9, + AlreadyInitialized = 3, + MissingKeyDepositPurse = 4, + MissingKeyLastProcessedDepositCounter = 5, + MissingKeyDepositEventDict = 6, + FailedToCreateDepositDict = 7, + FailedToReturnContractPurseAsReference = 8, } impl From for ApiError { diff --git a/kairos-contracts/rust-toolchain.toml b/kairos-contracts/rust-toolchain.toml index a0f1a930..5d56faf9 100644 --- a/kairos-contracts/rust-toolchain.toml +++ b/kairos-contracts/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2024-01-04" +channel = "nightly" From 75a57d55da70ace6f63ac6ccea95553bd8e51341 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Tue, 30 Apr 2024 17:24:34 +0200 Subject: [PATCH 076/115] reintroduce nightly version lock & update --- kairos-contracts/rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kairos-contracts/rust-toolchain.toml b/kairos-contracts/rust-toolchain.toml index 5d56faf9..46fb6e57 100644 --- a/kairos-contracts/rust-toolchain.toml +++ b/kairos-contracts/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly" +channel = "nightly-2024-04-09" From dfec9348ffc6dafe11cb83d286f2cc53d6e27a66 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Tue, 30 Apr 2024 10:27:59 -0500 Subject: [PATCH 077/115] Add wasm32-unknown-unknown to deposit-contract rust-toolchain.toml & configure build --- kairos-contracts/.cargo/config.toml | 2 ++ kairos-contracts/rust-toolchain.toml | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 kairos-contracts/.cargo/config.toml diff --git a/kairos-contracts/.cargo/config.toml b/kairos-contracts/.cargo/config.toml new file mode 100644 index 00000000..f4e8c002 --- /dev/null +++ b/kairos-contracts/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/kairos-contracts/rust-toolchain.toml b/kairos-contracts/rust-toolchain.toml index 46fb6e57..fe4064f4 100644 --- a/kairos-contracts/rust-toolchain.toml +++ b/kairos-contracts/rust-toolchain.toml @@ -1,2 +1,4 @@ [toolchain] channel = "nightly-2024-04-09" +targets = [ "wasm32-unknown-unknown" ] +profile = "minimal" From abdf5ccfd328e57adbeb905a02c9825c333ea767 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Tue, 30 Apr 2024 10:50:39 -0500 Subject: [PATCH 078/115] Provide more toolchain components in deposit-contract workspace --- kairos-contracts/rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kairos-contracts/rust-toolchain.toml b/kairos-contracts/rust-toolchain.toml index fe4064f4..ad5d6e8e 100644 --- a/kairos-contracts/rust-toolchain.toml +++ b/kairos-contracts/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] channel = "nightly-2024-04-09" +components = ["rustc", "rustfmt", "rust-src", "cargo", "clippy", "rust-docs", "rust-analyzer"] targets = [ "wasm32-unknown-unknown" ] -profile = "minimal" From 36f1736bedb2453ae50c00859dc5833587ed6054 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Wed, 1 May 2024 16:46:06 +0200 Subject: [PATCH 079/115] move nested workspace to root, fix pathbuf in tests --- Cargo.toml | 2 +- .../Cargo.toml | 0 .../tests/integration_tests.rs | 0 .../tests/lib.rs | 0 .../tests/test_fixture/mod.rs | 46 ++++++++----------- .../tests/test_fixture/utils.rs | 0 .../demo-contract-tests/rust-toolchain.toml | 2 - kairos-l1-utils/src/lib.rs | 33 ------------- 8 files changed, 21 insertions(+), 62 deletions(-) rename {kairos-contracts/demo-contract-tests => demo-contract-tests}/Cargo.toml (100%) rename {kairos-contracts/demo-contract-tests => demo-contract-tests}/tests/integration_tests.rs (100%) rename {kairos-contracts/demo-contract-tests => demo-contract-tests}/tests/lib.rs (100%) rename {kairos-contracts/demo-contract-tests => demo-contract-tests}/tests/test_fixture/mod.rs (85%) rename {kairos-contracts/demo-contract-tests => demo-contract-tests}/tests/test_fixture/utils.rs (100%) delete mode 100644 kairos-contracts/demo-contract-tests/rust-toolchain.toml diff --git a/Cargo.toml b/Cargo.toml index 332c1518..85db838e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ members = [ "kairos-tx", "kairos-test-utils", "kairos-l1-utils", - "kairos-contracts/demo-contract-tests", + "demo-contract-tests", ] [workspace.package] diff --git a/kairos-contracts/demo-contract-tests/Cargo.toml b/demo-contract-tests/Cargo.toml similarity index 100% rename from kairos-contracts/demo-contract-tests/Cargo.toml rename to demo-contract-tests/Cargo.toml diff --git a/kairos-contracts/demo-contract-tests/tests/integration_tests.rs b/demo-contract-tests/tests/integration_tests.rs similarity index 100% rename from kairos-contracts/demo-contract-tests/tests/integration_tests.rs rename to demo-contract-tests/tests/integration_tests.rs diff --git a/kairos-contracts/demo-contract-tests/tests/lib.rs b/demo-contract-tests/tests/lib.rs similarity index 100% rename from kairos-contracts/demo-contract-tests/tests/lib.rs rename to demo-contract-tests/tests/lib.rs diff --git a/kairos-contracts/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs similarity index 85% rename from kairos-contracts/demo-contract-tests/tests/test_fixture/mod.rs rename to demo-contract-tests/tests/test_fixture/mod.rs index d7c8549e..4f326c25 100644 --- a/kairos-contracts/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -6,11 +6,10 @@ use casper_types::{ account::AccountHash, contracts::NamedKeys, runtime_args, ContractHash, Key, RuntimeArgs, URef, U512, }; +use dotenvy::dotenv; use lazy_static::lazy_static; +use std::{env, path::PathBuf}; use utils::create_funded_dummy_account; -extern crate dotenvy; -use dotenvy::dotenv; -use std::env; pub const ACCOUNT_USER_1: [u8; 32] = [1u8; 32]; pub const ACCOUNT_USER_2: [u8; 32] = [2u8; 32]; @@ -18,10 +17,11 @@ pub const ACCOUNT_USER_3: [u8; 32] = [3u8; 32]; // This defines a static variable for the path to WASM binaries lazy_static! { - static ref PATH_TO_WASM_BINARIES: String = { + static ref PATH_TO_WASM_BINARIES: PathBuf = { dotenv().ok(); env::var("PATH_TO_WASM_BINARIES") .expect("Missing environment variable PATH_TO_WASM_BINARIES") + .into() }; } @@ -100,10 +100,10 @@ impl TestContext { let session_args = runtime_args! {}; let install_contract_request = ExecuteRequestBuilder::standard( admin, - &format!( - "{}/{}", - *PATH_TO_WASM_BINARIES, "demo-contract-optimized.wasm" - ), + &*PATH_TO_WASM_BINARIES + .join("demo-contract-optimized.wasm") + .to_str() + .expect("Failed to parse path as str"), session_args, ) .build(); @@ -134,12 +134,6 @@ impl TestContext { self.builder.get_purse_balance(contract_purse_uref) } - /*// read a u64 counter from the contract named keys e.g. "last_processed_deposit_counter" - pub fn read_counter_value(&mut self, account: AccountHash, name: &str) -> u64 { - let contract_hash = self.contract_hash("kairos_demo_contract", account); - self.builder.get_value(contract_hash, name) - }*/ - // see deposit-session pub fn run_deposit_session(&mut self, amount: U512, installer: AccountHash, user: AccountHash) { let session_args = runtime_args! { @@ -148,10 +142,10 @@ impl TestContext { }; let session_request = ExecuteRequestBuilder::standard( user, - &format!( - "{}/{}", - *PATH_TO_WASM_BINARIES, "deposit-session-optimized.wasm" - ), + &*PATH_TO_WASM_BINARIES + .join("deposit-session-optimized.wasm") + .to_str() + .expect("Failed to parse path as str"), session_args, ) .build(); @@ -171,10 +165,10 @@ impl TestContext { }; let session_request = ExecuteRequestBuilder::standard( msg_sender, - &format!( - "{}/{}", - *PATH_TO_WASM_BINARIES, "malicious-session-optimized.wasm" - ), + &*PATH_TO_WASM_BINARIES + .join("malicious-session-optimized.wasm") + .to_str() + .expect("Failed to parse path as str"), session_args, ) .build(); @@ -196,10 +190,10 @@ impl TestContext { }; let session_request = ExecuteRequestBuilder::standard( msg_sender, - &format!( - "{}/{}", - *PATH_TO_WASM_BINARIES, "malicious-reader-optimized.wasm" - ), + &*PATH_TO_WASM_BINARIES + .join("malicious-reader-optimized.wasm") + .to_str() + .expect("Failed to parse path as str"), session_args, ) .build(); diff --git a/kairos-contracts/demo-contract-tests/tests/test_fixture/utils.rs b/demo-contract-tests/tests/test_fixture/utils.rs similarity index 100% rename from kairos-contracts/demo-contract-tests/tests/test_fixture/utils.rs rename to demo-contract-tests/tests/test_fixture/utils.rs diff --git a/kairos-contracts/demo-contract-tests/rust-toolchain.toml b/kairos-contracts/demo-contract-tests/rust-toolchain.toml deleted file mode 100644 index 292fe499..00000000 --- a/kairos-contracts/demo-contract-tests/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "stable" diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 1d9b7223..07798411 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -57,39 +57,6 @@ pub async fn query_state_root_hash(node_address: &str) -> Digest { .unwrap() } -pub async fn query_contract_uref_from_installing_account( - node_address: &str, - srh: Digest, - account: Key, - contract_identifier: &str, - contract_uref: &str, -) -> URef { - let stored_value: StoredValue = query_stored_value( - node_address, - srh, - account, - vec![contract_identifier.to_owned()], - ) - .await; - let contract: ContractWasmHash = match stored_value { - StoredValue::Contract(contract) => *contract.contract_wasm_hash(), - _ => panic!("Missing or invalid Value"), - }; - let stored_value: StoredValue = query_stored_value( - node_address, - srh, - contract.into(), - vec![contract_uref.into()], - ) - .await; - let value: URef = match stored_value { - StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), - _ => panic!("Missing or invalid Value"), - }; - - value -} - pub async fn query_counter(node_address: &str, counter_uref: &str) -> u64 { let srh: Digest = query_state_root_hash(node_address).await; let stored_value: StoredValue = query_stored_value( From bbc25f1bcce7509f94441784c7924f3dd6fb775d Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Wed, 1 May 2024 21:47:15 +0200 Subject: [PATCH 080/115] add test that queries last_processed_deposit_counter --- kairos-l1-utils/src/lib.rs | 109 ++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 07798411..8ab2ae9a 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -10,7 +10,7 @@ use casper_client::{ SuccessResponse, }; use casper_types::{crypto::SecretKey, Key, RuntimeArgs}; -use std::fs; +use std::{fs, hash::Hash, path}; pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; @@ -93,6 +93,28 @@ async fn query_stored_value( .stored_value } +pub async fn query_contract_counter(node_address: &str, srh: Digest, contract_hash: Key, path: Vec) -> u64{ + let stored_value: StoredValue = query_global_state( + JsonRpcId::String(0.to_string()), + node_address, + Verbosity::Low, + casper_client::rpcs::GlobalStateIdentifier::StateRootHash(srh), + contract_hash.into(), + path, + ) + .await + .expect("Failed to query contract for path") + .result + .stored_value; + + let value: u64 = match stored_value{ + StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), + _ => panic!("Missing or invalid Value") + }; + + value +} + #[cfg_attr(not(feature = "cctl-tests"), ignore)] #[tokio::test] async fn install_wasm() { @@ -171,3 +193,88 @@ async fn install_wasm() { .await .unwrap() } + +#[cfg_attr(not(feature = "cctl-tests"), ignore)] +#[tokio::test] +async fn counter_query_test(){ + use anyhow::anyhow; + use backoff::{backoff::Constant, future::retry}; + use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; + use casper_types::{runtime_args, RuntimeArgs}; + use kairos_test_utils::cctl::CCTLNetwork; + use std::fs::File; + use std::io::Read; + use std::path::Path; + + let network = CCTLNetwork::run().await.unwrap(); + let node = network + .nodes + .first() + .expect("Expected at least one node after successful network run"); + let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); + + let wasm_path = Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); + let mut wasm_file: File = File::open(wasm_path).unwrap(); + let mut wasm_bytes: Vec = Vec::new(); + wasm_file.read_to_end(&mut wasm_bytes).unwrap(); + + let runtime_args: RuntimeArgs = runtime_args! {}; + let result: SuccessResponse = install_wasm_bytecode( + node_address, + "cspr-dev-cctl", + runtime_args, + &wasm_bytes, + network + .assets_dir + .join("users/user-1/secret_key.pem") + .to_str() + .unwrap(), + ) + .await; + + // wait for successful processing of deploy + retry( + Constant::new(std::time::Duration::from_millis(100)), + || async { + get_deploy( + JsonRpcId::Number(1), + node_address, + Verbosity::High, + result.result.deploy_hash, + true, + ) + .await + .map_err(|err| match &err { + Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { + backoff::Error::transient(anyhow!(err)) + } + _ => backoff::Error::permanent(anyhow!(err)), + }) + .map(|success| { + if success + .result + .execution_results + .iter() + .all(|execution_result| match execution_result.result { + casper_types::ExecutionResult::Success { .. } => true, + casper_types::ExecutionResult::Failure { .. } => false, + }) + { + Ok(()) + } else { + Err(backoff::Error::transient(anyhow!( + "Deploy was not processed yet" + ))) + } + })? + }, + ) + .await + .unwrap(); + + // this is the default cctl account for user-1 + let account: Key = Key::from_formatted_str("account-hash-5a9eb1f7da515d9fa2f0b74e18ec84cccf90f146269d538073416dff432a3c77").unwrap(); + let srh: Digest = query_state_root_hash(node_address).await; + let counter_value: u64 = query_contract_counter(node_address, srh, account, vec!["kairos_demo_contract".to_string(), "last_processed_deposit_counter".to_string()]).await; + assert_eq!(counter_value, 0_u64); +} From e272f3bdbd296c45f90d49cffdcb3fe7b92890a9 Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Wed, 1 May 2024 21:49:35 +0200 Subject: [PATCH 081/115] fix formatting --- kairos-l1-utils/src/lib.rs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 8ab2ae9a..3aea2263 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -2,7 +2,7 @@ use casper_client::{ get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, }; use casper_hashing::Digest; -use casper_types::{ContractWasmHash, URef}; +use casper_types::URef; use casper_client::{ rpcs::results::PutDeployResult, @@ -10,7 +10,7 @@ use casper_client::{ SuccessResponse, }; use casper_types::{crypto::SecretKey, Key, RuntimeArgs}; -use std::{fs, hash::Hash, path}; +use std::fs; pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; @@ -93,7 +93,12 @@ async fn query_stored_value( .stored_value } -pub async fn query_contract_counter(node_address: &str, srh: Digest, contract_hash: Key, path: Vec) -> u64{ +pub async fn query_contract_counter( + node_address: &str, + srh: Digest, + contract_hash: Key, + path: Vec, +) -> u64 { let stored_value: StoredValue = query_global_state( JsonRpcId::String(0.to_string()), node_address, @@ -107,9 +112,9 @@ pub async fn query_contract_counter(node_address: &str, srh: Digest, contract_ha .result .stored_value; - let value: u64 = match stored_value{ + let value: u64 = match stored_value { StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), - _ => panic!("Missing or invalid Value") + _ => panic!("Missing or invalid Value"), }; value @@ -196,7 +201,7 @@ async fn install_wasm() { #[cfg_attr(not(feature = "cctl-tests"), ignore)] #[tokio::test] -async fn counter_query_test(){ +async fn counter_query_test() { use anyhow::anyhow; use backoff::{backoff::Constant, future::retry}; use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; @@ -273,8 +278,20 @@ async fn counter_query_test(){ .unwrap(); // this is the default cctl account for user-1 - let account: Key = Key::from_formatted_str("account-hash-5a9eb1f7da515d9fa2f0b74e18ec84cccf90f146269d538073416dff432a3c77").unwrap(); + let account: Key = Key::from_formatted_str( + "account-hash-5a9eb1f7da515d9fa2f0b74e18ec84cccf90f146269d538073416dff432a3c77", + ) + .unwrap(); let srh: Digest = query_state_root_hash(node_address).await; - let counter_value: u64 = query_contract_counter(node_address, srh, account, vec!["kairos_demo_contract".to_string(), "last_processed_deposit_counter".to_string()]).await; + let counter_value: u64 = query_contract_counter( + node_address, + srh, + account, + vec![ + "kairos_demo_contract".to_string(), + "last_processed_deposit_counter".to_string(), + ], + ) + .await; assert_eq!(counter_value, 0_u64); } From aa86bd30dd959bf619deb2bbff7a65408dd26d8e Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Thu, 2 May 2024 23:16:35 +0200 Subject: [PATCH 082/115] temporary fix --- flake.lock | 12 ++++++------ kairos-l1-utils/src/lib.rs | 25 ++++++++++++++++--------- kairos-test-utils/src/cctl.rs | 1 - 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/flake.lock b/flake.lock index 377f026d..0c21367c 100644 --- a/flake.lock +++ b/flake.lock @@ -66,11 +66,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1714285404, - "narHash": "sha256-MmoQIO+KRiH3UnH0myAp2Fgi84rmpROMfw9VIbqrjHA=", + "lastModified": 1714631076, + "narHash": "sha256-at4+1R9gx3CGvX0ZJo9GwDZyt3RzOft7qDCTsYHjI4M=", "owner": "nix-community", "repo": "fenix", - "rev": "94be183087845937b0fd77281c37d0796572b899", + "rev": "22a9eb3f20dd340d084cee4426f386a90b1351ca", "type": "github" }, "original": { @@ -199,11 +199,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1714217560, - "narHash": "sha256-zttBYGaoHpZfqWHQ8OI5f9OkGHCHb8tDBMySwsYNa2U=", + "lastModified": 1714572655, + "narHash": "sha256-xjD8vmit0Nz1qaSSSpeXOK3saSvAZtOGHS2SHZE75Ek=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "f216be4a0746142c5f30835b254871256a7637b8", + "rev": "cfce2bb46da62950a8b70ddb0b2a12332da1b1e1", "type": "github" }, "original": { diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 3aea2263..06a22232 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -2,7 +2,7 @@ use casper_client::{ get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, }; use casper_hashing::Digest; -use casper_types::URef; +use casper_types::{account::AccountHash, PublicKey, URef}; use casper_client::{ rpcs::results::PutDeployResult, @@ -10,7 +10,7 @@ use casper_client::{ SuccessResponse, }; use casper_types::{crypto::SecretKey, Key, RuntimeArgs}; -use std::fs; +use std::{fs, thread, time::Duration}; pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; @@ -51,7 +51,7 @@ pub async fn query_state_root_hash(node_address: &str) -> Digest { None, ) .await - .unwrap() + .expect("Failed to get state root hash") .result .state_root_hash .unwrap() @@ -88,7 +88,7 @@ async fn query_stored_value( path, ) .await - .unwrap() + .expect("Failed to query stored value") .result .stored_value } @@ -119,7 +119,7 @@ pub async fn query_contract_counter( value } - +/* #[cfg_attr(not(feature = "cctl-tests"), ignore)] #[tokio::test] async fn install_wasm() { @@ -198,6 +198,7 @@ async fn install_wasm() { .await .unwrap() } +*/ #[cfg_attr(not(feature = "cctl-tests"), ignore)] #[tokio::test] @@ -277,11 +278,17 @@ async fn counter_query_test() { .await .unwrap(); + // replace this with a better solution + thread::sleep(Duration::from_secs(10)); + + let public_key_path = network + .assets_dir + .join("users/user-1/public_key.pem"); + + let public_key: PublicKey = PublicKey::from_file(public_key_path.to_str().unwrap()).unwrap(); + let account_hash: AccountHash = public_key.to_account_hash(); // this is the default cctl account for user-1 - let account: Key = Key::from_formatted_str( - "account-hash-5a9eb1f7da515d9fa2f0b74e18ec84cccf90f146269d538073416dff432a3c77", - ) - .unwrap(); + let account: Key = Key::from(account_hash); let srh: Digest = query_state_root_hash(node_address).await; let counter_value: u64 = query_contract_counter( node_address, diff --git a/kairos-test-utils/src/cctl.rs b/kairos-test-utils/src/cctl.rs index 897d9f55..6b12c639 100644 --- a/kairos-test-utils/src/cctl.rs +++ b/kairos-test-utils/src/cctl.rs @@ -133,7 +133,6 @@ impl Drop for CCTLNetwork { #[cfg(test)] mod tests { use super::*; - #[cfg_attr(not(feature = "cctl-tests"), ignore)] #[tokio::test] async fn test_cctl_network_starts_and_terminates() { From 3b599c872b796493ebba2b33ae2757a74bc38242 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Fri, 3 May 2024 10:47:37 -0500 Subject: [PATCH 083/115] Fix nix build --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 37a6ea9a..83bcfe85 100644 --- a/flake.nix +++ b/flake.nix @@ -84,6 +84,7 @@ "/kairos-test-utils" "/kairos-l1-utils" "/kairos-contracts" + "/demo-contract-tests" "/kairos-tx" "/Cargo.toml" "/Cargo.lock" From 9454305babdc7f1c679e802b9c7d9cf954f83805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Wed, 8 May 2024 14:07:23 -0500 Subject: [PATCH 084/115] kairos-l1-utils: format --- kairos-l1-utils/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index 06a22232..a33ec29c 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -281,9 +281,7 @@ async fn counter_query_test() { // replace this with a better solution thread::sleep(Duration::from_secs(10)); - let public_key_path = network - .assets_dir - .join("users/user-1/public_key.pem"); + let public_key_path = network.assets_dir.join("users/user-1/public_key.pem"); let public_key: PublicKey = PublicKey::from_file(public_key_path.to_str().unwrap()).unwrap(); let account_hash: AccountHash = public_key.to_account_hash(); From 589941ea628796bbba8a7e44f350c0edc27611c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Wed, 8 May 2024 14:36:46 -0500 Subject: [PATCH 085/115] fix lint errors --- demo-contract-tests/tests/test_fixture/mod.rs | 8 +- kairos-l1-utils/src/lib.rs | 351 +++++++++--------- 2 files changed, 184 insertions(+), 175 deletions(-) diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index 4f326c25..f5c85e6c 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -100,7 +100,7 @@ impl TestContext { let session_args = runtime_args! {}; let install_contract_request = ExecuteRequestBuilder::standard( admin, - &*PATH_TO_WASM_BINARIES + PATH_TO_WASM_BINARIES .join("demo-contract-optimized.wasm") .to_str() .expect("Failed to parse path as str"), @@ -142,7 +142,7 @@ impl TestContext { }; let session_request = ExecuteRequestBuilder::standard( user, - &*PATH_TO_WASM_BINARIES + PATH_TO_WASM_BINARIES .join("deposit-session-optimized.wasm") .to_str() .expect("Failed to parse path as str"), @@ -165,7 +165,7 @@ impl TestContext { }; let session_request = ExecuteRequestBuilder::standard( msg_sender, - &*PATH_TO_WASM_BINARIES + PATH_TO_WASM_BINARIES .join("malicious-session-optimized.wasm") .to_str() .expect("Failed to parse path as str"), @@ -190,7 +190,7 @@ impl TestContext { }; let session_request = ExecuteRequestBuilder::standard( msg_sender, - &*PATH_TO_WASM_BINARIES + PATH_TO_WASM_BINARIES .join("malicious-reader-optimized.wasm") .to_str() .expect("Failed to parse path as str"), diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs index a33ec29c..5ef9a752 100644 --- a/kairos-l1-utils/src/lib.rs +++ b/kairos-l1-utils/src/lib.rs @@ -2,7 +2,7 @@ use casper_client::{ get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, }; use casper_hashing::Digest; -use casper_types::{account::AccountHash, PublicKey, URef}; +use casper_types::URef; use casper_client::{ rpcs::results::PutDeployResult, @@ -10,7 +10,7 @@ use casper_client::{ SuccessResponse, }; use casper_types::{crypto::SecretKey, Key, RuntimeArgs}; -use std::{fs, thread, time::Duration}; +use std::fs; pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; @@ -104,7 +104,7 @@ pub async fn query_contract_counter( node_address, Verbosity::Low, casper_client::rpcs::GlobalStateIdentifier::StateRootHash(srh), - contract_hash.into(), + contract_hash, path, ) .await @@ -119,184 +119,193 @@ pub async fn query_contract_counter( value } -/* -#[cfg_attr(not(feature = "cctl-tests"), ignore)] -#[tokio::test] -async fn install_wasm() { - use anyhow::anyhow; - use backoff::{backoff::Constant, future::retry}; - use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; - use casper_types::{runtime_args, RuntimeArgs}; - use kairos_test_utils::cctl::CCTLNetwork; - use std::fs::File; - use std::io::Read; - use std::path::Path; - let network = CCTLNetwork::run().await.unwrap(); - let node = network - .nodes - .first() - .expect("Expected at least one node after successful network run"); - let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); +#[cfg(test)] +mod tests { + use super::*; + use std::thread; + /* + #[cfg_attr(not(feature = "cctl-tests"), ignore)] + #[tokio::test] + async fn install_wasm() { + use anyhow::anyhow; + use backoff::{backoff::Constant, future::retry}; + use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; + use casper_types::{runtime_args, RuntimeArgs}; + use kairos_test_utils::cctl::CCTLNetwork; + use std::fs::File; + use std::io::Read; + use std::path::Path; - let wasm_path = Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); - let mut wasm_file: File = File::open(wasm_path).unwrap(); - let mut wasm_bytes: Vec = Vec::new(); - wasm_file.read_to_end(&mut wasm_bytes).unwrap(); + let network = CCTLNetwork::run().await.unwrap(); + let node = network + .nodes + .first() + .expect("Expected at least one node after successful network run"); + let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); - let runtime_args: RuntimeArgs = runtime_args! {}; - let result: SuccessResponse = install_wasm_bytecode( - node_address, - "cspr-dev-cctl", - runtime_args, - &wasm_bytes, - network - .assets_dir - .join("users/user-1/secret_key.pem") - .to_str() - .unwrap(), - ) - .await; + let wasm_path = Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); + let mut wasm_file: File = File::open(wasm_path).unwrap(); + let mut wasm_bytes: Vec = Vec::new(); + wasm_file.read_to_end(&mut wasm_bytes).unwrap(); - // wait for successful processing of deploy - retry( - Constant::new(std::time::Duration::from_millis(100)), - || async { - get_deploy( - JsonRpcId::Number(1), - node_address, - Verbosity::High, - result.result.deploy_hash, - true, - ) - .await - .map_err(|err| match &err { - Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { - backoff::Error::transient(anyhow!(err)) - } - _ => backoff::Error::permanent(anyhow!(err)), - }) - .map(|success| { - if success - .result - .execution_results - .iter() - .all(|execution_result| match execution_result.result { - casper_types::ExecutionResult::Success { .. } => true, - casper_types::ExecutionResult::Failure { .. } => false, - }) - { - Ok(()) - } else { - Err(backoff::Error::transient(anyhow!( - "Deploy was not processed yet" - ))) - } - })? - }, - ) - .await - .unwrap() -} -*/ + let runtime_args: RuntimeArgs = runtime_args! {}; + let result: SuccessResponse = install_wasm_bytecode( + node_address, + "cspr-dev-cctl", + runtime_args, + &wasm_bytes, + network + .assets_dir + .join("users/user-1/secret_key.pem") + .to_str() + .unwrap(), + ) + .await; -#[cfg_attr(not(feature = "cctl-tests"), ignore)] -#[tokio::test] -async fn counter_query_test() { - use anyhow::anyhow; - use backoff::{backoff::Constant, future::retry}; - use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; - use casper_types::{runtime_args, RuntimeArgs}; - use kairos_test_utils::cctl::CCTLNetwork; - use std::fs::File; - use std::io::Read; - use std::path::Path; + // wait for successful processing of deploy + retry( + Constant::new(std::time::Duration::from_millis(100)), + || async { + get_deploy( + JsonRpcId::Number(1), + node_address, + Verbosity::High, + result.result.deploy_hash, + true, + ) + .await + .map_err(|err| match &err { + Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { + backoff::Error::transient(anyhow!(err)) + } + _ => backoff::Error::permanent(anyhow!(err)), + }) + .map(|success| { + if success + .result + .execution_results + .iter() + .all(|execution_result| match execution_result.result { + casper_types::ExecutionResult::Success { .. } => true, + casper_types::ExecutionResult::Failure { .. } => false, + }) + { + Ok(()) + } else { + Err(backoff::Error::transient(anyhow!( + "Deploy was not processed yet" + ))) + } + })? + }, + ) + .await + .unwrap() + } + */ - let network = CCTLNetwork::run().await.unwrap(); - let node = network - .nodes - .first() - .expect("Expected at least one node after successful network run"); - let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); + #[cfg_attr(not(feature = "cctl-tests"), ignore)] + #[tokio::test] + async fn counter_query_test() { + use anyhow::anyhow; + use backoff::{backoff::Constant, future::retry}; + use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; + use casper_types::account::AccountHash; + use casper_types::{crypto::PublicKey, runtime_args, RuntimeArgs}; + use kairos_test_utils::cctl::CCTLNetwork; + use std::fs::File; + use std::io::Read; + use std::path::Path; - let wasm_path = Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); - let mut wasm_file: File = File::open(wasm_path).unwrap(); - let mut wasm_bytes: Vec = Vec::new(); - wasm_file.read_to_end(&mut wasm_bytes).unwrap(); + let network = CCTLNetwork::run().await.unwrap(); + let node = network + .nodes + .first() + .expect("Expected at least one node after successful network run"); + let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); - let runtime_args: RuntimeArgs = runtime_args! {}; - let result: SuccessResponse = install_wasm_bytecode( - node_address, - "cspr-dev-cctl", - runtime_args, - &wasm_bytes, - network - .assets_dir - .join("users/user-1/secret_key.pem") - .to_str() - .unwrap(), - ) - .await; + let wasm_path = + Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); + let mut wasm_file: File = File::open(wasm_path).unwrap(); + let mut wasm_bytes: Vec = Vec::new(); + wasm_file.read_to_end(&mut wasm_bytes).unwrap(); - // wait for successful processing of deploy - retry( - Constant::new(std::time::Duration::from_millis(100)), - || async { - get_deploy( - JsonRpcId::Number(1), - node_address, - Verbosity::High, - result.result.deploy_hash, - true, - ) - .await - .map_err(|err| match &err { - Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { - backoff::Error::transient(anyhow!(err)) - } - _ => backoff::Error::permanent(anyhow!(err)), - }) - .map(|success| { - if success - .result - .execution_results - .iter() - .all(|execution_result| match execution_result.result { - casper_types::ExecutionResult::Success { .. } => true, - casper_types::ExecutionResult::Failure { .. } => false, - }) - { - Ok(()) - } else { - Err(backoff::Error::transient(anyhow!( - "Deploy was not processed yet" - ))) - } - })? - }, - ) - .await - .unwrap(); + let runtime_args: RuntimeArgs = runtime_args! {}; + let result: SuccessResponse = install_wasm_bytecode( + node_address, + "cspr-dev-cctl", + runtime_args, + &wasm_bytes, + network + .assets_dir + .join("users/user-1/secret_key.pem") + .to_str() + .unwrap(), + ) + .await; - // replace this with a better solution - thread::sleep(Duration::from_secs(10)); + // wait for successful processing of deploy + retry( + Constant::new(std::time::Duration::from_millis(100)), + || async { + get_deploy( + JsonRpcId::Number(1), + node_address, + Verbosity::High, + result.result.deploy_hash, + true, + ) + .await + .map_err(|err| match &err { + Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { + backoff::Error::transient(anyhow!(err)) + } + _ => backoff::Error::permanent(anyhow!(err)), + }) + .map(|success| { + if success + .result + .execution_results + .iter() + .all(|execution_result| match execution_result.result { + casper_types::ExecutionResult::Success { .. } => true, + casper_types::ExecutionResult::Failure { .. } => false, + }) + { + Ok(()) + } else { + Err(backoff::Error::transient(anyhow!( + "Deploy was not processed yet" + ))) + } + })? + }, + ) + .await + .unwrap(); - let public_key_path = network.assets_dir.join("users/user-1/public_key.pem"); + // replace this with a better solution + thread::sleep(std::time::Duration::from_secs(10)); - let public_key: PublicKey = PublicKey::from_file(public_key_path.to_str().unwrap()).unwrap(); - let account_hash: AccountHash = public_key.to_account_hash(); - // this is the default cctl account for user-1 - let account: Key = Key::from(account_hash); - let srh: Digest = query_state_root_hash(node_address).await; - let counter_value: u64 = query_contract_counter( - node_address, - srh, - account, - vec![ - "kairos_demo_contract".to_string(), - "last_processed_deposit_counter".to_string(), - ], - ) - .await; - assert_eq!(counter_value, 0_u64); + let public_key_path = network.assets_dir.join("users/user-1/public_key.pem"); + + let public_key: PublicKey = + PublicKey::from_file(public_key_path.to_str().unwrap()).unwrap(); + let account_hash: AccountHash = public_key.to_account_hash(); + // this is the default cctl account for user-1 + let account: Key = Key::from(account_hash); + let srh: Digest = query_state_root_hash(node_address).await; + let counter_value: u64 = query_contract_counter( + node_address, + srh, + account, + vec![ + "kairos_demo_contract".to_string(), + "last_processed_deposit_counter".to_string(), + ], + ) + .await; + assert_eq!(counter_value, 0_u64); + } } From 40822ed28a1d8d877641cb660e14ca4160c3c262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Wed, 8 May 2024 14:47:57 -0500 Subject: [PATCH 086/115] kairos-test-utils: wait for block 1 --- kairos-test-utils/src/cctl.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kairos-test-utils/src/cctl.rs b/kairos-test-utils/src/cctl.rs index 6b12c639..14678c05 100644 --- a/kairos-test-utils/src/cctl.rs +++ b/kairos-test-utils/src/cctl.rs @@ -111,6 +111,15 @@ impl CCTLNetwork { .await .expect("Waiting for network to pass genesis failed"); + tracing::info!("Waiting for block 1"); + let output = Command::new("cctl-chain-await-until-block-n") + .env("CCTL_ASSETS", &assets_dir) + .arg("height=1") + .output() + .expect("Waiting for network to start processing blocks failed"); + let output = std::str::from_utf8(output.stdout.as_slice()).unwrap(); + tracing::info!("{}", output); + Ok(CCTLNetwork { working_dir, assets_dir, From 606fd1d0616409ab18451ab1dea497e4b2d28010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Wed, 8 May 2024 15:02:20 -0500 Subject: [PATCH 087/115] kairos-l1-utils: remove --- Cargo.lock | 13 -- Cargo.toml | 1 - flake.nix | 1 - kairos-l1-utils/Cargo.toml | 20 --- kairos-l1-utils/src/lib.rs | 311 ------------------------------------- 5 files changed, 346 deletions(-) delete mode 100644 kairos-l1-utils/Cargo.toml delete mode 100644 kairos-l1-utils/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 33daa057..e175595d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2027,19 +2027,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "kairos-l1-utils" -version = "0.1.0" -dependencies = [ - "anyhow", - "backoff", - "casper-client", - "casper-hashing 2.0.0", - "casper-types 3.0.0", - "kairos-test-utils", - "tokio", -] - [[package]] name = "kairos-server" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 85db838e..09aa11bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ members = [ "kairos-server", "kairos-tx", "kairos-test-utils", - "kairos-l1-utils", "demo-contract-tests", ] diff --git a/flake.nix b/flake.nix index 83bcfe85..14d0705b 100644 --- a/flake.nix +++ b/flake.nix @@ -82,7 +82,6 @@ "/kairos-crypto" "/kairos-server" "/kairos-test-utils" - "/kairos-l1-utils" "/kairos-contracts" "/demo-contract-tests" "/kairos-tx" diff --git a/kairos-l1-utils/Cargo.toml b/kairos-l1-utils/Cargo.toml deleted file mode 100644 index 6d8ec299..00000000 --- a/kairos-l1-utils/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "kairos-l1-utils" -version.workspace = true -edition.workspace = true -license.workspace = true - -[dependencies] -casper-client = "2.0.0" -casper-types = "3.0.0" -casper-hashing = "2.0.0" -tokio = {version="1.36.0", features=["full"]} - -[features] -all-tests = ["cctl-tests"] -cctl-tests = [] - -[dev-dependencies] -anyhow = "*" -kairos-test-utils = { path = "../kairos-test-utils" } -backoff = { version = "0.4", features = ["tokio", "futures"]} diff --git a/kairos-l1-utils/src/lib.rs b/kairos-l1-utils/src/lib.rs deleted file mode 100644 index 5ef9a752..00000000 --- a/kairos-l1-utils/src/lib.rs +++ /dev/null @@ -1,311 +0,0 @@ -use casper_client::{ - get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity, -}; -use casper_hashing::Digest; -use casper_types::URef; - -use casper_client::{ - rpcs::results::PutDeployResult, - types::{Deploy, DeployBuilder, ExecutableDeployItem, Timestamp}, - SuccessResponse, -}; -use casper_types::{crypto::SecretKey, Key, RuntimeArgs}; -use std::fs; - -pub const DEFAULT_PAYMENT_AMOUNT: u64 = 1_000_000_000_000; - -pub async fn install_wasm_bytecode( - node_address: &str, - chain_name: &str, - runtime_args: RuntimeArgs, - module_bytes: &[u8], - secret_key_path: &str, -) -> SuccessResponse { - let session: ExecutableDeployItem = - ExecutableDeployItem::new_module_bytes(module_bytes.into(), runtime_args); - println!("{}", secret_key_path); - let secret_key_bytes: Vec = fs::read(secret_key_path).unwrap(); - let secret_key: SecretKey = SecretKey::from_pem(secret_key_bytes.clone()).unwrap(); - - let deploy: Deploy = DeployBuilder::new(chain_name, session, &secret_key) - .with_timestamp(Timestamp::now()) - .with_standard_payment(DEFAULT_PAYMENT_AMOUNT) - .build() - .unwrap(); - - casper_client::put_deploy( - JsonRpcId::String(0.to_string()), - node_address, - casper_client::Verbosity::Low, - deploy, - ) - .await - .unwrap() -} - -pub async fn query_state_root_hash(node_address: &str) -> Digest { - get_state_root_hash( - JsonRpcId::String(0.to_string()), - node_address, - Verbosity::Low, - None, - ) - .await - .expect("Failed to get state root hash") - .result - .state_root_hash - .unwrap() -} - -pub async fn query_counter(node_address: &str, counter_uref: &str) -> u64 { - let srh: Digest = query_state_root_hash(node_address).await; - let stored_value: StoredValue = query_stored_value( - node_address, - srh, - casper_types::Key::URef(URef::from_formatted_str(counter_uref).unwrap()), - Vec::new(), - ) - .await; - let value: u64 = match stored_value { - StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), - _ => panic!("Missing Value!"), - }; - value -} - -async fn query_stored_value( - node_address: &str, - srh: Digest, - key: Key, - path: Vec, -) -> StoredValue { - query_global_state( - JsonRpcId::String(0.to_string()), - node_address, - Verbosity::Low, - casper_client::rpcs::GlobalStateIdentifier::StateRootHash(srh), - key, - path, - ) - .await - .expect("Failed to query stored value") - .result - .stored_value -} - -pub async fn query_contract_counter( - node_address: &str, - srh: Digest, - contract_hash: Key, - path: Vec, -) -> u64 { - let stored_value: StoredValue = query_global_state( - JsonRpcId::String(0.to_string()), - node_address, - Verbosity::Low, - casper_client::rpcs::GlobalStateIdentifier::StateRootHash(srh), - contract_hash, - path, - ) - .await - .expect("Failed to query contract for path") - .result - .stored_value; - - let value: u64 = match stored_value { - StoredValue::CLValue(cl_value) => cl_value.into_t().unwrap(), - _ => panic!("Missing or invalid Value"), - }; - - value -} - -#[cfg(test)] -mod tests { - use super::*; - use std::thread; - /* - #[cfg_attr(not(feature = "cctl-tests"), ignore)] - #[tokio::test] - async fn install_wasm() { - use anyhow::anyhow; - use backoff::{backoff::Constant, future::retry}; - use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; - use casper_types::{runtime_args, RuntimeArgs}; - use kairos_test_utils::cctl::CCTLNetwork; - use std::fs::File; - use std::io::Read; - use std::path::Path; - - let network = CCTLNetwork::run().await.unwrap(); - let node = network - .nodes - .first() - .expect("Expected at least one node after successful network run"); - let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); - - let wasm_path = Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); - let mut wasm_file: File = File::open(wasm_path).unwrap(); - let mut wasm_bytes: Vec = Vec::new(); - wasm_file.read_to_end(&mut wasm_bytes).unwrap(); - - let runtime_args: RuntimeArgs = runtime_args! {}; - let result: SuccessResponse = install_wasm_bytecode( - node_address, - "cspr-dev-cctl", - runtime_args, - &wasm_bytes, - network - .assets_dir - .join("users/user-1/secret_key.pem") - .to_str() - .unwrap(), - ) - .await; - - // wait for successful processing of deploy - retry( - Constant::new(std::time::Duration::from_millis(100)), - || async { - get_deploy( - JsonRpcId::Number(1), - node_address, - Verbosity::High, - result.result.deploy_hash, - true, - ) - .await - .map_err(|err| match &err { - Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { - backoff::Error::transient(anyhow!(err)) - } - _ => backoff::Error::permanent(anyhow!(err)), - }) - .map(|success| { - if success - .result - .execution_results - .iter() - .all(|execution_result| match execution_result.result { - casper_types::ExecutionResult::Success { .. } => true, - casper_types::ExecutionResult::Failure { .. } => false, - }) - { - Ok(()) - } else { - Err(backoff::Error::transient(anyhow!( - "Deploy was not processed yet" - ))) - } - })? - }, - ) - .await - .unwrap() - } - */ - - #[cfg_attr(not(feature = "cctl-tests"), ignore)] - #[tokio::test] - async fn counter_query_test() { - use anyhow::anyhow; - use backoff::{backoff::Constant, future::retry}; - use casper_client::{get_deploy, Error, JsonRpcId, Verbosity}; - use casper_types::account::AccountHash; - use casper_types::{crypto::PublicKey, runtime_args, RuntimeArgs}; - use kairos_test_utils::cctl::CCTLNetwork; - use std::fs::File; - use std::io::Read; - use std::path::Path; - - let network = CCTLNetwork::run().await.unwrap(); - let node = network - .nodes - .first() - .expect("Expected at least one node after successful network run"); - let node_address: &str = &format!("http://localhost:{}", node.port.rpc_port); - - let wasm_path = - Path::new(env!("PATH_TO_WASM_BINARIES")).join("demo-contract-optimized.wasm"); - let mut wasm_file: File = File::open(wasm_path).unwrap(); - let mut wasm_bytes: Vec = Vec::new(); - wasm_file.read_to_end(&mut wasm_bytes).unwrap(); - - let runtime_args: RuntimeArgs = runtime_args! {}; - let result: SuccessResponse = install_wasm_bytecode( - node_address, - "cspr-dev-cctl", - runtime_args, - &wasm_bytes, - network - .assets_dir - .join("users/user-1/secret_key.pem") - .to_str() - .unwrap(), - ) - .await; - - // wait for successful processing of deploy - retry( - Constant::new(std::time::Duration::from_millis(100)), - || async { - get_deploy( - JsonRpcId::Number(1), - node_address, - Verbosity::High, - result.result.deploy_hash, - true, - ) - .await - .map_err(|err| match &err { - Error::ResponseIsHttpError { .. } | Error::FailedToGetResponse { .. } => { - backoff::Error::transient(anyhow!(err)) - } - _ => backoff::Error::permanent(anyhow!(err)), - }) - .map(|success| { - if success - .result - .execution_results - .iter() - .all(|execution_result| match execution_result.result { - casper_types::ExecutionResult::Success { .. } => true, - casper_types::ExecutionResult::Failure { .. } => false, - }) - { - Ok(()) - } else { - Err(backoff::Error::transient(anyhow!( - "Deploy was not processed yet" - ))) - } - })? - }, - ) - .await - .unwrap(); - - // replace this with a better solution - thread::sleep(std::time::Duration::from_secs(10)); - - let public_key_path = network.assets_dir.join("users/user-1/public_key.pem"); - - let public_key: PublicKey = - PublicKey::from_file(public_key_path.to_str().unwrap()).unwrap(); - let account_hash: AccountHash = public_key.to_account_hash(); - // this is the default cctl account for user-1 - let account: Key = Key::from(account_hash); - let srh: Digest = query_state_root_hash(node_address).await; - let counter_value: u64 = query_contract_counter( - node_address, - srh, - account, - vec![ - "kairos_demo_contract".to_string(), - "last_processed_deposit_counter".to_string(), - ], - ) - .await; - assert_eq!(counter_value, 0_u64); - } -} From 2cd0cb427fc7568afc9b58d8de462dbec345af44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 00:31:53 -0500 Subject: [PATCH 088/115] demo-contract-tests: refactor fixture and tests --- .../tests/integration_tests.rs | 130 +++++++--- demo-contract-tests/tests/lib.rs | 4 +- demo-contract-tests/tests/test_fixture/mod.rs | 235 ++++++------------ .../tests/test_fixture/utils.rs | 38 --- 4 files changed, 174 insertions(+), 233 deletions(-) delete mode 100644 demo-contract-tests/tests/test_fixture/utils.rs diff --git a/demo-contract-tests/tests/integration_tests.rs b/demo-contract-tests/tests/integration_tests.rs index 45607079..3788ad3d 100644 --- a/demo-contract-tests/tests/integration_tests.rs +++ b/demo-contract-tests/tests/integration_tests.rs @@ -1,64 +1,128 @@ mod test_fixture; #[cfg(test)] mod tests { - use crate::test_fixture::TestContext; - use casper_types::{account::AccountHash, U512}; + use crate::test_fixture::{run_session_with_args, TestContext}; + use casper_types::{runtime_args, RuntimeArgs, U512}; + use std::path::Path; #[test] fn should_install_deposit_contract() { - let mut fixture: TestContext = TestContext::new(); - fixture.install_demo_contract(fixture.account_1); - } - - fn setup() -> (TestContext, AccountHash, AccountHash) { - let fixture: TestContext = TestContext::new(); - let installer = fixture.account_1; - let user = fixture.account_2; - (fixture, installer, user) + let _fixture = TestContext::new(); } #[test] fn deposit_into_purse() { - let deposit_amount: U512 = U512::from(100000000000u64); - let (mut fixture, installer, user) = setup(); - fixture.install_demo_contract(installer); + let TestContext { + mut builder, + user_1, + contract_hash, + contract_purse, + } = TestContext::new(); - let user_purse_uref = fixture.get_account_purse_uref(user); - let user_balance_before = fixture.builder.get_purse_balance(user_purse_uref); + let user_uref = builder.get_expected_account(user_1).main_purse(); + let user_balance_before = builder.get_purse_balance(user_uref); - let contract_balance_before = fixture.get_contract_purse_balance(installer); + // check that the contract balance is zero before depositing + let contract_balance_before = builder.get_purse_balance(contract_purse); assert_eq!(contract_balance_before, U512::zero()); - fixture.run_deposit_session(deposit_amount, installer, user); + // user_1 deposits the deposit_amount + let deposit_session_path = + Path::new(env!("PATH_TO_WASM_BINARIES")).join("deposit-session-optimized.wasm"); + let deposit_amount = U512::from(100000000000u64); + let session_args = runtime_args! { + "amount" => deposit_amount, + "demo_contract" => contract_hash + }; + run_session_with_args( + &mut builder, + deposit_session_path.as_path(), + user_1, + session_args, + ); + builder.expect_success(); - let contract_balance_after = fixture.get_contract_purse_balance(installer); + // the contract balance should afterward equal to the deposit_amount + let contract_balance_after = builder.get_purse_balance(contract_purse); assert_eq!(contract_balance_after, deposit_amount); - let user_balance_after = fixture.builder.get_purse_balance(user_purse_uref); + let user_balance_after = builder.get_purse_balance(user_uref); assert!(user_balance_after <= user_balance_before - deposit_amount); } // see malicious-session #[test] fn run_malicious_session() { - let (mut fixture, installer, user) = setup(); - fixture.install_demo_contract(installer); - fixture.run_deposit_session(U512::from(100000000000u64), installer, user); - fixture.run_malicious_session(fixture.account_2, U512::from(100000000000u64), installer); + let TestContext { + mut builder, + user_1, + contract_hash, + .. + } = TestContext::new(); + + let deposit_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + .join("deposit-session-optimized.wasm"); + let session_args = runtime_args! { + "amount" => U512::from(100000000000u64), + "demo_contract" => contract_hash + }; + run_session_with_args( + &mut builder, + deposit_session_path.as_path(), + user_1, + session_args.clone(), + ); + builder.expect_success(); + + let malicious_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + .join("malicious-session-optimized.wasm"); + run_session_with_args( + &mut builder, + malicious_session_path.as_path(), + user_1, + session_args, + ); + builder.expect_failure(); } // see malicious-reader #[test] fn run_malicious_reader() { - let (mut fixture, installer, user) = setup(); - fixture.install_demo_contract(installer); - fixture.run_deposit_session(U512::from(100000000000u64), installer, user); - let deposit_purse_uref = fixture.get_contract_purse_uref(installer); - fixture.run_malicious_reader_session( - fixture.account_2, - U512::from(100000000000u64), - installer, - deposit_purse_uref, + let TestContext { + mut builder, + user_1, + contract_hash, + contract_purse, + } = TestContext::new(); + + let deposit_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + .join("deposit-session-optimized.wasm"); + let session_args = runtime_args! { + "amount" => U512::from(100000000000u64), + "demo_contract" => contract_hash + }; + run_session_with_args( + &mut builder, + deposit_session_path.as_path(), + user_1, + session_args, + ); + builder.expect_success(); + + let deposit_amount = U512::from(100000000000u64); + let session_args = runtime_args! { + "amount" => deposit_amount, + "demo_contract" => contract_hash, + "purse_uref" => contract_purse + }; + let malicious_reader_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + .join("malicious-reader-optimized.wasm"); + run_session_with_args( + &mut builder, + malicious_reader_session_path.as_path(), + user_1, + session_args, ); + builder.expect_failure(); } } diff --git a/demo-contract-tests/tests/lib.rs b/demo-contract-tests/tests/lib.rs index 66d4fc53..c288dfc5 100644 --- a/demo-contract-tests/tests/lib.rs +++ b/demo-contract-tests/tests/lib.rs @@ -1,3 +1 @@ -pub mod test_fixture { - pub mod utils; -} +pub mod test_fixture; diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index f5c85e6c..4c731e84 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -1,19 +1,25 @@ -mod utils; use casper_engine_test_support::{ - ExecuteRequestBuilder, InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST, + ExecuteRequestBuilder, WasmTestBuilder, ARG_AMOUNT, DEFAULT_ACCOUNT_ADDR, + DEFAULT_ACCOUNT_INITIAL_BALANCE, }; +use casper_execution_engine::storage::global_state::in_memory::InMemoryGlobalState; use casper_types::{ - account::AccountHash, contracts::NamedKeys, runtime_args, ContractHash, Key, RuntimeArgs, URef, - U512, + account::AccountHash, + crypto::{PublicKey, SecretKey}, + runtime_args, + system::{handle_payment::ARG_TARGET, mint::ARG_ID}, + RuntimeArgs, }; +use std::path::Path; + +use casper_engine_test_support::{InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST}; +use casper_types::{ContractHash, URef}; use dotenvy::dotenv; use lazy_static::lazy_static; use std::{env, path::PathBuf}; -use utils::create_funded_dummy_account; -pub const ACCOUNT_USER_1: [u8; 32] = [1u8; 32]; -pub const ACCOUNT_USER_2: [u8; 32] = [2u8; 32]; -pub const ACCOUNT_USER_3: [u8; 32] = [3u8; 32]; +pub const ADMIN_SECRET_KEY: [u8; 32] = [1u8; 32]; +pub const USER_1_SECRET_KEY: [u8; 32] = [2u8; 32]; // This defines a static variable for the path to WASM binaries lazy_static! { @@ -25,178 +31,89 @@ lazy_static! { }; } +#[derive(Default)] pub struct TestContext { pub builder: InMemoryWasmTestBuilder, - pub account_1: AccountHash, - pub account_2: AccountHash, - #[allow(dead_code)] - pub account_3: AccountHash, + pub user_1: AccountHash, + pub contract_hash: ContractHash, + pub contract_purse: URef, } impl TestContext { pub fn new() -> TestContext { let mut builder = InMemoryWasmTestBuilder::default(); builder.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST); - let account_1 = create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_1)); - let account_2 = create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_2)); - let account_3 = create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_3)); - TestContext { - builder, - account_1, - account_2, - account_3, - } - } + let admin = create_funded_account_for_secret_key_bytes(&mut builder, ADMIN_SECRET_KEY); + let user_1 = create_funded_account_for_secret_key_bytes(&mut builder, USER_1_SECRET_KEY); - pub fn named_keys(&self, account: AccountHash) -> NamedKeys { - self.builder - .get_expected_account(account) - .named_keys() - .clone() - } + let deposit_contract_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + .join("demo-contract-optimized.wasm"); + run_session_with_args( + &mut builder, + &deposit_contract_path, + admin, + runtime_args! {}, + ); - pub fn get_contract_named_key( - &self, - contract_name: &str, - key_name: &str, - account: AccountHash, - ) -> Key { - let contract_hash = self.contract_hash_from_named_keys(contract_name, account); - *self - .builder - .get_contract(contract_hash) - .expect("should have contract") + let contract_hash = builder + .get_expected_account(admin) .named_keys() - .get(key_name) - .expect("Key not found") - } - - pub fn contract_hash_from_named_keys( - &self, - key_name: &str, - account: AccountHash, - ) -> ContractHash { - self.named_keys(account) - .get(key_name) + .get("kairos_demo_contract") .expect("must have contract hash key as part of contract creation") .into_hash() .map(ContractHash::new) - .expect("must get contract hash") - } + .expect("must get contract hash"); - pub fn contract_hash(&self, name: &str, account: AccountHash) -> ContractHash { - self.builder - .get_expected_account(account) + let contract = builder + .get_contract(contract_hash) + .expect("should have contract"); + let contract_purse = *contract .named_keys() - .get(name) - .expect("must have contract hash key as part of contract creation") - .into_hash() - .map(ContractHash::new) - .expect("must get contract hash") - } - - pub fn install_demo_contract(&mut self, admin: AccountHash) { - let session_args = runtime_args! {}; - let install_contract_request = ExecuteRequestBuilder::standard( - admin, - PATH_TO_WASM_BINARIES - .join("demo-contract-optimized.wasm") - .to_str() - .expect("Failed to parse path as str"), - session_args, - ) - .build(); - self.builder - .exec(install_contract_request) - .expect_success() - .commit(); - } - - pub fn get_contract_purse_uref(&self, account: AccountHash) -> URef { - let seed_uref: URef = *self - .get_contract_named_key("kairos_demo_contract", "kairos_deposit_purse", account) - .as_uref() - .unwrap(); - seed_uref - } - - pub fn get_account_purse_uref(&self, account: AccountHash) -> URef { - self.builder.get_expected_account(account).main_purse() - } - - #[allow(dead_code)] - pub fn get_contract_purse_balance(&self, account: AccountHash) -> U512 { - let contract_purse_uref: URef = *self - .get_contract_named_key("kairos_demo_contract", "kairos_deposit_purse", account) + .get("kairos_deposit_purse") + .expect("Key not found") .as_uref() .unwrap(); - self.builder.get_purse_balance(contract_purse_uref) - } - // see deposit-session - pub fn run_deposit_session(&mut self, amount: U512, installer: AccountHash, user: AccountHash) { - let session_args = runtime_args! { - "amount" => amount, - "demo_contract" => self.contract_hash("kairos_demo_contract", installer) - }; - let session_request = ExecuteRequestBuilder::standard( - user, - PATH_TO_WASM_BINARIES - .join("deposit-session-optimized.wasm") - .to_str() - .expect("Failed to parse path as str"), - session_args, - ) - .build(); - self.builder.exec(session_request).expect_success().commit(); + TestContext { + builder, + user_1, + contract_hash, + contract_purse, + } } +} - // see malicious-session - pub fn run_malicious_session( - &mut self, - msg_sender: AccountHash, - amount: U512, - account: AccountHash, - ) { - let session_args = runtime_args! { - "amount" => amount, - "demo_contract" => self.contract_hash("kairos_demo_contract", account) - }; - let session_request = ExecuteRequestBuilder::standard( - msg_sender, - PATH_TO_WASM_BINARIES - .join("malicious-session-optimized.wasm") - .to_str() - .expect("Failed to parse path as str"), - session_args, - ) - .build(); - self.builder.exec(session_request).expect_failure().commit(); - } +pub fn run_session_with_args( + builder: &mut WasmTestBuilder, + session_wasm_path: &Path, + user: AccountHash, + runtime_args: RuntimeArgs, +) { + let session_request = + ExecuteRequestBuilder::standard(user, session_wasm_path.to_str().unwrap(), runtime_args) + .build(); + builder.exec(session_request).commit(); +} - // see malicious-reader - pub fn run_malicious_reader_session( - &mut self, - msg_sender: AccountHash, - amount: U512, - account: AccountHash, - deposit_purse_uref: URef, - ) { - let session_args = runtime_args! { - "amount" => amount, - "demo_contract" => self.contract_hash("kairos_demo_contract", account), - "purse_uref" => deposit_purse_uref - }; - let session_request = ExecuteRequestBuilder::standard( - msg_sender, - PATH_TO_WASM_BINARIES - .join("malicious-reader-optimized.wasm") - .to_str() - .expect("Failed to parse path as str"), - session_args, - ) - .build(); - self.builder.exec(session_request).expect_failure().commit(); - } +/// Creates a funded account for the given ed25519 secret key in bytes +/// It panics if the passed secret key bytes cannot be read +pub fn create_funded_account_for_secret_key_bytes( + builder: &mut WasmTestBuilder, + account_secret_key_bytes: [u8; 32], +) -> AccountHash { + let account_secret_key = SecretKey::ed25519_from_bytes(account_secret_key_bytes).unwrap(); + let account_public_key = PublicKey::from(&account_secret_key); + let account_hash = account_public_key.to_account_hash(); + let transfer = ExecuteRequestBuilder::transfer( + *DEFAULT_ACCOUNT_ADDR, + runtime_args! { + ARG_AMOUNT => DEFAULT_ACCOUNT_INITIAL_BALANCE / 10_u64, + ARG_TARGET => account_hash, + ARG_ID => Option::::None, + }, + ) + .build(); + builder.exec(transfer).expect_success().commit(); + account_hash } diff --git a/demo-contract-tests/tests/test_fixture/utils.rs b/demo-contract-tests/tests/test_fixture/utils.rs deleted file mode 100644 index dd1fa2cd..00000000 --- a/demo-contract-tests/tests/test_fixture/utils.rs +++ /dev/null @@ -1,38 +0,0 @@ -use casper_engine_test_support::{ - ExecuteRequestBuilder, WasmTestBuilder, ARG_AMOUNT, DEFAULT_ACCOUNT_ADDR, - DEFAULT_ACCOUNT_INITIAL_BALANCE, -}; -use casper_execution_engine::storage::global_state::in_memory::InMemoryGlobalState; -use casper_types::{ - account::AccountHash, - runtime_args, - system::{handle_payment::ARG_TARGET, mint::ARG_ID}, - PublicKey, RuntimeArgs, SecretKey, -}; - -// Creates a dummy account and transfer funds to it -pub fn create_funded_dummy_account( - builder: &mut WasmTestBuilder, - account_string: Option<[u8; 32]>, -) -> AccountHash { - let (_, account_public_key) = create_dummy_key_pair(account_string.unwrap_or([7u8; 32])); - let account = account_public_key.to_account_hash(); - let transfer = ExecuteRequestBuilder::transfer( - *DEFAULT_ACCOUNT_ADDR, - runtime_args! { - ARG_AMOUNT => DEFAULT_ACCOUNT_INITIAL_BALANCE / 10_u64, - ARG_TARGET => account, - ARG_ID => Option::::None, - }, - ) - .build(); - builder.exec(transfer).expect_success().commit(); - account -} - -pub fn create_dummy_key_pair(account_string: [u8; 32]) -> (SecretKey, PublicKey) { - let secret_key = - SecretKey::ed25519_from_bytes(account_string).expect("failed to create secret key"); - let public_key = PublicKey::from(&secret_key); - (secret_key, public_key) -} From f54df4f024ada4851b02dd89c88ed3448a3cbdbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 11:40:36 -0500 Subject: [PATCH 089/115] demo-contract-tests: refactor fixture --- Cargo.lock | 3 +- demo-contract-tests/Cargo.toml | 3 +- .../tests/integration_tests.rs | 119 ++++-------------- demo-contract-tests/tests/test_fixture/mod.rs | 98 +++++++++++---- 4 files changed, 102 insertions(+), 121 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e175595d..6d3d0b65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1017,8 +1017,7 @@ dependencies = [ "casper-engine-test-support", "casper-execution-engine", "casper-types 4.0.1", - "dotenvy", - "lazy_static", + "rand 0.8.5", ] [[package]] diff --git a/demo-contract-tests/Cargo.toml b/demo-contract-tests/Cargo.toml index b90227be..bb138f65 100644 --- a/demo-contract-tests/Cargo.toml +++ b/demo-contract-tests/Cargo.toml @@ -12,5 +12,4 @@ casper-engine-test-support = {version="7.0.0", default-features=false} casper-execution-engine = {version="7.0.0", default-features=false} casper-contract = {version="4.0.0", default-features=false} casper-types = {version="4.0.1", default-features=false} -dotenvy = "0.15.7" -lazy_static = "1.4.0" +rand = "0.8" diff --git a/demo-contract-tests/tests/integration_tests.rs b/demo-contract-tests/tests/integration_tests.rs index 3788ad3d..c3301b7f 100644 --- a/demo-contract-tests/tests/integration_tests.rs +++ b/demo-contract-tests/tests/integration_tests.rs @@ -1,9 +1,8 @@ mod test_fixture; #[cfg(test)] mod tests { - use crate::test_fixture::{run_session_with_args, TestContext}; - use casper_types::{runtime_args, RuntimeArgs, U512}; - use std::path::Path; + use crate::test_fixture::TestContext; + use casper_types::U512; #[test] fn should_install_deposit_contract() { @@ -11,118 +10,46 @@ mod tests { } #[test] - fn deposit_into_purse() { - let TestContext { - mut builder, - user_1, - contract_hash, - contract_purse, - } = TestContext::new(); + fn test_deposit_succeeds() { + let mut fixture = TestContext::new(); - let user_uref = builder.get_expected_account(user_1).main_purse(); - let user_balance_before = builder.get_purse_balance(user_uref); + let user = fixture.create_funded_user(); + let user_balance_before = fixture.get_user_balance(user); // check that the contract balance is zero before depositing - let contract_balance_before = builder.get_purse_balance(contract_purse); + let deposit_amount = U512::from(100000000000u64); + let contract_balance_before = fixture.get_contract_balance(); assert_eq!(contract_balance_before, U512::zero()); // user_1 deposits the deposit_amount - let deposit_session_path = - Path::new(env!("PATH_TO_WASM_BINARIES")).join("deposit-session-optimized.wasm"); - let deposit_amount = U512::from(100000000000u64); - let session_args = runtime_args! { - "amount" => deposit_amount, - "demo_contract" => contract_hash - }; - run_session_with_args( - &mut builder, - deposit_session_path.as_path(), - user_1, - session_args, - ); - builder.expect_success(); + fixture.deposit_succeeds(user, deposit_amount); // the contract balance should afterward equal to the deposit_amount - let contract_balance_after = builder.get_purse_balance(contract_purse); + let contract_balance_after = fixture.get_contract_balance(); assert_eq!(contract_balance_after, deposit_amount); - let user_balance_after = builder.get_purse_balance(user_uref); + let user_balance_after = fixture.get_user_balance(user); assert!(user_balance_after <= user_balance_before - deposit_amount); } - // see malicious-session #[test] - fn run_malicious_session() { - let TestContext { - mut builder, - user_1, - contract_hash, - .. - } = TestContext::new(); + fn test_transfer_from_contract_purse_to_user_fails() { + let mut fixture = TestContext::new(); - let deposit_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) - .join("deposit-session-optimized.wasm"); - let session_args = runtime_args! { - "amount" => U512::from(100000000000u64), - "demo_contract" => contract_hash - }; - run_session_with_args( - &mut builder, - deposit_session_path.as_path(), - user_1, - session_args.clone(), - ); - builder.expect_success(); + let user = fixture.create_funded_user(); + let amount = U512::from(100000000000u64); + fixture.deposit_succeeds(user, amount); - let malicious_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) - .join("malicious-session-optimized.wasm"); - run_session_with_args( - &mut builder, - malicious_session_path.as_path(), - user_1, - session_args, - ); - builder.expect_failure(); + fixture.transfer_from_contract_purse_to_user_fails(user, amount) } - // see malicious-reader #[test] - fn run_malicious_reader() { - let TestContext { - mut builder, - user_1, - contract_hash, - contract_purse, - } = TestContext::new(); + fn test_transfer_from_contract_purse_by_uref_should_fails() { + let mut fixture = TestContext::new(); + let user = fixture.create_funded_user(); + let amount = U512::from(100000000000u64); + fixture.deposit_succeeds(user, amount); - let deposit_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) - .join("deposit-session-optimized.wasm"); - let session_args = runtime_args! { - "amount" => U512::from(100000000000u64), - "demo_contract" => contract_hash - }; - run_session_with_args( - &mut builder, - deposit_session_path.as_path(), - user_1, - session_args, - ); - builder.expect_success(); - - let deposit_amount = U512::from(100000000000u64); - let session_args = runtime_args! { - "amount" => deposit_amount, - "demo_contract" => contract_hash, - "purse_uref" => contract_purse - }; - let malicious_reader_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) - .join("malicious-reader-optimized.wasm"); - run_session_with_args( - &mut builder, - malicious_reader_session_path.as_path(), - user_1, - session_args, - ); - builder.expect_failure(); + fixture.transfer_from_contract_purse_by_uref_to_user_fails(user, amount) } } diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index 4c731e84..1fa6487e 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -8,35 +8,21 @@ use casper_types::{ crypto::{PublicKey, SecretKey}, runtime_args, system::{handle_payment::ARG_TARGET, mint::ARG_ID}, - RuntimeArgs, + RuntimeArgs, U512, }; use std::path::Path; use casper_engine_test_support::{InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST}; use casper_types::{ContractHash, URef}; -use dotenvy::dotenv; -use lazy_static::lazy_static; -use std::{env, path::PathBuf}; +use std::env; pub const ADMIN_SECRET_KEY: [u8; 32] = [1u8; 32]; -pub const USER_1_SECRET_KEY: [u8; 32] = [2u8; 32]; - -// This defines a static variable for the path to WASM binaries -lazy_static! { - static ref PATH_TO_WASM_BINARIES: PathBuf = { - dotenv().ok(); - env::var("PATH_TO_WASM_BINARIES") - .expect("Missing environment variable PATH_TO_WASM_BINARIES") - .into() - }; -} #[derive(Default)] pub struct TestContext { pub builder: InMemoryWasmTestBuilder, - pub user_1: AccountHash, - pub contract_hash: ContractHash, - pub contract_purse: URef, + contract_hash: ContractHash, + contract_purse: URef, } impl TestContext { @@ -45,8 +31,6 @@ impl TestContext { builder.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST); let admin = create_funded_account_for_secret_key_bytes(&mut builder, ADMIN_SECRET_KEY); - let user_1 = create_funded_account_for_secret_key_bytes(&mut builder, USER_1_SECRET_KEY); - let deposit_contract_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) .join("demo-contract-optimized.wasm"); run_session_with_args( @@ -77,11 +61,83 @@ impl TestContext { TestContext { builder, - user_1, contract_hash, contract_purse, } } + + pub fn create_funded_user(&mut self) -> AccountHash { + let mut random_secret_key: [u8; 32] = rand::random(); + while random_secret_key == ADMIN_SECRET_KEY { + random_secret_key = rand::random(); + } + create_funded_account_for_secret_key_bytes(&mut self.builder, random_secret_key) + } + + pub fn get_user_balance(&mut self, user: AccountHash) -> U512 { + let user_uref = self.builder.get_expected_account(user).main_purse(); + self.builder.get_purse_balance(user_uref) + } + + pub fn get_contract_balance(&mut self) -> U512 { + self.builder.get_purse_balance(self.contract_purse) + } + + pub fn deposit_succeeds(&mut self, depositor: AccountHash, amount: U512) { + let deposit_session_path = + Path::new(env!("PATH_TO_WASM_BINARIES")).join("deposit-session-optimized.wasm"); + let session_args = runtime_args! { + "amount" => amount, + "demo_contract" => self.contract_hash + }; + run_session_with_args( + &mut self.builder, + deposit_session_path.as_path(), + depositor, + session_args, + ); + self.builder.expect_success(); + } + + pub fn transfer_from_contract_purse_to_user_fails( + &mut self, + receiver: AccountHash, + amount: U512, + ) { + let session_args = runtime_args! { + "amount" => amount, + "demo_contract" => self.contract_hash + }; + let malicious_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + .join("malicious-session-optimized.wasm"); + run_session_with_args( + &mut self.builder, + malicious_session_path.as_path(), + receiver, + session_args, + ); + self.builder.expect_failure(); + } + pub fn transfer_from_contract_purse_by_uref_to_user_fails( + &mut self, + receiver: AccountHash, + amount: U512, + ) { + let session_args = runtime_args! { + "amount" => amount, + "demo_contract" => self.contract_hash, + "purse_uref" => self.contract_purse + }; + let malicious_reader_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + .join("malicious-reader-optimized.wasm"); + run_session_with_args( + &mut self.builder, + malicious_reader_session_path.as_path(), + receiver, + session_args, + ); + self.builder.expect_failure(); + } } pub fn run_session_with_args( From 33ea2fc7ae1557dfc131fc5a51b8a74017b5dc92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 11:51:27 -0500 Subject: [PATCH 090/115] demo-contract-tests: add tests to check that admin can't take funds --- .../tests/integration_tests.rs | 23 ++++++++++++++++++- demo-contract-tests/tests/test_fixture/mod.rs | 4 +++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/demo-contract-tests/tests/integration_tests.rs b/demo-contract-tests/tests/integration_tests.rs index c3301b7f..cdc86fe0 100644 --- a/demo-contract-tests/tests/integration_tests.rs +++ b/demo-contract-tests/tests/integration_tests.rs @@ -44,7 +44,18 @@ mod tests { } #[test] - fn test_transfer_from_contract_purse_by_uref_should_fails() { + fn test_transfer_from_contract_purse_to_admin_fails() { + let mut fixture = TestContext::new(); + + let user = fixture.create_funded_user(); + let amount = U512::from(100000000000u64); + fixture.deposit_succeeds(user, amount); + + fixture.transfer_from_contract_purse_to_user_fails(fixture.admin, amount) + } + + #[test] + fn test_transfer_from_contract_purse_by_uref_to_user_should_fails() { let mut fixture = TestContext::new(); let user = fixture.create_funded_user(); let amount = U512::from(100000000000u64); @@ -52,4 +63,14 @@ mod tests { fixture.transfer_from_contract_purse_by_uref_to_user_fails(user, amount) } + + #[test] + fn test_transfer_from_contract_purse_by_uref_to_admin_should_fails() { + let mut fixture = TestContext::new(); + let user = fixture.create_funded_user(); + let amount = U512::from(100000000000u64); + fixture.deposit_succeeds(user, amount); + + fixture.transfer_from_contract_purse_by_uref_to_user_fails(fixture.admin, amount) + } } diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index 1fa6487e..684e9f62 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -20,7 +20,8 @@ pub const ADMIN_SECRET_KEY: [u8; 32] = [1u8; 32]; #[derive(Default)] pub struct TestContext { - pub builder: InMemoryWasmTestBuilder, + builder: InMemoryWasmTestBuilder, + pub admin: AccountHash, contract_hash: ContractHash, contract_purse: URef, } @@ -61,6 +62,7 @@ impl TestContext { TestContext { builder, + admin, contract_hash, contract_purse, } From 5f04db2bb94cde5e72f1065e63fb4ee3ce957ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 11:54:38 -0500 Subject: [PATCH 091/115] demo-contract-tests: remove unused dependency --- Cargo.lock | 1 - demo-contract-tests/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d3d0b65..8c16e3c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1012,7 +1012,6 @@ dependencies = [ name = "demo-contract-tests" version = "0.1.0" dependencies = [ - "base64 0.21.7", "casper-contract", "casper-engine-test-support", "casper-execution-engine", diff --git a/demo-contract-tests/Cargo.toml b/demo-contract-tests/Cargo.toml index bb138f65..a3c02a61 100644 --- a/demo-contract-tests/Cargo.toml +++ b/demo-contract-tests/Cargo.toml @@ -7,7 +7,6 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dev-dependencies] -base64 = {version = "0.21.2", default-features = false, features = ["alloc"] } casper-engine-test-support = {version="7.0.0", default-features=false} casper-execution-engine = {version="7.0.0", default-features=false} casper-contract = {version="4.0.0", default-features=false} From 164a60b676ea601a00b835f2dd8c33ada9d91f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 12:13:20 -0500 Subject: [PATCH 092/115] don't ignore .env --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index e4383a5f..37358052 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ result target .tmp .nixos-test-history -.env From 34a07383e7fc3085e4ad1ab1202952d36cd5520f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 12:24:48 -0500 Subject: [PATCH 093/115] demo-contract: remove u64::from --- kairos-contracts/demo-contract/contract/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 780b46d4..667039a9 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -96,7 +96,7 @@ pub extern "C" fn call() { }; // this counter will be udpated by the entry point that processes / verifies batches let mut named_keys = NamedKeys::new(); - let last_processed_deposit_counter = storage::new_uref(u64::from(0u8)); + let last_processed_deposit_counter = storage::new_uref(0u64); named_keys.insert( KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER.to_string(), From 496d3777fd707d7fa362fae560fe919b172a7367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 12:35:02 -0500 Subject: [PATCH 094/115] fix lockfile --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d412224a..56b990b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2015,7 +2015,7 @@ dependencies = [ "kairos-test-utils", "kairos-tx", "predicates", - "reqwest 0.12.4", + "reqwest 0.12.3", "serde", "serde_json", "thiserror", From 5da25a9db2f190e6d8797df7f2e4611652001844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 13:33:46 -0500 Subject: [PATCH 095/115] demo-contract: account -> depositor --- kairos-contracts/demo-contract/contract/src/main.rs | 2 +- kairos-contracts/demo-contract/contract/src/utils/events.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 667039a9..d54aee5f 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -77,7 +77,7 @@ pub extern "C" fn deposit() { u64::try_from(amount).unwrap_or_else(|_| runtime::revert(ApiError::InvalidArgument)); let new_deposit_record: Deposit = Deposit { - account: get_immediate_caller().unwrap_or_revert(), + depositor: get_immediate_caller().unwrap_or_revert(), amount, timestamp: None, }; diff --git a/kairos-contracts/demo-contract/contract/src/utils/events.rs b/kairos-contracts/demo-contract/contract/src/utils/events.rs index 6afe6559..5ce91271 100644 --- a/kairos-contracts/demo-contract/contract/src/utils/events.rs +++ b/kairos-contracts/demo-contract/contract/src/utils/events.rs @@ -5,7 +5,7 @@ use casper_types::Key; #[derive(Event)] pub struct Deposit { - pub account: Key, + pub depositor: Key, pub amount: u64, pub timestamp: Option, } From 09da0ad18d4ced479497a2d6d16c25026b166c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 13:34:26 -0500 Subject: [PATCH 096/115] demo-contract: minor init refactor --- .../demo-contract/contract/src/main.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index d54aee5f..26492139 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -2,6 +2,7 @@ #![no_main] extern crate alloc; use alloc::string::ToString; +use alloc::vec; use casper_contract::{ contract_api::{runtime, storage, system}, unwrap_or_revert::UnwrapOrRevert, @@ -87,21 +88,18 @@ pub extern "C" fn deposit() { #[no_mangle] pub extern "C" fn call() { - let entry_points = { - let mut entry_points = EntryPoints::new(); - entry_points.add_entry_point(entry_points::init()); - entry_points.add_entry_point(entry_points::get_purse()); - entry_points.add_entry_point(entry_points::deposit()); - entry_points - }; + let entry_points = EntryPoints::from(vec![ + entry_points::init(), + entry_points::get_purse(), + entry_points::deposit(), + ]); + // this counter will be udpated by the entry point that processes / verifies batches - let mut named_keys = NamedKeys::new(); let last_processed_deposit_counter = storage::new_uref(0u64); - - named_keys.insert( + let named_keys = NamedKeys::from([( KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER.to_string(), last_processed_deposit_counter.into(), - ); + )]); let (contract_hash, _) = storage::new_locked_contract( entry_points, From b663b89cb45a04c4a27633ea7859b5a646f7c51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Thu, 9 May 2024 14:25:18 -0500 Subject: [PATCH 097/115] demo-contract: remove timestamp from deposit event --- kairos-contracts/demo-contract/contract/src/main.rs | 1 - kairos-contracts/demo-contract/contract/src/utils/events.rs | 2 -- 2 files changed, 3 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 26492139..6ab84149 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -80,7 +80,6 @@ pub extern "C" fn deposit() { let new_deposit_record: Deposit = Deposit { depositor: get_immediate_caller().unwrap_or_revert(), amount, - timestamp: None, }; // this increases a counter automatically - we don't need to create one ourselves casper_event_standard::emit(new_deposit_record); diff --git a/kairos-contracts/demo-contract/contract/src/utils/events.rs b/kairos-contracts/demo-contract/contract/src/utils/events.rs index 5ce91271..d0a3d310 100644 --- a/kairos-contracts/demo-contract/contract/src/utils/events.rs +++ b/kairos-contracts/demo-contract/contract/src/utils/events.rs @@ -1,11 +1,9 @@ use casper_event_standard::Event; extern crate alloc; -use alloc::string::String; use casper_types::Key; #[derive(Event)] pub struct Deposit { pub depositor: Key, pub amount: u64, - pub timestamp: Option, } From 5241499c6e737974cab18d1c39a27779e7d64dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Wed, 15 May 2024 12:14:41 -0400 Subject: [PATCH 098/115] update lockfile --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index cb82fb06..0760af87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2045,7 +2045,7 @@ dependencies = [ "kairos-trie", "kairos-tx", "proptest", - "reqwest 0.12.4", + "reqwest 0.12.3", "serde", "serde_json", "sha2 0.10.8", From 8440fa41aea414a4dc1072ecf14ccf075bb4e07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:24:46 +0200 Subject: [PATCH 099/115] Remove outdated comment about security badges. --- kairos-contracts/demo-contract/contract/src/main.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 6ab84149..3ba43904 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -24,10 +24,7 @@ use utils::errors::DepositError; use utils::events::Deposit; use utils::get_immediate_caller; -// This entry point is called once when the contract is installed -// and sets up the security badges with the installer as an admin or the -// optional list of admins. -// The optional list of admins is passed to the installation session as a runtime argument. +// This entry point is called once when the contract is installed. // The contract purse will be created in contract context so that it is "owned" by the contract // rather than the installing account. #[no_mangle] From 25a70d1db9ca02240654caffa372e4e150c85332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:26:34 +0200 Subject: [PATCH 100/115] Simplify comment about contract utilities. --- kairos-contracts/demo-contract/contract/src/utils.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/utils.rs b/kairos-contracts/demo-contract/contract/src/utils.rs index 461d74c2..e02a5ee6 100644 --- a/kairos-contracts/demo-contract/contract/src/utils.rs +++ b/kairos-contracts/demo-contract/contract/src/utils.rs @@ -1,8 +1,5 @@ -/* - The utilities found in this file were scraped from other Casper contracts, - mainly cep-78 and cep-18. - This file is not necessarily due for review, unless breaking changes are suspected. -*/ +// Utilities copied from cep-78 and cep-18 implementation. + use casper_contract::contract_api::runtime; use casper_types::{system::CallStackElement, Key}; From 9ec324f6fa6226e43c820e80036bdb7dd51c473a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:30:13 +0200 Subject: [PATCH 101/115] Remove unused `test-support` feature from contract dependency. --- kairos-contracts/demo-contract/contract/Cargo.toml | 2 +- kairos-contracts/demo-contract/deposit-session/Cargo.toml | 2 +- kairos-contracts/demo-contract/malicious-reader/Cargo.toml | 2 +- kairos-contracts/demo-contract/malicious-session/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index 8e102c8d..2bdf3997 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["std", "test-support"]} +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["std"]} casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", default-features=false} casper-event-standard= {git="https://github.com/cspr-rad/casper-event-standard", branch="kairos-demo-1.5.6", default-features=false} base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } diff --git a/kairos-contracts/demo-contract/deposit-session/Cargo.toml b/kairos-contracts/demo-contract/deposit-session/Cargo.toml index d8abdfd0..4b335f1e 100644 --- a/kairos-contracts/demo-contract/deposit-session/Cargo.toml +++ b/kairos-contracts/demo-contract/deposit-session/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["test-support"]} +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} [[bin]] diff --git a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml index d139388f..13a19774 100644 --- a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["test-support"]} +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} [[bin]] diff --git a/kairos-contracts/demo-contract/malicious-session/Cargo.toml b/kairos-contracts/demo-contract/malicious-session/Cargo.toml index b8a599bf..2ca8e7d2 100644 --- a/kairos-contracts/demo-contract/malicious-session/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-session/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["test-support"]} +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} [[bin]] From 8d648e42152df06015794abaab19c4a736da6246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:40:29 +0200 Subject: [PATCH 102/115] Remove unused `bincode` dependency and use `no-std-helpers`. Bincode was unnecessarily included with default features, so it included panic handlers from `std`. It is better to make contract a `no_std`, so it's smaller. For such case, panic handlers can be registered with `no-std-helpers` feature in `casper-contract`. --- kairos-contracts/Cargo.lock | 10 ---------- kairos-contracts/demo-contract/contract/Cargo.toml | 3 +-- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/kairos-contracts/Cargo.lock b/kairos-contracts/Cargo.lock index 0654b265..28c148ac 100644 --- a/kairos-contracts/Cargo.lock +++ b/kairos-contracts/Cargo.lock @@ -38,15 +38,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -157,7 +148,6 @@ name = "contract" version = "0.1.0" dependencies = [ "base64 0.20.0", - "bincode", "casper-contract", "casper-event-standard", "casper-types", diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index 2bdf3997..b4bdf908 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -5,11 +5,10 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["std"]} +casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["no-std-helpers"]} casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", default-features=false} casper-event-standard= {git="https://github.com/cspr-rad/casper-event-standard", branch="kairos-demo-1.5.6", default-features=false} base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } -bincode = "1.3.3" [build] target = "wasm32-unknown-unknown" From b17471f71caf2e0914ae959bec6e22904d899bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:40:59 +0200 Subject: [PATCH 103/115] Remove unused `base64` dependency. --- kairos-contracts/Cargo.lock | 9 +-------- kairos-contracts/demo-contract/contract/Cargo.toml | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/kairos-contracts/Cargo.lock b/kairos-contracts/Cargo.lock index 28c148ac..5b0d6352 100644 --- a/kairos-contracts/Cargo.lock +++ b/kairos-contracts/Cargo.lock @@ -26,12 +26,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" - [[package]] name = "base64ct" version = "1.6.0" @@ -106,7 +100,7 @@ version = "4.0.1" source = "git+https://github.com/cspr-rad/casper-node?branch=kairos-demo-1.5.6#35222130c58b3c9997a358d4248ddae603836496" dependencies = [ "base16", - "base64 0.13.1", + "base64", "bitflags", "blake2", "ed25519-dalek", @@ -147,7 +141,6 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" name = "contract" version = "0.1.0" dependencies = [ - "base64 0.20.0", "casper-contract", "casper-event-standard", "casper-types", diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index b4bdf908..8f1f1684 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -8,7 +8,6 @@ license.workspace = true casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["no-std-helpers"]} casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", default-features=false} casper-event-standard= {git="https://github.com/cspr-rad/casper-event-standard", branch="kairos-demo-1.5.6", default-features=false} -base64 = { version = "0.20.0", default-features = false, features = ["alloc"] } [build] target = "wasm32-unknown-unknown" From 46b1fc45142200918562c7e1c0aaf853ef2be483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:43:54 +0200 Subject: [PATCH 104/115] Unify format of `Cargo.toml` files. --- demo-contract-tests/Cargo.toml | 10 ++++------ kairos-contracts/demo-contract/contract/Cargo.toml | 6 +++--- .../demo-contract/deposit-session/Cargo.toml | 4 ++-- .../demo-contract/malicious-reader/Cargo.toml | 6 ++---- .../demo-contract/malicious-session/Cargo.toml | 6 ++---- kairos-test-utils/Cargo.toml | 1 - 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/demo-contract-tests/Cargo.toml b/demo-contract-tests/Cargo.toml index a3c02a61..1fdb26e6 100644 --- a/demo-contract-tests/Cargo.toml +++ b/demo-contract-tests/Cargo.toml @@ -4,11 +4,9 @@ version.workspace = true edition.workspace = true license.workspace = true -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dev-dependencies] -casper-engine-test-support = {version="7.0.0", default-features=false} -casper-execution-engine = {version="7.0.0", default-features=false} -casper-contract = {version="4.0.0", default-features=false} -casper-types = {version="4.0.1", default-features=false} +casper-engine-test-support = { version = "7.0.0", default-features = false } +casper-execution-engine = { version = "7.0.0", default-features = false } +casper-contract = { version = "4.0.0", default-features = false } +casper-types = { version = "4.0.1", default-features = false } rand = "0.8" diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index 8f1f1684..2432e189 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -5,9 +5,9 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", features=["no-std-helpers"]} -casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6", default-features=false} -casper-event-standard= {git="https://github.com/cspr-rad/casper-event-standard", branch="kairos-demo-1.5.6", default-features=false} +casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6", features = ["no-std-helpers"] } +casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6", default-features = false } +casper-event-standard = { git = "https://github.com/cspr-rad/casper-event-standard", branch = "kairos-demo-1.5.6", default-features = false } [build] target = "wasm32-unknown-unknown" diff --git a/kairos-contracts/demo-contract/deposit-session/Cargo.toml b/kairos-contracts/demo-contract/deposit-session/Cargo.toml index 4b335f1e..40247d30 100644 --- a/kairos-contracts/demo-contract/deposit-session/Cargo.toml +++ b/kairos-contracts/demo-contract/deposit-session/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} -casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} +casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } +casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } [[bin]] name = "deposit-session" diff --git a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml index 13a19774..58fa27f2 100644 --- a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml @@ -4,11 +4,9 @@ version.workspace = true edition.workspace = true license.workspace = true -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} -casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} +casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } +casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } [[bin]] name = "malicious-reader" diff --git a/kairos-contracts/demo-contract/malicious-session/Cargo.toml b/kairos-contracts/demo-contract/malicious-session/Cargo.toml index 2ca8e7d2..81b75600 100644 --- a/kairos-contracts/demo-contract/malicious-session/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-session/Cargo.toml @@ -4,11 +4,9 @@ version.workspace = true edition.workspace = true license.workspace = true -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -casper-contract = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} -casper-types = {git="https://github.com/cspr-rad/casper-node", branch="kairos-demo-1.5.6"} +casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } +casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } [[bin]] name = "malicious-session" diff --git a/kairos-test-utils/Cargo.toml b/kairos-test-utils/Cargo.toml index 94a3d187..3c6c2753 100644 --- a/kairos-test-utils/Cargo.toml +++ b/kairos-test-utils/Cargo.toml @@ -15,7 +15,6 @@ bench = false all-tests = ["cctl-tests"] cctl-tests = [] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] [dependencies] From 0709c3e47ae7aa4934459a12814081bd5c8643bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:52:12 +0200 Subject: [PATCH 105/115] Switch to Casper dependencies from crates. --- kairos-contracts/Cargo.lock | 12 ++++++++---- kairos-contracts/demo-contract/contract/Cargo.toml | 6 +++--- .../demo-contract/deposit-session/Cargo.toml | 4 ++-- .../demo-contract/malicious-reader/Cargo.toml | 4 ++-- .../demo-contract/malicious-session/Cargo.toml | 4 ++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kairos-contracts/Cargo.lock b/kairos-contracts/Cargo.lock index 5b0d6352..0507942d 100644 --- a/kairos-contracts/Cargo.lock +++ b/kairos-contracts/Cargo.lock @@ -67,7 +67,8 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "casper-contract" version = "4.0.0" -source = "git+https://github.com/cspr-rad/casper-node?branch=kairos-demo-1.5.6#35222130c58b3c9997a358d4248ddae603836496" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d42901eb5b09bb79e7d7403642e70983ccac0f4812edf1de77d978abea5f3299" dependencies = [ "casper-types", "hex_fmt", @@ -77,7 +78,8 @@ dependencies = [ [[package]] name = "casper-event-standard" version = "0.5.0" -source = "git+https://github.com/cspr-rad/casper-event-standard?branch=kairos-demo-1.5.6#88b855da23d855d9680816a3dbb4b2e0c4f0ffa7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3a1bdb142b4bfcdceec757422b2e292f446b72ce3613f881eb694f3925ef10" dependencies = [ "casper-contract", "casper-event-standard-macro", @@ -87,7 +89,8 @@ dependencies = [ [[package]] name = "casper-event-standard-macro" version = "0.5.0" -source = "git+https://github.com/cspr-rad/casper-event-standard?branch=kairos-demo-1.5.6#88b855da23d855d9680816a3dbb4b2e0c4f0ffa7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "485810e6c8387863a92e9b81e4e66ce290e2c96c0ad8ec4352e95128aa88900e" dependencies = [ "proc-macro2", "quote", @@ -97,7 +100,8 @@ dependencies = [ [[package]] name = "casper-types" version = "4.0.1" -source = "git+https://github.com/cspr-rad/casper-node?branch=kairos-demo-1.5.6#35222130c58b3c9997a358d4248ddae603836496" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" dependencies = [ "base16", "base64", diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index 2432e189..4c8b3df7 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -5,9 +5,9 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6", features = ["no-std-helpers"] } -casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6", default-features = false } -casper-event-standard = { git = "https://github.com/cspr-rad/casper-event-standard", branch = "kairos-demo-1.5.6", default-features = false } +casper-contract = { version = "4.0.0", features = ["no-std-helpers"] } +casper-types = { version = "4.0.1", default-features = false } +casper-event-standard = { version = "0.5.0", default-features = false } [build] target = "wasm32-unknown-unknown" diff --git a/kairos-contracts/demo-contract/deposit-session/Cargo.toml b/kairos-contracts/demo-contract/deposit-session/Cargo.toml index 40247d30..9cd0af28 100644 --- a/kairos-contracts/demo-contract/deposit-session/Cargo.toml +++ b/kairos-contracts/demo-contract/deposit-session/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } -casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } +casper-contract = { version = "4.0.0" } +casper-types = { version = "4.0.1" } [[bin]] name = "deposit-session" diff --git a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml index 58fa27f2..e40d8088 100644 --- a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } -casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } +casper-contract = { version = "4.0.0" } +casper-types = { version = "4.0.1" } [[bin]] name = "malicious-reader" diff --git a/kairos-contracts/demo-contract/malicious-session/Cargo.toml b/kairos-contracts/demo-contract/malicious-session/Cargo.toml index 81b75600..72d22678 100644 --- a/kairos-contracts/demo-contract/malicious-session/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-session/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } -casper-types = { git = "https://github.com/cspr-rad/casper-node", branch = "kairos-demo-1.5.6" } +casper-contract = { version = "4.0.0" } +casper-types = { version = "4.0.1" } [[bin]] name = "malicious-session" From 8cf3bc58cb24afd65ad6d2bea015bcd443be0f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 10:58:00 +0200 Subject: [PATCH 106/115] Disable default features where possible. --- kairos-contracts/demo-contract/contract/Cargo.toml | 2 +- kairos-contracts/demo-contract/deposit-session/Cargo.toml | 4 ++-- kairos-contracts/demo-contract/malicious-reader/Cargo.toml | 4 ++-- kairos-contracts/demo-contract/malicious-session/Cargo.toml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index 4c8b3df7..98c37e7c 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { version = "4.0.0", features = ["no-std-helpers"] } +casper-contract = { version = "4.0.0", default-features = false, features = ["no-std-helpers"] } casper-types = { version = "4.0.1", default-features = false } casper-event-standard = { version = "0.5.0", default-features = false } diff --git a/kairos-contracts/demo-contract/deposit-session/Cargo.toml b/kairos-contracts/demo-contract/deposit-session/Cargo.toml index 9cd0af28..b91b602a 100644 --- a/kairos-contracts/demo-contract/deposit-session/Cargo.toml +++ b/kairos-contracts/demo-contract/deposit-session/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { version = "4.0.0" } -casper-types = { version = "4.0.1" } +casper-contract = { version = "4.0.0", default-features = false } +casper-types = { version = "4.0.1", default-features = false } [[bin]] name = "deposit-session" diff --git a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml index e40d8088..fe44b678 100644 --- a/kairos-contracts/demo-contract/malicious-reader/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-reader/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { version = "4.0.0" } -casper-types = { version = "4.0.1" } +casper-contract = { version = "4.0.0", default-features = false } +casper-types = { version = "4.0.1", default-features = false } [[bin]] name = "malicious-reader" diff --git a/kairos-contracts/demo-contract/malicious-session/Cargo.toml b/kairos-contracts/demo-contract/malicious-session/Cargo.toml index 72d22678..86c34b86 100644 --- a/kairos-contracts/demo-contract/malicious-session/Cargo.toml +++ b/kairos-contracts/demo-contract/malicious-session/Cargo.toml @@ -5,8 +5,8 @@ edition.workspace = true license.workspace = true [dependencies] -casper-contract = { version = "4.0.0" } -casper-types = { version = "4.0.1" } +casper-contract = { version = "4.0.0", default-features = false } +casper-types = { version = "4.0.1", default-features = false } [[bin]] name = "malicious-session" From 757c612cbe16b6d2fb08cdca9f81edf899431b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 11:09:31 +0200 Subject: [PATCH 107/115] Fix misplaced args with contract package/uref. --- kairos-contracts/demo-contract/contract/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 3ba43904..4cffb7b1 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -100,8 +100,8 @@ pub extern "C" fn call() { let (contract_hash, _) = storage::new_locked_contract( entry_points, Some(named_keys), - Some(KAIROS_DEPOSIT_CONTRACT_UREF.to_string()), Some(KAIROS_DEPOSIT_CONTRACT_PACKAGE.to_string()), + Some(KAIROS_DEPOSIT_CONTRACT_UREF.to_string()), ); let contract_hash_key = Key::from(contract_hash); runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); From 8010d8ef245b607efa5ee04bab001b4998efe205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 11:12:46 +0200 Subject: [PATCH 108/115] Stored contract name is actually a contract hash. --- kairos-contracts/demo-contract/contract/src/constants.rs | 5 ++--- kairos-contracts/demo-contract/contract/src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/kairos-contracts/demo-contract/contract/src/constants.rs b/kairos-contracts/demo-contract/contract/src/constants.rs index 3fc43dad..6cdd782a 100644 --- a/kairos-contracts/demo-contract/contract/src/constants.rs +++ b/kairos-contracts/demo-contract/contract/src/constants.rs @@ -1,6 +1,5 @@ -pub const KAIROS_DEPOSIT_CONTRACT_NAME: &str = "kairos_demo_contract"; - -pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE: &str = "kairos_contract_package"; +pub const KAIROS_DEPOSIT_CONTRACT_HASH: &str = "kairos_demo_contract"; +pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE_HASH: &str = "kairos_contract_package"; pub const KAIROS_DEPOSIT_CONTRACT_UREF: &str = "demo_contract"; pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_counter"; diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index 4cffb7b1..c6f8afbe 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -14,7 +14,7 @@ use casper_types::{ }; mod constants; use constants::{ - KAIROS_DEPOSIT_CONTRACT_NAME, KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_CONTRACT_UREF, + KAIROS_DEPOSIT_CONTRACT_HASH, KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_CONTRACT_UREF, KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, }; @@ -104,7 +104,7 @@ pub extern "C" fn call() { Some(KAIROS_DEPOSIT_CONTRACT_UREF.to_string()), ); let contract_hash_key = Key::from(contract_hash); - runtime::put_key(KAIROS_DEPOSIT_CONTRACT_NAME, contract_hash_key); + runtime::put_key(KAIROS_DEPOSIT_CONTRACT_HASH, contract_hash_key); let init_args = runtime_args! {}; // Call the init entry point of the newly installed contract From 4bcb72e9046e2fa442e4ee04f34ec1c0191bd173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 11:20:45 +0200 Subject: [PATCH 109/115] Avoid using "deposit contract" name. --- demo-contract-tests/tests/integration_tests.rs | 2 +- demo-contract-tests/tests/test_fixture/mod.rs | 11 +++-------- .../demo-contract/contract/src/constants.rs | 6 +++--- kairos-contracts/demo-contract/contract/src/main.rs | 13 ++++++------- .../demo-contract/deposit-session/src/main.rs | 8 ++++---- .../demo-contract/malicious-reader/src/main.rs | 2 +- .../demo-contract/malicious-session/src/main.rs | 2 +- 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/demo-contract-tests/tests/integration_tests.rs b/demo-contract-tests/tests/integration_tests.rs index cdc86fe0..1df16e77 100644 --- a/demo-contract-tests/tests/integration_tests.rs +++ b/demo-contract-tests/tests/integration_tests.rs @@ -5,7 +5,7 @@ mod tests { use casper_types::U512; #[test] - fn should_install_deposit_contract() { + fn should_install_contract() { let _fixture = TestContext::new(); } diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index 684e9f62..1450fd82 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -32,19 +32,14 @@ impl TestContext { builder.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST); let admin = create_funded_account_for_secret_key_bytes(&mut builder, ADMIN_SECRET_KEY); - let deposit_contract_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) + let contract_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) .join("demo-contract-optimized.wasm"); - run_session_with_args( - &mut builder, - &deposit_contract_path, - admin, - runtime_args! {}, - ); + run_session_with_args(&mut builder, &contract_path, admin, runtime_args! {}); let contract_hash = builder .get_expected_account(admin) .named_keys() - .get("kairos_demo_contract") + .get("kairos_contract_hash") .expect("must have contract hash key as part of contract creation") .into_hash() .map(ContractHash::new) diff --git a/kairos-contracts/demo-contract/contract/src/constants.rs b/kairos-contracts/demo-contract/contract/src/constants.rs index 6cdd782a..565de552 100644 --- a/kairos-contracts/demo-contract/contract/src/constants.rs +++ b/kairos-contracts/demo-contract/contract/src/constants.rs @@ -1,6 +1,6 @@ -pub const KAIROS_DEPOSIT_CONTRACT_HASH: &str = "kairos_demo_contract"; -pub const KAIROS_DEPOSIT_CONTRACT_PACKAGE_HASH: &str = "kairos_contract_package"; -pub const KAIROS_DEPOSIT_CONTRACT_UREF: &str = "demo_contract"; +pub const KAIROS_CONTRACT_HASH: &str = "kairos_contract_hash"; +pub const KAIROS_CONTRACT_PACKAGE_HASH: &str = "kairos_contract_package_hash"; +pub const KAIROS_CONTRACT_UREF: &str = "kairos_contract_uref"; pub const KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER: &str = "last_processed_deposit_counter"; pub const KAIROS_DEPOSIT_PURSE: &str = "kairos_deposit_purse"; diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index c6f8afbe..cd65fa7b 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -14,9 +14,8 @@ use casper_types::{ }; mod constants; use constants::{ - KAIROS_DEPOSIT_CONTRACT_HASH, KAIROS_DEPOSIT_CONTRACT_PACKAGE, KAIROS_DEPOSIT_CONTRACT_UREF, - KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, - RUNTIME_ARG_TEMP_PURSE, + KAIROS_CONTRACT_HASH, KAIROS_CONTRACT_PACKAGE_HASH, KAIROS_CONTRACT_UREF, KAIROS_DEPOSIT_PURSE, + KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, RUNTIME_ARG_AMOUNT, RUNTIME_ARG_TEMP_PURSE, }; mod entry_points; mod utils; @@ -57,7 +56,7 @@ pub extern "C" fn get_purse() { // Entry point called by a user through session code to deposit funds. // Due to Casper < 2.0 purse management and access control, it is necessary that -// a temporary purse is funded and passed to the deposit contract, since this is +// a temporary purse is funded and passed to the contract, since this is // the only secure method of making a payment to a contract purse. #[no_mangle] pub extern "C" fn deposit() { @@ -100,11 +99,11 @@ pub extern "C" fn call() { let (contract_hash, _) = storage::new_locked_contract( entry_points, Some(named_keys), - Some(KAIROS_DEPOSIT_CONTRACT_PACKAGE.to_string()), - Some(KAIROS_DEPOSIT_CONTRACT_UREF.to_string()), + Some(KAIROS_CONTRACT_PACKAGE_HASH.to_string()), + Some(KAIROS_CONTRACT_UREF.to_string()), ); let contract_hash_key = Key::from(contract_hash); - runtime::put_key(KAIROS_DEPOSIT_CONTRACT_HASH, contract_hash_key); + runtime::put_key(KAIROS_CONTRACT_HASH, contract_hash_key); let init_args = runtime_args! {}; // Call the init entry point of the newly installed contract diff --git a/kairos-contracts/demo-contract/deposit-session/src/main.rs b/kairos-contracts/demo-contract/deposit-session/src/main.rs index 3729e7c5..6fda219d 100644 --- a/kairos-contracts/demo-contract/deposit-session/src/main.rs +++ b/kairos-contracts/demo-contract/deposit-session/src/main.rs @@ -1,9 +1,9 @@ /* - Transfer native Casper tokens from the caller to the deposit smart contract. + Transfer native Casper tokens from the caller to the smart contract. Due to the purse access control in Casper 1.5.x, a temporary purse is created and funded - by the user first, to then be passed to the deposit contract. + by the user first, to then be passed to the contract. - Finally the temporary purse is emptied / all funds are transferred to the deposit contract's + Finally the temporary purse is emptied / all funds are transferred to the contract's purse. */ #![no_std] @@ -16,7 +16,7 @@ pub extern "C" fn call() { let contract_hash: ContractHash = runtime::get_named_arg("demo_contract"); let amount: U512 = runtime::get_named_arg("amount"); let source: URef = account::get_main_purse(); - // create a temporary purse that can be passed to the deposit contract + // create a temporary purse that can be passed to the contract // this is required due to the access control model of the purse system used // in casper_node 1.5.x // this will likely be drastically changed in 2.0 diff --git a/kairos-contracts/demo-contract/malicious-reader/src/main.rs b/kairos-contracts/demo-contract/malicious-reader/src/main.rs index dee773d1..75722e56 100644 --- a/kairos-contracts/demo-contract/malicious-reader/src/main.rs +++ b/kairos-contracts/demo-contract/malicious-reader/src/main.rs @@ -1,6 +1,6 @@ /* This session code emulates an attack where a user tries to transfer funds - out of the deposit contract's purse, by passing the deposit contract purse as a runtime argument + out of the contract's purse, by passing the contract purse as a runtime argument and calling transfer_from_purse_to_purse */ diff --git a/kairos-contracts/demo-contract/malicious-session/src/main.rs b/kairos-contracts/demo-contract/malicious-session/src/main.rs index 02294fa1..ec1a3878 100644 --- a/kairos-contracts/demo-contract/malicious-session/src/main.rs +++ b/kairos-contracts/demo-contract/malicious-session/src/main.rs @@ -1,6 +1,6 @@ /* This session code emulates an attack where a user tries to transfer funds - out of the deposit contract's purse, by querying the get_purse entry point + out of the contract's purse, by querying the get_purse entry point and calling transfer_from_purse_to_purse */ From 5ef3efde7c7cafbbacea17b75f61dd82285f763e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 11:26:50 +0200 Subject: [PATCH 110/115] Switch back to stable toolchain for non-WASM targets. --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 14d0705b..826817a6 100644 --- a/flake.nix +++ b/flake.nix @@ -44,8 +44,8 @@ perSystem = { config, self', inputs', system, pkgs, lib, ... }: let rustToolchain = with inputs'.fenix.packages; combine [ - latest.toolchain - targets.wasm32-unknown-unknown.latest.rust-std + stable.toolchain + targets.wasm32-unknown-unknown.latest.rust-std # WASM contracts are build with nigthly. ]; craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolchain; From ce89f5320021b89e9b5e732c35ab61716c3a0dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 11:51:21 +0200 Subject: [PATCH 111/115] Replace compile-time env with helper for WASM directory. --- demo-contract-tests/tests/test_fixture/mod.rs | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index 1450fd82..56d6e7df 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -10,7 +10,7 @@ use casper_types::{ system::{handle_payment::ARG_TARGET, mint::ARG_ID}, RuntimeArgs, U512, }; -use std::path::Path; +use std::path::{Path, PathBuf}; use casper_engine_test_support::{InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST}; use casper_types::{ContractHash, URef}; @@ -26,14 +26,32 @@ pub struct TestContext { contract_purse: URef, } +fn get_wasm_directory() -> PathBuf { + // Environment variable or default path. + let base_path = if let Ok(custom_path) = env::var("PATH_TO_WASM_BINARIES") { + PathBuf::from(custom_path) + } else if cfg!(debug_assertions) { + PathBuf::from("../kairos-contracts/target/wasm32-unknown-unknown/debug/") + } else { + PathBuf::from("../kairos-contracts/target/wasm32-unknown-unknown/release/") + }; + if !base_path.exists() { + panic!("WASM directory does not exist: {}", base_path.display()); + } + + // TODO: Ensure all WASM files are optimized + //optimize_wasm_files(&base_path)?; + + base_path +} + impl TestContext { pub fn new() -> TestContext { let mut builder = InMemoryWasmTestBuilder::default(); builder.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST); let admin = create_funded_account_for_secret_key_bytes(&mut builder, ADMIN_SECRET_KEY); - let contract_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) - .join("demo-contract-optimized.wasm"); + let contract_path = get_wasm_directory().join("demo-contract-optimized.wasm"); run_session_with_args(&mut builder, &contract_path, admin, runtime_args! {}); let contract_hash = builder @@ -81,8 +99,7 @@ impl TestContext { } pub fn deposit_succeeds(&mut self, depositor: AccountHash, amount: U512) { - let deposit_session_path = - Path::new(env!("PATH_TO_WASM_BINARIES")).join("deposit-session-optimized.wasm"); + let deposit_session_path = get_wasm_directory().join("deposit-session-optimized.wasm"); let session_args = runtime_args! { "amount" => amount, "demo_contract" => self.contract_hash @@ -105,8 +122,7 @@ impl TestContext { "amount" => amount, "demo_contract" => self.contract_hash }; - let malicious_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) - .join("malicious-session-optimized.wasm"); + let malicious_session_path = get_wasm_directory().join("malicious-session-optimized.wasm"); run_session_with_args( &mut self.builder, malicious_session_path.as_path(), @@ -125,8 +141,8 @@ impl TestContext { "demo_contract" => self.contract_hash, "purse_uref" => self.contract_purse }; - let malicious_reader_session_path = std::path::Path::new(env!("PATH_TO_WASM_BINARIES")) - .join("malicious-reader-optimized.wasm"); + let malicious_reader_session_path = + get_wasm_directory().join("malicious-reader-optimized.wasm"); run_session_with_args( &mut self.builder, malicious_reader_session_path.as_path(), From fe652c17c85c429a32984796fedb53d12faa4e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 12:36:49 +0200 Subject: [PATCH 112/115] Add `wasm-opt` dependency. --- Cargo.lock | 134 +++++++++++++++++++++++++++++++++ demo-contract-tests/Cargo.toml | 1 + 2 files changed, 135 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 0760af87..e3d78d33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -815,6 +815,16 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -988,6 +998,50 @@ dependencies = [ "syn 2.0.58", ] +[[package]] +name = "cxx" +version = "1.0.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb497fad022245b29c2a0351df572e2d67c1046bcef2260ebc022aec81efea82" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9327c7f9fbd6329a200a5d4aa6f674c60ab256525ff0084b52a889d4e4c60cee" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2 1.0.79", + "quote 1.0.35", + "scratch", + "syn 2.0.58", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "688c799a4a846f1c0acb9f36bb9c6272d9b3d9457f3633c7753c6057270df13c" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.122" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bc249a7e3cd554fd2e8e08a426e9670c50bbfc9a621653cfa9accc9641783" +dependencies = [ + "proc-macro2 1.0.79", + "quote 1.0.35", + "syn 2.0.58", +] + [[package]] name = "datasize" version = "0.2.15" @@ -1017,6 +1071,7 @@ dependencies = [ "casper-execution-engine", "casper-types 4.0.1", "rand 0.8.5", + "wasm-opt", ] [[package]] @@ -2153,6 +2208,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "link-cplusplus" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" +dependencies = [ + "cc", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -3246,6 +3310,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scratch" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" + [[package]] name = "sd-notify" version = "0.4.1" @@ -3636,6 +3706,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "terminal_size" version = "0.3.0" @@ -3957,6 +4036,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" + [[package]] name = "unicode-xid" version = "0.1.0" @@ -4141,6 +4226,46 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "wasm-opt" +version = "0.116.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd87a4c135535ffed86123b6fb0f0a5a0bc89e50416c942c5f0662c645f679c" +dependencies = [ + "anyhow", + "libc", + "strum", + "strum_macros", + "tempfile", + "thiserror", + "wasm-opt-cxx-sys", + "wasm-opt-sys", +] + +[[package]] +name = "wasm-opt-cxx-sys" +version = "0.116.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c57b28207aa724318fcec6575fe74803c23f6f266fce10cbc9f3f116762f12e" +dependencies = [ + "anyhow", + "cxx", + "cxx-build", + "wasm-opt-sys", +] + +[[package]] +name = "wasm-opt-sys" +version = "0.116.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a1cce564dc768dacbdb718fc29df2dba80bd21cb47d8f77ae7e3d95ceb98cbe" +dependencies = [ + "anyhow", + "cc", + "cxx", + "cxx-build", +] + [[package]] name = "wasm-streams" version = "0.4.0" @@ -4180,6 +4305,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/demo-contract-tests/Cargo.toml b/demo-contract-tests/Cargo.toml index 1fdb26e6..df2b55fd 100644 --- a/demo-contract-tests/Cargo.toml +++ b/demo-contract-tests/Cargo.toml @@ -10,3 +10,4 @@ casper-execution-engine = { version = "7.0.0", default-features = false } casper-contract = { version = "4.0.0", default-features = false } casper-types = { version = "4.0.1", default-features = false } rand = "0.8" +wasm-opt = "0.116" From 6119d499405b3c3797db0060afdaa758208a5853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 12:37:03 +0200 Subject: [PATCH 113/115] Run WASM optimization in tests runtime. --- demo-contract-tests/tests/test_fixture/mod.rs | 68 +++++++++++++++++-- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index 56d6e7df..afd0a99b 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -15,6 +15,7 @@ use std::path::{Path, PathBuf}; use casper_engine_test_support::{InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST}; use casper_types::{ContractHash, URef}; use std::env; +use std::fs; pub const ADMIN_SECRET_KEY: [u8; 32] = [1u8; 32]; @@ -30,21 +31,76 @@ fn get_wasm_directory() -> PathBuf { // Environment variable or default path. let base_path = if let Ok(custom_path) = env::var("PATH_TO_WASM_BINARIES") { PathBuf::from(custom_path) - } else if cfg!(debug_assertions) { - PathBuf::from("../kairos-contracts/target/wasm32-unknown-unknown/debug/") } else { - PathBuf::from("../kairos-contracts/target/wasm32-unknown-unknown/release/") + let project_root = env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string()); + if cfg!(debug_assertions) { + PathBuf::from(project_root) + .join("../kairos-contracts/target/wasm32-unknown-unknown/debug/") + } else { + PathBuf::from(project_root) + .join("../kairos-contracts/target/wasm32-unknown-unknown/release/") + } }; if !base_path.exists() { - panic!("WASM directory does not exist: {}", base_path.display()); + let build_type = if cfg!(debug_assertions) { + "debug" + } else { + "release" + }; + panic!("WASM directory does not exist: {}. Please build smart contracts at `./kairos-contracts` with `cargo build` for {}.", base_path.display(), build_type); } - // TODO: Ensure all WASM files are optimized - //optimize_wasm_files(&base_path)?; + // Ensure all WASM files are optimized. + optimize_wasm_files(&base_path).expect("Unable to optimize WASM files"); base_path } +fn optimize_wasm_files(dir: &Path) -> Result<(), String> { + let entries = fs::read_dir(dir).map_err(|e| e.to_string())?; + + let mut found_wasm = false; + for entry in entries { + let entry = entry.map_err(|e| e.to_string())?; + let path = entry.path(); + if path.extension().and_then(|s| s.to_str()) == Some("wasm") { + found_wasm = true; + + // Skip already optimized files. + let file_name = path.file_name().unwrap().to_str().unwrap(); + if file_name.ends_with("-optimized.wasm") { + continue; + } + + // Skip if optimized file already exists. + let optimized_file_name = format!( + "{}-optimized.wasm", + file_name.strip_suffix(".wasm").unwrap() + ); + let optimized_file_path = dir.join(&optimized_file_name); + if optimized_file_path.exists() { + continue; + } + + // Optimize and save as new file. + let infile = path.to_str().unwrap().to_string(); + let outfile = optimized_file_path.to_str().unwrap().to_string(); + + let mut opts = wasm_opt::OptimizationOptions::new_optimize_for_size(); + opts.add_pass(wasm_opt::Pass::StripDebug); + opts.add_pass(wasm_opt::Pass::SignextLowering); + + opts.run(&infile, &outfile).map_err(|e| e.to_string())?; + } + } + + if !found_wasm { + return Err("No WASM files found in the directory. You should change directory to `./kairos-contracts` and build with `cargo build && cargo build --release`.".to_string()); + } + + Ok(()) +} + impl TestContext { pub fn new() -> TestContext { let mut builder = InMemoryWasmTestBuilder::default(); From 42fff3486816aaeb84cbc8ebfe6eee52f75e2cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 12:39:27 +0200 Subject: [PATCH 114/115] Refactor WASM helper for tests. --- demo-contract-tests/tests/test_fixture/mod.rs | 82 ++----------------- .../tests/test_fixture/wasm_helper.rs | 78 ++++++++++++++++++ 2 files changed, 83 insertions(+), 77 deletions(-) create mode 100644 demo-contract-tests/tests/test_fixture/wasm_helper.rs diff --git a/demo-contract-tests/tests/test_fixture/mod.rs b/demo-contract-tests/tests/test_fixture/mod.rs index afd0a99b..a3515a5d 100644 --- a/demo-contract-tests/tests/test_fixture/mod.rs +++ b/demo-contract-tests/tests/test_fixture/mod.rs @@ -1,3 +1,5 @@ +mod wasm_helper; + use casper_engine_test_support::{ ExecuteRequestBuilder, WasmTestBuilder, ARG_AMOUNT, DEFAULT_ACCOUNT_ADDR, DEFAULT_ACCOUNT_INITIAL_BALANCE, @@ -10,12 +12,12 @@ use casper_types::{ system::{handle_payment::ARG_TARGET, mint::ARG_ID}, RuntimeArgs, U512, }; -use std::path::{Path, PathBuf}; +use std::path::Path; use casper_engine_test_support::{InMemoryWasmTestBuilder, PRODUCTION_RUN_GENESIS_REQUEST}; use casper_types::{ContractHash, URef}; -use std::env; -use std::fs; + +use self::wasm_helper::get_wasm_directory; pub const ADMIN_SECRET_KEY: [u8; 32] = [1u8; 32]; @@ -27,80 +29,6 @@ pub struct TestContext { contract_purse: URef, } -fn get_wasm_directory() -> PathBuf { - // Environment variable or default path. - let base_path = if let Ok(custom_path) = env::var("PATH_TO_WASM_BINARIES") { - PathBuf::from(custom_path) - } else { - let project_root = env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string()); - if cfg!(debug_assertions) { - PathBuf::from(project_root) - .join("../kairos-contracts/target/wasm32-unknown-unknown/debug/") - } else { - PathBuf::from(project_root) - .join("../kairos-contracts/target/wasm32-unknown-unknown/release/") - } - }; - if !base_path.exists() { - let build_type = if cfg!(debug_assertions) { - "debug" - } else { - "release" - }; - panic!("WASM directory does not exist: {}. Please build smart contracts at `./kairos-contracts` with `cargo build` for {}.", base_path.display(), build_type); - } - - // Ensure all WASM files are optimized. - optimize_wasm_files(&base_path).expect("Unable to optimize WASM files"); - - base_path -} - -fn optimize_wasm_files(dir: &Path) -> Result<(), String> { - let entries = fs::read_dir(dir).map_err(|e| e.to_string())?; - - let mut found_wasm = false; - for entry in entries { - let entry = entry.map_err(|e| e.to_string())?; - let path = entry.path(); - if path.extension().and_then(|s| s.to_str()) == Some("wasm") { - found_wasm = true; - - // Skip already optimized files. - let file_name = path.file_name().unwrap().to_str().unwrap(); - if file_name.ends_with("-optimized.wasm") { - continue; - } - - // Skip if optimized file already exists. - let optimized_file_name = format!( - "{}-optimized.wasm", - file_name.strip_suffix(".wasm").unwrap() - ); - let optimized_file_path = dir.join(&optimized_file_name); - if optimized_file_path.exists() { - continue; - } - - // Optimize and save as new file. - let infile = path.to_str().unwrap().to_string(); - let outfile = optimized_file_path.to_str().unwrap().to_string(); - - let mut opts = wasm_opt::OptimizationOptions::new_optimize_for_size(); - opts.add_pass(wasm_opt::Pass::StripDebug); - opts.add_pass(wasm_opt::Pass::SignextLowering); - - opts.run(&infile, &outfile).map_err(|e| e.to_string())?; - } - } - - if !found_wasm { - return Err("No WASM files found in the directory. You should change directory to `./kairos-contracts` and build with `cargo build && cargo build --release`.".to_string()); - } - - Ok(()) -} - impl TestContext { pub fn new() -> TestContext { let mut builder = InMemoryWasmTestBuilder::default(); diff --git a/demo-contract-tests/tests/test_fixture/wasm_helper.rs b/demo-contract-tests/tests/test_fixture/wasm_helper.rs new file mode 100644 index 00000000..902c237c --- /dev/null +++ b/demo-contract-tests/tests/test_fixture/wasm_helper.rs @@ -0,0 +1,78 @@ +use std::env; +use std::fs; +use std::path::Path; +use std::path::PathBuf; + +pub fn get_wasm_directory() -> PathBuf { + // Environment variable or default path. + let base_path = if let Ok(custom_path) = env::var("PATH_TO_WASM_BINARIES") { + PathBuf::from(custom_path) + } else { + let project_root = env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string()); + if cfg!(debug_assertions) { + PathBuf::from(project_root) + .join("../kairos-contracts/target/wasm32-unknown-unknown/debug/") + } else { + PathBuf::from(project_root) + .join("../kairos-contracts/target/wasm32-unknown-unknown/release/") + } + }; + if !base_path.exists() { + let build_type = if cfg!(debug_assertions) { + "debug" + } else { + "release" + }; + panic!("WASM directory does not exist: {}. Please build smart contracts at `./kairos-contracts` with `cargo build` for {}.", base_path.display(), build_type); + } + + // Ensure all WASM files are optimized. + optimize_files(&base_path).expect("Unable to optimize WASM files"); + + base_path +} + +fn optimize_files(dir: &Path) -> Result<(), String> { + let entries = fs::read_dir(dir).map_err(|e| e.to_string())?; + + let mut found_wasm = false; + for entry in entries { + let entry = entry.map_err(|e| e.to_string())?; + let path = entry.path(); + if path.extension().and_then(|s| s.to_str()) == Some("wasm") { + found_wasm = true; + + // Skip already optimized files. + let file_name = path.file_name().unwrap().to_str().unwrap(); + if file_name.ends_with("-optimized.wasm") { + continue; + } + + // Skip if optimized file already exists. + let optimized_file_name = format!( + "{}-optimized.wasm", + file_name.strip_suffix(".wasm").unwrap() + ); + let optimized_file_path = dir.join(&optimized_file_name); + if optimized_file_path.exists() { + continue; + } + + // Optimize and save as new file. + let infile = path.to_str().unwrap().to_string(); + let outfile = optimized_file_path.to_str().unwrap().to_string(); + + let mut opts = wasm_opt::OptimizationOptions::new_optimize_for_size(); + opts.add_pass(wasm_opt::Pass::StripDebug); + opts.add_pass(wasm_opt::Pass::SignextLowering); + + opts.run(&infile, &outfile).map_err(|e| e.to_string())?; + } + } + + if !found_wasm { + return Err("No WASM files found in the directory. You should change directory to `./kairos-contracts` and build with `cargo build && cargo build --release`.".to_string()); + } + + Ok(()) +} From 0c3ff1a2346fca741b9b45b0002acbf4286db143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 17 May 2024 15:35:42 +0200 Subject: [PATCH 115/115] Revert "Switch back to stable toolchain for non-WASM targets." For now we can stick to unstable one, to avoid heavy CI/CD. --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 826817a6..14d0705b 100644 --- a/flake.nix +++ b/flake.nix @@ -44,8 +44,8 @@ perSystem = { config, self', inputs', system, pkgs, lib, ... }: let rustToolchain = with inputs'.fenix.packages; combine [ - stable.toolchain - targets.wasm32-unknown-unknown.latest.rust-std # WASM contracts are build with nigthly. + latest.toolchain + targets.wasm32-unknown-unknown.latest.rust-std ]; craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolchain;