LLZK 2.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.,
25 !felt.type<"bn254">) or left unspecified (!felt.type), to be filled in by the
26 backend consumer of LLZK IR.
27 Leaving the field unspecified may reduce the power of certain transformation passes.
28
29 Backends are responsible for performing conversions between felts of different
30 fields. If a circuit needs to encode translations between fields, the circuit
31 may define a function prototype, e.g.:
32
33 ```llzk
34 function.def @convert(%a : !felt.type<"bn254">) -> !felt.type<"goldilocks">;
35 ```
36
37 and perform the lowering of calls to this conversion function in a
38 backend-specific manner.
39
40 The field name can be chosen from one of the built-in fields or specified using
41 `felt.field` specification attributes on the root module.
42 }];
43
44 let parameters = (ins OptionalParameter<"::mlir::StringAttr">:$fieldName);
45
46 let assemblyFormat = "(`<` $fieldName^ `>`)?";
47
48 // Default when omitted: felt.type with no fieldName
49 let builderCall = "::llzk::felt::FeltType::get($_builder.getContext())";
50
51 let builders = [
52 // Like the default builder but with null for the optional field name.
53 AttrBuilder<(ins), [{ return $_get(context, ::mlir::StringAttr()); }]>,
54 AttrBuilder<
55 (ins "::llvm::StringRef":$fieldName),
56 [{ return $_get(context, ::mlir::StringAttr::get(context, fieldName)); }]>];
57
58 let extraClassDeclaration = [{
59 bool hasField() const {
60 auto name = getFieldName();
61 return name && !name.empty();
62 }
63
64 const ::llzk::Field &getField() const;
65 }];
66
67 let genVerifyDecl = 1;
68}
69
70#endif // LLZK_FELT_TYPES