mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
zkas: Add a field definition on top of the circuit file.
Currently unused, but will probably be expanded to define proofs over different fields.
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
<definitions>
|
<definitions>
|
||||||
<context id="keywords" style-ref="keyword">
|
<context id="keywords" style-ref="keyword">
|
||||||
<keyword>k</keyword>
|
<keyword>k</keyword>
|
||||||
|
<keyword>field</keyword>
|
||||||
<keyword>constant</keyword>
|
<keyword>constant</keyword>
|
||||||
<keyword>witness</keyword>
|
<keyword>witness</keyword>
|
||||||
<keyword>circuit</keyword>
|
<keyword>circuit</keyword>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ local number = token(l.NUMBER, l.integer)
|
|||||||
|
|
||||||
-- Keywords.
|
-- Keywords.
|
||||||
local keyword = token(l.KEYWORD, word_match{
|
local keyword = token(l.KEYWORD, word_match{
|
||||||
'k', 'constant', 'witness', 'circuit',
|
'k', "field", 'constant', 'witness', 'circuit',
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Constants.
|
-- Constants.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ endif
|
|||||||
|
|
||||||
syn keyword zkasKeyword
|
syn keyword zkasKeyword
|
||||||
\ k
|
\ k
|
||||||
|
\ field
|
||||||
\ constant
|
\ constant
|
||||||
\ witness
|
\ witness
|
||||||
\ circuit
|
\ circuit
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Simple" {
|
constant "Simple" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Arith" {}
|
constant "Arith" {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Burn" {
|
constant "Burn" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
# This is basically the el gamal scheme in ZK
|
# This is basically the el gamal scheme in ZK
|
||||||
|
|
||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Encrypt" {}
|
constant "Encrypt" {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "InclusionProof" {
|
constant "InclusionProof" {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Lead" {
|
constant "Lead" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Mint" {
|
constant "Mint" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Opcodes" {
|
constant "Opcodes" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
# 2 ** k is the maximum nubmer of rows in the circuit.
|
# 2 ** k is the maximum nubmer of rows in the circuit.
|
||||||
k = 11;
|
k = 11;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
# Section to declare constants used in the circuit.
|
# Section to declare constants used in the circuit.
|
||||||
# "Set_V1" is the namepsace of circuit.
|
# "Set_V1" is the namepsace of circuit.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "tx" {
|
constant "tx" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "Vote" {
|
constant "Vote" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "RlnSignal" {}
|
constant "RlnSignal" {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "RlnSlash" {}
|
constant "RlnSlash" {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "ConsensusBurn_V1" {
|
constant "ConsensusBurn_V1" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "ConsensusMint_V1" {
|
constant "ConsensusMint_V1" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "ConsensusProposal_V1" {
|
constant "ConsensusProposal_V1" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "DaoExec" {
|
constant "DaoExec" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "DaoMint" {
|
constant "DaoMint" {
|
||||||
EcFixedPoint VALUE_COMMIT_RANDOM,
|
EcFixedPoint VALUE_COMMIT_RANDOM,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "DaoProposeInput" {
|
constant "DaoProposeInput" {
|
||||||
EcFixedPointBase NULLIFIER_K,
|
EcFixedPointBase NULLIFIER_K,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "DaoProposeMain" {
|
constant "DaoProposeMain" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "DaoVoteInput" {
|
constant "DaoVoteInput" {
|
||||||
EcFixedPointBase NULLIFIER_K,
|
EcFixedPointBase NULLIFIER_K,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "DaoVoteMain" {
|
constant "DaoVoteMain" {
|
||||||
EcFixedPoint VALUE_COMMIT_RANDOM,
|
EcFixedPoint VALUE_COMMIT_RANDOM,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "DeriveContractID" {
|
constant "DeriveContractID" {
|
||||||
EcFixedPointBase NULLIFIER_K,
|
EcFixedPointBase NULLIFIER_K,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# The k parameter defining the number of rows used in our circuit (2^k)
|
# The k parameter defining the number of rows used in our circuit (2^k)
|
||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
# The constants we define for our circuit
|
# The constants we define for our circuit
|
||||||
constant "Burn_V1" {
|
constant "Burn_V1" {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# The k parameter defining the number of rows used in our circuit (2^k)
|
# The k parameter defining the number of rows used in our circuit (2^k)
|
||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
# The constants we define for our circuit
|
# The constants we define for our circuit
|
||||||
constant "Mint_V1" {
|
constant "Mint_V1" {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "TokenFreeze_V1" {
|
constant "TokenFreeze_V1" {
|
||||||
EcFixedPointBase NULLIFIER_K,
|
EcFixedPointBase NULLIFIER_K,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Circuit used to mint arbitrary coins given a mint authority secret.
|
# Circuit used to mint arbitrary coins given a mint authority secret.
|
||||||
|
|
||||||
k = 13;
|
k = 13;
|
||||||
|
field = "pallas";
|
||||||
|
|
||||||
constant "TokenMint_V1" {
|
constant "TokenMint_V1" {
|
||||||
EcFixedPointShort VALUE_COMMIT_VALUE,
|
EcFixedPointShort VALUE_COMMIT_VALUE,
|
||||||
|
|||||||
@@ -21,3 +21,6 @@ pub const MAX_K: u32 = 16;
|
|||||||
|
|
||||||
/// Maximum allowed namespace length in bytes
|
/// Maximum allowed namespace length in bytes
|
||||||
pub const MAX_NS_LEN: usize = 32;
|
pub const MAX_NS_LEN: usize = 32;
|
||||||
|
|
||||||
|
/// Allowed fields for proofs
|
||||||
|
pub const ALLOWED_FIELDS: [&str; 1] = ["pallas"];
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use itertools::Itertools;
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
ast::{Arg, Constant, Literal, Statement, StatementType, Variable, Witness},
|
ast::{Arg, Constant, Literal, Statement, StatementType, Variable, Witness},
|
||||||
constants::{MAX_K, MAX_NS_LEN},
|
constants::{ALLOWED_FIELDS, MAX_K, MAX_NS_LEN},
|
||||||
error::ErrorEmitter,
|
error::ErrorEmitter,
|
||||||
lexer::{Token, TokenType},
|
lexer::{Token, TokenType},
|
||||||
LitType, Opcode, VarType,
|
LitType, Opcode, VarType,
|
||||||
@@ -30,7 +30,7 @@ use super::{
|
|||||||
|
|
||||||
/// zkas language builtin keywords.
|
/// zkas language builtin keywords.
|
||||||
/// These can not be used anywhere except where they are expected.
|
/// These can not be used anywhere except where they are expected.
|
||||||
const KEYWORDS: [&str; 4] = ["k", "constant", "witness", "circuit"];
|
const KEYWORDS: [&str; 5] = ["k", "field", "constant", "witness", "circuit"];
|
||||||
|
|
||||||
/// Forbidden namespaces
|
/// Forbidden namespaces
|
||||||
const NOPE_NS: [&str; 4] = [".constant", ".literal", ".witness", ".circuit"];
|
const NOPE_NS: [&str; 4] = [".constant", ".literal", ".witness", ".circuit"];
|
||||||
@@ -145,16 +145,57 @@ impl Parser {
|
|||||||
number.token_type != TokenType::Number ||
|
number.token_type != TokenType::Number ||
|
||||||
semicolon.token_type != TokenType::Semicolon
|
semicolon.token_type != TokenType::Semicolon
|
||||||
{
|
{
|
||||||
self.error.abort("Source file does not start with k=n;", 0, 0);
|
self.error.abort("Source file does not start with k=n;", k.line, k.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
if k.token != "k" {
|
if k.token != "k" {
|
||||||
self.error.abort("Source file does not start with k=n;", 0, 0);
|
self.error.abort("Source file does not start with k=n;", k.line, k.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
let declared_k = number.token.parse().unwrap();
|
let declared_k = number.token.parse().unwrap();
|
||||||
if declared_k > MAX_K {
|
if declared_k > MAX_K {
|
||||||
self.error.abort(&format!("k param is too high, max allowed is {}", MAX_K), 0, 0);
|
self.error.abort(
|
||||||
|
&format!("k param is too high, max allowed is {}", MAX_K),
|
||||||
|
number.line,
|
||||||
|
number.column,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then we declare the field we're working in.
|
||||||
|
let Some((field, equal, field_name, semicolon)) = iter.next_tuple() else {
|
||||||
|
self.error.abort("Source file does not declare field after k", k.line, k.column);
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
if field.token_type != TokenType::Symbol ||
|
||||||
|
equal.token_type != TokenType::Assign ||
|
||||||
|
field_name.token_type != TokenType::String ||
|
||||||
|
semicolon.token_type != TokenType::Semicolon
|
||||||
|
{
|
||||||
|
self.error.abort(
|
||||||
|
"Source file does not declare field after k",
|
||||||
|
field.line,
|
||||||
|
field.column,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if field.token != "field" {
|
||||||
|
self.error.abort(
|
||||||
|
"Source file does not declare field after k",
|
||||||
|
field.line,
|
||||||
|
field.column,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ALLOWED_FIELDS.contains(&field_name.token.as_str()) {
|
||||||
|
self.error.abort(
|
||||||
|
&format!(
|
||||||
|
"Declared field \"{}\" is not supported. Use any of: {:?}",
|
||||||
|
field_name.token, ALLOWED_FIELDS
|
||||||
|
),
|
||||||
|
field_name.line,
|
||||||
|
field_name.column,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Some(t) = iter.next() {
|
while let Some(t) = iter.next() {
|
||||||
|
|||||||
Reference in New Issue
Block a user