Fixes issue where sampler takes proof from dataset/verify tree for slot proof.

This commit is contained in:
benbierens 2024-01-16 13:22:31 +01:00 committed by Dmitriy Ryajov
parent 622239ffbd
commit d80ddd41df
2 changed files with 12 additions and 14 deletions

View File

@ -37,12 +37,13 @@ type
Sample* = object
data*: Cell
proof*: Poseidon2Proof
slotProof*: Poseidon2Proof
cellProof*: Poseidon2Proof
ProofInput* = object
entropy*: Poseidon2Hash
verifyRoot*: Poseidon2Hash
slotProof*: Poseidon2Proof
verifyProof*: Poseidon2Proof
numSlots*: Natural
numCells*: Natural
slotIndex*: Natural
@ -88,16 +89,15 @@ proc getProofInput*(
return failure("Failed to parse entropy")
without verifyTree =? self.builder.verifyTree and
slotProof =? verifyTree.getProof(self.index) and
verifyProof =? verifyTree.getProof(self.index) and
verifyRoot =? verifyTree.root(), err:
error "Failed to get slot proof from verify tree", err = err.msg
return failure(err)
let
treeCid = self.builder.manifest.treeCid
slotTreeCid = self.builder.manifest.slotRoots[self.index]
cellIdxs = entropy.cellIndices(
self.builder.slotRoots[self.index],
self.builder.slotIndicies(self.index),
self.builder.numSlotCells,
nSamples)
@ -105,7 +105,7 @@ proc getProofInput*(
index = self.index
samples = nSamples
cells = cellIdxs
treeCid = treeCid
slotTreeCid = slotTreeCid
trace "Collecting input for proof"
let samples = collect(newSeq):
@ -119,8 +119,8 @@ proc getProofInput*(
blockIdx = blockIdx
blkCellIdx = blkCellIdx
without (cid, _) =? await self.blockStore.getCidAndProof(
self.builder.manifest.treeCid,
without (cid, slotProof) =? await self.blockStore.getCidAndProof(
slotTreeCid,
blockIdx.Natural), err:
error "Failed to get block from block store", err = err.msg
return failure(err)
@ -135,12 +135,12 @@ proc getProofInput*(
let cellData = self.getCell(bytes, blkCellIdx)
Sample(data: cellData, proof: blockProof)
Sample(data: cellData, slotProof: slotProof, cellProof: blockProof)
success ProofInput(
entropy: entropy,
verifyRoot: verifyRoot,
slotProof: slotProof,
verifyProof: verifyProof,
numSlots: self.builder.numSlots,
numCells: self.builder.numSlotCells,
slotIndex: self.index,

View File

@ -17,7 +17,7 @@ import pkg/constantine/math/arithmetic
import ../../merkletree
func extractLowBits[n: static int](elm: BigInt[n], k: int): uint64 =
func extractLowBits*[n: static int](elm: BigInt[n], k: int): uint64 =
assert( k > 0 and k <= 64 )
var r = 0'u64
for i in 0..<k:
@ -72,11 +72,9 @@ func cellIndex*(
func cellIndices*(
entropy: Poseidon2Hash,
slotRoot: Poseidon2Hash,
validIdxs: seq[int],
numCells: Natural, nSamples: Natural): seq[Natural] =
var indices: seq[int]
while (indices.len < nSamples):
let idx = entropy.cellIndex(slotRoot, numCells, indices.len + 1)
if idx.toBlockIdx(numCells) in validIdxs:
indices.add(idx)
indices.add(idx)