Skip to content

Commit

Permalink
fix: u64 convert panic
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Aug 16, 2024
1 parent fc1706d commit 744f3be
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 65 deletions.
18 changes: 7 additions & 11 deletions user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ fn build_user_op_model(
.map(|e| e.account)
.collect();

let call_gas_limit = user_op.user_op.call_gas_limit.as_u64();
let verification_gas_limit = user_op.user_op.verification_gas_limit.as_u64();
let pre_verification_gas = user_op.user_op.pre_verification_gas.as_u64();

let factory = extract_address(&user_op.user_op.init_code);
let paymaster = extract_address(&user_op.user_op.paymaster_and_data);
let sender = user_op.user_op.sender;
Expand All @@ -166,9 +162,9 @@ fn build_user_op_model(
nonce: H256::from_uint(&user_op.user_op.nonce),
init_code: none_if_empty(user_op.user_op.init_code),
call_data: user_op.user_op.call_data,
call_gas_limit,
verification_gas_limit,
pre_verification_gas,
call_gas_limit: user_op.user_op.call_gas_limit,
verification_gas_limit: user_op.user_op.verification_gas_limit,
pre_verification_gas: user_op.user_op.pre_verification_gas,
max_fee_per_gas: user_op.user_op.max_fee_per_gas,
max_priority_fee_per_gas: user_op.user_op.max_priority_fee_per_gas,
paymaster_and_data: none_if_empty(user_op.user_op.paymaster_and_data),
Expand All @@ -187,13 +183,13 @@ fn build_user_op_model(
paymaster,
status: user_op_event.success,
revert_reason: revert_event.map(|e| e.revert_reason),
gas: call_gas_limit
+ verification_gas_limit * if paymaster.is_none() { 1 } else { 3 }
+ pre_verification_gas,
gas: user_op.user_op.call_gas_limit
+ user_op.user_op.verification_gas_limit * if paymaster.is_none() { 1 } else { 3 }
+ user_op.user_op.pre_verification_gas,
gas_price: user_op_event
.actual_gas_cost
.div(user_op_event.actual_gas_used),
gas_used: user_op_event.actual_gas_used.as_u64(),
gas_used: user_op_event.actual_gas_used,
sponsor_type: extract_sponsor_type(sender, paymaster, &tx_deposits),
user_logs_start_index,
user_logs_count,
Expand Down
13 changes: 5 additions & 8 deletions user-ops-indexer/user-ops-indexer-logic/src/indexer/v07/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethers::prelude::{
abi::{AbiDecode, Address},
abigen,
types::{Bytes, Log, TransactionReceipt, H256},
BigEndianHash, EthEvent,
BigEndianHash, EthEvent, U256,
};
use lazy_static::lazy_static;
use std::ops::Div;
Expand Down Expand Up @@ -154,15 +154,12 @@ fn build_user_op_model(

let (verification_gas_limit, call_gas_limit) =
unpack_uints(&user_op.user_op.account_gas_limits[..]);
let verification_gas_limit = verification_gas_limit.as_u64();
let call_gas_limit = call_gas_limit.as_u64();
let pre_verification_gas = user_op.user_op.pre_verification_gas.as_u64();
let pre_verification_gas = user_op.user_op.pre_verification_gas;
let (paymaster_verification_gas_limit, paymaster_post_op_gas_limit) =
if user_op.user_op.paymaster_and_data.len() >= 52 {
let (a, b) = unpack_uints(&user_op.user_op.paymaster_and_data[20..52]);
(a.as_u64(), b.as_u64())
unpack_uints(&user_op.user_op.paymaster_and_data[20..52])
} else {
(0, 0)
(U256::zero(), U256::zero())
};
let gas = call_gas_limit
+ verification_gas_limit
Expand Down Expand Up @@ -208,7 +205,7 @@ fn build_user_op_model(
gas_price: user_op_event
.actual_gas_cost
.div(user_op_event.actual_gas_used),
gas_used: user_op_event.actual_gas_used.as_u64(),
gas_used: user_op_event.actual_gas_used,
sponsor_type: extract_sponsor_type(sender, paymaster, &tx_deposits),
user_logs_start_index,
user_logs_count,
Expand Down
56 changes: 28 additions & 28 deletions user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use crate::{
pub use entity::sea_orm_active_enums::{EntryPointVersion, SponsorType};
use entity::user_operations::Model;
use ethers::prelude::{
abi::AbiEncode, core::utils::to_checksum, Address, BigEndianHash, Bytes, H128, H256, U256,
abi::AbiEncode, core::utils::to_checksum, Address, BigEndianHash, Bytes, H256, U256,
};
use num_traits::cast::ToPrimitive;
use sea_orm::{prelude::BigDecimal, ActiveEnum};
use sea_orm::ActiveEnum;
use std::ops::Mul;

#[derive(Clone, Debug, PartialEq)]
Expand All @@ -18,9 +18,9 @@ pub struct UserOp {
pub nonce: H256,
pub init_code: Option<Bytes>,
pub call_data: Bytes,
pub call_gas_limit: u64,
pub verification_gas_limit: u64,
pub pre_verification_gas: u64,
pub call_gas_limit: U256,
pub verification_gas_limit: U256,
pub pre_verification_gas: U256,
pub max_fee_per_gas: U256,
pub max_priority_fee_per_gas: U256,
pub paymaster_and_data: Option<Bytes>,
Expand All @@ -39,9 +39,9 @@ pub struct UserOp {
pub paymaster: Option<Address>,
pub status: bool,
pub revert_reason: Option<Bytes>,
pub gas: u64,
pub gas: U256,
pub gas_price: U256,
pub gas_used: u64,
pub gas_used: U256,
pub sponsor_type: SponsorType,
pub user_logs_start_index: u32,
pub user_logs_count: u32,
Expand Down Expand Up @@ -72,9 +72,9 @@ impl From<UserOp> for Model {
nonce: v.nonce.as_bytes().to_vec(),
init_code: v.init_code.clone().map(|a| a.to_vec()),
call_data: v.call_data.to_vec(),
call_gas_limit: BigDecimal::from(v.call_gas_limit),
verification_gas_limit: BigDecimal::from(v.verification_gas_limit),
pre_verification_gas: BigDecimal::from(v.pre_verification_gas),
call_gas_limit: u256_to_decimal(v.call_gas_limit),
verification_gas_limit: u256_to_decimal(v.verification_gas_limit),
pre_verification_gas: u256_to_decimal(v.pre_verification_gas),
max_fee_per_gas: u256_to_decimal(v.max_fee_per_gas),
max_priority_fee_per_gas: u256_to_decimal(v.max_priority_fee_per_gas),
paymaster_and_data: v.paymaster_and_data.clone().map(|a| a.to_vec()),
Expand All @@ -93,9 +93,9 @@ impl From<UserOp> for Model {
paymaster: v.paymaster.map(|a| a.as_bytes().to_vec()),
status: v.status,
revert_reason: v.revert_reason.clone().map(|a| a.to_vec()),
gas: BigDecimal::from(v.gas),
gas: u256_to_decimal(v.gas),
gas_price: u256_to_decimal(v.gas_price),
gas_used: BigDecimal::from(v.gas_used),
gas_used: u256_to_decimal(v.gas_used),
sponsor_type: v.sponsor_type.clone(),
user_logs_start_index: v.user_logs_start_index as i32,
user_logs_count: v.user_logs_count as i32,
Expand All @@ -113,9 +113,9 @@ impl From<Model> for UserOp {
nonce: H256::from_slice(&v.nonce),
init_code: v.init_code.clone().map(Bytes::from),
call_data: Bytes::from(v.call_data.clone()),
call_gas_limit: v.call_gas_limit.to_u64().unwrap_or(0),
verification_gas_limit: v.verification_gas_limit.to_u64().unwrap_or(0),
pre_verification_gas: v.pre_verification_gas.to_u64().unwrap_or(0),
call_gas_limit: U256::from(v.call_gas_limit.to_u128().unwrap_or(0)),
verification_gas_limit: U256::from(v.verification_gas_limit.to_u128().unwrap_or(0)),
pre_verification_gas: U256::from(v.pre_verification_gas.to_u128().unwrap_or(0)),
max_fee_per_gas: U256::from(v.max_fee_per_gas.to_u128().unwrap_or(0)),
max_priority_fee_per_gas: U256::from(v.max_priority_fee_per_gas.to_u128().unwrap_or(0)),
paymaster_and_data: v.paymaster_and_data.clone().map(Bytes::from),
Expand All @@ -134,9 +134,9 @@ impl From<Model> for UserOp {
paymaster: v.paymaster.clone().map(|a| Address::from_slice(&a)),
status: v.status,
revert_reason: v.revert_reason.clone().map(Bytes::from),
gas: v.gas.to_u64().unwrap_or(0),
gas: U256::from(v.gas.to_u128().unwrap_or(0)),
gas_price: U256::from(v.gas_price.to_u128().unwrap_or(0)),
gas_used: v.gas_used.to_u64().unwrap_or(0),
gas_used: U256::from(v.gas_used.to_u128().unwrap_or(0)),
sponsor_type: v.sponsor_type.clone(),
user_logs_start_index: v.user_logs_start_index as u32,
user_logs_count: v.user_logs_count as u32,
Expand All @@ -158,9 +158,9 @@ impl From<UserOp> for user_ops_indexer_proto::blockscout::user_ops_indexer::v1::
nonce: U256::from(v.nonce.as_fixed_bytes()).to_string(),
init_code: v.init_code.map_or("0x".to_string(), |b| b.to_string()),
call_data: v.call_data.to_string(),
call_gas_limit: v.call_gas_limit,
verification_gas_limit: v.verification_gas_limit,
pre_verification_gas: v.pre_verification_gas,
call_gas_limit: v.call_gas_limit.to_string(),
verification_gas_limit: v.verification_gas_limit.to_string(),
pre_verification_gas: v.pre_verification_gas.to_string(),
max_fee_per_gas: v.max_fee_per_gas.to_string(),
max_priority_fee_per_gas: v.max_priority_fee_per_gas.to_string(),
paymaster_and_data: v
Expand All @@ -179,14 +179,14 @@ impl From<UserOp> for user_ops_indexer_proto::blockscout::user_ops_indexer::v1::
call_data: v.call_data.to_string(),
account_gas_limits: H256::from_slice(
[
H128::from_low_u64_be(v.verification_gas_limit).as_bytes(),
H128::from_low_u64_be(v.call_gas_limit).as_bytes(),
&H256::from_uint(&v.verification_gas_limit).as_bytes()[16..],
&H256::from_uint(&v.call_gas_limit).as_bytes()[16..],
]
.concat()
.as_slice(),
)
.encode_hex(),
pre_verification_gas: v.pre_verification_gas,
pre_verification_gas: v.pre_verification_gas.to_string(),
gas_fees: H256::from_slice(
[
&H256::from_uint(&v.max_fee_per_gas).as_bytes()[16..],
Expand All @@ -212,9 +212,9 @@ impl From<UserOp> for user_ops_indexer_proto::blockscout::user_ops_indexer::v1::
sender: to_checksum(&v.sender, None),
nonce: v.nonce.encode_hex(),
call_data: v.call_data.to_string(),
call_gas_limit: v.call_gas_limit,
verification_gas_limit: v.verification_gas_limit,
pre_verification_gas: v.pre_verification_gas,
call_gas_limit: v.call_gas_limit.to_string(),
verification_gas_limit: v.verification_gas_limit.to_string(),
pre_verification_gas: v.pre_verification_gas.to_string(),
max_fee_per_gas: v.max_fee_per_gas.to_string(),
max_priority_fee_per_gas: v.max_priority_fee_per_gas.to_string(),
signature: v.signature.to_string(),
Expand All @@ -233,9 +233,9 @@ impl From<UserOp> for user_ops_indexer_proto::blockscout::user_ops_indexer::v1::
paymaster: v.paymaster.map(|a| to_checksum(&a, None)),
status: v.status,
revert_reason: v.revert_reason.map(|b| b.to_string()),
gas: v.gas,
gas: v.gas.to_string(),
gas_price: v.gas_price.to_string(),
gas_used: v.gas_used,
gas_used: v.gas_used.to_string(),
sponsor_type: v.sponsor_type.to_value().to_string(),
user_logs_start_index: v.user_logs_start_index,
user_logs_count: v.user_logs_count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ message RawUserOpV06 {
string nonce = 2;
string init_code = 3;
string call_data = 4;
uint64 call_gas_limit = 5;
uint64 verification_gas_limit = 6;
uint64 pre_verification_gas = 7;
string call_gas_limit = 5;
string verification_gas_limit = 6;
string pre_verification_gas = 7;
string max_fee_per_gas = 8;
string max_priority_fee_per_gas = 9;
string paymaster_and_data = 10;
Expand All @@ -171,7 +171,7 @@ message RawUserOpV07 {
string init_code = 3;
string call_data = 4;
string account_gas_limits = 5; // call_gas_limit + verification_gas_limit
uint64 pre_verification_gas = 6;
string pre_verification_gas = 6;
string gas_fees = 7; // max_fee_per_gas + max_priority_fee_per_gas
string paymaster_and_data = 8; // paymaster + paymaster_verification_gas_limit + post_op_gas_limit + paymaster_data
string signature = 9;
Expand All @@ -182,9 +182,9 @@ message UserOp {
string sender = 2;
string nonce = 3;
string call_data = 4;
uint64 call_gas_limit = 5;
uint64 verification_gas_limit = 6;
uint64 pre_verification_gas = 7;
string call_gas_limit = 5;
string verification_gas_limit = 6;
string pre_verification_gas = 7;
string max_fee_per_gas = 8;
string max_priority_fee_per_gas = 9;
string signature = 10;
Expand All @@ -206,9 +206,9 @@ message UserOp {
optional string paymaster = 23;
bool status = 24;
optional string revert_reason = 25;
uint64 gas = 26;
string gas = 26;
string gas_price = 27;
uint64 gas_used = 28;
string gas_used = 28;
string sponsor_type = 29;
uint32 user_logs_start_index = 30;
uint32 user_logs_count = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,10 @@ definitions:
type: string
call_gas_limit:
type: string
format: uint64
verification_gas_limit:
type: string
format: uint64
pre_verification_gas:
type: string
format: uint64
max_fee_per_gas:
type: string
max_priority_fee_per_gas:
Expand All @@ -539,7 +536,6 @@ definitions:
title: call_gas_limit + verification_gas_limit
pre_verification_gas:
type: string
format: uint64
gas_fees:
type: string
title: max_fee_per_gas + max_priority_fee_per_gas
Expand All @@ -561,13 +557,10 @@ definitions:
type: string
call_gas_limit:
type: string
format: uint64
verification_gas_limit:
type: string
format: uint64
pre_verification_gas:
type: string
format: uint64
max_fee_per_gas:
type: string
max_priority_fee_per_gas:
Expand Down Expand Up @@ -611,12 +604,10 @@ definitions:
type: string
gas:
type: string
format: uint64
gas_price:
type: string
gas_used:
type: string
format: uint64
sponsor_type:
type: string
user_logs_start_index:
Expand Down

0 comments on commit 744f3be

Please sign in to comment.