Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

/// @title MultichainACL smart contract
/// @dev sources:
/// - github.com/zama-ai/fhevm/blob/main/gateway-contracts/contracts/MultichainACL.sol
/// - github.com/zama-ai/fhevm/blob/main/gateway-contracts/contracts/interfaces/IMultichainACL.sol
/// @notice This contract is a mock of the MultichainACL contract from L2.
contract MultichainACL {
error CoprocessorAlreadyAllowedAccount(bytes32 ctHandle, address account, address txSender);
error CoprocessorAlreadyAllowedPublicDecrypt(bytes32 ctHandle, address txSender);

event AllowAccount(bytes32 indexed ctHandle, address accountAddress);
event AllowPublicDecrypt(bytes32 indexed ctHandle);

bool alreadyAllowedRevert;

constructor(bool _alreadyAllowedRevert) {
alreadyAllowedRevert = _alreadyAllowedRevert;
}

function allowAccount(bytes32 ctHandle, address accountAddress, bytes calldata /* extraData */) public {
if (alreadyAllowedRevert) {
revert CoprocessorAlreadyAllowedAccount(ctHandle, accountAddress, msg.sender);
}
emit AllowAccount(ctHandle, accountAddress);
}

function allowPublicDecrypt(bytes32 ctHandle, bytes calldata /* extraData */) public {
if (alreadyAllowedRevert) {
revert CoprocessorAlreadyAllowedPublicDecrypt(ctHandle, msg.sender);
}
emit AllowPublicDecrypt(ctHandle);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

/// @title MultichainAcl smart contract
/// @dev source: github.com/zama-ai/fhevm-gateway/blob/main/contracts/MultichainAcl.sol
/// @notice This contract is a mock of the MultichainAcl contract from L2.
contract MultichainAcl {
error CoprocessorAlreadyAllowedAccount(bytes32 ctHandle, address account, address coprocessor);
/// @title MultichainACL smart contract
/// @dev sources:
/// - github.com/zama-ai/fhevm/blob/main/gateway-contracts/contracts/MultichainACL.sol
/// - github.com/zama-ai/fhevm/blob/main/gateway-contracts/contracts/interfaces/IMultichainACL.sol
/// @notice This contract is a mock of the MultichainACL contract from L2.
contract MultichainACL {
error CoprocessorAlreadyAllowedAccount(bytes32 ctHandle, address account, address txSender);
error CoprocessorAlreadyAllowedPublicDecrypt(bytes32 ctHandle, address txSender);

event AllowAccount(bytes32 indexed ctHandle, address accountAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ use fhevm_engine_common::{tenant_keys::query_tenant_info, types::AllowEvents, ut
use sqlx::{Pool, Postgres};
use tokio::task::JoinSet;
use tracing::{debug, error, info, warn};
use MultichainAcl::MultichainAclErrors;
use MultichainACL::MultichainACLErrors;

sol!(
#[sol(rpc)]
MultichainAcl,
"artifacts/MultichainAcl.sol/MultichainAcl.json"
MultichainACL,
"artifacts/MultichainACL.sol/MultichainACL.json"
);

struct Key {
Expand All @@ -56,15 +56,15 @@ impl Display for Key {
}

#[derive(Clone)]
pub struct MultichainAclOperation<P: Provider<Ethereum> + Clone + 'static> {
pub struct MultichainACLOperation<P: Provider<Ethereum> + Clone + 'static> {
multichain_acl_address: Address,
provider: NonceManagedProvider<P>,
conf: crate::ConfigSettings,
gas: Option<u64>,
db_pool: Pool<Postgres>,
}

impl<P: Provider<Ethereum> + Clone + 'static> MultichainAclOperation<P> {
impl<P: Provider<Ethereum> + Clone + 'static> MultichainACLOperation<P> {
/// Sends a transaction
///
/// TODO: Refactor: Avoid code duplication
Expand Down Expand Up @@ -205,10 +205,10 @@ impl<P: Provider<Ethereum> + Clone + 'static> MultichainAclOperation<P> {

fn already_allowed_error(&self, err: &RpcError<TransportErrorKind>) -> Option<Address> {
err.as_error_resp()
.and_then(|payload| payload.as_decoded_interface_error::<MultichainAclErrors>())
.and_then(|payload| payload.as_decoded_interface_error::<MultichainACLErrors>())
.map(|error| match error {
MultichainAclErrors::CoprocessorAlreadyAllowedAccount(c) => c.coprocessor,
MultichainAclErrors::CoprocessorAlreadyAllowedPublicDecrypt(c) => c.txSender,
MultichainACLErrors::CoprocessorAlreadyAllowedAccount(c) => c.txSender, /* coprocessor address */
MultichainACLErrors::CoprocessorAlreadyAllowedPublicDecrypt(c) => c.txSender,
})
}

Expand Down Expand Up @@ -239,7 +239,7 @@ impl<P: Provider<Ethereum> + Clone + 'static> MultichainAclOperation<P> {
}
}

impl<P: Provider<Ethereum> + Clone + 'static> MultichainAclOperation<P> {
impl<P: Provider<Ethereum> + Clone + 'static> MultichainACLOperation<P> {
pub fn new(
multichain_acl_address: Address,
provider: NonceManagedProvider<P>,
Expand All @@ -250,7 +250,7 @@ impl<P: Provider<Ethereum> + Clone + 'static> MultichainAclOperation<P> {
info!(
gas = gas.unwrap_or(0),
multichain_acl_address = %multichain_acl_address,
"Creating MultichainAclOperation"
"Creating MultichainACLOperation"
);

Self {
Expand Down Expand Up @@ -349,7 +349,7 @@ impl<P: Provider<Ethereum> + Clone + 'static> MultichainAclOperation<P> {
}

#[async_trait]
impl<P> TransactionOperation<P> for MultichainAclOperation<P>
impl<P> TransactionOperation<P> for MultichainACLOperation<P>
where
P: alloy::providers::Provider<Ethereum> + Clone + 'static,
{
Expand All @@ -372,7 +372,7 @@ where
.fetch_all(&self.db_pool)
.await?;

let multichain_acl = MultichainAcl::new(self.multichain_acl_address, self.provider.inner());
let multichain_acl = MultichainACL::new(self.multichain_acl_address, self.provider.inner());

info!(rows_count = rows.len(), "Selected rows to process");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<P: Provider<Ethereum> + Clone + 'static> TransactionSender<P> {
gas,
db_pool.clone(),
)),
Arc::new(ops::allow_handle::MultichainAclOperation::new(
Arc::new(ops::allow_handle::MultichainACLOperation::new(
multichain_acl_address,
provider.clone(),
conf.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy::network::TxSigner;
use alloy::providers::ProviderBuilder;
use alloy::signers::local::PrivateKeySigner;
use alloy::{primitives::Address, providers::WsConnect};
use common::{MultichainAcl, SignerType, TestEnvironment};
use common::{MultichainACL, SignerType, TestEnvironment};

use fhevm_engine_common::types::AllowEvents;
use rand::random;
Expand Down Expand Up @@ -107,7 +107,7 @@ async fn allow_call(
.await?,
Some(env.wallet.default_signer().address()),
);
let multichain_acl = MultichainAcl::deploy(&provider_deploy, already_allowed_revert).await?;
let multichain_acl = MultichainACL::deploy(&provider_deploy, already_allowed_revert).await?;

let txn_sender = TransactionSender::new(
PrivateKeySigner::random().address(),
Expand Down Expand Up @@ -227,7 +227,7 @@ async fn stop_on_backend_gone(#[case] signer_type: SignerType) -> anyhow::Result
Some(env.wallet.default_signer().address()),
);
let already_allowed_revert = false;
let multichain_acl = MultichainAcl::deploy(&provider_deploy, already_allowed_revert).await?;
let multichain_acl = MultichainACL::deploy(&provider_deploy, already_allowed_revert).await?;

let txn_sender = TransactionSender::new(
PrivateKeySigner::random().address(),
Expand Down Expand Up @@ -326,7 +326,7 @@ async fn retry_on_aws_kms_error(#[case] signer_type: SignerType) -> anyhow::Resu
Some(env.wallet.default_signer().address()),
);
let already_allowed_revert = false;
let multichain_acl = MultichainAcl::deploy(&provider_deploy, already_allowed_revert).await?;
let multichain_acl = MultichainACL::deploy(&provider_deploy, already_allowed_revert).await?;

let txn_sender = TransactionSender::new(
PrivateKeySigner::random().address(),
Expand Down
4 changes: 2 additions & 2 deletions coprocessor/fhevm-engine/transaction-sender/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ sol!(

sol!(
#[sol(rpc)]
MultichainAcl,
"artifacts/MultichainAcl.sol/MultichainAcl.json"
MultichainACL,
"artifacts/MultichainACL.sol/MultichainACL.json"
);

pub enum SignerType {
Expand Down
Loading