Links

Commands

In this article, we will list all the useful commands in Keelung.

Interpret a program

You can feed a Keelung program into the interpreter to test and see if it is working as expected.
interpret :: FieldType -> Comp t -> [Integer] -> [Integer] -> IO [Integer]

Shorthands

We provide shorthands like gf181 for interpret GF181. Here are all the other shorthands of interpret:
gf181 = interpret GF181 :: Comp t -> [GF181] -> [GF181] -> IO [N GF181]
bn128 = interpret BN128 :: Comp t -> [BN128] -> [BN128] -> IO [N BN128]
b64 = interpret B64 :: Comp t -> [B64 ] -> [B64 ] -> IO [N B64 ]

Example

Take square for example:
square :: Comp Field
square = do
x <- input Public
return (x * x)
If we apply [2] as the public input and [] as the private input to interpret GF181 square, we'd get:
stack repl
> interpret GF181 square [2] []
[4]

Compile a program

To generate R1CS constraints, specify the type of field to use and a Keelung program into the compile function:
compile :: FieldType -> Comp t -> IO (Either Error (R1CS Integer))
Here's the definition of R1CS in case you want to do something with it.

Example

Take square for example, we'd get:
stack repl
> compile GF181 square
Right R1CS {
Constriant (1):
Ordinary constriants (1):
$1 * $1 = $0
Variables (2):
Output variable : $0
Public Input variable : $1
}

Generate a proof

The command for generating a proof is almost identical to that of interpret, except that instead of getting a list of outputs, you get a proof file named proof in the current working directory.
generate :: FieldType -> Comp t -> [Integer] -> [Integer] -> IO ()

Verify a proof

Copyright © 2023 BTQ