From fd0cfdfd49335a5e986d290f8ad468577f7c25cf Mon Sep 17 00:00:00 2001 From: Vineet Pant <10172895+vineetpant@users.noreply.github.com> Date: Mon, 28 Jul 2025 11:34:40 +0530 Subject: [PATCH 1/3] update Log type for LogIndex --- eth.nimble | 3 ++- eth/common/receipts.nim | 13 +++++++++---- eth/rlp.nim | 10 +++++++++- eth/rlp/writer.nim | 9 ++++++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/eth.nimble b/eth.nimble index b080720f..da690812 100644 --- a/eth.nimble +++ b/eth.nimble @@ -21,7 +21,8 @@ requires "nim >= 2.0.10", "unittest2", "results", "minilru", - "snappy" + "snappy", + "ssz_serialization" let nimc = getEnv("NIMC", "nim") # Which nim compiler to use let lang = getEnv("NIMLANG", "c") # Which backend (c/cpp/js) diff --git a/eth/common/receipts.nim b/eth/common/receipts.nim index 659f9c12..d10df1e8 100644 --- a/eth/common/receipts.nim +++ b/eth/common/receipts.nim @@ -9,18 +9,23 @@ import ./[addresses, base, hashes, transactions], - ../bloom + ../bloom, + ssz_serialization export addresses, base, hash, transactions +const + MAX_TOPICS_PER_LOG* = 4 + MAX_LOG_DATA_SIZE* = 1 shl 24 + type Topic* = Bytes32 # topic can be Hash32 or zero padded bytes array Log* = object - address*: Address - topics*: seq[Topic] - data*: seq[byte] + address*: Address + topics*: List[Topic, MAX_TOPICS_PER_LOG] + data*: ByteList[MAX_LOG_DATA_SIZE] # easily convertible between # ReceiptType and TxType diff --git a/eth/rlp.nim b/eth/rlp.nim index 81370a1b..cd52357b 100644 --- a/eth/rlp.nim +++ b/eth/rlp.nim @@ -14,7 +14,8 @@ import stew/[byteutils, shims/macros], results, ./rlp/[writer, object_serialization], - ./rlp/priv/defs + ./rlp/priv/defs, + ssz_serialization from stew/objects import checkedEnumAssign @@ -420,6 +421,13 @@ func readImpl[R, E](rlp: var Rlp, T: type array[R, E]): T = rlp.positionAfter(item) +func readImpl*[E; N: static[int]](rlp: var Rlp, T: type List[E, N]): List[E, N] = + mixin read + T.init(rlp.read(seq[E])) + +func readImpl*[N: static[int]](rlp: var Rlp, T: type ByteList[N]): ByteList[N] = + T.init(rlp.read(seq[byte])) + func readImpl[E](rlp: var Rlp, T: type seq[E]): T = mixin read let item = rlp.item() diff --git a/eth/rlp/writer.nim b/eth/rlp/writer.nim index 5582f00d..e0ed260f 100644 --- a/eth/rlp/writer.nim +++ b/eth/rlp/writer.nim @@ -16,7 +16,8 @@ import default_writer, utils, stint, - ../common/hashes + ../common/hashes, + ssz_serialization export arraybuf, default_writer, length_writer, two_pass_writer, hash_writer @@ -43,6 +44,12 @@ proc appendInt(self: var RlpWriter, i: SomeUnsignedInt) = template appendImpl(self: var RlpWriter, data: openArray[byte]) = self.appendBlob(data) +template appendImpl*[T; N: static[int]](self: var RlpWriter, data: List[T, N]) = + self.append(data.asSeq) + +template appendImpl*[N: static[int]](self: var RlpWriter, data: ByteList[N]) = + self.appendRawBytes(data.asSeq) + template appendImpl(self: var RlpWriter, data: openArray[char]) = self.appendBlob(data.toOpenArrayByte(0, data.high)) From 9b165d71dbbbb71b449e372a7936eff57d741bdf Mon Sep 17 00:00:00 2001 From: Vineet Pant <10172895+vineetpant@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:07:05 +0530 Subject: [PATCH 2/3] fix type error for Log changes --- eth/common/ssz_utils.nim | 12 ++++++++++++ tests/common/test_common.nim | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 eth/common/ssz_utils.nim diff --git a/eth/common/ssz_utils.nim b/eth/common/ssz_utils.nim new file mode 100644 index 00000000..66a792c1 --- /dev/null +++ b/eth/common/ssz_utils.nim @@ -0,0 +1,12 @@ +import ssz_serialization + +proc `==`*[T; N: static[int]](a, b: List[T, N]): bool = + if a.len != b.len: # compare length first + return false + for i in 0.. Date: Sat, 25 Oct 2025 15:38:19 +0530 Subject: [PATCH 3/3] fix: IndexDefect crash with SSZ List[T, N] RLP encoding --- eth/rlp/writer.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/eth/rlp/writer.nim b/eth/rlp/writer.nim index e0ed260f..de597e93 100644 --- a/eth/rlp/writer.nim +++ b/eth/rlp/writer.nim @@ -86,6 +86,13 @@ proc countNestedListsDepth(T: type): int {.compileTime.} = when T is Option or T is Opt: result += countNestedListsDepth(innerType(dummy)) + elif T is List: + # Handle SSZ List[T, N] types - safely count depth without using elementType + inc result + # For SSZ List, we know it's one level of list nesting, but we can't safely + # access the element type here due to compilation issues, so we assume + # simple element types (like Hash32) which don't add additional depth + discard elif T is UInt256: discard elif T is object or T is tuple: @@ -98,6 +105,10 @@ proc countNestedListsDepth(T: type): int {.compileTime.} = proc countNestedListsDepth[E](T: type openArray[E]): int = countNestedListsDepth(seq[E]) +# Specialized overload for SSZ List types +proc countNestedListsDepth[T; N: static[int]](L: type List[T, N]): int = + 1 + countNestedListsDepth(T) + proc countOptionalFields(T: type): int {.compileTime.} = mixin enumerateRlpFields