diff --git a/.vscode/settings.json b/.vscode/settings.json index c475319..3514bd7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,3 @@ { - "editor.detectIndentation": false, - "editor.insertSpaces": true + "nim.nimprettyIndent": 2 } \ No newline at end of file diff --git a/constantine b/constantine index c7979b0..1edbc23 160000 --- a/constantine +++ b/constantine @@ -1 +1 @@ -Subproject commit c7979b003372b329dd450ff152bb5945cafb0db5 +Subproject commit 1edbc23a7b2cf04ed039f4ba76f0da69229b1f42 diff --git a/eth_verkle/ipa/ipa_proof.nim b/eth_verkle/ipa/ipa_proof.nim index 01a7eef..8f8e117 100644 --- a/eth_verkle/ipa/ipa_proof.nim +++ b/eth_verkle/ipa/ipa_proof.nim @@ -6,16 +6,20 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - ../../../constantine/constantine/[ethereum_verkle_trees, ethereum_verkle_primitives] - -# ######################################################################## + ../../../constantine/constantine/ + [ + ethereum_verkle_trees, + ethereum_verkle_primitives + ], + ../../../constantine/constantine/serialization/[codecs, codecs_banderwagon, codecs_status_codes] + +######################################################################### # # Verkle Proof Types required to Interface Eth Verkle IPA in Constantine # -# ########################################################################\ +######################################################################### -const - IpaProofDepth*: int = 8 +const IpaProofDepth*: int = 8 type IPAProofVkt* = object C_L: array[IpaProofDepth, array[32, byte]] @@ -81,8 +85,16 @@ func loadStateDiff* (res: var StateDiff, inp: StateDiff)= res[i].SuffixDiffsInVKT[j].Suffix = auxSuffix for k in 0 ..< 32: - if inp[i].SuffixDiffsInVKT[j].CurrentVal[k] == fromHex("0x00"): - res[i].SuffixDiffsInVKT[j].CurrentValue + var aux = fromHex(array[1, byte], "0x00") + if inp[i].SuffixDiffsInVKT[j].CurrentVal[k] != aux[0]: + res[i].SuffixDiffsInVKT[j].CurrentVal[k] = aux[0] + res[i].SuffixDiffsInVKT[j].CurrentVal[k] = inp[i].SuffixDiffsInVKT[j].CurrentVal[k] + + for k in 0 ..< 32: + var aux = fromHex(array[1, byte], "0x00") + if inp[i].SuffixDiffsInVKT[j].NewVal[k] != aux[0]: + res[i].SuffixDiffsInVKT[j].NewVal[k] = aux[0] + res[i].SuffixDiffsInVKT[j].NewVal[k] = inp[i].SuffixDiffsInVKT[j].NewVal[k] \ No newline at end of file diff --git a/eth_verkle/ipa/verkle_proof_utils.nim b/eth_verkle/ipa/verkle_proof_utils.nim new file mode 100644 index 0000000..47ce503 --- /dev/null +++ b/eth_verkle/ipa/verkle_proof_utils.nim @@ -0,0 +1,67 @@ +# Nimbus +# Copyright (c) 2021-2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +import + tables, + ../../../constantine/constantine/[ + ethereum_verkle_trees, + ethereum_verkle_primitives + ], + ../../../constantine/constantine/serialization/[ + codecs, codecs_banderwagon, + codecs_status_codes + ], + ../math + +######################################################################### +# +# Verkle Proof Items and it's Utilities +# +######################################################################### + +type ProofElements* = object + Cis*: var seq[EC_P] + Zis*: var seq[byte] + Yis*: var seq[Field] + Fis*: var seq[seq[Field]] + CommByPath*: var Table[string, EC_P] + Vals*: seq[seq[byte]] + cisZisTup*: var Table[EC_P, Table[uint8, bool]] + +######################################################################### +# +# Utilities to Merge Proof Items +# +######################################################################### + +func mergeProofElements* (res: var ProofElements, other: var ProofElements)= + if res.cisZisTup.len == 0: + for i, ci in res.Cis: + if not res.cisZisTup.hasKey(ci): + res.cisZisTup[ci] = initTable[uint8, bool]() + res.cisZisTup[ci][res.Zis[i]] = true + + for i, ci in other.Cis: + + if not res.cisZisTup.hasKey(ci): + res.cisZisTup[ci] = initTable[byte, bool]() + + if res.cisZisTup[ci].hasKey(other.Zis[i]): + continue + + res.cisZisTup[ci][other.Zis[i]] = true + res.Cis.add(ci) + res.Zis.add(other.Zis[i]) + + if res.Fis.len > 0: + res.Fis.add(other.Fis[i]) + + for path, c in other.CommByPath.pairs(): + if not res.CommByPath.hasKey(path): + res.CommByPath[path] = c + + res.Vals.add(other.Vals)