diff --git a/Cargo.lock b/Cargo.lock index 0114213..37270d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,32 +62,6 @@ dependencies = [ "libc", ] -[[package]] -name = "appchain-core-contract-client" -version = "0.1.0" -dependencies = [ - "appchain-utils", - "async-trait", - "color-eyre", - "dirs", - "hex", - "log", - "num-traits", - "serde_json", - "starknet", - "starknet-accounts 0.6.1", - "starknet-contract 0.6.0", - "starknet-core 0.7.2", - "starknet-crypto 0.6.1", - "starknet-ff 0.3.5", - "starknet-instance", - "starknet-providers 0.7.0", - "starknet-signers 0.5.0", - "thiserror", - "tokio", - "url", -] - [[package]] name = "appchain-utils" version = "0.1.0" @@ -566,6 +540,32 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "core-contract-client" +version = "0.1.0" +dependencies = [ + "appchain-utils", + "async-trait", + "color-eyre", + "dirs", + "hex", + "log", + "num-traits", + "serde_json", + "starknet", + "starknet-accounts 0.6.1", + "starknet-contract 0.6.0", + "starknet-core 0.7.2", + "starknet-crypto 0.6.1", + "starknet-ff 0.3.5", + "starknet-instance", + "starknet-providers 0.7.0", + "starknet-signers 0.5.0", + "thiserror", + "tokio", + "url", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -4050,6 +4050,28 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "verifier-contract-client" +version = "0.1.0" +dependencies = [ + "appchain-utils", + "async-trait", + "color-eyre", + "dirs", + "hex", + "log", + "num-traits", + "serde_json", + "starknet", + "starknet-accounts 0.6.1", + "starknet-core 0.7.2", + "starknet-ff 0.3.5", + "starknet-providers 0.7.0", + "thiserror", + "tokio", + "url", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 49eb0f5..0f559dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ resolver = "2" members = [ "crates/l2/starknet-core-contract-client", - "crates/l2/ethereum-instance", "crates/l2/starknet-eth-bridge-client", "crates/l2/starknet-token-bridge-client", "crates/l2/starkgate-manager-client", "crates/l2/utils", "crates/l2/starknet-erc20-client", "crates/l2/starkgate-registry-client", "crates/l2/starknet-proxy-client", "crates/l3/appchain-core-contract-client", "crates/l3/starknet-instance", "crates/l3/appchain-utils" -] + "crates/l2/ethereum-instance", "crates/l2/starknet-eth-bridge-client", "crates/l2/starknet-token-bridge-client", "crates/l2/starkgate-manager-client", "crates/l2/utils", "crates/l2/starknet-erc20-client", "crates/l2/starkgate-registry-client", "crates/l2/starknet-proxy-client", "crates/l3/core-contract-client", "crates/l3/starknet-instance", "crates/l3/appchain-utils" +, "crates/l3/verifier-contract-client"] [workspace.package] authors = ["Starkware Exploration Team", "OnlyDust Contributors"] diff --git a/Makefile b/Makefile index dc96074..18bcd89 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,4 @@ artifacts: forge build cp out/UnsafeProxy.sol/UnsafeProxy.json crates/starknet-proxy-client/src/artifacts/ cp out/StarknetSovereign.sol/Starknet.json crates/starknet-core-contract-client/src/artifacts/ - (cd lib/piltover && scarb build && cp target/dev/* ../../crates/l3/appchain-core-contract-client/artifacts) \ No newline at end of file + (cd lib/piltover && scarb build && cp target/dev/* ../../crates/l3/core-contract-client/artifacts) \ No newline at end of file diff --git a/crates/l3/appchain-core-contract-client/Cargo.toml b/crates/l3/core-contract-client/Cargo.toml similarity index 95% rename from crates/l3/appchain-core-contract-client/Cargo.toml rename to crates/l3/core-contract-client/Cargo.toml index c5cade9..0630ad5 100644 --- a/crates/l3/appchain-core-contract-client/Cargo.toml +++ b/crates/l3/core-contract-client/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "appchain-core-contract-client" +name = "core-contract-client" edition.workspace = true version.workspace = true authors.workspace = true diff --git a/crates/l3/appchain-core-contract-client/src/clients/mod.rs b/crates/l3/core-contract-client/src/clients/mod.rs similarity index 99% rename from crates/l3/appchain-core-contract-client/src/clients/mod.rs rename to crates/l3/core-contract-client/src/clients/mod.rs index b69cfb6..fb8d51a 100644 --- a/crates/l3/appchain-core-contract-client/src/clients/mod.rs +++ b/crates/l3/core-contract-client/src/clients/mod.rs @@ -1,9 +1,8 @@ use crate::interfaces::core_contract::CoreContract; use crate::interfaces::messaging::Messaging; use crate::interfaces::operator::Operator; -use starknet_ff::FieldElement; - use appchain_utils::LocalWalletSignerMiddleware; +use starknet_ff::FieldElement; pub struct StarknetCoreContractClient<'a> { operator: Operator<'a>, diff --git a/crates/l3/appchain-core-contract-client/src/interfaces/core_contract.rs b/crates/l3/core-contract-client/src/interfaces/core_contract.rs similarity index 100% rename from crates/l3/appchain-core-contract-client/src/interfaces/core_contract.rs rename to crates/l3/core-contract-client/src/interfaces/core_contract.rs diff --git a/crates/l3/appchain-core-contract-client/src/interfaces/messaging.rs b/crates/l3/core-contract-client/src/interfaces/messaging.rs similarity index 100% rename from crates/l3/appchain-core-contract-client/src/interfaces/messaging.rs rename to crates/l3/core-contract-client/src/interfaces/messaging.rs diff --git a/crates/l3/appchain-core-contract-client/src/interfaces/mod.rs b/crates/l3/core-contract-client/src/interfaces/mod.rs similarity index 70% rename from crates/l3/appchain-core-contract-client/src/interfaces/mod.rs rename to crates/l3/core-contract-client/src/interfaces/mod.rs index 828004c..3bae6a7 100644 --- a/crates/l3/appchain-core-contract-client/src/interfaces/mod.rs +++ b/crates/l3/core-contract-client/src/interfaces/mod.rs @@ -1,3 +1,3 @@ pub mod core_contract; pub mod messaging; -pub mod operator; +pub mod operator; \ No newline at end of file diff --git a/crates/l3/appchain-core-contract-client/src/interfaces/operator.rs b/crates/l3/core-contract-client/src/interfaces/operator.rs similarity index 100% rename from crates/l3/appchain-core-contract-client/src/interfaces/operator.rs rename to crates/l3/core-contract-client/src/interfaces/operator.rs diff --git a/crates/l3/appchain-core-contract-client/src/lib.rs b/crates/l3/core-contract-client/src/lib.rs similarity index 100% rename from crates/l3/appchain-core-contract-client/src/lib.rs rename to crates/l3/core-contract-client/src/lib.rs diff --git a/crates/l3/verifier-contract-client/Cargo.toml b/crates/l3/verifier-contract-client/Cargo.toml new file mode 100644 index 0000000..a38e97e --- /dev/null +++ b/crates/l3/verifier-contract-client/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "verifier-contract-client" +authors.workspace = true +edition.workspace = true +repository.workspace = true +version.workspace = true + +[dependencies] +starknet = { workspace = true } +dirs = { workspace = true } +serde_json = { workspace = true } +thiserror = { workspace = true } +hex = { workspace = true } +appchain-utils = { path = "../appchain-utils" } +tokio = { workspace = true } +log = { workspace = true } +num-traits = { workspace = true } +async-trait = { workspace = true } +starknet-accounts = { workspace = true } +starknet-core = { workspace = true } +starknet-ff = { workspace = true } +starknet-providers = { workspace = true } +url = { workspace = true } +color-eyre = { workspace = true } \ No newline at end of file diff --git a/crates/l3/verifier-contract-client/src/clients/mod.rs b/crates/l3/verifier-contract-client/src/clients/mod.rs new file mode 100644 index 0000000..66183d2 --- /dev/null +++ b/crates/l3/verifier-contract-client/src/clients/mod.rs @@ -0,0 +1,21 @@ +use crate::interfaces::verifier_contract::VerifierContract; +use appchain_utils::LocalWalletSignerMiddleware; +use starknet_ff::FieldElement; + +pub struct StarknetVerifierContractClient<'a> { + verifier_contract: VerifierContract<'a>, +} + +impl<'a> StarknetVerifierContractClient<'a> { + pub fn new(address: FieldElement, signer: &'a LocalWalletSignerMiddleware) -> Self { + Self { + verifier_contract: VerifierContract::new(address, signer), + } + } +} + +impl<'a> AsRef> for StarknetVerifierContractClient<'a> { + fn as_ref(&self) -> &VerifierContract<'a> { + &self.verifier_contract + } +} diff --git a/crates/l3/verifier-contract-client/src/interfaces/mod.rs b/crates/l3/verifier-contract-client/src/interfaces/mod.rs new file mode 100644 index 0000000..750b46e --- /dev/null +++ b/crates/l3/verifier-contract-client/src/interfaces/mod.rs @@ -0,0 +1 @@ +pub mod verifier_contract; diff --git a/crates/l3/verifier-contract-client/src/interfaces/verifier_contract.rs b/crates/l3/verifier-contract-client/src/interfaces/verifier_contract.rs new file mode 100644 index 0000000..70c8ac4 --- /dev/null +++ b/crates/l3/verifier-contract-client/src/interfaces/verifier_contract.rs @@ -0,0 +1,61 @@ +use appchain_utils::LocalWalletSignerMiddleware; +use appchain_utils::{call_contract, invoke_contract}; +use color_eyre::eyre::eyre; +use color_eyre::Result; +use starknet_accounts::ConnectedAccount; +use starknet_core::types::{FieldElement, InvokeTransactionResult}; +use starknet_providers::jsonrpc::HttpTransport; +use starknet_providers::JsonRpcClient; + +pub struct VerifierContract<'a> { + signer: &'a LocalWalletSignerMiddleware, + address: FieldElement, +} + +impl<'a> VerifierContract<'a> { + pub fn new(address: FieldElement, signer: &'a LocalWalletSignerMiddleware) -> Self { + Self { signer, address } + } + + fn provider(&self) -> &JsonRpcClient { + self.signer.provider() + } + pub async fn verify_and_register_fact( + &self, + serialized_proof: Vec, + ) -> Result { + invoke_contract( + self.signer, + self.address, + "verify_and_register_fact", + serialized_proof, + ) + .await + } + + pub async fn verify_and_register_fact_from_contract( + &self, + contract_address: FieldElement, + ) -> Result { + let mut calldata = Vec::new(); + calldata.push(contract_address); + + invoke_contract( + self.signer, + self.address, + "verify_and_register_fact_from_contract", + vec![contract_address], + ) + .await + } + + pub async fn is_valid(&self, fact: FieldElement) -> Result { + let provider = self.provider(); + let values = call_contract(provider, self.address, "is_valid", vec![fact]).await?; + + values + .first() + .map(|value| *value != FieldElement::ZERO) + .ok_or_else(|| eyre!("Contract error: expected at least one return value")) + } +} diff --git a/crates/l3/verifier-contract-client/src/lib.rs b/crates/l3/verifier-contract-client/src/lib.rs new file mode 100644 index 0000000..d9945cf --- /dev/null +++ b/crates/l3/verifier-contract-client/src/lib.rs @@ -0,0 +1,20 @@ +pub mod clients; +pub mod interfaces; + +use appchain_utils::deploy_contract; +use appchain_utils::{LocalWalletSignerMiddleware, NO_CONSTRUCTOR_ARG}; +use clients::StarknetVerifierContractClient; +use color_eyre::Result; +use std::path::Path; + + +pub async fn deploy_starknet_verifier_contract<'a>( + signer: &'a LocalWalletSignerMiddleware, + path_to_sierra: &Path, + path_to_casm: &Path, +) -> Result> { + let contract_address = + deploy_contract(signer, path_to_sierra, path_to_casm, NO_CONSTRUCTOR_ARG).await?; + + Ok(StarknetVerifierContractClient::new(contract_address, signer)) +}