Skip to content

Commit

Permalink
chore: move hash inside user operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Jan 12, 2024
1 parent 0473b51 commit 6d5262d
Show file tree
Hide file tree
Showing 43 changed files with 753 additions and 598 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Rust toolchain (stable)
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@1.73.0
with:
components: clippy

Expand Down
39 changes: 3 additions & 36 deletions Cargo.lock

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

18 changes: 9 additions & 9 deletions bin/silius/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use silius_primitives::{
provider::BlockStream,
reputation::ReputationEntry,
simulation::CodeHash,
UserOperation, UserOperationHash, Wallet,
UserOperationHash, UserOperationSigned, Wallet,
};
use silius_rpc::{
debug_api::{DebugApiServer, DebugApiServerImpl},
Expand Down Expand Up @@ -105,17 +105,17 @@ where
eth_client_version,
);

let chain_id = eth_client.get_chainid().await?;
let chain_conn = Chain::from(chain_id.as_u64());
let chain_id = eth_client.get_chainid().await?.as_u64();
let chain_conn = Chain::from(chain_id);

let wallet: Wallet;
if args.send_bundle_mode == SendStrategy::Flashbots {
wallet = Wallet::from_file(args.mnemonic_file.into(), &chain_id, true)
wallet = Wallet::from_file(args.mnemonic_file.into(), chain_id, true)
.map_err(|error| eyre::format_err!("Could not load mnemonic file: {}", error))?;
info!("Wallet Signer {:?}", wallet.signer);
info!("Flashbots Signer {:?}", wallet.flashbots_signer);
} else {
wallet = Wallet::from_file(args.mnemonic_file.into(), &chain_id, false)
wallet = Wallet::from_file(args.mnemonic_file.into(), chain_id, false)
.map_err(|error| eyre::format_err!("Could not load mnemonic file: {}", error))?;
info!("{:?}", wallet.signer);
}
Expand Down Expand Up @@ -189,7 +189,7 @@ where
args.min_priority_fee_per_gas,
);
let mempool = Mempool::new(
Arc::new(RwLock::new(HashMap::<UserOperationHash, UserOperation>::default())),
Arc::new(RwLock::new(HashMap::<UserOperationHash, UserOperationSigned>::default())),
Arc::new(RwLock::new(HashMap::<Address, HashSet<UserOperationHash>>::default())),
Arc::new(RwLock::new(HashMap::<Address, HashSet<UserOperationHash>>::default())),
Arc::new(RwLock::new(HashMap::<UserOperationHash, Vec<CodeHash>>::default())),
Expand Down Expand Up @@ -283,7 +283,7 @@ where
args.min_priority_fee_per_gas,
);
let mempool = Mempool::new(
Arc::new(RwLock::new(HashMap::<UserOperationHash, UserOperation>::default())),
Arc::new(RwLock::new(HashMap::<UserOperationHash, UserOperationSigned>::default())),
Arc::new(RwLock::new(HashMap::<Address, HashSet<UserOperationHash>>::default())),
Arc::new(RwLock::new(HashMap::<Address, HashSet<UserOperationHash>>::default())),
Arc::new(RwLock::new(HashMap::<UserOperationHash, Vec<CodeHash>>::default())),
Expand Down Expand Up @@ -472,11 +472,11 @@ pub fn create_wallet(args: CreateWalletArgs) -> eyre::Result<()> {
let path = unwrap_path_or_home(args.output_path)?;

if args.flashbots_key {
let wallet = Wallet::build_random(path, &args.chain_id, true)?;
let wallet = Wallet::build_random(path, args.chain_id, true)?;
info!("Wallet signer {:?}", wallet.signer);
info!("Flashbots signer {:?}", wallet.flashbots_signer);
} else {
let wallet = Wallet::build_random(path, &args.chain_id, false)?;
let wallet = Wallet::build_random(path, args.chain_id, false)?;
info!("Wallet signer {:?}", wallet.signer);
}

Expand Down
4 changes: 2 additions & 2 deletions bin/silius/src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ pub struct CreateWalletArgs {
pub output_path: Option<ExpandedPathBuf>,

/// The chain id.
#[clap(long, value_parser=parse_u256, default_value="1")]
pub chain_id: U256,
#[clap(long, default_value = "1")]
pub chain_id: u64,

/// Whether to create a Flashbots key.
#[clap(long, default_value_t = false)]
Expand Down
17 changes: 10 additions & 7 deletions crates/bundler/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ where
info!(
"Creating a new bundle with {} user operations: {:?}",
uos.len(),
uos.iter()
.map(|uo| uo.hash(&self.entry_point, &self.chain.id().into()))
.collect::<Vec<UserOperationHash>>()
uos.iter().map(|uo| uo.hash).collect::<Vec<UserOperationHash>>()
);
trace!("Bundle content: {uos:?}");

Expand All @@ -178,6 +176,7 @@ where
///
/// # Arguments
/// * `client` - A provider that implements [Middleware](Middleware) trait
/// * `uos` - Vector of [UserOperations](UserOperation)
///
/// # Returns
/// * `TypedTransaction` - A [TypedTransaction](TypedTransaction)
Expand All @@ -201,8 +200,12 @@ where
self.beneficiary
};

let mut tx: TypedTransaction =
ep.handle_ops(uos.clone().into_iter().map(Into::into).collect(), beneficiary).tx;
let mut tx: TypedTransaction = ep
.handle_ops(
uos.clone().into_iter().map(|uo| uo.user_operation.into()).collect(),
beneficiary,
)
.tx;

match self.chain.id() {
// Mumbai
Expand Down Expand Up @@ -521,7 +524,7 @@ mod test {

let eth_client = Arc::new(Provider::<Ws>::connect(anvil.ws_endpoint()).await?);
let ep_address = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789".parse::<Address>()?;
let wallet = Wallet::from_phrase(KEY_PHRASE, &anvil.chain_id().into(), true)?;
let wallet = Wallet::from_phrase(KEY_PHRASE, anvil.chain_id(), true)?;

// Create a bundler and connect to the Anvil
let bundler = Bundler::new(
Expand Down Expand Up @@ -559,7 +562,7 @@ mod test {
"{}/.silius/0x129D197b2a989C6798601A49D89a4AEC822A17a3",
std::env::var("HOME").unwrap()
);
let wallet = Wallet::from_file(dir.into(), &U256::from(5), true)?;
let wallet = Wallet::from_file(dir.into(), 5, true)?;

let bundler = Bundler::new(
wallet.clone(),
Expand Down
10 changes: 5 additions & 5 deletions crates/contracts/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::gen::entry_point_api::{self, EntryPointAPICalls};
use ethers::{abi::AbiDecode, types::Bytes};
use silius_primitives::UserOperation;
use silius_primitives::UserOperationSigned;

impl From<UserOperation> for entry_point_api::UserOperation {
fn from(uo: UserOperation) -> Self {
impl From<UserOperationSigned> for entry_point_api::UserOperation {
fn from(uo: UserOperationSigned) -> Self {
Self {
sender: uo.sender,
nonce: uo.nonce,
Expand All @@ -20,7 +20,7 @@ impl From<UserOperation> for entry_point_api::UserOperation {
}
}

impl From<entry_point_api::UserOperation> for UserOperation {
impl From<entry_point_api::UserOperation> for UserOperationSigned {
fn from(uo: entry_point_api::UserOperation) -> Self {
Self {
sender: uo.sender,
Expand All @@ -38,7 +38,7 @@ impl From<entry_point_api::UserOperation> for UserOperation {
}
}

pub fn parse_from_input_data(data: Bytes) -> Option<Vec<UserOperation>> {
pub fn parse_from_input_data(data: Bytes) -> Option<Vec<UserOperationSigned>> {
EntryPointAPICalls::decode(data).ok().and_then(|call| match call {
EntryPointAPICalls::HandleOps(ops) => {
Some(ops.ops.into_iter().map(|op| op.into()).collect())
Expand Down
93 changes: 93 additions & 0 deletions crates/grpc/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub mod types {
impl From<silius_primitives::UserOperation> for UserOperation {
fn from(user_operation: silius_primitives::UserOperation) -> Self {
Self {
hash: Some(user_operation.hash.into()),
sender: Some(user_operation.sender.into()),
nonce: Some(user_operation.nonce.into()),
init_code: prost::bytes::Bytes::copy_from_slice(user_operation.init_code.as_ref()),
Expand All @@ -115,6 +116,98 @@ pub mod types {

impl From<UserOperation> for silius_primitives::UserOperation {
fn from(user_operation: UserOperation) -> Self {
Self {
hash: {
if let Some(hash) = user_operation.hash {
hash.into()
} else {
UserOperationHash::default()
}
},
user_operation: silius_primitives::UserOperationSigned {
sender: {
if let Some(sender) = user_operation.sender {
sender.into()
} else {
Address::zero()
}
},
nonce: {
if let Some(nonce) = user_operation.nonce {
nonce.into()
} else {
U256::zero()
}
},
init_code: user_operation.init_code.into(),
call_data: user_operation.call_data.into(),
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: user_operation.paymaster_and_data.into(),
signature: user_operation.signature.into(),
},
}
}
}

impl From<silius_primitives::UserOperationSigned> for UserOperationSigned {
fn from(user_operation: silius_primitives::UserOperationSigned) -> Self {
Self {
sender: Some(user_operation.sender.into()),
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: 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(),
),
signature: prost::bytes::Bytes::copy_from_slice(user_operation.signature.as_ref()),
}
}
}

impl From<UserOperationSigned> for silius_primitives::UserOperationSigned {
fn from(user_operation: UserOperationSigned) -> Self {
Self {
sender: {
if let Some(sender) = user_operation.sender {
Expand Down
15 changes: 15 additions & 0 deletions crates/grpc/src/protos/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ message SupportedEntryPoint {
}

message UserOperation {
types.H256 hash = 1;
types.H160 sender = 2;
PbU256 nonce = 3;
bytes init_code = 4;
bytes call_data = 5;
PbU256 call_gas_limit = 6;
PbU256 verification_gas_limit = 7;
PbU256 pre_verification_gas = 8;
PbU256 max_fee_per_gas = 9;
PbU256 max_priority_fee_per_gas = 10;
bytes paymaster_and_data = 11;
bytes signature = 12;
}

message UserOperationSigned {
types.H160 sender = 1;
PbU256 nonce = 2;
bytes init_code = 3;
Expand Down
2 changes: 1 addition & 1 deletion crates/grpc/src/protos/uopool/uopool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ message UserOperationHashRequest{
}

message GetUserOperationByHashResponse{
types.UserOperation user_operation = 1;
types.UserOperationSigned user_operation = 1;
types.H160 entry_point = 2;
types.H256 transaction_hash = 3;
types.H256 block_hash = 4;
Expand Down
Loading

0 comments on commit 6d5262d

Please sign in to comment.