From 1d652ec2765157c61be81bfcb8fc0332aa689fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20P=C5=99evr=C3=A1til?= Date: Mon, 17 Jun 2024 23:10:29 +0200 Subject: [PATCH 1/2] fix: fixed bytes dyn abi packed encoding --- crates/dyn-abi/src/dynamic/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/dyn-abi/src/dynamic/value.rs b/crates/dyn-abi/src/dynamic/value.rs index b2b15ee1b..dd65c1eee 100644 --- a/crates/dyn-abi/src/dynamic/value.rs +++ b/crates/dyn-abi/src/dynamic/value.rs @@ -677,7 +677,7 @@ impl DynSolValue { Self::Bool(b) => buf.push(*b as u8), Self::String(s) => buf.extend_from_slice(s.as_bytes()), Self::Bytes(bytes) => buf.extend_from_slice(bytes), - Self::FixedBytes(word, size) => buf.extend_from_slice(&word[..(*size).max(32)]), + Self::FixedBytes(word, size) => buf.extend_from_slice(&word[..*size]), Self::Int(num, size) => { let byte_size = *size / 8; let start = 32usize.saturating_sub(byte_size); From 63ecdd42a8da1e77b60e84c11373a48dc28cd95e Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 17 Jun 2024 23:45:05 +0200 Subject: [PATCH 2/2] chore: use min, add tests --- crates/dyn-abi/src/dynamic/ty.rs | 32 +++++++++++++++++++++++++---- crates/dyn-abi/src/dynamic/value.rs | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/dyn-abi/src/dynamic/ty.rs b/crates/dyn-abi/src/dynamic/ty.rs index 2b6d80fe7..d7c64fde4 100644 --- a/crates/dyn-abi/src/dynamic/ty.rs +++ b/crates/dyn-abi/src/dynamic/ty.rs @@ -1108,10 +1108,10 @@ re-enc: {re_enc} assert!( packed == expected, " - type: {ty} - value: {value:?} -packed: {packed} -expect: {expected}", + type: {ty} + value: {value:?} + packed: {packed} +expected: {expected}", packed = hex::encode(packed), expected = hex::encode(expected), ); @@ -1175,6 +1175,30 @@ expect: {expected}", bytes_2("bytes", "0001", "0001"), bytes_3("bytes", "000102", "000102"), + fbytes_1("bytes1", "00", "00"), + fbytes_2("bytes2", "1234", "1234"), + fbytes_3("(address,bytes20)", "(\ + 1111111111111111111111111111111111111111,\ + 2222222222222222222222222222222222222222\ + )", " + 1111111111111111111111111111111111111111 + 2222222222222222222222222222222222222222 + "), + fbytes_4("bytes20[]", "[\ + 1111111111111111111111111111111111111111,\ + 2222222222222222222222222222222222222222\ + ]", " + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + "), + fbytes_5("bytes20[2]", "[\ + 1111111111111111111111111111111111111111,\ + 2222222222222222222222222222222222222222\ + ]", " + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + "), + dynamic_array_of_addresses("address[]", "[\ 1111111111111111111111111111111111111111,\ 2222222222222222222222222222222222222222\ diff --git a/crates/dyn-abi/src/dynamic/value.rs b/crates/dyn-abi/src/dynamic/value.rs index dd65c1eee..fe0100fe0 100644 --- a/crates/dyn-abi/src/dynamic/value.rs +++ b/crates/dyn-abi/src/dynamic/value.rs @@ -677,7 +677,7 @@ impl DynSolValue { Self::Bool(b) => buf.push(*b as u8), Self::String(s) => buf.extend_from_slice(s.as_bytes()), Self::Bytes(bytes) => buf.extend_from_slice(bytes), - Self::FixedBytes(word, size) => buf.extend_from_slice(&word[..*size]), + Self::FixedBytes(word, size) => buf.extend_from_slice(&word[..(*size).min(32)]), Self::Int(num, size) => { let byte_size = *size / 8; let start = 32usize.saturating_sub(byte_size);