-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(eth-verkle-ipa): transcript now use a cryptographic sponge-l…
…ike API
- Loading branch information
Showing
11 changed files
with
309 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
constantine/commitments/eth_verkle_inner_product_arguments.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Constantine | ||
# Copyright (c) 2018-2019 Status Research & Development GmbH | ||
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy | ||
# Licensed and distributed under either of | ||
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). | ||
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). | ||
# at your option. This file may not be copied, modified, or distributed except according to those terms. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Constantine | ||
# Copyright (c) 2018-2019 Status Research & Development GmbH | ||
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy | ||
# Licensed and distributed under either of | ||
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). | ||
# * Apache v2 license (license terms in the root directory or at http://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 | ||
../hashes, | ||
../serialization/[endians, codecs_banderwagon], | ||
../math/[arithmetic, ec_twistededwards], | ||
../math/config/curves, | ||
../math/io/io_bigints, | ||
../math_arbitrary_precision/arithmetic/limbs_divmod_vartime, | ||
../platforms/primitives | ||
|
||
# ############################################################ | ||
# | ||
# Transcripts | ||
# | ||
# ############################################################ | ||
|
||
# High-level transcripts designs | ||
# - https://merlin.cool/ | ||
# https://github.com/dalek-cryptography/merlin | ||
# - https://eprint.iacr.org/2023/691 | ||
# | ||
# Practical implementations | ||
# - https://github.com/crate-crypto/verkle-trie-ref/blob/master/ipa/transcript.py | ||
# - https://github.com/zcash/halo2/blob/halo2_proofs-0.3.0/halo2_proofs/src/transcript.rs | ||
# - https://github.com/arkworks-rs/poly-commit/blob/12f5529/poly-commit/src/ipa_pc/mod.rs#L34-L44 | ||
# | ||
# Unfortunately, while the cryptographic sponge-like API to absorb_entropy / squeeze_challenge | ||
# is shared, the actual usage differs significantly: | ||
# - Ethereum verkle trie uses polynomial labels for domain separation | ||
# - Halo2 has no labels | ||
# - arkworks has no labels and does not absorb commitments | ||
# https://github.com/arkworks-rs/poly-commit/issues/140 | ||
# which likely exposes it to Weak Fiat-Shamir attacks. | ||
|
||
func initTranscript*(ctx: var CryptoHash, label: openArray[char]) = | ||
ctx.init() | ||
ctx.update(label) | ||
|
||
func domainSeparator*(ctx: var CryptoHash, label: openArray[char]) = | ||
# A domain separator is used to: | ||
# - Separate between adding elements to the transcript and squeezing elements out | ||
# - Separate sub-protocols | ||
ctx.update(label) | ||
|
||
func absorb*(ctx: var CryptoHash, label: openArray[char], message: openArray[byte]) = | ||
ctx.update(label) | ||
ctx.update(message) | ||
|
||
func absorb*(ctx: var CryptoHash, label: openArray[char], v: uint64) = | ||
ctx.update(label) | ||
ctx.update(v.toBytes(bigEndian)) | ||
|
||
func absorb*(ctx: var CryptoHash, label: openArray[char], point: ECP_TwEdwards[Fp[Banderwagon]]) = | ||
var bytes {.noInit.}: array[32, byte] | ||
bytes.serialize(point) | ||
ctx.absorb(label, bytes) | ||
|
||
func absorb*(ctx: var CryptoHash, label: openArray[char], scalar: Fr[Banderwagon]) = | ||
var bytes {.noInit.}: array[32, byte] | ||
bytes.serialize_fr(scalar, littleEndian) | ||
ctx.absorb(label, bytes) | ||
|
||
func absorb(ctx: var CryptoHash, label: openArray[char], scalar: matchingOrderBigInt(Banderwagon)) = | ||
var bytes {.noInit.}: array[32, byte] | ||
bytes.serialize_scalar(scalar, littleEndian) | ||
ctx.absorb(label, bytes) | ||
|
||
func squeezeChallenge*(ctx: var CryptoHash, label: openArray[char], challenge: var matchingOrderBigInt(Banderwagon)) = | ||
## Generating a challenge based on the Fiat-Shamir transform | ||
ctx.domainSeparator(label) | ||
|
||
# Finalise the transcript state into a hash | ||
var digest {.noInit.}: array[32, byte] | ||
ctx.finish(digest) | ||
|
||
var big {.noInit.}: BigInt[32*8] | ||
big.unmarshal(digest, littleEndian) | ||
discard challenge.reduce_vartime(big, Fr[Banderwagon].fieldMod()) | ||
|
||
# Reset the Transcript state & absorb the freshly generated challenge | ||
ctx.init() | ||
ctx.absorb(label, challenge) | ||
|
||
func squeezeChallenge*(ctx: var CryptoHash, label: openArray[char], challenge: var Fr[Banderwagon]) = | ||
## Generating a challenge based on the Fiat-Shamir transform | ||
var big {.noInit.}: matchingOrderBigInt(Banderwagon) | ||
ctx.squeezeChallenge(label, big) | ||
challenge.fromBig(big) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.