Skip to content

Commit 9138c0e

Browse files
committed
Replace poseidon2 F type with int as temporary stand-in for verification hashes
1 parent 7f28e98 commit 9138c0e

File tree

2 files changed

+31
-56
lines changed

2 files changed

+31
-56
lines changed

codex/manifest/types.nim

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
# This module defines Manifest and all related types
1111

1212
import std/tables
13+
import std/strutils
1314
import pkg/libp2p
14-
import pkg/constantine/math/io/io_fields
15-
import pkg/poseidon2
1615

1716
import ../units
1817
export units
19-
export curves # workaround for "undeclared identifier: 'getCurveOrder'" from constantine
2018

2119
const
2220
BlockCodec* = multiCodec("raw")
@@ -25,21 +23,23 @@ const
2523
type
2624
ManifestCoderType*[codec: static MultiCodec] = object
2725
DagPBCoder* = ManifestCoderType[multiCodec("dag-pb")]
28-
VerificationHash* = F
26+
VerificationHash* = int
27+
# TODO: Replace this with a wrapper type that supports Poseidon2
28+
# and is can be encoded/decoded, AND is JSON-serializable
2929

3030
const
3131
ManifestContainers* = {
3232
$DagPBCodec: DagPBCoder()
3333
}.toTable
3434

35-
proc `==`*(a, b: VerificationHash): bool =
36-
a.toHex() == b.toHex()
37-
3835
proc fromInt*(T: type VerificationHash, value: SomeInteger | SomeUnsignedInt): VerificationHash =
39-
toF(value)
36+
value.int
4037

4138
proc encode*(a: VerificationHash): string =
42-
a.toHex()
39+
$a
4340

4441
proc decode*(T: type VerificationHash, str: string): VerificationHash =
45-
F.fromHex(str)
42+
try:
43+
parseInt(str)
44+
except ValueError:
45+
0

tests/codex/testmanifest.nim

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,37 @@ import ./helpers
1111
import ./examples
1212

1313
checksuite "Manifest":
14-
test "Should encode/decode to/from base manifest":
15-
var
16-
manifest = Manifest.new(
17-
treeCid = Cid.example,
18-
blockSize = 1.MiBs,
19-
datasetSize = 100.MiBs)
20-
21-
let
22-
e = manifest.encode().tryGet()
23-
decoded = Manifest.decode(e).tryGet()
24-
25-
check:
26-
decoded == manifest
27-
28-
test "Should encode/decode to/from protected manifest":
29-
var
30-
manifest = Manifest.new(
31-
manifest = Manifest.new(
32-
treeCid = Cid.example,
33-
blockSize = 1.MiBs,
34-
datasetSize = 100.MiBs),
35-
treeCid = Cid.example,
36-
datasetSize = 200.MiBs,
37-
eck = 10,
38-
ecM = 10
39-
)
40-
41-
let
42-
e = manifest.encode().tryGet()
43-
decoded = Manifest.decode(e).tryGet()
44-
45-
check:
46-
decoded == manifest
47-
48-
test "Should encode/decode to/from verifiable manifest":
49-
let protectedManifest = Manifest.new(
50-
manifest = Manifest.new(
51-
treeCid = Cid.example,
52-
blockSize = 1.MiBs,
53-
datasetSize = 100.MiBs),
14+
let
15+
manifest = Manifest.new(
16+
treeCid = Cid.example,
17+
blockSize = 1.MiBs,
18+
datasetSize = 100.MiBs
19+
)
20+
protectedManifest = Manifest.new(
21+
manifest = manifest,
5422
treeCid = Cid.example,
5523
datasetSize = 200.MiBs,
5624
eck = 10,
5725
ecM = 10
5826
)
59-
60-
var manifest = Manifest.new(
27+
verifiableManifest = Manifest.new(
6128
manifest = protectedManifest,
6229
verificationRoot = VerificationHash.fromInt(12),
6330
slotRoots = @[VerificationHash.fromInt(23), VerificationHash.fromInt(34)]
6431
).tryGet()
6532

66-
let
67-
e = manifest.encode().tryGet()
68-
decoded = Manifest.decode(e).tryGet()
33+
proc encodeDecode(manifest: Manifest): Manifest =
34+
let e = manifest.encode().tryGet()
35+
Manifest.decode(e).tryGet()
36+
37+
test "Should encode/decode to/from base manifest":
38+
check:
39+
encodeDecode(manifest) == manifest
6940

41+
test "Should encode/decode to/from protected manifest":
7042
check:
71-
decoded == manifest
43+
encodeDecode(protectedManifest) == protectedManifest
7244

45+
test "Should encode/decode to/from verifiable manifest":
46+
check:
47+
encodeDecode(verifiableManifest) == verifiableManifest

0 commit comments

Comments
 (0)