From 07e5427fa8963e67986c51e653212bc07d239ba5 Mon Sep 17 00:00:00 2001 From: Ilyar Date: Tue, 12 Nov 2024 12:00:54 +0100 Subject: [PATCH] wip --- .gitignore | 1 + Cargo.lock | 73 ++++++++++++++++++----------------- Cargo.toml | 4 +- Makefile | 40 +++++++++++-------- cli/Cargo.toml | 4 +- cli/main.rs | 46 ++++++++++++++-------- readme.md | 31 ++++++++++++--- rustfmt.toml | 2 +- script/{Demo.sol => demo.sol} | 18 ++++----- sdk/Cargo.toml | 10 +++++ sdk/lib.rs | 1 + version | 1 + 12 files changed, 145 insertions(+), 86 deletions(-) rename script/{Demo.sol => demo.sol} (78%) create mode 100644 sdk/Cargo.toml create mode 100644 sdk/lib.rs create mode 100644 version diff --git a/.gitignore b/.gitignore index e42a258..3d3ab7e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /cache /broadcast /dependencies +/contract/sdk \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c7f2d64..6f913f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,7 +50,7 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "alloy" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-contract", @@ -90,7 +90,7 @@ dependencies = [ [[package]] name = "alloy-consensus" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-eips", "alloy-primitives", @@ -99,14 +99,13 @@ dependencies = [ "auto_impl", "c-kzg", "derive_more", - "k256", "serde", ] [[package]] name = "alloy-contract" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-dyn-abi", "alloy-json-abi", @@ -180,7 +179,7 @@ dependencies = [ [[package]] name = "alloy-eips" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-eip2930", "alloy-eip7702", @@ -197,7 +196,7 @@ dependencies = [ [[package]] name = "alloy-genesis" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-primitives", "alloy-serde", @@ -219,7 +218,7 @@ dependencies = [ [[package]] name = "alloy-json-rpc" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -232,7 +231,7 @@ dependencies = [ [[package]] name = "alloy-network" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-eips", @@ -246,15 +245,13 @@ dependencies = [ "async-trait", "auto_impl", "futures-utils-wasm", - "serde", - "serde_json", "thiserror", ] [[package]] name = "alloy-network-primitives" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-eips", @@ -266,7 +263,7 @@ dependencies = [ [[package]] name = "alloy-node-bindings" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-genesis", "alloy-primitives", @@ -310,7 +307,7 @@ dependencies = [ [[package]] name = "alloy-provider" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-chains", "alloy-consensus", @@ -354,7 +351,7 @@ dependencies = [ [[package]] name = "alloy-pubsub" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -394,7 +391,7 @@ dependencies = [ [[package]] name = "alloy-rpc-client" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -419,7 +416,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-primitives", "alloy-rpc-types-engine", @@ -432,10 +429,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-anvil" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-primitives", - "alloy-rpc-types-eth", "alloy-serde", "serde", ] @@ -443,7 +439,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types-engine" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-eips", @@ -458,7 +454,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types-eth" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-eips", @@ -476,7 +472,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types-trace" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-primitives", "alloy-rpc-types-eth", @@ -489,7 +485,7 @@ dependencies = [ [[package]] name = "alloy-serde" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-primitives", "serde", @@ -499,7 +495,7 @@ dependencies = [ [[package]] name = "alloy-signer" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-primitives", "async-trait", @@ -512,7 +508,7 @@ dependencies = [ [[package]] name = "alloy-signer-aws" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-network", @@ -529,7 +525,7 @@ dependencies = [ [[package]] name = "alloy-signer-ledger" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-network", @@ -546,7 +542,7 @@ dependencies = [ [[package]] name = "alloy-signer-local" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-network", @@ -566,7 +562,7 @@ dependencies = [ [[package]] name = "alloy-signer-trezor" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-consensus", "alloy-network", @@ -655,7 +651,7 @@ dependencies = [ [[package]] name = "alloy-transport" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-json-rpc", "base64 0.22.1", @@ -674,7 +670,7 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -688,7 +684,7 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -706,7 +702,7 @@ dependencies = [ [[package]] name = "alloy-transport-ws" version = "0.5.4" -source = "git+https://github.com/alloy-rs/alloy#46af931db74617e118a3f7459c2e4b126548af8b" +source = "git+https://github.com/alloy-rs/alloy?rev=b2278c4#b2278c40b2693908e4e5108d65ade26e8d716765" dependencies = [ "alloy-pubsub", "alloy-transport", @@ -1339,8 +1335,8 @@ name = "cli" version = "1.0.0-alpha.0" dependencies = [ "alloy", - "contract", "eyre", + "reaconcom", "serde_json", "tokio", ] @@ -1451,7 +1447,7 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "contract" -version = "0.1.0" +version = "1.0.0-alpha.0" dependencies = [ "alloy", ] @@ -2902,6 +2898,13 @@ dependencies = [ "rand_core", ] +[[package]] +name = "reaconcom" +version = "1.0.0-alpha.0" +dependencies = [ + "contract", +] + [[package]] name = "recvmsg" version = "1.0.0" @@ -4038,9 +4041,9 @@ checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wasmtimer" -version = "0.4.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb4f099acbc1043cc752b91615b24b02d7f6fcd975bd781fed9f50b3c3e15bf7" +checksum = "c7ed9d8b15c7fb594d72bfb4b5a276f3d2029333cd93a932f376f5937f6f80ee" dependencies = [ "futures", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index 831da18..7159218 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,11 +2,11 @@ resolver = "2" members = [ "cli", - "build/bindings", ] [workspace.dependencies] -contract = { path = "build/bindings" } +reaconcom = { path = "sdk" } +contract = { path = "contract/sdk" } [profile.release] opt-level = 3 diff --git a/Makefile b/Makefile index 2ba74f4..6222f8b 100644 --- a/Makefile +++ b/Makefile @@ -4,18 +4,26 @@ default: release dependencies: forge soldeer install - -build: dependencies contract - forge build --sizes - -build/bindings: build - forge bind --single-file --crate-name contract --skip-cargo-toml --alloy - -release/reaconcom: build/bindings +build/contract/%.sol: contract/%.sol dependencies + forge build --out build/contract $< +build/script/%.sol: script/%.sol dependencies + forge build --out build/script $< + +contract/sdk: build/contract/Service.sol build/contract/ReactiveHandler.sol + forge bind --bindings-path contract/sdk \ +--select ReactiveHandler \ +--select Service \ +--crate-name contract \ +--crate-version $(shell cat version) \ +--alloy --alloy-version b2278c4 + +release/reaconcom: contract/sdk cargo build --release -p cli mrdir -p release cp target/release/reaconcom release/reaconcom release: release/reaconcom +run: + cargo run -p cli build/computing.wasm.gz: cargo run -p computing @@ -27,22 +35,22 @@ clean: forge clean rm -fr dependencies cache broadcast release -lint: build/bindings +lint: contract/sdk forge fmt --check - #FIXME cargo +nightly fmt --all --check - #FIXME cargo +nightly clippy + cargo +nightly fmt --all --check + cargo +nightly clippy -fmt: build/bindings +fmt: contract/sdk forge fmt cargo +nightly fmt --all -test-contract: build/bindings +test-contract: contract/sdk forge test test: test-contract - #FIXME cargo +nightly test + cargo +nightly test qa: lint test -deploy: build - FOUNDRY_PROFILE=local forge script script/Demo.sol:Deploy --broadcast +deploy: build/script/demo.sol + FOUNDRY_PROFILE=local forge script --quiet --broadcast script/demo.sol:deploy diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 473c4d5..ad52533 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -9,9 +9,9 @@ name = "reaconcom" path = "main.rs" [dependencies] -contract.workspace = true +reaconcom.workspace = true eyre = "0.6" -alloy = { git = "https://github.com/alloy-rs/alloy", features = [ +alloy = { git = "https://github.com/alloy-rs/alloy", rev = "b2278c4", features = [ "full", "node-bindings", "rpc-types-debug", diff --git a/cli/main.rs b/cli/main.rs index 2e84730..e5c2133 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1,36 +1,50 @@ use alloy::{ - primitives::Address, + network::EthereumWallet, + primitives::{Address, U256}, providers::{Provider, ProviderBuilder, WsConnect}, + signers::local::{coins_bip39::English, LocalSignerError, MnemonicBuilder, PrivateKeySigner}, }; -use contract::Service; -use eyre::Result; +use reaconcom::Service; -#[tokio::main] -async fn main() -> Result<()> { - // Set up the HTTP transport which is consumed by the RPC client. - // let rpc_url = "https://eth.merkle.io".parse()?; - // let rpc_url = "http://localhost:8545".parse()?; - // Create a provider with the HTTP transport using the `reqwest` crate. - // let provider = ProviderBuilder::new().on_http(rpc_url); +fn new_singer(phrase: &str) -> Result { + let index = 0u32; + let password = ""; + + // Access mnemonic phrase with password. + // Child key at derivation path: m/44'/60'/0'/0/{index}. + MnemonicBuilder::::default() + .phrase(phrase) + .index(index)? + // Use this if your mnemonic is encrypted. + .password(password) + .build() +} - // Create the provider +#[tokio::main] +async fn main() -> eyre::Result<()> { + let phrase = "test test test test test test test test test test test junk"; let rpc_url = "ws://localhost:8545"; + let wallet = EthereumWallet::from(new_singer(phrase)?); let ws = WsConnect::new(rpc_url); - let provider = ProviderBuilder::new().on_ws(ws).await?; + let provider = + ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_ws(ws).await?; // Get latest block number - let latest_block = provider.clone().get_block_number().await?; + let latest_block = provider.get_block_number().await?; // Print the block number println!("Latest block number: {latest_block}"); - let address = "0x5fbdb2315678afecb367f032d93f642f64180aa3".parse::
()?; + let address = "0x9d4454b023096f34b160d6b654540c56a1f81688".parse::
()?; // let contract = Service::new(address, provider); let tx_hash = contract.increment().send().await?.watch().await?; - println!("Incremented number: {tx_hash}"); + println!("increment tx: {tx_hash}"); let number = contract.number().call().await?._0; println!("number={number}"); - + let leader = contract.leader().call().await?._0; + println!("leader={leader}"); + let tx_hash = contract.dibs(U256::from(7)).send().await?.watch().await?; + println!("dibs tx: {tx_hash}"); Ok(()) } diff --git a/readme.md b/readme.md index 04979c0..cbe29df 100644 --- a/readme.md +++ b/readme.md @@ -3,12 +3,9 @@ **Rea**ctive **Con**fidential **Com**puting work fully on-chain and trusted execution environments (TEE) via Intel SGX ```mermaid ---- -title: Reaconcom ---- %%{ init: { 'flowchart': { 'curve': 'basis' } } }%% flowchart RL - subgraph cli["CLI"] + subgraph cli["reaconcom-cli"] setup -. call .-> computing subgraph SN["Secret Network"] subgraph CC["Confidential Computing"] @@ -46,6 +43,30 @@ flowchart RL gatewayL1 -. callback .-> appL1 ``` +```mermaid +sequenceDiagram + actor external + box L1 Network + participant ServiceContract + end + box Secret Network + participant John + end + actor setup + + rect rgb(191, 223, 255) + note right of Alice: Alice calls John. + Alice->>+John: Hello John, how are you? + rect rgb(200, 150, 255) + Alice->>+John: John, can you hear me? + John-->>-Alice: Hi Alice, I can hear you! + end + John-->>-Alice: I feel great! + end + Alice ->>+ John: Did you want to go to the game tonight? + John -->>- Alice: Yeah! See you there. +``` + ## Work in progress - [x] gateway contract via Secret Network @@ -89,4 +110,4 @@ make fmt ```shell make release -``` \ No newline at end of file +``` diff --git a/rustfmt.toml b/rustfmt.toml index 49ddcd8..8ccbebf 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -12,7 +12,7 @@ wrap_comments = true # ignore automatically generated bindings ignore = [ - "build/bindings/" + "contract/sdk/" ] # See more keys and their definitions at https://rust-lang.github.io/rustfmt diff --git a/script/Demo.sol b/script/demo.sol similarity index 78% rename from script/Demo.sol rename to script/demo.sol index 8a94b08..85bd61e 100644 --- a/script/Demo.sol +++ b/script/demo.sol @@ -6,15 +6,15 @@ import {Service, topicIncremented} from "../contract/Service.sol"; import {ReactiveHandler} from "../contract/ReactiveHandler.sol"; import {Reactive} from "../contract/Reactive.sol"; -contract Deploy is Script { - uint256 constant LOCAL_CHAIN_ID = 31337; - address constant KOPLI_CALLBACK_PROXY_ADDR = address(0x0000000000000000000000000000000000fffFfF); - uint256 currentChainId; - address deployer; - uint256 deployerPrivateKey; - Service public service; - ReactiveHandler public reactiveHandler; - Reactive public reactive; +contract deploy is Script { + uint256 private constant LOCAL_CHAIN_ID = 31337; + address private constant KOPLI_CALLBACK_PROXY_ADDR = address(0x0000000000000000000000000000000000fffFfF); + uint256 private currentChainId; + address private deployer; + uint256 private deployerPrivateKey; + Service private service; + ReactiveHandler private reactiveHandler; + Reactive private reactive; function setUp() public { currentChainId = block.chainid; diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml new file mode 100644 index 0000000..a5496bb --- /dev/null +++ b/sdk/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "reaconcom" +version = "1.0.0-alpha.0" +edition = "2021" + +[lib] +path = "lib.rs" + +[dependencies] +contract.workspace = true diff --git a/sdk/lib.rs b/sdk/lib.rs new file mode 100644 index 0000000..d829073 --- /dev/null +++ b/sdk/lib.rs @@ -0,0 +1 @@ +pub use contract::{reactivehandler::ReactiveHandler, service::Service}; diff --git a/version b/version new file mode 100644 index 0000000..d7261d8 --- /dev/null +++ b/version @@ -0,0 +1 @@ +1.0.0-alpha.0 \ No newline at end of file