From b67de6b2eb3ca4ee7980a1cc6759100f982aea53 Mon Sep 17 00:00:00 2001 From: Rory Neithinger Date: Wed, 21 Aug 2024 22:52:52 -0700 Subject: [PATCH 1/3] Fix off-by-one error when string len is 32 --- stylus-sdk/src/storage/bytes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stylus-sdk/src/storage/bytes.rs b/stylus-sdk/src/storage/bytes.rs index c142df4..55f14b5 100644 --- a/stylus-sdk/src/storage/bytes.rs +++ b/stylus-sdk/src/storage/bytes.rs @@ -216,7 +216,7 @@ impl StorageBytes { /// Determines the slot and offset for the element at an index. fn index_slot(&self, index: usize) -> (U256, u8) { let slot = match self.len() { - 33.. => self.base() + U256::from(index / 32), + 32.. => self.base() + U256::from(index / 32), _ => self.root, }; (slot, (index % 32) as u8) From 748744bfb8d951aab9f3c39f4aceb4242a138082 Mon Sep 17 00:00:00 2001 From: Rory Neithinger Date: Fri, 2 Aug 2024 12:29:03 -0700 Subject: [PATCH 2/3] Fix Bytes type for export-abi --- stylus-sdk/src/abi/export/internal.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stylus-sdk/src/abi/export/internal.rs b/stylus-sdk/src/abi/export/internal.rs index 129183a..a182e3f 100644 --- a/stylus-sdk/src/abi/export/internal.rs +++ b/stylus-sdk/src/abi/export/internal.rs @@ -4,9 +4,12 @@ //! This module provides functions for code generated by `stylus-sdk-proc` for the `export-abi` command. //! Most users shouldn't call these. -use alloy_primitives::{Address, FixedBytes, Signed, Uint}; use core::any::TypeId; +use alloy_primitives::{Address, FixedBytes, Signed, Uint}; + +use crate::abi::Bytes; + /// Represents a unique Solidity Type. pub struct InnerType { /// Full interface string. @@ -58,7 +61,7 @@ macro_rules! impl_inner { }; } -impl_inner!(bool u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 String Address); +impl_inner!(bool u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 String Address Bytes); impl InnerTypes for Uint {} impl InnerTypes for Signed {} From ee3ef0536d12311ac0bbc891b648607b43de913c Mon Sep 17 00:00:00 2001 From: Rory Neithinger Date: Wed, 21 Aug 2024 22:20:03 -0700 Subject: [PATCH 3/3] Fix return encoding for sequence types --- stylus-sdk/src/abi/internal.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stylus-sdk/src/abi/internal.rs b/stylus-sdk/src/abi/internal.rs index 4c8e7ba..ade2505 100644 --- a/stylus-sdk/src/abi/internal.rs +++ b/stylus-sdk/src/abi/internal.rs @@ -21,9 +21,7 @@ where #[inline(always)] fn encode(self) -> ArbResult { // coerce types into a tuple of at least 1 element - Ok(<(::SolType,) as SolType>::abi_encode( - &(self,), - )) + Ok(<::SolType>::abi_encode(&self)) } }