Skip to content

Commit

Permalink
fix(json-abi): correct to_sol for arrays of contracts (alloy-rs#586)
Browse files Browse the repository at this point in the history
* fix(json-abi): correct to_sol for arrays of contracts

* fix

* ci

* ci

* chore: dead codes
  • Loading branch information
DaniPopes authored Mar 25, 2024
1 parent ff33969 commit 525a233
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 31 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@miri
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo miri setup ${{ matrix.flags }}
- run: cargo miri test ${{ matrix.flags }}

wasm:
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/coerce.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{dynamic::ty::as_tuple, DynSolType, DynSolValue, Result};
use alloc::vec::Vec;
use alloy_primitives::{Address, FixedBytes, Function, Sign, I256, U256};
use alloy_primitives::{Address, Function, Sign, I256, U256};
use alloy_sol_types::Word;
use core::fmt;
use hex::FromHexError;
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/dynamic/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{DynSolType, DynSolValue, Error, Result};
use alloc::vec::Vec;
use alloy_primitives::{keccak256, Selector};
use alloy_primitives::Selector;
use alloy_sol_types::SolError;

/// See [alloy_sol_types::Panic] for signature details.
Expand Down
1 change: 1 addition & 0 deletions crates/dyn-abi/src/dynamic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ re-enc: {re_enc}
}

#[test]
#[cfg_attr(miri, ignore = "takes too long")]
fn recursive_dos() {
// https://github.com/alloy-rs/core/issues/490
let payload = "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020";
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/ext/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Specifier<DynSolError> for Error {
}

/// Provides error encoding and decoding for the [`Error`] type.
pub trait ErrorExt: sealed::Sealed {
pub trait ErrorExt: Sealed {
/// Decode the error from the given data.
fn decode_error(&self, data: &[u8]) -> crate::Result<crate::DecodedError>;
}
Expand Down
7 changes: 4 additions & 3 deletions crates/dyn-abi/src/specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This is a simple representation of Solidity type grammar.
use crate::{DynSolEvent, DynSolType, Result};
use crate::{DynSolType, Result};
use alloc::vec::Vec;
use alloy_json_abi::{EventParam, Param};
use parser::{ParameterSpecifier, Parameters, RootType, TupleSpecifier, TypeSpecifier, TypeStem};
Expand All @@ -14,8 +14,9 @@ use alloy_json_abi::InternalType;
/// some Solidity interface item.
///
/// The `Specifier` trait is implemented by types that can be resolved into
/// Solidity interace items, e.g. [`DynSolType`] or [`DynSolEvent`]. ABI and
/// related systems have many different ways of specifying Solidity interfaces.
/// Solidity interace items, e.g. [`DynSolType`] or [`DynSolEvent`](crate::DynSolEvent).
///
/// ABI and related systems have many different ways of specifying Solidity interfaces.
/// This trait provides a single pattern for resolving those encodings into
/// Solidity interface items.
///
Expand Down
4 changes: 4 additions & 0 deletions crates/json-abi/src/internal_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ mod test {
);

parser_test!("contract Item", InternalType::Contract("Item".into()));
parser_test!("contract Item[]", InternalType::Contract("Item[]".into()));
parser_test!("contract Item[][2]", InternalType::Contract("Item[][2]".into()));
parser_test!("contract Item[][2][]", InternalType::Contract("Item[][2][]".into()));

parser_test!(
"address payable",
InternalType::AddressPayable("address payable".to_string())
Expand Down
21 changes: 15 additions & 6 deletions crates/json-abi/src/to_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,28 @@ impl ToSol for EventParam {
}
}

fn param<'a>(
mut type_name: &'a str,
internal_type: Option<&'a InternalType>,
fn param(
type_name: &str,
internal_type: Option<&InternalType>,
indexed: bool,
name: &str,
components: &[Param],
out: &mut SolPrinter<'_>,
) {
let mut type_name = type_name;
let storage;
if let Some(it) = internal_type {
type_name = match it {
InternalType::AddressPayable(_) => "address payable",
InternalType::Contract(_) => "address",
InternalType::Struct { ty, .. }
InternalType::Contract(s) => {
if let Some(start) = s.find('[') {
storage = format!("address{}", &s[start..]);
&storage
} else {
"address"
}
}
InternalType::AddressPayable(ty)
| InternalType::Struct { ty, .. }
| InternalType::Enum { ty, .. }
| InternalType::Other { ty, .. } => ty,
};
Expand Down
Loading

0 comments on commit 525a233

Please sign in to comment.