Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added verifier contract l3 interface #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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/appchain-client", "crates/l3/starknet-instance", "crates/l3/appchain-utils"
]

[workspace.package]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
(cd lib/piltover && scarb build && cp target/dev/* ../../crates/l3/appchain-client/artifacts)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "appchain-core-contract-client"
name = "appchain-client"
edition.workspace = true
version.workspace = true
authors.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::interfaces::core_contract::CoreContract;
use crate::interfaces::messaging::Messaging;
use crate::interfaces::operator::Operator;
use starknet_ff::FieldElement;

use crate::interfaces::verifier_contract::VerifierContract;
use appchain_utils::LocalWalletSignerMiddleware;
use starknet_ff::FieldElement;

pub struct StarknetCoreContractClient<'a> {
operator: Operator<'a>,
messaging: Messaging<'a>,
core_contract: CoreContract<'a>,
verifier_contract: VerifierContract<'a>,
}

impl<'a> StarknetCoreContractClient<'a> {
Expand All @@ -17,6 +18,7 @@ impl<'a> StarknetCoreContractClient<'a> {
operator: Operator::new(address, signer),
messaging: Messaging::new(address, signer),
core_contract: CoreContract::new(address, signer),
verifier_contract: VerifierContract::new(address, signer),
aniketpr01 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand All @@ -38,3 +40,9 @@ impl<'a> AsRef<CoreContract<'a>> for StarknetCoreContractClient<'a> {
&self.core_contract
}
}

impl<'a> AsRef<VerifierContract<'a>> for StarknetCoreContractClient<'a> {
fn as_ref(&self) -> &VerifierContract<'a> {
&self.verifier_contract
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod core_contract;
pub mod messaging;
pub mod operator;
pub mod verifier_contract;
61 changes: 61 additions & 0 deletions crates/l3/appchain-client/src/interfaces/verifier_contract.rs
Original file line number Diff line number Diff line change
@@ -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<HttpTransport> {
self.signer.provider()
}
pub async fn verify_and_register_fact(
&self,
serialized_proof: Vec<FieldElement>,
) -> Result<InvokeTransactionResult> {
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<InvokeTransactionResult> {
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<bool> {
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"))
}
}