Skip to content

Commit

Permalink
Reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 11, 2024
1 parent 2739dbf commit 0d8005f
Showing 1 changed file with 36 additions and 49 deletions.
85 changes: 36 additions & 49 deletions world-chain-builder/src/pool/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,44 +133,32 @@ where
}

pub fn validate_4337(&self, transaction: &Tx) -> Result<(), TransactionValidationError> {
transaction
.input()
.len()
.gt(&3)
.then(|| {
let selector: &[u8; 4] = &transaction.input()[0..4].try_into().unwrap();
match *selector {
IEntryPoint::handleAggregatedOpsCall::SELECTOR => {
let result = IEntryPoint::handleAggregatedOpsCall::abi_decode(
transaction.input(),
true,
)
if transaction.input().len() <= 3 {
Err(WorldChainTransactionPoolInvalid::Invalid4337CalldataLength)?;
}

let selector: &[u8; 4] = &transaction.input()[0..4].try_into().unwrap();
match *selector {
IEntryPoint::handleAggregatedOpsCall::SELECTOR => {
let result =
IEntryPoint::handleAggregatedOpsCall::abi_decode(transaction.input(), true)
.map_err(|_| WorldChainTransactionPoolInvalid::AbiDecodeError)?;
if result._0.len() != 1 {
return Err(
WorldChainTransactionPoolInvalid::Invalid4337UserOpsLength.into()
);
}
}
IEntryPoint::handleOpsCall::SELECTOR => {
let result =
IEntryPoint::handleOpsCall::abi_decode(transaction.input(), true)
.map_err(|_| WorldChainTransactionPoolInvalid::AbiDecodeError)?;
if result._0.len() != 1 {
return Err(
WorldChainTransactionPoolInvalid::Invalid4337UserOpsLength.into()
);
}
}
_ => {
return Err(
WorldChainTransactionPoolInvalid::Invalid4337EntryPointSelector.into(),
);
}
if result._0.len() != 1 {
return Err(WorldChainTransactionPoolInvalid::Invalid4337UserOpsLength.into());
}
}
IEntryPoint::handleOpsCall::SELECTOR => {
let result = IEntryPoint::handleOpsCall::abi_decode(transaction.input(), true)
.map_err(|_| WorldChainTransactionPoolInvalid::AbiDecodeError)?;
if result._0.len() != 1 {
return Err(WorldChainTransactionPoolInvalid::Invalid4337UserOpsLength.into());
}
Ok::<(), WorldChainTransactionPoolInvalid>(())
})
.ok_or(WorldChainTransactionPoolInvalid::Invalid4337CalldataLength)??;
}
_ => {
return Err(WorldChainTransactionPoolInvalid::Invalid4337EntryPointSelector.into());
}
}

Ok(())
}

Expand Down Expand Up @@ -290,19 +278,8 @@ where

#[cfg(test)]
pub mod tests {
use crate::pbh::payload::{PbhPayload, Proof};
use crate::pool::bindings::IEntryPoint::{
handleAggregatedOpsCall, handleOpsCall, IEntryPointCalls, PackedUserOperation,
UserOpsPerAggregator,
};
use crate::pool::ordering::WorldChainOrdering;
use crate::pool::root::{LATEST_ROOT_SLOT, OP_WORLD_ID};
use crate::pool::tx::WorldChainPooledTransaction;
use crate::test::{get_pbh_transaction, valid_pbh_payload, world_chain_validator};
use alloy_eips::eip2718::Decodable2718;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::keccak256;
use alloy_primitives::{Address, U256 as Uint};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{keccak256, Address, U256 as Uint};
use alloy_rpc_types::{TransactionInput, TransactionRequest};
use alloy_signer_local::LocalSigner;
use alloy_sol_types::SolInterface;
Expand All @@ -319,6 +296,16 @@ pub mod tests {
use semaphore::Field;
use test_case::test_case;

use crate::pbh::payload::{PbhPayload, Proof};
use crate::pool::bindings::IEntryPoint::{
handleAggregatedOpsCall, handleOpsCall, IEntryPointCalls, PackedUserOperation,
UserOpsPerAggregator,
};
use crate::pool::ordering::WorldChainOrdering;
use crate::pool::root::{LATEST_ROOT_SLOT, OP_WORLD_ID};
use crate::pool::tx::WorldChainPooledTransaction;
use crate::test::{get_pbh_transaction, valid_pbh_payload, world_chain_validator};

#[tokio::test]
async fn validate_pbh_transaction() {
let validator = world_chain_validator(Address::with_last_byte(1));
Expand Down

0 comments on commit 0d8005f

Please sign in to comment.