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 01/57] 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 02/57] 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 03/57] 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 04/57] 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 05/57] 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 06/57] 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 07/57] 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 08/57] 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 09/57] 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 10/57] 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 11/57] 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 12/57] 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 13/57] 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 14/57] 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 15/57] 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 16/57] 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 17/57] 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 18/57] 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 19/57] 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 20/57] 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 21/57] 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 22/57] 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 23/57] 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 24/57] 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 25/57] 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 26/57] 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 27/57] 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 28/57] 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 29/57] 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 30/57] 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 31/57] 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 32/57] 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 33/57] 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 34/57] 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 35/57] 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 36/57] 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 37/57] 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 38/57] 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 39/57] 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 40/57] 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 41/57] 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 42/57] 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 43/57] 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 44/57] 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 45/57] 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 46/57] 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 47/57] 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 48/57] 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 49/57] 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 50/57] 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 51/57] 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 52/57] 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 53/57] 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 54/57] 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 55/57] 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 56/57] 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 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 57/57] 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