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

Enable validating tests #80

Merged
merged 4 commits into from
Jun 4, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/contracts/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Level {
pub opcodes: HashMap<String, u64>,
#[serde(rename = "contractSize")]
pub contract_size: HashMap<Address, u64>,
pub oog: Option<bool>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
Expand Down
34 changes: 34 additions & 0 deletions crates/uopool/src/canonical/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub enum SimulateValidationError {
CodeHashesValidation {
message: String,
},
OutOfGas {},
UnknownError {
error: String,
},
Expand Down Expand Up @@ -140,6 +141,11 @@ impl From<SimulateValidationError> for SimulationError {
SimulateValidationError::CodeHashesValidation { message } => {
SimulationError::owned(OPCODE_VALIDATION_ERROR_CODE, message, None::<bool>)
}
SimulateValidationError::OutOfGas {} => SimulationError::owned(
OPCODE_VALIDATION_ERROR_CODE,
"UserOperation out of gas",
None::<bool>,
),
SimulateValidationError::UnknownError { error } => {
SimulationError::owned(ErrorCode::InternalError.code(), error, None::<bool>)
}
Expand Down Expand Up @@ -311,6 +317,17 @@ impl<M: Middleware + 'static> UoPool<M> {
};
}

fn check_oog(&self, trace: &JsTracerFrame) -> Result<(), SimulateValidationError> {
for (index, _) in LEVEL_TO_ENTITY.iter().enumerate() {
if let Some(level) = trace.number_levels.get(index) {
if level.oog.unwrap_or(false) {
return Err(SimulateValidationError::OutOfGas {});
}
}
}
Ok(())
}

fn forbidden_opcodes(&self, trace: &JsTracerFrame) -> Result<(), SimulateValidationError> {
for (index, _) in LEVEL_TO_ENTITY.iter().enumerate() {
if let Some(level) = trace.number_levels.get(index) {
Expand Down Expand Up @@ -533,6 +550,21 @@ impl<M: Middleware + 'static> UoPool<M> {
let mut calls: Vec<CallEntry> = vec![];
self.parse_call_stack(trace, &mut calls)?;

// check recursive call entrypoint method
let call_into_entry_point = calls.iter().find(|call| {
call.to.unwrap_or_default() == self.entry_point.address()
&& call.from.unwrap_or_default() != self.entry_point.address()
&& (call.method.is_some()
&& call.method.clone().unwrap_or_default() != *"depositTo")
});
if call_into_entry_point.is_some() {
return Err(SimulateValidationError::CallStackValidation {
message: format!(
"illegal call into EntryPoint during validation {call_into_entry_point:?}"
),
});
}

for (index, stake_info) in stake_info_by_entity.iter().enumerate() {
if LEVEL_TO_ENTITY[index] == "paymaster" {
let call = calls.iter().find(|call| {
Expand Down Expand Up @@ -682,6 +714,8 @@ impl<M: Middleware + 'static> UoPool<M> {
&mut stake_info_by_entity,
);

self.check_oog(&js_trace)?;

// may not invokes any forbidden opcodes
self.forbidden_opcodes(&js_trace)?;

Expand Down
1 change: 1 addition & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version = "1.69.0"
[dev-dependencies]
aa-bundler-contracts = { path = "../crates/contracts" }
aa-bundler-primitives = { path = "../crates/primitives" }
aa-bundler-uopool = { path = "../crates/uopool" }

anyhow = "1"
ethers = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions tests/src/common/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ abigen!(
TracerTest,
"$CARGO_WORKSPACE_DIR/thirdparty/bundler/packages/bundler/artifacts/contracts/tests/TracerTest.sol/TracerTest.json"
);
abigen!(
TestCoin,
"$CARGO_WORKSPACE_DIR/thirdparty/bundler/packages/bundler/artifacts/contracts/tests/TestCoin.sol/TestCoin.json"
);
16 changes: 13 additions & 3 deletions tests/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use ethers::{
use tempdir::TempDir;

use self::gen::{
EntryPointContract, TestOpcodesAccount, TestOpcodesAccountFactory, TestRecursionAccount,
TestRulesAccountFactory, TestStorageAccount, TestStorageAccountFactory, TracerTest,
EntryPointContract, TestCoin, TestOpcodesAccount, TestOpcodesAccountFactory,
TestRecursionAccount, TestRulesAccountFactory, TestStorageAccount, TestStorageAccountFactory,
TracerTest,
};
pub mod gen;

Expand Down Expand Up @@ -67,8 +68,9 @@ pub async fn deploy_test_opcode_account_factory<M: Middleware + 'static>(

pub async fn deploy_test_storage_account_factory<M: Middleware + 'static>(
client: Arc<M>,
test_coin_addr: Address,
) -> anyhow::Result<DeployedContract<TestStorageAccountFactory<M>>> {
let (factory, receipt) = TestStorageAccountFactory::deploy(client, ())?
let (factory, receipt) = TestStorageAccountFactory::deploy(client, test_coin_addr)?
.send_with_receipt()
.await?;
let address = receipt.contract_address.unwrap();
Expand Down Expand Up @@ -114,6 +116,14 @@ pub async fn deploy_tracer_test<M: Middleware + 'static>(
Ok(DeployedContract::new(factory, address))
}

pub async fn deploy_test_coin<M: Middleware + 'static>(
client: Arc<M>,
) -> anyhow::Result<DeployedContract<TestCoin<M>>> {
let (factory, receipt) = TestCoin::deploy(client, ())?.send_with_receipt().await?;
let address = receipt.contract_address.unwrap();
Ok(DeployedContract::new(factory, address))
}

pub async fn sign(
user_op: &mut UserOperation,
entry_point_address: &Address,
Expand Down
Loading