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

chore: move hash inside user operation #276

Merged
merged 2 commits into from
Jan 17, 2024
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
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.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ run-silius-create-wallet:
cargo run --release -- create-wallet --output-path ${HOME}/.silius

run-silius-debug:
cargo run --release -- node --eth-client-address ws://127.0.0.1:8546 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3 --poll-interval 5
cargo run --release -- node --eth-client-address ws://127.0.0.1:8546 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3

run-silius-debug-mode:
cargo run --profile debug-fast -- node --verbosity 4 --eth-client-address ws://127.0.0.1:8546 --mnemonic-file /home/vid/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3 --poll-interval 5
cargo run --profile debug-fast -- node --verbosity 4 --eth-client-address ws://127.0.0.1:8546 --mnemonic-file /home/vid/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3

fetch-thirdparty:
git submodule update --init
Expand Down
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
64 changes: 56 additions & 8 deletions crates/grpc/src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Code adapted from: https://github.com/ledgerwatch/interfaces/blob/master/src/lib.rs#L1
pub mod types {

use arrayref::array_ref;
use ethers::types::{Address, Bloom, U256};
use prost::bytes::Buf;
use silius_primitives::{reputation::Status, UserOperationHash};
use std::str::FromStr;

tonic::include_proto!("types");
Expand Down Expand Up @@ -73,7 +71,7 @@ pub mod types {
}
}

impl From<H256> for UserOperationHash {
impl From<H256> for silius_primitives::UserOperationHash {
fn from(val: H256) -> Self {
Self::from(ethers::types::H256::from(val))
}
Expand All @@ -95,6 +93,56 @@ 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()),
uo: Some(UserOperationSigned {
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<UserOperation> for silius_primitives::UserOperation {
fn from(user_operation: UserOperation) -> Self {
Self {
hash: {
if let Some(hash) = user_operation.hash {
hash.into()
} else {
silius_primitives::UserOperationHash::default()
}
},
user_operation: {
if let Some(uo) = user_operation.uo {
uo.into()
} else {
silius_primitives::UserOperationSigned::default()
}
},
}
}
}

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()),
Expand All @@ -113,8 +161,8 @@ pub mod types {
}
}

impl From<UserOperation> for silius_primitives::UserOperation {
fn from(user_operation: UserOperation) -> Self {
impl From<UserOperationSigned> for silius_primitives::UserOperationSigned {
fn from(user_operation: UserOperationSigned) -> Self {
Self {
sender: {
if let Some(sender) = user_operation.sender {
Expand Down Expand Up @@ -180,7 +228,7 @@ pub mod types {
addr: Some(reputation_entry.address.into()),
uo_seen: reputation_entry.uo_seen,
uo_included: reputation_entry.uo_included,
stat: match Status::from(reputation_entry.status) {
stat: match silius_primitives::reputation::Status::from(reputation_entry.status) {
silius_primitives::reputation::Status::OK => ReputationStatus::Ok,
silius_primitives::reputation::Status::THROTTLED => ReputationStatus::Throttled,
silius_primitives::reputation::Status::BANNED => ReputationStatus::Banned,
Expand Down Expand Up @@ -308,8 +356,8 @@ pub mod types {
}
}

impl From<UserOperationHash> for H256 {
fn from(value: UserOperationHash) -> Self {
impl From<silius_primitives::UserOperationHash> for H256 {
fn from(value: silius_primitives::UserOperationHash) -> Self {
Self::from(value.0)
}
}
Expand Down
5 changes: 5 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,11 @@ message SupportedEntryPoint {
}

message UserOperation {
types.H256 hash = 1;
UserOperationSigned uo = 2;
}

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