Skip to content

Commit

Permalink
add: proof merge func
Browse files Browse the repository at this point in the history
  • Loading branch information
agnxsh committed Feb 28, 2024
1 parent 91ad3dd commit c24f8d4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"editor.detectIndentation": false,
"editor.insertSpaces": true
"nim.nimprettyIndent": 2
}
2 changes: 1 addition & 1 deletion constantine
Submodule constantine updated 41 files
+12 −14 README.md
+0 −27 benchmarks/bench_fields_template.nim
+0 −3 benchmarks/bench_fp.nim
+0 −188 benchmarks/bench_verkle_primitives.nim
+2 −2 constantine-rust/constantine-halo2-zal/Cargo.toml
+2 −2 constantine-rust/constantine-halo2-zal/benches/msm.rs
+5 −3 constantine-rust/constantine-halo2-zal/src/lib.rs
+1 −6 constantine.nimble
+5 −5 constantine/commitments/kzg_polynomial_commitments.nim
+61 −49 constantine/eth_verkle_ipa/barycentric_form.nim
+1 −5 constantine/eth_verkle_ipa/eth_verkle_constants.nim
+3 −151 constantine/eth_verkle_ipa/ipa_prover.nim
+2 −2 constantine/eth_verkle_ipa/ipa_verifier.nim
+2 −102 constantine/eth_verkle_ipa/multiproof.nim
+14 −27 constantine/eth_verkle_ipa/transcript_gen.nim
+1 −7 constantine/ethereum_verkle_trees.nim
+1 −1 constantine/math/arithmetic/finite_fields.nim
+0 −91 constantine/math/arithmetic/finite_fields_square_root.nim
+0 −99 constantine/math/arithmetic/finite_fields_square_root_precomp.nim
+0 −1,488 constantine/math/constants/bandersnatch_sqrt.nim
+0 −1,489 constantine/math/constants/banderwagon_sqrt.nim
+1 −5 constantine/math/constants/zoo_square_roots.nim
+45 −68 constantine/math/elliptic/ec_endomorphism_accel.nim
+1 −1 constantine/math/elliptic/ec_multi_scalar_mul_parallel.nim
+0 −44 constantine/math/elliptic/ec_twistededwards_affine.nim
+0 −19 constantine/math/elliptic/ec_twistededwards_projective.nim
+1 −240 constantine/math_codegen/fields_nvidia.nim
+0 −13 constantine/platforms/code_generator/ir.nim
+0 −7 constantine/platforms/code_generator/nvidia.nim
+4 −5 constantine/platforms/code_generator/nvidia_inlineasm.nim
+2 −8 constantine/platforms/isa/macro_assembler_x86_att.nim
+3 −9 constantine/platforms/isa/macro_assembler_x86_intel.nim
+4 −198 constantine/serialization/codecs_banderwagon.nim
+2 −11 docs/crypto-nvidia_gpus.md
+6 −136 tests/gpu/t_nvidia_fp.nim
+1 −1 tests/math_elliptic_curves/t_ec_sage_template.nim
+0 −181 tests/math_elliptic_curves/t_ec_shortw_prj_edge_case_345.nim
+0 −29 tests/math_elliptic_curves/t_ec_template.nim
+56 −203 tests/t_ethereum_verkle_ipa_primitives.nim
+79 −111 tests/t_ethereum_verkle_ipa_test_helper.nim
+1 −62 tests/t_ethereum_verkle_primitives.nim
28 changes: 20 additions & 8 deletions eth_verkle/ipa/ipa_proof.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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]



67 changes: 67 additions & 0 deletions eth_verkle/ipa/verkle_proof_utils.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c24f8d4

Please sign in to comment.