diff --git a/Cargo.lock b/Cargo.lock index 3c0476f3..709bd08b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2456,6 +2456,7 @@ name = "kairos-circuit-logic" version = "0.1.0" dependencies = [ "borsh", + "casper-event-standard", "kairos-trie", "kairos-tx", "proptest", diff --git a/kairos-contracts/Cargo.lock b/kairos-contracts/Cargo.lock index d147125d..706880ff 100644 --- a/kairos-contracts/Cargo.lock +++ b/kairos-contracts/Cargo.lock @@ -777,6 +777,7 @@ name = "kairos-circuit-logic" version = "0.1.0" dependencies = [ "borsh", + "casper-event-standard", "kairos-trie", "serde", "sha2", diff --git a/kairos-contracts/demo-contract/contract-utils/src/constants.rs b/kairos-contracts/demo-contract/contract-utils/src/constants.rs index 00fd9279..35b5c422 100644 --- a/kairos-contracts/demo-contract/contract-utils/src/constants.rs +++ b/kairos-contracts/demo-contract/contract-utils/src/constants.rs @@ -10,6 +10,7 @@ pub const RUNTIME_ARG_INITIAL_TRIE_ROOT: &str = "initial_trie_root"; pub const RUNTIME_ARG_TEMP_PURSE: &str = "temp_purse"; pub const RUNTIME_ARG_AMOUNT: &str = "amount"; pub const RUNTIME_ARG_RECEIPT: &str = "risc0_receipt"; +pub const RUNTIME_ARG_RECIPIENT: &str = "risc0_recipient"; pub const EP_INIT_NAME: &str = "init"; pub const EP_GET_PURSE_NAME: &str = "get_purse"; diff --git a/kairos-contracts/demo-contract/contract-utils/src/lib.rs b/kairos-contracts/demo-contract/contract-utils/src/lib.rs index 56bd8c05..4274e4ab 100644 --- a/kairos-contracts/demo-contract/contract-utils/src/lib.rs +++ b/kairos-contracts/demo-contract/contract-utils/src/lib.rs @@ -1,13 +1,4 @@ #![no_std] pub mod constants; -use casper_event_standard::casper_types::Key; -use casper_event_standard::Event; - extern crate alloc; - -#[derive(Event)] -pub struct Deposit { - pub depositor: Key, - pub amount: u64, -} diff --git a/kairos-contracts/demo-contract/contract/Cargo.toml b/kairos-contracts/demo-contract/contract/Cargo.toml index 0d951cc6..3f3863a6 100644 --- a/kairos-contracts/demo-contract/contract/Cargo.toml +++ b/kairos-contracts/demo-contract/contract/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true license.workspace = true [dependencies] -kairos-circuit-logic = {path="../../../kairos-prover/kairos-circuit-logic", default-features=false, features=["serde"]} +kairos-circuit-logic = {path="../../../kairos-prover/kairos-circuit-logic", default-features=false, features=["serde", "casper-event-standard"]} kairos-verifier-risc0-lib = {path="../../../kairos-prover/kairos-verifier-risc0-lib", default-features=false, features=["verifier", "disable-dev-mode"]} serde = {version="1", default-features=false, features=["derive"]} serde-json-wasm = { version="1", default-features=false } diff --git a/kairos-contracts/demo-contract/contract/src/entry_points.rs b/kairos-contracts/demo-contract/contract/src/entry_points.rs index 27db698c..3bb52b53 100644 --- a/kairos-contracts/demo-contract/contract/src/entry_points.rs +++ b/kairos-contracts/demo-contract/contract/src/entry_points.rs @@ -2,7 +2,7 @@ use alloc::vec; use casper_types::{CLType, EntryPoint, EntryPointAccess, EntryPointType, Parameter}; use contract_utils::constants::{ EP_DEPOSIT_NAME, EP_GET_PURSE_NAME, EP_INIT_NAME, EP_SUBMIT_NAME, RUNTIME_ARG_AMOUNT, - RUNTIME_ARG_RECEIPT, RUNTIME_ARG_TEMP_PURSE, + RUNTIME_ARG_RECEIPT, RUNTIME_ARG_RECIPIENT, RUNTIME_ARG_TEMP_PURSE, }; pub fn init() -> EntryPoint { @@ -29,6 +29,7 @@ pub fn deposit() -> EntryPoint { EntryPoint::new( EP_DEPOSIT_NAME, vec![ + Parameter::new(RUNTIME_ARG_RECIPIENT, CLType::PublicKey), Parameter::new(RUNTIME_ARG_AMOUNT, CLType::U512), Parameter::new(RUNTIME_ARG_TEMP_PURSE, CLType::URef), ], diff --git a/kairos-contracts/demo-contract/contract/src/main.rs b/kairos-contracts/demo-contract/contract/src/main.rs index a0435d5d..ca9fa55a 100644 --- a/kairos-contracts/demo-contract/contract/src/main.rs +++ b/kairos-contracts/demo-contract/contract/src/main.rs @@ -8,7 +8,7 @@ use casper_contract::{ unwrap_or_revert::UnwrapOrRevert, }; use casper_event_standard::Schemas; -use casper_types::bytesrepr::Bytes; +use casper_types::bytesrepr::{Bytes, ToBytes}; use casper_types::{ contracts::NamedKeys, runtime_args, AccessRights, ApiError, CLValue, EntryPoints, Key, RuntimeArgs, URef, U512, @@ -16,9 +16,9 @@ use casper_types::{ use contract_utils::constants::{ KAIROS_CONTRACT_HASH, KAIROS_CONTRACT_PACKAGE_HASH, KAIROS_CONTRACT_UREF, KAIROS_DEPOSIT_PURSE, KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER, KAIROS_TRIE_ROOT, RUNTIME_ARG_AMOUNT, - RUNTIME_ARG_INITIAL_TRIE_ROOT, RUNTIME_ARG_RECEIPT, RUNTIME_ARG_TEMP_PURSE, + RUNTIME_ARG_INITIAL_TRIE_ROOT, RUNTIME_ARG_RECEIPT, RUNTIME_ARG_RECIPIENT, + RUNTIME_ARG_TEMP_PURSE, }; -use contract_utils::Deposit; mod entry_points; mod utils; use kairos_verifier_risc0_lib::verifier::Receipt; @@ -29,7 +29,7 @@ use utils::get_immediate_caller; #[allow(unused)] use casper_contract_no_std_helpers; -use kairos_circuit_logic::ProofOutputs; +use kairos_circuit_logic::{transactions::L1Deposit, ProofOutputs}; // This entry point is called once when the contract is installed. // The contract purse will be created in contract context so that it is "owned" by the contract @@ -41,7 +41,7 @@ pub extern "C" fn init() { } // initialize event schema - let schemas = Schemas::new().with::(); + let schemas = Schemas::new().with::(); casper_event_standard::init(schemas); let new_deposit_purse: URef = system::create_purse(); @@ -69,6 +69,7 @@ pub extern "C" fn get_purse() { #[no_mangle] pub extern "C" fn deposit() { let temp_purse: URef = runtime::get_named_arg(RUNTIME_ARG_TEMP_PURSE); + let recipient: casper_types::PublicKey = runtime::get_named_arg(RUNTIME_ARG_RECIPIENT); 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) @@ -81,10 +82,13 @@ pub extern "C" fn deposit() { let amount = u64::try_from(amount).unwrap_or_else(|_| runtime::revert(ApiError::InvalidArgument)); - let new_deposit_record: Deposit = Deposit { - depositor: get_immediate_caller().unwrap_or_revert(), - amount, - }; + // FIXME: verify that the caller's account hash matches a depositor public key argument. + // We have to ensure we know who the depositor is for regulatory reasons. + // We could check that the recipient of the funds is the caller or off chain get another signature from the public key. + let _account_hash = get_immediate_caller().unwrap_or_revert(); + + let recipient = recipient.into_bytes().unwrap_or_revert(); + let new_deposit_record: L1Deposit = L1Deposit { recipient, amount }; // this increases a counter automatically - we don't need to create one ourselves casper_event_standard::emit(new_deposit_record); } diff --git a/kairos-prover/Cargo.lock b/kairos-prover/Cargo.lock index 557db991..1a9e6d75 100644 --- a/kairos-prover/Cargo.lock +++ b/kairos-prover/Cargo.lock @@ -108,9 +108,9 @@ dependencies = [ "ark-serialize", "ark-snark", "ark-std", - "blake2", + "blake2 0.10.6", "derivative", - "digest", + "digest 0.10.7", "sha2", ] @@ -142,7 +142,7 @@ dependencies = [ "ark-serialize", "ark-std", "derivative", - "digest", + "digest 0.10.7", "itertools 0.10.5", "num-bigint 0.4.5", "num-traits", @@ -222,7 +222,7 @@ checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ "ark-serialize-derive", "ark-std", - "digest", + "digest 0.10.7", "num-bigint 0.4.5", ] @@ -393,6 +393,24 @@ dependencies = [ "rustc-demangle", ] +[[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" @@ -405,6 +423,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[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" @@ -462,13 +486,24 @@ dependencies = [ "nom", ] +[[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 = "blake2" version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -563,6 +598,64 @@ dependencies = [ "serde", ] +[[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-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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" +dependencies = [ + "base16", + "base64 0.13.1", + "bitflags 1.3.2", + "blake2 0.9.2", + "ed25519-dalek", + "hex", + "hex_fmt", + "k256", + "num", + "num-derive", + "num-integer", + "num-rational", + "num-traits", + "rand", + "serde", + "serde_bytes", + "serde_json", + "uint", +] + [[package]] name = "cc" version = "1.0.99" @@ -717,13 +810,22 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[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]] @@ -736,6 +838,43 @@ dependencies = [ "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.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "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.67", +] + [[package]] name = "cust" version = "0.3.2" @@ -782,6 +921,16 @@ dependencies = [ "find_cuda_helper", ] +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "derivative" version = "2.2.0" @@ -826,6 +975,15 @@ dependencies = [ "syn 2.0.67", ] +[[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" @@ -894,7 +1052,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05213e96f184578b5f70105d4d0a644a168e99e12d7bea0b200c15d67b5c182" dependencies = [ - "digest", + "digest 0.10.7", "futures", "rand", "reqwest 0.11.27", @@ -902,6 +1060,43 @@ dependencies = [ "tokio", ] +[[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.12.0" @@ -914,6 +1109,24 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4445909572dbd556c457c849c4ca58623d84b27c8fff1e74b0b4227d8b90d17b" +[[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 = "encoding_rs" version = "0.8.34" @@ -990,6 +1203,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "find_cuda_helper" version = "0.2.0" @@ -1154,6 +1373,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -1192,6 +1412,17 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[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 = "h2" version = "0.3.26" @@ -1274,6 +1505,21 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[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 = "home" version = "0.5.9" @@ -1521,11 +1767,24 @@ dependencies = [ "wasm-bindgen", ] +[[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 = "kairos-circuit-logic" version = "0.1.0" dependencies = [ "borsh", + "casper-event-standard", "kairos-trie", "kairos-tx", "proptest", @@ -1561,7 +1820,7 @@ version = "0.1.0" source = "git+https://github.com/cspr-rad/kairos-trie#35367cb60a0ac1cba86e5a6ac3e87b04ae18255f" dependencies = [ "bumpalo", - "digest", + "digest 0.10.7", "ouroboros", "serde", ] @@ -1827,6 +2086,20 @@ dependencies = [ "winapi", ] +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint 0.4.5", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.3.3" @@ -1857,6 +2130,17 @@ 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" @@ -1866,6 +2150,28 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint 0.4.5", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1930,6 +2236,12 @@ 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 = "option-ext" version = "0.2.0" @@ -2034,6 +2346,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2467,6 +2789,16 @@ dependencies = [ "winreg 0.52.0", ] +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + [[package]] name = "ring" version = "0.17.8" @@ -2644,11 +2976,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53342780aef2d31ccc0526e6d4b151dab69e678d2e1495b2270ed40f5e1df6f4" dependencies = [ "anyhow", - "blake2", + "blake2 0.10.6", "bytemuck", "cfg-if", "cust", - "digest", + "digest 0.10.7", "ff", "hex", "hex-literal", @@ -2884,6 +3216,19 @@ dependencies = [ "untrusted", ] +[[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.23" @@ -2899,6 +3244,15 @@ 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.203" @@ -2964,7 +3318,7 @@ checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -2974,7 +3328,7 @@ source = "git+https://github.com/risc0/RustCrypto-hashes?tag=sha2-v0.10.6-riscze dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -2986,6 +3340,16 @@ dependencies = [ "lazy_static", ] +[[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 = "simd-adler32" version = "0.3.7" @@ -3045,6 +3409,16 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "sppark" version = "0.1.6" @@ -3484,6 +3858,18 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e36a83ea2b3c704935a01b4642946aadd445cea40b10935e3f8bd8052b8193d6" +[[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" diff --git a/kairos-prover/kairos-circuit-logic/Cargo.toml b/kairos-prover/kairos-circuit-logic/Cargo.toml index 11c8a25c..320292ce 100644 --- a/kairos-prover/kairos-circuit-logic/Cargo.toml +++ b/kairos-prover/kairos-circuit-logic/Cargo.toml @@ -12,6 +12,7 @@ asn1 = ["dep:kairos-tx"] borsh = ["dep:borsh"] arbitrary = ["dep:proptest", "dep:test-strategy", "std", "test-logic"] test-logic = [] +casper-event-standard = ["dep:casper-event-standard"] [dependencies] kairos-tx = { path = "../../kairos-tx", default-features = false, optional = true } @@ -20,6 +21,8 @@ serde = { version = "1", default-features = false, features = ["derive", "alloc" sha2 = { version = "0.10", default-features = false } borsh = { version = "1", default-features = false, features = ["derive"], optional = true } +casper-event-standard = { version = "0.5", optional = true } + # dev dependencies enabled by arbitrary test-strategy = { version = "0.3", optional = true } proptest = { version = "1", optional = true } diff --git a/kairos-prover/kairos-circuit-logic/src/transactions.rs b/kairos-prover/kairos-circuit-logic/src/transactions.rs index 43e7c527..1ef4be8d 100644 --- a/kairos-prover/kairos-circuit-logic/src/transactions.rs +++ b/kairos-prover/kairos-circuit-logic/src/transactions.rs @@ -51,6 +51,10 @@ pub struct Transfer { feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize) )] +#[cfg_attr( + feature = "casper-event-standard", + derive(casper_event_standard::Event) +)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct L1Deposit { pub recipient: PublicKey, diff --git a/kairos-server/Cargo.toml b/kairos-server/Cargo.toml index f12a8cc4..560cd066 100644 --- a/kairos-server/Cargo.toml +++ b/kairos-server/Cargo.toml @@ -36,7 +36,7 @@ tracing-subscriber = { version = "0.3", features = ["std", "env-filter"] } hex = "0.4" kairos-tx = { path = "../kairos-tx" } contract-utils = { path = "../kairos-contracts/demo-contract/contract-utils" } -kairos-circuit-logic = { path = "../kairos-prover/kairos-circuit-logic", features = ["serde", "asn1"] } +kairos-circuit-logic = { path = "../kairos-prover/kairos-circuit-logic", features = ["serde", "asn1", "casper-event-standard"] } kairos-trie = { git = "https://github.com/cspr-rad/kairos-trie" } sha2 = "0.10" reqwest = { version = "0.12", features = ["json"] } diff --git a/kairos-server/src/l1_sync/event_manager.rs b/kairos-server/src/l1_sync/event_manager.rs index 17a3b27f..1f71a16c 100644 --- a/kairos-server/src/l1_sync/event_manager.rs +++ b/kairos-server/src/l1_sync/event_manager.rs @@ -4,7 +4,6 @@ use casper_event_toolkit::casper_types::bytesrepr::FromBytes; use casper_event_toolkit::fetcher::{Fetcher, Schemas}; use casper_event_toolkit::metadata::CesMetadataRef; use casper_event_toolkit::rpc::client::CasperClient; -use contract_utils::Deposit; use crate::state::ServerStateInner; use kairos_circuit_logic::transactions::{KairosTransaction, L1Deposit}; @@ -60,7 +59,7 @@ impl EventManager { match event.name.as_str() { "Deposit" => { // Parse simplified deposit data. - let (deposit, _) = Deposit::from_bytes(&event_bytes) + let (deposit, _) = L1Deposit::from_bytes(&event_bytes) .expect("Failed to parse deposit event from bytes"); let amount = deposit.amount; diff --git a/kairos-session-code/deposit-session/src/main.rs b/kairos-session-code/deposit-session/src/main.rs index 107eba84..d707a8a4 100644 --- a/kairos-session-code/deposit-session/src/main.rs +++ b/kairos-session-code/deposit-session/src/main.rs @@ -9,11 +9,12 @@ #![no_main] use casper_contract::contract_api::{account, runtime, system}; -use casper_types::{runtime_args, ContractHash, RuntimeArgs, URef, U512}; +use casper_types::{runtime_args, ContractHash, PublicKey, RuntimeArgs, URef, U512}; #[no_mangle] pub extern "C" fn call() { let contract_hash: ContractHash = runtime::get_named_arg("demo_contract"); + let public_key: PublicKey = runtime::get_named_arg("recipient"); 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 contract @@ -30,6 +31,7 @@ pub extern "C" fn call() { "deposit", runtime_args! { "temp_purse" => temp_purse, + "recipient" => public_key, "amount" => amount }, );