LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Types.td
Go to the documentation of this file.
1//===-- Types.td -------------------------------------------*- tablegen -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLZK_FELT_TYPES
11#define LLZK_FELT_TYPES
12
13include "llzk/Dialect/Felt/IR/Dialect.td"
14
15include "mlir/IR/AttrTypeBase.td"
16include "mlir/IR/BuiltinTypes.td"
17include "mlir/IR/BuiltinTypeInterfaces.td"
18include "mlir/Interfaces/MemorySlotInterfaces.td"
19
20def LLZK_FeltType : TypeDef<FeltDialect, "Felt"> {
21 let mnemonic = "type";
22 let summary = "finite field element";
23 let description = [{
24 An element of a finite field. The field can be specified (e.g., !felt.type<"bn254">)
25 or left unspecified (!felt.type), to be filled in by the backend consumer of LLZK IR.
26 Leaving the field unspecified may reduce the power of certain transformation passes.
27
28 For a field with prime modulus `p`, a felt denotes a residue modulo `p`, with its
29 canonical representative in `[0, p)`. An unreduced integer representation does not
30 denote a distinct value outside this range.
31
32 Backends are responsible for performing conversions between felts of different
33 fields. If a circuit needs to encode translations between fields, the circuit
34 may define a function prototype, e.g.:
35
36 ```llzk
37 function.def @convert(%a : !felt.type<"bn254">) -> !felt.type<"goldilocks">;
38 ```
39
40 and perform the lowering of calls to this conversion function in a
41 backend-specific manner.
42
43 The field name can be chosen from one of the built-in fields or specified using
44 `felt.field` specification attributes on the root module.
45 }];
46
47 let parameters = (ins OptionalParameter<"::mlir::StringAttr">:$fieldName);
48
49 let assemblyFormat = "(`<` $fieldName^ `>`)?";
50
51 // Default when omitted: felt.type with no fieldName
52 let builderCall = "::llzk::felt::FeltType::get($_builder.getContext())";
53
54 let builders = [
55 // Like the default builder but with null for the optional field name.
56 AttrBuilder<(ins), [{ return $_get(context, ::mlir::StringAttr()); }]>,
57 AttrBuilder<
58 (ins "::llvm::StringRef":$fieldName),
59 [{ return $_get(context, ::mlir::StringAttr::get(context, fieldName)); }]>];
60
61 let extraClassDeclaration = [{
62 bool hasField() const {
63 auto name = getFieldName();
64 return name && !name.empty();
65 }
66
67 const ::llzk::Field &getField() const;
68 }];
69
70 let genVerifyDecl = 1;
71}
72
73#endif // LLZK_FELT_TYPES