diff --git a/Cargo.lock b/Cargo.lock index ad9e97bb..5f8278af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7062,6 +7062,7 @@ dependencies = [ "lazy_static", "libp2p", "libp2p-mplex", + "sha2 0.10.8", "silius-primitives", "snap", "ssz_rs", diff --git a/README.md b/README.md index c8e6f22e..aeb15b06 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,10 @@ The address of the entry point smart contract is the same on all EVM networks. | :--------: | :-------: | :-------: | :-------: | | [0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789](https://blockscan.com/address/0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789) | 0.6.0 | [9b5f2e4](https://github.com/eth-infinitism/account-abstraction/commit/9b5f2e4bb30a81aa30761749d9e2e43fee64c768) | [April 2023](https://blog.openzeppelin.com/eip-4337-ethereum-account-abstraction-incremental-audit) +## Paymasters and account factories + +You can find a list of many paymasters and account factories [here](https://docs.google.com/spreadsheets/d/1QJEYDOr-AMD2bNAoupfjQJYJabFgdb2TRSyekdIfquM/edit#gid=0). + ## Examples To get started, check the examples [here](./examples/). More examples will be added in the future. diff --git a/bin/silius/src/cli/args.rs b/bin/silius/src/cli/args.rs index 68eedc58..cfeabd52 100644 --- a/bin/silius/src/cli/args.rs +++ b/bin/silius/src/cli/args.rs @@ -7,7 +7,7 @@ use ethers::types::{Address, U256}; use expanded_pathbuf::ExpandedPathBuf; use silius_p2p::config::{Config, ListenAddr}; use silius_primitives::{ - bundler::SendBundleMode, + bundler::{SendBundleMode, DEFAULT_BUNDLE_INTERVAL}, consts::{ networking::{ DEFAULT_BUNDLER_GRPC_PORT, DEFAULT_HTTP_RPC_PORT, DEFAULT_UOPOOL_GRPC_PORT, @@ -56,7 +56,7 @@ pub struct BundlerArgs { /// The bundle interval in seconds. /// /// By default the interval time is set to 10 - #[clap(long, default_value_t = 10)] + #[clap(long, default_value_t = DEFAULT_BUNDLE_INTERVAL)] pub bundle_interval: u64, /// Sets the send bundle mode. diff --git a/crates/p2p/Cargo.toml b/crates/p2p/Cargo.toml index c527cc2b..0af8f2a7 100644 --- a/crates/p2p/Cargo.toml +++ b/crates/p2p/Cargo.toml @@ -22,6 +22,7 @@ futures = "0.3.28" futures-bounded = "0.2.0" lazy_static = { workspace = true } libp2p-mplex = { version = "0.40.0" } +sha2 = "0.10.8" silius-primitives = { path = "../primitives" } snap = "1" ssz_rs = { workspace = true } diff --git a/crates/p2p/src/behaviour.rs b/crates/p2p/src/behaviour.rs index 7e091dd2..396d6c6e 100644 --- a/crates/p2p/src/behaviour.rs +++ b/crates/p2p/src/behaviour.rs @@ -36,6 +36,7 @@ impl Behaviour { let reqrep = request_response::Behaviour::new(Default::default()); let discovery = Discovery::new(enr, key, config)?; let peer_manager = PeerManager::new(ping_interval, target_peers); + Ok(Self { gossipsub, reqrep, diff --git a/crates/p2p/src/gossipsub.rs b/crates/p2p/src/gossipsub.rs index f696bbe1..dfcb7c10 100644 --- a/crates/p2p/src/gossipsub.rs +++ b/crates/p2p/src/gossipsub.rs @@ -1,9 +1,11 @@ use libp2p::gossipsub::{ - Behaviour, ConfigBuilder, DataTransform, IdentTopic, Message, MessageAuthenticity, RawMessage, - TopicHash, ValidationMode, WhitelistSubscriptionFilter, + Behaviour, ConfigBuilder, DataTransform, IdentTopic, Message, MessageAuthenticity, MessageId, + RawMessage, TopicHash, ValidationMode, WhitelistSubscriptionFilter, }; +use sha2::{Digest, Sha256}; use silius_primitives::consts::p2p::{ - MAX_GOSSIP_SNAP_SIZE, SSZ_SNAPPY_ENCODING, TOPIC_PREFIX, USER_OPS_WITH_ENTRY_POINT_TOPIC, + MAX_GOSSIP_SNAP_SIZE, MESSAGE_DOMAIN_VALID_SNAPPY, SSZ_SNAPPY_ENCODING, TOPIC_PREFIX, + USER_OPS_WITH_ENTRY_POINT_TOPIC, }; use snap::raw::{decompress_len, Decoder, Encoder}; use std::{ @@ -27,6 +29,7 @@ impl SnappyTransform { } } } + impl Default for SnappyTransform { fn default() -> Self { SnappyTransform { @@ -93,11 +96,31 @@ pub fn topic(mempool_id: &str) -> IdentTopic { )) } +pub fn message_id_fn(message: &Message) -> MessageId { + let topic_bytes = message.topic.as_str().as_bytes(); + let topic_len_bytes = topic_bytes.len().to_le_bytes(); + + let mut vec: Vec = Vec::with_capacity( + MESSAGE_DOMAIN_VALID_SNAPPY.len() + + topic_len_bytes.len() + + topic_bytes.len() + + message.data.len(), + ); + vec.extend_from_slice(&MESSAGE_DOMAIN_VALID_SNAPPY); + vec.extend_from_slice(&topic_len_bytes); + vec.extend_from_slice(topic_bytes); + vec.extend_from_slice(&message.data); + + Sha256::digest(vec)[..20].into() +} + /// Creates a gossipsub instance with the given mempool ids pub fn create_gossisub(mempool_ids: Vec) -> Result { let filter = create_whitelist_filter(mempool_ids.clone()); let gs_config = ConfigBuilder::default() + .validate_messages() .validation_mode(ValidationMode::Anonymous) + .message_id_fn(message_id_fn) .build()?; let snappy_transform = SnappyTransform::new(MAX_GOSSIP_SNAP_SIZE); let mut gossipsub = Gossipsub::new_with_subscription_filter_and_transform( @@ -112,5 +135,6 @@ pub fn create_gossisub(mempool_ids: Vec) -> Result SanityCheck for CallGas { uo: &UserOperation, _mempool: &Mempool, _reputation: &Reputation, - helper: &SanityHelper, + _helper: &SanityHelper, ) -> Result<(), SanityCheckError> where T: UserOperationAct, @@ -37,43 +35,10 @@ impl SanityCheck for CallGas { H: HashSetOp, R: ReputationEntryOp, { - let exec_res = match helper.entry_point.simulate_handle_op(uo.clone()).await { - Ok(res) => res, - Err(err) => { - return Err(match err { - EntryPointErr::FailedOp(f) => { - SanityCheckError::Validation { message: f.reason } - } - _ => SanityCheckError::UnknownError { - message: format!("{err:?}"), - }, - }) - } - }; - - let block = helper - .entry_point - .eth_client() - .get_block(BlockNumber::Latest) - .await - .map_err(|err| SanityCheckError::UnknownError { - message: err.to_string(), - })? - .ok_or(SanityCheckError::UnknownError { - message: "No block found".to_string(), - })?; - let base_fee_per_gas = block - .base_fee_per_gas - .ok_or(SanityCheckError::UnknownError { - message: "No base fee".to_string(), - })?; - - let call_gas_limit = calculate_call_gas_limit( - exec_res.paid, - exec_res.pre_op_gas, - uo.max_fee_per_gas - .min(uo.max_priority_fee_per_gas + base_fee_per_gas), - ); + // call gas limit is at least the cost of a CALL with non-zero value + // https://github.com/wolflo/evm-opcodes/blob/main/gas.md#aa-1-call + // gas_cost = 100 + 9000 + let call_gas_limit = U256::from(9100); if uo.call_gas_limit >= call_gas_limit { return Ok(()); diff --git a/docs/P2P.md b/docs/P2P.md index 71ac8ed6..f8c02d92 100644 --- a/docs/P2P.md +++ b/docs/P2P.md @@ -35,11 +35,11 @@ cargo run -- node --eth-client-address http://127.0.0.1:8545 --mnemonic-file ./b Run first peer node ``` -cargo run -- node --eth-client-address http://127.0.0.1:8545 --mnemonic-file ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --http.port 4001 --eth-client-proxy-address http://127.0.0.1:8545 --p2p.baddr 127.0.0.1 --bootnodes "enr:-Iu4QBh2tesC8BokO61v1w43MnbfHF5H95ZJNHVEQaRq_MjFFuxmeVQnoEXxUDk5qKJCHM944gC72Xg4dYwRkGt9zA4BgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKRdyIA8OvArCcZbt3hoJHu4nVe6CblqjO0CnrbGACi-IN0Y3CCEPGDdWRwghDx" --enable-p2p --discovery.port 4338 --p2p.port 4338 --datadir ./.local/node1 +cargo run -- node --eth-client-address http://127.0.0.1:8545 --mnemonic-file ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --uopool.port 3004 --bundler.port 3005 --http --http.port 4001 --eth-client-proxy-address http://127.0.0.1:8545 --p2p.baddr 127.0.0.1 --bootnodes "enr:-Iu4QBh2tesC8BokO61v1w43MnbfHF5H95ZJNHVEQaRq_MjFFuxmeVQnoEXxUDk5qKJCHM944gC72Xg4dYwRkGt9zA4BgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKRdyIA8OvArCcZbt3hoJHu4nVe6CblqjO0CnrbGACi-IN0Y3CCEPGDdWRwghDx" --enable-p2p --discovery.port 4338 --p2p.port 4338 --datadir ./.local/node1 ``` Run second peer node ``` -cargo run -- node --eth-client-address http://127.0.0.1:8545 --mnemonic-file ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --http.port 4002 --eth-client-proxy-address http://127.0.0.1:8545 --p2p.baddr 127.0.0.1 --bootnodes "enr:-Iu4QBh2tesC8BokO61v1w43MnbfHF5H95ZJNHVEQaRq_MjFFuxmeVQnoEXxUDk5qKJCHM944gC72Xg4dYwRkGt9zA4BgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKRdyIA8OvArCcZbt3hoJHu4nVe6CblqjO0CnrbGACi-IN0Y3CCEPGDdWRwghDx" --enable-p2p --discovery.port 4339 --p2p.port 4339 --datadir ./.local/node2 +cargo run -- node --eth-client-address http://127.0.0.1:8545 --mnemonic-file ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --uopool.port 3006 --bundler.port 3007 --http --http.port 4002 --eth-client-proxy-address http://127.0.0.1:8545 --p2p.baddr 127.0.0.1 --bootnodes "enr:-Iu4QBh2tesC8BokO61v1w43MnbfHF5H95ZJNHVEQaRq_MjFFuxmeVQnoEXxUDk5qKJCHM944gC72Xg4dYwRkGt9zA4BgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKRdyIA8OvArCcZbt3hoJHu4nVe6CblqjO0CnrbGACi-IN0Y3CCEPGDdWRwghDx" --enable-p2p --discovery.port 4339 --p2p.port 4339 --datadir ./.local/node2 ```