2024-01-17 19:24:34 +00:00
|
|
|
import std/sequtils
|
|
|
|
import std/sugar
|
|
|
|
import std/random
|
|
|
|
import std/strutils
|
|
|
|
|
|
|
|
import pkg/questionable/results
|
|
|
|
import pkg/constantine/math/arithmetic
|
|
|
|
import pkg/constantine/math/io/io_fields
|
|
|
|
import pkg/poseidon2/io
|
|
|
|
import pkg/poseidon2
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/asynctest
|
feat: create logging proxy (#663)
* implement a logging proxy
The logging proxy:
- prevents the need to import chronicles (as well as export except toJson),
- prevents the need to override `writeValue` or use or import nim-json-seralization elsewhere in the codebase, allowing for sole use of utils/json for de/serialization,
- and handles json formatting correctly in chronicles json sinks
* Rename logging -> logutils to avoid ambiguity with common names
* clean up
* add setProperty for JsonRecord, remove nim-json-serialization conflict
* Allow specifying textlines and json format separately
Not specifying a LogFormat will apply the formatting to both textlines and json sinks.
Specifying a LogFormat will apply the formatting to only that sink.
* remove unneeded usages of std/json
We only need to import utils/json instead of std/json
* move serialization from rest/json to utils/json so it can be shared
* fix NoColors ambiguity
Was causing unit tests to fail on Windows.
* Remove nre usage to fix Windows error
Windows was erroring with `could not load: pcre64.dll`. Instead of fixing that error, remove the pcre usage :)
* Add logutils module doc
* Shorten logutils.formatIt for `NBytes`
Both json and textlines formatIt were not needed, and could be combined into one formatIt
* remove debug integration test config
debug output and logformat of json for integration test logs
* Use ## module doc to support docgen
* bump nim-poseidon2 to export fromBytes
Before the changes in this branch, fromBytes was likely being resolved by nim-stew, or other dependency. With the changes in this branch, that dependency was removed and fromBytes could no longer be resolved. By exporting fromBytes from nim-poseidon, the correct resolution is now happening.
* fixes to get compiling after rebasing master
* Add support for Result types being logged using formatIt
2024-01-23 07:35:03 +00:00
|
|
|
import pkg/nimcrypto
|
2024-01-17 19:24:34 +00:00
|
|
|
import pkg/codex/stores/cachestore
|
|
|
|
import pkg/codex/chunker
|
|
|
|
import pkg/codex/stores
|
|
|
|
import pkg/codex/blocktype as bt
|
|
|
|
import pkg/codex/contracts/requests
|
|
|
|
import pkg/codex/contracts
|
|
|
|
import pkg/codex/merkletree
|
|
|
|
import pkg/codex/stores/cachestore
|
|
|
|
|
|
|
|
import pkg/codex/slots/sampler
|
|
|
|
import pkg/codex/slots/builder/builder
|
|
|
|
|
|
|
|
import ../helpers
|
|
|
|
import ../examples
|
|
|
|
import ../merkletree/helpers
|
|
|
|
import testsampler_expected
|
|
|
|
import ./provingtestenv
|
|
|
|
|
|
|
|
asyncchecksuite "Test DataSampler":
|
|
|
|
var
|
|
|
|
env: ProvingTestEnvironment
|
|
|
|
dataSampler: DataSampler
|
|
|
|
blk: bt.Block
|
|
|
|
cell0Bytes: seq[byte]
|
|
|
|
cell1Bytes: seq[byte]
|
|
|
|
cell2Bytes: seq[byte]
|
|
|
|
|
|
|
|
proc createDataSampler(): Future[void] {.async.} =
|
|
|
|
dataSampler = DataSampler.new(
|
|
|
|
datasetSlotIndex,
|
|
|
|
env.localStore,
|
|
|
|
SlotsBuilder.new(env.localStore, env.manifest).tryGet()).tryGet()
|
|
|
|
|
|
|
|
setup:
|
|
|
|
randomize()
|
|
|
|
env = await createProvingTestEnvironment()
|
|
|
|
let bytes = newSeqWith(bytesPerBlock, rand(uint8))
|
|
|
|
blk = bt.Block.new(bytes).tryGet()
|
|
|
|
cell0Bytes = bytes[0..<DefaultCellSize.uint64]
|
|
|
|
cell1Bytes = bytes[DefaultCellSize.uint64..<(DefaultCellSize.uint64*2)]
|
|
|
|
cell2Bytes = bytes[(DefaultCellSize.uint64*2)..<(DefaultCellSize.uint64*3)]
|
|
|
|
|
|
|
|
await createDataSampler()
|
|
|
|
|
|
|
|
teardown:
|
|
|
|
reset(env)
|
|
|
|
reset(dataSampler)
|
|
|
|
|
|
|
|
test "Can get cell from block":
|
|
|
|
let
|
|
|
|
sample0 = dataSampler.getCell(blk.data, 0)
|
|
|
|
sample1 = dataSampler.getCell(blk.data, 1)
|
|
|
|
sample2 = dataSampler.getCell(blk.data, 2)
|
|
|
|
|
|
|
|
check:
|
|
|
|
sample0 == cell0Bytes
|
|
|
|
sample1 == cell1Bytes
|
|
|
|
sample2 == cell2Bytes
|
|
|
|
|
|
|
|
test "Can gather proof input":
|
|
|
|
let
|
|
|
|
nSamples = 3
|
|
|
|
challengeBytes = env.challenge.toBytes()
|
|
|
|
input = (await dataSampler.getProofInput(challengeBytes, nSamples)).tryget()
|
|
|
|
|
|
|
|
proc equal(a: Poseidon2Hash, b: Poseidon2Hash): bool =
|
|
|
|
a.toDecimal() == b.toDecimal()
|
|
|
|
|
|
|
|
proc toStr(proof: Poseidon2Proof): string =
|
|
|
|
let a = proof.path.mapIt(toHex(it))
|
|
|
|
join(a)
|
|
|
|
|
|
|
|
let
|
|
|
|
expectedBlockSlotProofs = getExpectedBlockSlotProofs()
|
|
|
|
expectedCellBlockProofs = getExpectedCellBlockProofs()
|
|
|
|
expectedCellData = getExpectedCellData()
|
|
|
|
expectedProof = env.datasetToSlotTree.getProof(datasetSlotIndex).tryGet()
|
|
|
|
|
|
|
|
check:
|
|
|
|
equal(input.verifyRoot, env.datasetRootHash)
|
|
|
|
equal(input.entropy, env.challenge)
|
|
|
|
input.numCells == ((bytesPerBlock * numberOfSlotBlocks) div DefaultCellSize.int).Natural
|
|
|
|
input.numSlots == totalNumberOfSlots.Natural
|
|
|
|
input.slotIndex == env.slot.slotIndex.truncate(Natural)
|
|
|
|
input.verifyProof == expectedProof
|
|
|
|
|
|
|
|
# block-slot proofs
|
|
|
|
input.samples[0].slotBlockIdx == 2
|
|
|
|
input.samples[1].slotBlockIdx == 2
|
|
|
|
input.samples[2].slotBlockIdx == 0
|
|
|
|
toStr(input.samples[0].slotProof) == expectedBlockSlotProofs[0]
|
|
|
|
toStr(input.samples[1].slotProof) == expectedBlockSlotProofs[1]
|
|
|
|
toStr(input.samples[2].slotProof) == expectedBlockSlotProofs[2]
|
|
|
|
|
|
|
|
# cell-block proofs
|
|
|
|
input.samples[0].blockCellIdx == 26
|
|
|
|
input.samples[1].blockCellIdx == 29
|
|
|
|
input.samples[2].blockCellIdx == 29
|
|
|
|
toStr(input.samples[0].cellProof) == expectedCellBlockProofs[0]
|
|
|
|
toStr(input.samples[1].cellProof) == expectedCellBlockProofs[1]
|
|
|
|
toStr(input.samples[2].cellProof) == expectedCellBlockProofs[2]
|
|
|
|
|
|
|
|
# # cell data
|
feat: create logging proxy (#663)
* implement a logging proxy
The logging proxy:
- prevents the need to import chronicles (as well as export except toJson),
- prevents the need to override `writeValue` or use or import nim-json-seralization elsewhere in the codebase, allowing for sole use of utils/json for de/serialization,
- and handles json formatting correctly in chronicles json sinks
* Rename logging -> logutils to avoid ambiguity with common names
* clean up
* add setProperty for JsonRecord, remove nim-json-serialization conflict
* Allow specifying textlines and json format separately
Not specifying a LogFormat will apply the formatting to both textlines and json sinks.
Specifying a LogFormat will apply the formatting to only that sink.
* remove unneeded usages of std/json
We only need to import utils/json instead of std/json
* move serialization from rest/json to utils/json so it can be shared
* fix NoColors ambiguity
Was causing unit tests to fail on Windows.
* Remove nre usage to fix Windows error
Windows was erroring with `could not load: pcre64.dll`. Instead of fixing that error, remove the pcre usage :)
* Add logutils module doc
* Shorten logutils.formatIt for `NBytes`
Both json and textlines formatIt were not needed, and could be combined into one formatIt
* remove debug integration test config
debug output and logformat of json for integration test logs
* Use ## module doc to support docgen
* bump nim-poseidon2 to export fromBytes
Before the changes in this branch, fromBytes was likely being resolved by nim-stew, or other dependency. With the changes in this branch, that dependency was removed and fromBytes could no longer be resolved. By exporting fromBytes from nim-poseidon, the correct resolution is now happening.
* fixes to get compiling after rebasing master
* Add support for Result types being logged using formatIt
2024-01-23 07:35:03 +00:00
|
|
|
nimcrypto.toHex(input.samples[0].data) == expectedCellData[0]
|
|
|
|
nimcrypto.toHex(input.samples[1].data) == expectedCellData[1]
|
|
|
|
nimcrypto.toHex(input.samples[2].data) == expectedCellData[2]
|