From 85cfe2dad196c67a58981047124aee154c797ce5 Mon Sep 17 00:00:00 2001 From: KimiWu Date: Mon, 15 Apr 2024 11:21:43 +0800 Subject: [PATCH] fix: drifted pos cal. --- geth-utils/gethutil/mpt/witness/branch.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/geth-utils/gethutil/mpt/witness/branch.go b/geth-utils/gethutil/mpt/witness/branch.go index 13ba11dce2..a3560ce9e1 100644 --- a/geth-utils/gethutil/mpt/witness/branch.go +++ b/geth-utils/gethutil/mpt/witness/branch.go @@ -203,12 +203,15 @@ func getNibbles(leafKeyRow []byte) []byte { nibbles = append(nibbles, leafKeyRow[1]-16) } } else { - keyLen := int(leafKeyRow[2] - 128) - if (leafKeyRow[3] != 32) && (leafKeyRow[3] != 0) { // second term is for extension node - if leafKeyRow[3] < 32 { // extension node - nibbles = append(nibbles, leafKeyRow[3]-16) + // [248 202 48 184 199 248 197 128 131 4 147 224 98 148 0 ...] + // `202` (leafKeyRow[1]) is the length of the payload + // `48` (leafKeyRow[2]) is the first byte of the payload + keyLen := int(leafKeyRow[1] - 128) + if (leafKeyRow[2] != 32) && (leafKeyRow[2] != 0) { // second term is for extension node + if leafKeyRow[2] < 32 { // extension node + nibbles = append(nibbles, leafKeyRow[2]-16) } else { // leaf - nibbles = append(nibbles, leafKeyRow[3]-48) + nibbles = append(nibbles, leafKeyRow[2]-48) } } for i := 0; i < keyLen-1; i++ { // -1 because the first byte doesn't have any nibbles