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

Various fixes #135

Merged
merged 5 commits into from
May 26, 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
7 changes: 3 additions & 4 deletions .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
pull_request:
types:
- closed
push:
branches:
- main

name: Create and publish a Docker image

Expand All @@ -12,7 +12,6 @@ env:
jobs:
build-and-push-image:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
contents: read
packages: write
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <h1 align="center"> AA - Bundler </h1>

<p align="center">Rust implementation for Bundler - ERC-4337 (Account Abstraction).</p>
<p align="center">Rust Bundler - <a href="https://eips.ethereum.org/EIPS/eip-4337">ERC-4337 (Account Abstraction)</a>.</p>

<p align="center">
<img src="./docs/images/logo.jpeg" width="300" height="300">
Expand All @@ -10,6 +10,8 @@

For more information: https://hackmd.io/@Vid201/aa-bundler-rust

<i>This project is still under active development.</i>

## Prerequisites

Rust version: 1.69.0
Expand Down Expand Up @@ -52,6 +54,14 @@ Run only JSON-RPC API:
cargo run --release --bin bundler-rpc
```

## Supported networks

Bundler was tested on the following networks:

| Chain | Mainnet | Testnet |
| :--------: | :-------: | :-------: |
| Ethereum | :soon: | :soon: (Goerli), :heavy_check_mark: (Sepolia) |

## Contributing

Thank you for showing interest in contributing to the project!
Expand All @@ -70,6 +80,8 @@ make lint
make test
```

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. 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!

## Contact

The best place for the discussion is the dedicated [Telegram group](https://t.me/+sKeRcN4j3MM3NmNk).
Expand All @@ -79,4 +91,11 @@ The best place for the discussion is the dedicated [Telegram group](https://t.me
This project is dual-licensed under Apache 2.0 and MIT terms:

- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
- MIT License ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

## Acknowledgements

- [Bundler - eth-infinitism](https://github.com/eth-infinitism/bundler)
- [Akula](https://github.com/akula-bft/akula)
- [ethers-rs](https://github.com/gakonst/ethers-rs)
- [Reth](https://github.com/paradigmxyz/reth)
51 changes: 41 additions & 10 deletions crates/grpc/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ pub mod types {
nonce: Some(user_operation.nonce.into()),
init_code: prost::bytes::Bytes::copy_from_slice(user_operation.init_code.as_ref()),
call_data: prost::bytes::Bytes::copy_from_slice(user_operation.call_data.as_ref()),
call_gas_limit: user_operation.call_gas_limit.as_u64(),
verification_gas_limit: user_operation.verification_gas_limit.as_u64(),
pre_verification_gas: user_operation.pre_verification_gas.as_u64(),
max_fee_per_gas: user_operation.max_fee_per_gas.as_u64(),
max_priority_fee_per_gas: user_operation.max_priority_fee_per_gas.as_u64(),
call_gas_limit: Some(user_operation.call_gas_limit.into()),
verification_gas_limit: Some(user_operation.verification_gas_limit.into()),
pre_verification_gas: Some(user_operation.pre_verification_gas.into()),
max_fee_per_gas: Some(user_operation.max_fee_per_gas.into()),
max_priority_fee_per_gas: Some(user_operation.max_priority_fee_per_gas.into()),
paymaster_and_data: prost::bytes::Bytes::copy_from_slice(
user_operation.paymaster_and_data.as_ref(),
),
Expand Down Expand Up @@ -135,11 +135,42 @@ pub mod types {
},
init_code: Bytes::from(user_operation.init_code),
call_data: Bytes::from(user_operation.call_data),
call_gas_limit: U256::from(user_operation.call_gas_limit),
verification_gas_limit: U256::from(user_operation.verification_gas_limit),
pre_verification_gas: U256::from(user_operation.pre_verification_gas),
max_fee_per_gas: U256::from(user_operation.max_fee_per_gas),
max_priority_fee_per_gas: U256::from(user_operation.max_priority_fee_per_gas),
call_gas_limit: {
if let Some(call_gas_limit) = user_operation.call_gas_limit {
call_gas_limit.into()
} else {
U256::zero()
}
},
verification_gas_limit: {
if let Some(verification_gas_limit) = user_operation.verification_gas_limit {
verification_gas_limit.into()
} else {
U256::zero()
}
},
pre_verification_gas: {
if let Some(pre_verification_gas) = user_operation.pre_verification_gas {
pre_verification_gas.into()
} else {
U256::zero()
}
},
max_fee_per_gas: {
if let Some(max_fee_per_gas) = user_operation.max_fee_per_gas {
max_fee_per_gas.into()
} else {
U256::zero()
}
},
max_priority_fee_per_gas: {
if let Some(max_priority_fee_per_gas) = user_operation.max_priority_fee_per_gas
{
max_priority_fee_per_gas.into()
} else {
U256::zero()
}
},
paymaster_and_data: Bytes::from(user_operation.paymaster_and_data),
signature: Bytes::from(user_operation.signature),
}
Expand Down
10 changes: 5 additions & 5 deletions crates/grpc/src/protos/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ message UserOperation {
PbU256 nonce = 2;
bytes init_code = 3;
bytes call_data = 4;
uint64 call_gas_limit = 5;
uint64 verification_gas_limit = 6;
uint64 pre_verification_gas = 7;
uint64 max_fee_per_gas = 8;
uint64 max_priority_fee_per_gas = 9;
PbU256 call_gas_limit = 5;
PbU256 verification_gas_limit = 6;
PbU256 pre_verification_gas = 7;
PbU256 max_fee_per_gas = 8;
PbU256 max_priority_fee_per_gas = 9;
bytes paymaster_and_data = 10;
bytes signature = 11;
}
Expand Down
8 changes: 3 additions & 5 deletions crates/grpc/src/uopool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,11 @@ where
.get(&mempool_id)
.ok_or_else(|| tonic::Status::invalid_argument("entry point not supported"))?;

match uopool.simulate_user_operation(&user_operation).await {
Ok(simulation_result) => {
match uopool.simulate_validation(&user_operation).await {
Ok(simulate_validation_result) => {
let pre_verification_gas =
Overhead::default().calculate_pre_verification_gas(&user_operation);

let verification_gas_limit = match simulation_result.simulate_validation_result
{
let verification_gas_limit = match simulate_validation_result {
SimulateValidationResult::ValidationResult(validation_result) => {
validation_result.return_info.0
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uopool/src/canonical/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub struct SimulationResult {
}

impl<M: Middleware + 'static> UoPool<M> {
async fn simulate_validation(
pub async fn simulate_validation(
&self,
user_operation: &UserOperation,
) -> Result<SimulateValidationResult, SimulateValidationError> {
Expand Down
9 changes: 4 additions & 5 deletions crates/uopool/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ impl Overhead {
})
.sum::<u128>(),
);
let length_in_word = ((user_operation_packed.len() + 31) as f64) / 32_f64;
u256_from_f64_saturating(
(self.fixed.as_u128() as f64) / (self.bundle_size.as_u128() as f64)
+ (call_data_cost
+ self.per_user_op
+ self.per_user_op_word * user_operation_packed.len())
.as_u128() as f64,
+ ((call_data_cost + self.per_user_op).as_u128() as f64)
+ (self.per_user_op_word.as_u128() as f64) * length_in_word,
zsluedem marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down Expand Up @@ -112,7 +111,7 @@ pub mod tests {

assert_eq!(
gas_overhead.calculate_pre_verification_gas(&user_operation),
U256::from(48684)
U256::from(45340)
);
}

Expand Down