Skip to content

Commit d96ac9d

Browse files
committed
[ fix ] witness generation (wtns binaries) for Snarkjs
1 parent 4e572a8 commit d96ac9d

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

app/Encode.hs

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Keelung.Syntax.Counters
2828
import Keelung.CircuitFormat hiding (WtnsBinHeader(..))
2929
import Keelung (FieldType(..))
3030
import Data.Int (Int64)
31-
import GHC.Num (integerLogBase)
3231
import Debug.Trace
3332

3433
-- | IMPORTANT: Make sure major, minor and patch versions are updated
@@ -68,8 +67,11 @@ serializeInputAndWitnessToBin p witnessVec =
6867
toLazyByteString $
6968
int32LE (fromIntegral (primeLen p))
7069
<> lazyByteString primeBS
71-
<> int32LE (fromIntegral $ length witnesses)
72-
wtnses = toLazyByteString $ mconcat (fitPrimeSize p 1 : map (fitPrimeSize p . mod p . fromIntegral) witnesses)
70+
<> int32LE (fromIntegral $ length witnesses + 1)
71+
wtnses = toLazyByteString $ mconcat (fitPrimeSize p 1 : map (fitPrimeSize p . toInteger) witnesses)
72+
-- "wtns, version 2, 2 sections"
73+
meta :: ByteString
74+
meta = BS.pack [0x77, 0x74, 0x6e, 0x73, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00]
7375
in meta
7476
<> BS.pack [0x01, 0x00, 0x00, 0x00]
7577
<> secLength header
@@ -79,9 +81,6 @@ serializeInputAndWitnessToBin p witnessVec =
7981
<> wtnses
8082
where
8183
secLength = toLazyByteString . word64LE . fromIntegral . BS.length
82-
-- "wtns, version 2, 2 sections"
83-
meta :: ByteString
84-
meta = BS.pack [0x77, 0x74, 0x6e, 0x73, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00]
8584
--------------------------------------------------------------------------------
8685

8786
-- | Encodes a R1CS in the JSON Lines text file format

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ source-repository-package
88
source-repository-package
99
type: git
1010
location: https://github.com/btq-ag/keelung.git
11-
tag: 2cc69fcf6a982ae6dddda52db3ad15709b3e8f87
11+
tag: 07b492fa27cd7ed0716046afe141ba0c241c1b8e
1212

1313
with-compiler: ghc-9.2.8

stack.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ packages:
4343
extra-deps:
4444
- git: https://github.com/btq-ag/galois-field.git
4545
commit: d7d0da6b5df8045afdfb820ba8d08f34dc4c3e58
46-
- ../keelung
47-
# - git: https://github.com/btq-ag/keelung.git
48-
# commit: 2cc69fcf6a982ae6dddda52db3ad15709b3e8f87
46+
- git: https://github.com/btq-ag/keelung.git
47+
commit: 07b492fa27cd7ed0716046afe141ba0c241c1b8e
4948
- MonadRandom-0.5.3@sha256:bb553af2bac914362a54983e4ed2e0b6352c09b73a1e1e280ec4befe14c4270c,1456
5049
- mod-0.1.2.2@sha256:58bc3a1471bbbc55569bf61fd49b537c3e64b0a86dd79522ca1d7805400523ce,2248
5150
- poly-0.5.1.0@sha256:8c574f017913982fd70567545bec423823ff5bdf236c19d1443f3af47e0218ba,3418

stack.yaml.lock

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ packages:
1515
original:
1616
commit: d7d0da6b5df8045afdfb820ba8d08f34dc4c3e58
1717
git: https://github.com/btq-ag/galois-field.git
18+
- completed:
19+
commit: 07b492fa27cd7ed0716046afe141ba0c241c1b8e
20+
git: https://github.com/btq-ag/keelung.git
21+
name: keelung
22+
pantry-tree:
23+
sha256: d3a63f7756f91b0d3df17aa6cd8b1eec13735bc71a1f451b3ab05e57290085c5
24+
size: 2004
25+
version: 0.25.0
26+
original:
27+
commit: 07b492fa27cd7ed0716046afe141ba0c241c1b8e
28+
git: https://github.com/btq-ag/keelung.git
1829
- completed:
1930
hackage: MonadRandom-0.5.3@sha256:bb553af2bac914362a54983e4ed2e0b6352c09b73a1e1e280ec4befe14c4270c,1456
2031
pantry-tree:

0 commit comments

Comments
 (0)