-
Notifications
You must be signed in to change notification settings - Fork 22
refactor: make inputs public in CRISP circuit #995
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [package] | ||
| name = "evm-helpers" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| description = "CRISP EVM Contract Helpers" | ||
|
|
||
| [dependencies] | ||
| alloy.workspace = true | ||
| eyre.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| tokio.workspace = true | ||
| alloy = { workspace = true, features = ["node-bindings"] } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| // | ||
| // This file is provided WITHOUT ANY WARRANTY; | ||
| // without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. | ||
|
|
||
| use alloy::{ | ||
| network::{Ethereum, EthereumWallet}, | ||
| primitives::{Address, U256}, | ||
| providers::{ | ||
| fillers::{ | ||
| BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, | ||
| WalletFiller, | ||
| }, | ||
| Identity, ProviderBuilder, RootProvider, | ||
| }, | ||
| rpc::types::TransactionReceipt, | ||
| signers::local::PrivateKeySigner, | ||
| sol, | ||
| }; | ||
| use eyre::Result; | ||
| use std::sync::Arc; | ||
|
|
||
| sol! { | ||
| #[derive(Debug)] | ||
| #[sol(rpc)] | ||
| contract CRISPProgram { | ||
| function setRoundData(uint256 _root, address _token, uint256 _balanceThreshold) external; | ||
| } | ||
| } | ||
|
|
||
| /// Type alias for write provider (same as EnclaveWriteProvider) | ||
| pub type CRISPWriteProvider = FillProvider< | ||
| JoinFill< | ||
| JoinFill< | ||
| Identity, | ||
| JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>, | ||
| >, | ||
| WalletFiller<EthereumWallet>, | ||
| >, | ||
| RootProvider<Ethereum>, | ||
| Ethereum, | ||
| >; | ||
|
|
||
| /// CRISP contract instance for interacting with CRISPProgram | ||
| #[derive(Clone)] | ||
| pub struct CRISPContract { | ||
| provider: Arc<CRISPWriteProvider>, | ||
| contract_address: Address, | ||
| } | ||
|
|
||
| impl CRISPContract { | ||
| /// Get the contract address | ||
| pub fn address(&self) -> &Address { | ||
| &self.contract_address | ||
| } | ||
|
|
||
| /// Create a new CRISP contract instance | ||
| pub async fn new( | ||
| http_rpc_url: &str, | ||
| private_key: &str, | ||
| contract_address: &str, | ||
| ) -> Result<CRISPContract> { | ||
| let contract_address = contract_address.parse()?; | ||
| let signer: PrivateKeySigner = private_key.parse()?; | ||
| let wallet = EthereumWallet::from(signer); | ||
| let provider = ProviderBuilder::new() | ||
| .wallet(wallet) | ||
| .connect(http_rpc_url) | ||
| .await?; | ||
|
|
||
| Ok(CRISPContract { | ||
| provider: Arc::new(provider), | ||
| contract_address, | ||
| }) | ||
| } | ||
|
|
||
| /// Set round data on the CRISPProgram contract | ||
| pub async fn set_round_data( | ||
| &self, | ||
| merkle_root: U256, | ||
| token_address: Address, | ||
| balance_threshold: U256, | ||
| ) -> Result<TransactionReceipt> { | ||
| let contract = CRISPProgram::new(self.contract_address, self.provider.as_ref()); | ||
| let receipt = contract | ||
| .setRoundData(merkle_root, token_address, balance_threshold) | ||
| .send() | ||
| .await? | ||
| .get_receipt() | ||
| .await?; | ||
|
|
||
| Ok(receipt) | ||
| } | ||
| } | ||
|
|
||
| /// Factory for creating CRISP contract instances | ||
| pub struct CRISPContractFactory; | ||
|
|
||
| impl CRISPContractFactory { | ||
| /// Create a write-capable contract | ||
| pub async fn create_write( | ||
| http_rpc_url: &str, | ||
| contract_address: &str, | ||
| private_key: &str, | ||
| ) -> Result<CRISPContract> { | ||
| CRISPContract::new(http_rpc_url, private_key, contract_address).await | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| // | ||
| // This file is provided WITHOUT ANY WARRANTY; | ||
| // without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. | ||
|
|
||
| use alloy::node_bindings::{Anvil, AnvilInstance}; | ||
| use alloy::providers::{Provider, ProviderBuilder, WsConnect}; | ||
| use alloy::signers::local::PrivateKeySigner; | ||
| use evm_helpers::CRISPContractFactory; | ||
| use eyre::Result; | ||
|
|
||
| async fn setup_provider() -> Result<(impl Provider, String, AnvilInstance)> { | ||
| let anvil = Anvil::new().block_time_f64(0.01).try_spawn()?; | ||
| let provider = ProviderBuilder::new() | ||
| .wallet(PrivateKeySigner::from_slice(&anvil.keys()[0].to_bytes())?) | ||
| .connect_ws(WsConnect::new(anvil.ws_endpoint())) | ||
| .await?; | ||
| let endpoint = anvil.ws_endpoint().to_string(); | ||
| Ok((provider, endpoint, anvil)) | ||
| } | ||
|
cedoor marked this conversation as resolved.
|
||
|
|
||
| #[tokio::test] | ||
| async fn test_factory_creates_contract() -> Result<()> { | ||
| let (_, endpoint, _anvil) = setup_provider().await?; | ||
| let private_key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; // Anvil default | ||
| let contract_address = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; // Dummy address | ||
|
|
||
| let contract = | ||
| CRISPContractFactory::create_write(&endpoint, contract_address, private_key).await?; | ||
|
|
||
| // Verify the contract was created successfully | ||
| assert_eq!( | ||
| contract.address().to_string().to_lowercase(), | ||
| contract_address.to_lowercase() | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_factory_invalid_address() { | ||
| let (_, endpoint, _anvil) = setup_provider().await.unwrap(); | ||
| let private_key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; | ||
| let invalid_address = "not-an-address"; | ||
|
|
||
| let result = CRISPContractFactory::create_write(&endpoint, invalid_address, private_key).await; | ||
| assert!(result.is_err()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_factory_invalid_private_key() { | ||
| let (_, endpoint, _anvil) = setup_provider().await.unwrap(); | ||
| let invalid_key = "not-a-key"; | ||
| let contract_address = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; | ||
|
|
||
| let result = CRISPContractFactory::create_write(&endpoint, contract_address, invalid_key).await; | ||
| assert!(result.is_err()); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.