Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Known Addresses v3: dataDecoded (#372)
Browse files Browse the repository at this point in the history
* Naive implementation not covering multiSend fixed tests

* Added unit tests with expected business logic

* Added simplest case test

* Added test for array_value

* Added skip for duplicate and 0x0 values

* Added test for empty result

* Added test and implementation for multisig. Multisig with nesting still needed

* Added json for a multiSend nested in another multiSend

* Doctored json in order to test that we reaaally don't call info_provider for nested addresses in nested multiSends

* Added feature flag
  • Loading branch information
jpalvarezl authored May 5, 2021
1 parent e9cf668 commit 4634ced
Show file tree
Hide file tree
Showing 10 changed files with 580 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ pub fn redis_scan_count() -> usize {
usize_with_default("REDIS_SCAN_COUNT", 300)
}

pub fn feature_flag_nested_decoding() -> bool {
bool_with_default("FEATURE_FLAG_NESTED_DECODING", true)
}

pub fn build_number() -> Option<String> {
option_env!("BUILD_NUMBER").map(|it| it.to_string())
}
Expand Down
72 changes: 72 additions & 0 deletions src/json/commons/DOCTORED_data_decoded_nested_multi_sends.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"method": "multiSend",
"parameters": [
{
"name": "transactions",
"type": "bytes",
"value": "0x0084fd13abadf6f5f6c20f5482f264b71f353cc22d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000084fd13abadf6f5f6c20f5482f264b71f353cc22d0000000000000000000000000000000000000000000000000000000000bc614e0068881260bd04e9dac7f77a314360ce05435b4818000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e48d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000990084fd13abadf6f5f6c20f5482f264b71f353cc22d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000084fd13abadf6f5f6c20f5482f264b71f353cc22d0000000000000000000000000000000000000000000000000000000000bc614e00000000000000",
"valueDecoded": [
{
"operation": 0,
"to": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"value": "0",
"data": "0xa9059cbb00000000000000000000000084fd13abadf6f5f6c20f5482f264b71f353cc22d0000000000000000000000000000000000000000000000000000000000bc614e",
"dataDecoded": {
"method": "transfer",
"parameters": [
{
"name": "to",
"type": "address",
"value": "0x991c44331f0E59510Bcff76edBA06C3f552Eef8B"
},
{
"name": "value",
"type": "uint256",
"value": "12345678"
}
]
}
},
{
"operation": 0,
"to": "0x68881260bd04E9dAc7F77a314360ce05435B4818",
"value": "0",
"data": "0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000990084fd13abadf6f5f6c20f5482f264b71f353cc22d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000084fd13abadf6f5f6c20f5482f264b71f353cc22d0000000000000000000000000000000000000000000000000000000000bc614e00000000000000",
"dataDecoded": {
"method": "multiSend",
"parameters": [
{
"name": "transactions",
"type": "bytes",
"value": "0x0084fd13abadf6f5f6c20f5482f264b71f353cc22d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000084fd13abadf6f5f6c20f5482f264b71f353cc22d0000000000000000000000000000000000000000000000000000000000bc614e",
"valueDecoded": [
{
"operation": 0,
"to": "0x84fd13aBadF6F5F6c20F5482F264b71F353cc22d",
"value": "0",
"data": "0xa9059cbb00000000000000000000000084fd13abadf6f5f6c20f5482f264b71f353cc22d0000000000000000000000000000000000000000000000000000000000bc614e",
"dataDecoded": {
"method": "transfer",
"parameters": [
{
"name": "to",
"type": "address",
"value": "0x84fd13aBadF6F5F6c20F5482F264b71F353cc22d"
},
{
"name": "value",
"type": "uint256",
"value": "12345678"
}
]
}
}
]
}
]
}
}
]
}
]
}
2 changes: 2 additions & 0 deletions src/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub const DATA_DECODED_SWAP_ARRAY_VALUES: &str =
include_str!("commons/data_decoded_swap_array_values.json");
pub const DATA_DECODED_MULTI_SEND_SINGLE_INNER_TRANSACTION: &str =
include_str!("commons/data_decoded_multi_send_single_inner_transaction.json");
pub const DOCTORED_DATA_DECODED_NESTED_MULTI_SENDS: &str =
include_str!("commons/DOCTORED_data_decoded_nested_multi_sends.json");

pub const BALANCE_ETHER: &str = include_str!("balances/balance_ether.json");
pub const BALANCE_COMPOUND_ETHER: &str = include_str!("balances/balance_compound_ether.json");
Expand Down
88 changes: 86 additions & 2 deletions src/models/converters/data_decoded.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::models::commons::DataDecoded;
use crate::config::feature_flag_nested_decoding;
use crate::models::commons::{DataDecoded, ParamValue, Parameter, ValueDecodedType};
use crate::models::service::transactions::SettingsInfo;
use crate::providers::address_info::AddressInfo;
use crate::providers::info::InfoProvider;
use crate::utils::{
ADD_OWNER_WITH_THRESHOLD, CHANGE_MASTER_COPY, CHANGE_THRESHOLD, DISABLE_MODULE, ENABLE_MODULE,
REMOVE_OWNER, SET_FALLBACK_HANDLER, SWAP_OWNER,
MULTI_SEND, MULTI_SEND_TRANSACTIONS_PARAM, REMOVE_OWNER, SET_FALLBACK_HANDLER, SWAP_OWNER,
};
use std::collections::HashMap;

impl DataDecoded {
pub(super) fn to_settings_info(
Expand Down Expand Up @@ -73,3 +76,84 @@ impl DataDecoded {
}
}
}

impl DataDecoded {
pub(super) fn build_address_info_index(
&self,
info_provider: &mut impl InfoProvider,
) -> Option<HashMap<String, AddressInfo>> {
if !feature_flag_nested_decoding() {
return None;
}

let mut index = HashMap::new();
if self.method == MULTI_SEND {
if let Some(value_decoded_type) =
&self.get_parameter_value_decoded(MULTI_SEND_TRANSACTIONS_PARAM)
{
match value_decoded_type {
ValueDecodedType::InternalTransaction(transactions) => {
transactions.iter().for_each(|transaction| {
insert_value_into_index(&transaction.to, &mut index, info_provider);
put_parameter_into_index(
&transaction
.data_decoded
.as_ref()
.map(|it| it.parameters.to_owned())
.flatten(),
&mut index,
info_provider,
)
})
}
}
}
} else {
put_parameter_into_index(&self.parameters, &mut index, info_provider);
}
if index.is_empty() {
None
} else {
Some(index)
}
}
}

fn put_parameter_into_index(
parameters: &Option<Vec<Parameter>>,
index: &mut HashMap<String, AddressInfo>,
info_provider: &mut impl InfoProvider,
) {
if let Some(parameters) = parameters {
for parameter in parameters {
match &parameter.value {
ParamValue::SingleValue(value) => {
insert_value_into_index(value, index, info_provider)
}
ParamValue::ArrayValue(values) => {
for value in values {
if let ParamValue::SingleValue(value) = value {
insert_value_into_index(value, index, info_provider)
}
}
}
}
}
}
}

fn insert_value_into_index(
value: &String,
index: &mut HashMap<String, AddressInfo>,
info_provider: &mut impl InfoProvider,
) {
if value.len() == 42
&& value.starts_with("0x")
&& value != "0x0000000000000000000000000000000000000000"
&& !index.contains_key(value)
{
if let Some(address_info) = info_provider.full_address_info_search(&value).ok() {
index.insert(value.to_owned(), address_info);
};
}
}
Loading

0 comments on commit 4634ced

Please sign in to comment.