Skip to content

Commit 7c5dacf

Browse files
Vid201zsluedem
authored andcommitted
chore: update bundler spec tests, update debug send bundle, aa51
1 parent d03bb23 commit 7c5dacf

File tree

10 files changed

+102
-27
lines changed

10 files changed

+102
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
- uses: actions/checkout@v4
100100
with:
101101
repository: eth-infinitism/bundler-spec-tests
102-
ref: 'b9f192f39298e6586729d40f29e3098c92e5c0b9'
102+
ref: '08cbbfcb9e37b84c0ef9e546975f88fa638cac61'
103103
submodules: true
104104

105105
- uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ make lint
137137
make test
138138
```
139139

140-
Official [bundler spec tests](https://github.com/eth-infinitism/bundler-spec-tests) developed by the [eth-infinitism](https://github.com/eth-infinitism/) team are also included in the repo's CI pipeline (commit: [b9f192f39298e6586729d40f29e3098c92e5c0b9](https://github.com/eth-infinitism/bundler-spec-tests/tree/b9f192f39298e6586729d40f29e3098c92e5c0b9)). You can find more information on how to run tests [here](https://github.com/eth-infinitism/bundler-spec-tests). Make sure your contribution doesn't break the tests!
140+
Official [bundler spec tests](https://github.com/eth-infinitism/bundler-spec-tests) developed by the [eth-infinitism](https://github.com/eth-infinitism/) team are also included in the repo's CI pipeline (commit: [08cbbfcb9e37b84c0ef9e546975f88fa638cac61](https://github.com/eth-infinitism/bundler-spec-tests/tree/08cbbfcb9e37b84c0ef9e546975f88fa638cac61)). You can find more information on how to run tests [here](https://github.com/eth-infinitism/bundler-spec-tests). Make sure your contribution doesn't break the tests!
141141

142142
## Contact
143143

crates/bundler/src/bundler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ where
143143
///
144144
/// # Returns
145145
/// * `H256` - The hash
146-
pub async fn send_bundle(&self, uos: &Vec<UserOperation>) -> eyre::Result<H256> {
146+
pub async fn send_bundle(&self, uos: &Vec<UserOperation>) -> eyre::Result<Option<H256>> {
147147
if uos.is_empty() {
148148
info!("Skipping creating a new bundle, no user operations");
149-
return Ok(H256::default());
149+
return Ok(None);
150150
};
151151

152152
info!(
@@ -167,6 +167,6 @@ where
167167
self.beneficiary
168168
);
169169

170-
Ok(hash)
170+
Ok(Some(hash))
171171
}
172172
}

crates/grpc/src/bundler.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ where
5454
Ok(uos)
5555
}
5656

57-
pub async fn send_bundles(&self) -> eyre::Result<H256> {
58-
let mut tx_hashes: Vec<H256> = vec![];
57+
pub async fn send_bundles(&self) -> eyre::Result<Option<H256>> {
58+
let mut tx_hashes: Vec<Option<H256>> = vec![];
5959

6060
for bundler in self.bundlers.iter() {
6161
let uos =
@@ -67,7 +67,7 @@ where
6767

6868
// FIXME: Because currently the bundler support multiple bundler and
6969
// we don't have a way to know which bundler is the one that is
70-
Ok(tx_hashes.into_iter().next().expect("Must have at least one tx hash"))
70+
Ok(tx_hashes.into_iter().next().expect("At least one bundler must be present"))
7171
}
7272

7373
pub fn stop_bundling(&self) {
@@ -158,7 +158,27 @@ where
158158
.send_bundles()
159159
.await
160160
.map_err(|e| tonic::Status::internal(format!("Send bundle now with error: {e:?}")))?;
161-
Ok(Response::new(SendBundleNowResponse { res: Some(res.into()) }))
161+
162+
if let Some(tx_hash) = res {
163+
// wait for the tx to be mined
164+
loop {
165+
let tx_receipt = self
166+
.bundlers
167+
.first()
168+
.expect("Must have at least one bundler")
169+
.eth_client
170+
.get_transaction_receipt(tx_hash)
171+
.await;
172+
if let Ok(tx_receipt) = tx_receipt {
173+
if tx_receipt.is_some() {
174+
break;
175+
}
176+
}
177+
tokio::time::sleep(Duration::from_millis(50)).await;
178+
}
179+
}
180+
181+
Ok(Response::new(SendBundleNowResponse { res: Some(res.unwrap_or_default().into()) }))
162182
}
163183
}
164184

crates/mempool/src/validate/mod.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ macro_rules! sanity_check_impls {
119119
( $( $name:ident )+ ) => {
120120
#[allow(non_snake_case)]
121121
#[async_trait::async_trait]
122-
impl<M: Middleware, $($name : SanityCheck<M>,)+ > SanityCheck<M> for ($($name,)+)
122+
impl<M: Middleware, $($name : SanityCheck<M>,)+> SanityCheck<M> for ($($name,)+)
123123
{
124124
async fn check_user_operation<T, Y, X, Z, H, R>(
125125
&self,
@@ -143,6 +143,7 @@ macro_rules! sanity_check_impls {
143143
}
144144
};
145145
}
146+
146147
#[async_trait::async_trait]
147148
impl<M: Middleware> SanityCheck<M> for () {
148149
async fn check_user_operation<T, Y, X, Z, H, R>(
@@ -164,7 +165,7 @@ impl<M: Middleware> SanityCheck<M> for () {
164165
}
165166
}
166167

167-
// These macro enable people to chain sanity check implementations.:
168+
// These macro enable people to chain sanity check implementations:
168169
// `(SanityCheck1, SanityCheck2, SanityCheck3, ...).check_user_operation(uo, mempool, reputation,
169170
// helper)`` SanityCheck1,2,3 could be any data type which implement SanityCheck trait.
170171
sanity_check_impls! { A }
@@ -203,11 +204,12 @@ pub trait SimulationCheck: Send + Sync {
203204
helper: &mut SimulationHelper,
204205
) -> Result<(), SimulationError>;
205206
}
207+
206208
macro_rules! simulation_check_impls {
207209
( $( $name:ident )+ ) => {
208210
#[allow(non_snake_case)]
209211
#[async_trait::async_trait]
210-
impl<$($name : SimulationCheck,)+ > SimulationCheck for ($($name,)+)
212+
impl<$($name : SimulationCheck,)+> SimulationCheck for ($($name,)+)
211213
{
212214
fn check_user_operation(
213215
&self,
@@ -223,15 +225,19 @@ macro_rules! simulation_check_impls {
223225
};
224226
}
225227

226-
// These macro enable people to chain simulation check implementations.:
228+
// These macro enable people to chain simulation check implementations:
227229
// `(SimulationCheck1, SimulationCheck2, SimulationCheck3, ...).check_user_operation(uo, helper)``
228-
// SimulationChekc1,2,3 could be any data type which implement SimulationCheck trait.
229-
simulation_check_impls! {A}
230-
simulation_check_impls! {A B}
231-
simulation_check_impls! {A B C}
232-
simulation_check_impls! {A B C D}
233-
simulation_check_impls! {A B C D E}
234-
simulation_check_impls! {A B C D E F}
230+
// SimulationCheck1,2,3 could be any data type which implement SimulationCheck trait.
231+
simulation_check_impls! { A }
232+
simulation_check_impls! { A B }
233+
simulation_check_impls! { A B C }
234+
simulation_check_impls! { A B C D }
235+
simulation_check_impls! { A B C D F }
236+
simulation_check_impls! { A B C D F G }
237+
simulation_check_impls! { A B C D F G I }
238+
simulation_check_impls! { A B C D F G I J }
239+
simulation_check_impls! { A B C D F G I J K }
240+
simulation_check_impls! { A B C D F G I J K L }
235241

236242
/// The [UserOperation](UserOperation) simulation trace check helper trait.
237243
pub struct SimulationTraceHelper<'a, M: Middleware + Send + Sync + 'static> {
@@ -283,6 +289,7 @@ pub trait SimulationTraceCheck<M: Middleware>: Send + Sync {
283289
H: HashSetOp,
284290
R: ReputationEntryOp;
285291
}
292+
286293
macro_rules! simulation_trace_check_impls {
287294
( $( $name:ident )+ ) => {
288295
#[allow(non_snake_case)]
@@ -311,6 +318,7 @@ macro_rules! simulation_trace_check_impls {
311318
}
312319
};
313320
}
321+
314322
#[async_trait::async_trait]
315323
impl<M: Middleware> SimulationTraceCheck<M> for () {
316324
async fn check_user_operation<T, Y, X, Z, H, R>(
@@ -332,7 +340,7 @@ impl<M: Middleware> SimulationTraceCheck<M> for () {
332340
}
333341
}
334342

335-
// These macro enable people to chain simulation check implementations.:
343+
// These macro enable people to chain simulation check implementations:
336344
// `(SimulationTraceCheck1, SimulationTraceCheck2, SimulationTraceCheck3,
337345
// ...).check_user_operation(uo, mempool, reputeation helper)`` SimulationTraceCheck1,2,3 could be
338346
// any data type which implement SimulationTraceCheck trait.

crates/mempool/src/validate/simulation/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
//! timestamp via a `eth_call` to the Ethereum execution client.
33
pub mod signature;
44
pub mod timestamp;
5+
pub mod verification_extra_gas;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::{
2+
validate::{SimulationCheck, SimulationHelper},
3+
SimulationError,
4+
};
5+
use silius_contracts::entry_point::SimulateValidationResult;
6+
use silius_primitives::{constants::validation::simulation::MIN_EXTRA_GAS, UserOperation};
7+
8+
#[derive(Clone)]
9+
pub struct VerificationExtraGas;
10+
11+
impl SimulationCheck for VerificationExtraGas {
12+
/// The [check_user_operation] method implementation validates the needed extra gas.
13+
///
14+
/// # Arguments
15+
/// `uo` - Not used in this check
16+
/// `helper` - The [SimulationHelper](crate::validate::SimulationHelper)
17+
///
18+
/// # Returns
19+
/// None if the check passes, otherwise a [SimulationError] error.
20+
fn check_user_operation(
21+
&self,
22+
uo: &UserOperation,
23+
helper: &mut SimulationHelper,
24+
) -> Result<(), SimulationError> {
25+
let pre_op_gas = match helper.simulate_validation_result {
26+
SimulateValidationResult::ValidationResult(res) => res.return_info.0,
27+
SimulateValidationResult::ValidationResultWithAggregation(res) => res.return_info.0,
28+
};
29+
30+
let extra_gas = uo.verification_gas_limit - (pre_op_gas - uo.pre_verification_gas);
31+
32+
if extra_gas.as_u64() < MIN_EXTRA_GAS {
33+
return Err(SimulationError::Validation {
34+
inner: "Verification gas should have extra 2000 gas (has ${extra_gas})".into(),
35+
});
36+
}
37+
38+
Ok(())
39+
}
40+
}

crates/mempool/src/validate/validator.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use super::{
33
call_gas::CallGas, entities::Entities, max_fee::MaxFee, paymaster::Paymaster,
44
sender::Sender, unstaked_entities::UnstakedEntities, verification_gas::VerificationGas,
55
},
6-
simulation::{signature::Signature, timestamp::Timestamp},
6+
simulation::{
7+
signature::Signature, timestamp::Timestamp, verification_extra_gas::VerificationExtraGas,
8+
},
79
simulation_trace::{
810
call_stack::CallStack, code_hashes::CodeHashes, external_contracts::ExternalContracts,
911
gas::Gas, opcodes::Opcodes, storage_access::StorageAccess,
@@ -35,14 +37,14 @@ use tracing::debug;
3537
pub type StandardValidator<M> = StandardUserOperationValidator<
3638
M,
3739
(Sender, VerificationGas, CallGas, MaxFee, Paymaster, Entities, UnstakedEntities),
38-
(Signature, Timestamp),
40+
(Signature, Timestamp, VerificationExtraGas),
3941
(Gas, Opcodes, ExternalContracts, StorageAccess, CallStack, CodeHashes),
4042
>;
4143

4244
type UnsafeValidator<M> = StandardUserOperationValidator<
4345
M,
4446
(Sender, VerificationGas, CallGas, MaxFee, Paymaster, Entities, UnstakedEntities),
45-
(Signature, Timestamp),
47+
(Signature, Timestamp, VerificationExtraGas),
4648
(),
4749
>;
4850

@@ -115,7 +117,7 @@ pub fn new_canonical<M: Middleware + 'static>(
115117
Entities,
116118
UnstakedEntities,
117119
),
118-
(Signature, Timestamp),
120+
(Signature, Timestamp, VerificationExtraGas),
119121
(Gas, Opcodes, ExternalContracts, StorageAccess, CallStack, CodeHashes),
120122
)
121123
}
@@ -138,7 +140,7 @@ pub fn new_canonical_unsafe<M: Middleware + Clone + 'static>(
138140
Entities,
139141
UnstakedEntities,
140142
),
141-
(Signature, Timestamp),
143+
(Signature, Timestamp, VerificationExtraGas),
142144
(),
143145
)
144146
}

crates/primitives/src/constants.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ pub mod validation {
5656
pub const THROTTLING_SLACK: u64 = 10;
5757
pub const BAN_SLACK: u64 = 50;
5858
}
59+
60+
/// Simulation
61+
pub mod simulation {
62+
pub const MIN_EXTRA_GAS: u64 = 2000;
63+
}
5964
}
6065

6166
/// Flashbots relay endpoints

crates/rpc/src/debug.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ impl DebugApiServer for DebugApiServerImpl {
230230
/// This is useful for testing or in situations where waiting for the next scheduled bundle is
231231
/// not desirable.
232232
///
233-
///
234233
/// # Returns
235234
/// * `RpcResult<H256>` - The hash of the bundle that was sent.
236235
async fn send_bundle_now(&self) -> RpcResult<H256> {

0 commit comments

Comments
 (0)