- Rust 96%
- HTML 2%
- JavaScript <1%
- Shell <1%
nbv (nothing but vectors) #
If algebras exist, and languages exist, there is a set of minimally abstracted algebraic languages. This repository attempts to represent a member of that set.
A language designed to compile programs to r1cs for arithmetizing/arguing on mathematical machines. Each function collapses a tuple of input variables to a single output variable using a set of functions and precompiles.
A minimal, imperative, expression of algebraic logic.
Language #
nbv is a scripting language for expressing mathematical relations between vectors in a scalar field.
Two types of variables exist:
staticvariables, which are known at compile timeletvariables, which are known at witness computation time
All variables are vectors. Vectors of length 1 may be used to index other vectors using bracket syntax e.g. let x[100]. Lengths and types are 100% statically analyzed or compile fails.
Run locally #
git clone https://codeberg.org/ccertain/nbv
cd nbv
cargo run --bin=nbv --release -- demo slip
Change the demo.nbv script and re-run to argue a different program.
You'll need Rust installed to run this.
Docker #
If you have Docker, the following command should work:
docker run -it --rm rust:bullseye bash -c "git clone https://codeberg.org/ccertain/nbv && cd nbv && cargo run --bin=nbv --release -- demo slip"
Language support tracking #
Features
Features #
-
all variables are vectors with static length
-
automatic element-wise vector operations
-
throws if vectors of mismatched size are used in an operation e.g.
val[0..10] * lav[0..5]- NOTE: range syntax is not implemented and maybe/probably won't be
-
functions cannot be declared, each file is a single function
-
files are not imported, function calls match the filename and tell the compiler what files are needed
-
all function calls are inlined at call site
-
r1cs witnesses are computed using a static nbv script
-
-
-
-
-
Example #
# comments start with a pound sign
# the first non-comment, non-whitespace line MAY be a declaration of function inputs
(x, y)
# if this function is called with a non-static x, compilation will fail
static z = x * x
# statics can be used to address vectors
# if x is not of length 1, z will not be of length 1, and compilation will fail
# if z+1 is beyond the bounds of y, compilation will fail
y[z + 1]
# ^ the final non-whitespace line MAY be an expression that is returned to caller
# expressions evaluate to a single variable/vector
Example ZKP #
(input)
# read the first witness input
let x = input[0]
# read the remaining input
let mut v = slice_to_end(input, 1)
# the ! operator invokes a precompile with some arguments
static v_len = len! v
# loop is a precompile that accepts a block as the final argument
loop! v_len, i {
v[i] = x * v[i]
}
# this vector is written as public output
v
See the demo for more.
Rust example #
See the matmul example for a Rust implementation running a script inlined as a string.