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

fix int overflow crash for onchain events #204

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
26 changes: 16 additions & 10 deletions src/connectors/onchain_events/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use alloy_primitives::{address, Address, FixedBytes, Uint};
use alloy_primitives::{address, ruint::FromUintError, Address, FixedBytes};
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
use alloy_rpc_types::{Filter, Log};
use alloy_sol_types::{sol, SolEvent};
Expand Down Expand Up @@ -81,6 +81,12 @@ pub enum SubscribeError {
#[error(transparent)]
UnableToParseLog(#[from] alloy_sol_types::Error),

#[error(transparent)]
UnableToConvertToU64(#[from] FromUintError<u64>),

#[error(transparent)]
UnableToConvertToU32(#[from] FromUintError<u32>),

#[error("Empty rpc url")]
EmptyRpcUrl,

Expand Down Expand Up @@ -263,13 +269,13 @@ impl Subscriber {
match event.topic0() {
Some(&StorageRegistryAbi::Rent::SIGNATURE_HASH) => {
let StorageRegistryAbi::Rent { payer, fid, units } = event.log_decode()?.inner.data;
let fid = Uint::to::<u64>(&fid);
let fid = fid.try_into()?;
add_event(
fid,
OnChainEventType::EventTypeStorageRent,
on_chain_event::Body::StorageRentEventBody(StorageRentEventBody {
payer: payer.to_vec(),
units: Uint::to::<u32>(&units),
units: units.try_into()?,
expiry: (block_timestamp + RENT_EXPIRY_IN_SECONDS) as u32,
}),
)
Expand All @@ -278,7 +284,7 @@ impl Subscriber {
}
Some(&IdRegistryAbi::Register::SIGNATURE_HASH) => {
let IdRegistryAbi::Register { to, id, recovery } = event.log_decode()?.inner.data;
let fid = Uint::to::<u64>(&id);
let fid = id.try_into()?;
add_event(
fid,
OnChainEventType::EventTypeIdRegister,
Expand All @@ -294,7 +300,7 @@ impl Subscriber {
}
Some(&IdRegistryAbi::Transfer::SIGNATURE_HASH) => {
let IdRegistryAbi::Transfer { from, to, id } = event.log_decode()?.inner.data;
let fid = Uint::to::<u64>(&id);
let fid = id.try_into()?;
add_event(
fid,
OnChainEventType::EventTypeIdRegister,
Expand All @@ -311,7 +317,7 @@ impl Subscriber {
Some(&IdRegistryAbi::ChangeRecoveryAddress::SIGNATURE_HASH) => {
let IdRegistryAbi::ChangeRecoveryAddress { id, recovery } =
event.log_decode()?.inner.data;
let fid = Uint::to::<u64>(&id);
let fid = id.try_into()?;
add_event(
fid,
OnChainEventType::EventTypeIdRegister,
Expand All @@ -334,7 +340,7 @@ impl Subscriber {
metadatatype,
metadata,
} = event.log_decode()?.inner.data;
let fid = Uint::to::<u64>(&fid);
let fid = fid.try_into()?;
add_event(
fid,
OnChainEventType::EventTypeSigner,
Expand All @@ -355,7 +361,7 @@ impl Subscriber {
key: _,
keyBytes,
} = event.log_decode()?.inner.data;
let fid = Uint::to::<u64>(&fid);
let fid = fid.try_into()?;
add_event(
fid,
OnChainEventType::EventTypeSigner,
Expand All @@ -376,7 +382,7 @@ impl Subscriber {
key: _,
keyBytes,
} = event.log_decode()?.inner.data;
let fid = Uint::to::<u64>(&fid);
let fid = fid.try_into()?;
add_event(
fid,
OnChainEventType::EventTypeSigner,
Expand All @@ -393,7 +399,7 @@ impl Subscriber {
}
Some(&KeyRegistryAbi::Migrated::SIGNATURE_HASH) => {
let KeyRegistryAbi::Migrated { keysMigratedAt } = event.log_decode()?.inner.data;
let migrated_at = Uint::to::<u32>(&keysMigratedAt);
let migrated_at = keysMigratedAt.try_into()?;
add_event(
0,
OnChainEventType::EventTypeSignerMigrated,
Expand Down