|
1 | 1 | package witness
|
2 | 2 |
|
3 |
| -// setExtNodeSelectors sets in the branch init row the information about the extension node. |
4 |
| -func setExtNodeSelectors(row, proofEl []byte, numberOfNibbles int, branchC16 byte) { |
5 |
| - row[isExtensionPos] = 1 |
6 |
| - if len(proofEl) > 56 { // 56 because there is 1 byte for length |
7 |
| - // isCExtLongerThan55 doesn't need to be set here |
8 |
| - row[isSExtLongerThan55Pos] = 1 |
9 |
| - } |
10 |
| - |
11 |
| - if len(proofEl) < 32 { |
12 |
| - // isExtNodeSNonHashed doesn't need to be set here |
13 |
| - row[isExtNodeSNonHashedPos] = 1 |
14 |
| - } |
15 |
| - |
16 |
| - if numberOfNibbles == 1 { |
17 |
| - if branchC16 == 1 { |
18 |
| - row[isExtShortC16Pos] = 1 |
19 |
| - } else { |
20 |
| - row[isExtShortC1Pos] = 1 |
21 |
| - } |
22 |
| - } else { |
23 |
| - if numberOfNibbles%2 == 0 { |
24 |
| - if branchC16 == 1 { |
25 |
| - row[isExtLongEvenC16Pos] = 1 |
26 |
| - } else { |
27 |
| - row[isExtLongEvenC1Pos] = 1 |
28 |
| - } |
29 |
| - } else { |
30 |
| - if branchC16 == 1 { |
31 |
| - row[isExtLongOddC16Pos] = 1 |
32 |
| - } else { |
33 |
| - row[isExtLongOddC1Pos] = 1 |
34 |
| - } |
35 |
| - } |
36 |
| - } |
37 |
| -} |
38 |
| - |
39 |
| -func prepareEmptyExtensionRows(beforeModification, afterModification bool) [][]byte { |
40 |
| - ext_row1 := make([]byte, rowLen) |
41 |
| - ext_row2 := make([]byte, rowLen) |
42 |
| - if !beforeModification && !afterModification { |
43 |
| - ext_row1 = append(ext_row1, 16) |
44 |
| - ext_row2 = append(ext_row2, 17) |
45 |
| - } else if beforeModification { |
46 |
| - ext_row1 = append(ext_row1, 20) |
47 |
| - ext_row2 = append(ext_row2, 21) |
48 |
| - } else if afterModification { |
49 |
| - ext_row1 = append(ext_row1, 22) |
50 |
| - ext_row2 = append(ext_row2, 23) |
51 |
| - } |
52 |
| - |
53 |
| - return [][]byte{ext_row1, ext_row2} |
54 |
| -} |
55 |
| - |
56 |
| -// TODO: remove when Nodes are fully implemented |
57 |
| -func prepareExtensionRows(extNibbles [][]byte, extensionNodeInd int, proofEl1, proofEl2 []byte, beforeModification, afterModification bool) (byte, []byte, []byte) { |
58 |
| - var extensionRowS []byte |
59 |
| - var extensionRowC []byte |
60 |
| - |
61 |
| - extRows := prepareEmptyExtensionRows(beforeModification, afterModification) |
62 |
| - extensionRowS = extRows[0] |
63 |
| - extensionRowC = extRows[1] |
64 |
| - prepareExtensionRow(extensionRowS, proofEl1, true) |
65 |
| - prepareExtensionRow(extensionRowC, proofEl2, false) |
66 |
| - |
67 |
| - evenNumberOfNibbles := proofEl1[2] == 0 |
68 |
| - keyLen := getExtensionNodeKeyLen(proofEl1) |
69 |
| - numberOfNibbles := getExtensionNumberOfNibbles(proofEl1) |
70 |
| - |
71 |
| - // We need nibbles as witness to compute key RLC, so we set them |
72 |
| - // into extensionRowC s_advices (we can do this because both extension |
73 |
| - // nodes have the same key, so we can have this info only in one). |
74 |
| - // There can be more up to 64 nibbles, but there is only 32 bytes |
75 |
| - // in extensionRowC s_advices. So we store every second nibble (having |
76 |
| - // the whole byte and one nibble is enough to compute the other nibble). |
77 |
| - startNibblePos := 2 // we don't need any nibbles for case keyLen = 1 |
78 |
| - if keyLen > 1 { |
79 |
| - if evenNumberOfNibbles { |
80 |
| - startNibblePos = 1 |
81 |
| - } else { |
82 |
| - startNibblePos = 2 |
83 |
| - } |
84 |
| - } |
85 |
| - ind := 0 |
86 |
| - for j := startNibblePos; j < len(extNibbles[extensionNodeInd]); j += 2 { |
87 |
| - extensionRowC[branchNodeRLPLen+ind] = |
88 |
| - extNibbles[extensionNodeInd][j] |
89 |
| - ind++ |
90 |
| - } |
91 |
| - |
92 |
| - return numberOfNibbles, extensionRowS, extensionRowC |
93 |
| -} |
94 |
| - |
95 | 3 | func prepareExtensions(extNibbles [][]byte, extensionNodeInd int, proofEl1, proofEl2 []byte) (byte, []byte, [][]byte) {
|
96 | 4 | var values [][]byte
|
97 | 5 | v1 := make([]byte, valueLen)
|
@@ -197,77 +105,6 @@ func getExtensionNodeNibbles(proofEl []byte) []byte {
|
197 | 105 | return nibbles
|
198 | 106 | }
|
199 | 107 |
|
200 |
| -// TODO: remove when Nodes are fully implemented |
201 |
| -func prepareExtensionRow(witnessRow, proofEl []byte, setKey bool) { |
202 |
| - // storageProof[i]: |
203 |
| - // [228,130,0,149,160,114,253,150,133,18,192,156,19,241,162,51,210,24,1,151,16,48,7,177,42,60,49,34,230,254,242,79,132,165,90,75,249] |
204 |
| - // Note that the first element (228 in this case) can go much higher - for example, if there |
205 |
| - // are 40 nibbles, this would take 20 bytes which would make the first element 248. |
206 |
| - |
207 |
| - // If only one nibble in key: |
208 |
| - // [226,16,160,172,105,12... |
209 |
| - // Could also be non-hashed branch: |
210 |
| - // [223,16,221,198,132,32,0,0,0,1,198,132,32,0,0,0,1,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128] |
211 |
| - |
212 |
| - // Extension node with non-hashed branch: |
213 |
| - // List contains up to 55 bytes (192 + 55) |
214 |
| - // [247,160,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,213,128,194,32,1,128,194,32,1,128,128,128,128,128,128,128,128,128,128,128,128,128] |
215 |
| - |
216 |
| - // List contains more than 55 bytes |
217 |
| - // [248,58,159,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,217,128,196,130,32,0,1,128,196,130,32,0,1,128,128,128,128,128,128,128,128,128,128,128,128,128] |
218 |
| - |
219 |
| - // Note that the extension node can be much shorter than the one above - in case when |
220 |
| - // there are less nibbles, so we cannot say that 226 appears as the first byte only |
221 |
| - // when there are hashed nodes in the branch and there is only one nibble. |
222 |
| - // Branch with two non-hashed nodes (that's the shortest possible branch): |
223 |
| - // [217,128,196,130,32,0,1,128,196,130,32,0,1,128,128,128,128,128,128,128,128,128,128,128,128,128] |
224 |
| - // Note: branch contains at least 26 bytes. 192 + 26 = 218 |
225 |
| - |
226 |
| - /* |
227 |
| - If proofEl[0] <= 247 (length at most 55, so proofEl[1] doesn't specify the length of the whole |
228 |
| - remaining stream, only of the next substream) |
229 |
| - If proofEl[1] <= 128: |
230 |
| - There is only 1 byte for nibbles (keyLen = 1) and this is proofEl[1]. |
231 |
| - Else: |
232 |
| - Nibbles are stored in more than 1 byte, proofEl[1] specifies the length of bytes. |
233 |
| - Else: |
234 |
| - proofEl[1] contains the length of the remaining stream. |
235 |
| - proofEl[2] specifies the length of the bytes (for storing nibbles). |
236 |
| - Note that we can't have only one nibble in this case. |
237 |
| - */ |
238 |
| - |
239 |
| - if setKey { |
240 |
| - witnessRow[0] = proofEl[0] |
241 |
| - witnessRow[1] = proofEl[1] |
242 |
| - } |
243 |
| - |
244 |
| - lenKey, startKey := getExtensionLenStartKey(proofEl) |
245 |
| - if startKey == 3 { |
246 |
| - witnessRow[2] = proofEl[2] |
247 |
| - } |
248 |
| - |
249 |
| - if setKey { |
250 |
| - for j := 0; j < lenKey; j++ { |
251 |
| - witnessRow[startKey+j] = proofEl[startKey+j] |
252 |
| - } |
253 |
| - } |
254 |
| - |
255 |
| - encodedNodeLen := proofEl[startKey+lenKey] |
256 |
| - nodeLen := byte(0) |
257 |
| - start := branch2start |
258 |
| - if encodedNodeLen > 192 { |
259 |
| - // we have a list, that means a non-hashed node |
260 |
| - nodeLen = encodedNodeLen - 192 |
261 |
| - } else if encodedNodeLen == 160 { |
262 |
| - // hashed-node |
263 |
| - nodeLen = encodedNodeLen - 128 |
264 |
| - } |
265 |
| - witnessRow[start] = encodedNodeLen |
266 |
| - for j := 0; j < int(nodeLen); j++ { |
267 |
| - witnessRow[start+1+j] = proofEl[startKey+lenKey+1+j] |
268 |
| - } |
269 |
| -} |
270 |
| - |
271 | 108 | func prepareExtension(v1, v2, proofEl []byte, setKey bool) []byte {
|
272 | 109 | // storageProof[i]:
|
273 | 110 | // [228,130,0,149,160,114,253,150,133,18,192,156,19,241,162,51,210,24,1,151,16,48,7,177,42,60,49,34,230,254,242,79,132,165,90,75,249]
|
|
0 commit comments