ソースを参照

zkas: Rename "contract" to "witness".

parazyd 3 年 前
コミット
be9013ed31

+ 5 - 5
doc/src/zkas/bincode.md

@@ -5,7 +5,7 @@ The bincode design for zkas is the compiled code in the form of a
 binary blob, that can be read by a program and fed into the VM.
 binary blob, that can be read by a program and fed into the VM.
 
 
 Our programs consist of four sections: `constant`, `literal`,
 Our programs consist of four sections: `constant`, `literal`,
-`contract`, and `circuit`. Our bincode represents the
+`witness`, and `circuit`. Our bincode represents the
 same. Additionally, there is an optional section called `.debug`
 same. Additionally, there is an optional section called `.debug`
 which can hold debug info related to the binary.
 which can hold debug info related to the binary.
 
 
@@ -27,7 +27,7 @@ CONSTANT_TYPE CONSTANT_NAME
 LITERAL
 LITERAL
 LITERAL
 LITERAL
 ...
 ...
-.contract
+.witness
 WITNESS_TYPE
 WITNESS_TYPE
 WITNESS_TYPE
 WITNESS_TYPE
 ...
 ...
@@ -68,7 +68,7 @@ source code, e.g.:
 
 
 ```
 ```
 constant "MyNamespace" { ... }
 constant "MyNamespace" { ... }
-contract "MyNamespace" { ... }
+witness  "MyNamespace" { ... }
 circuit  "MyNamespace" { ... }
 circuit  "MyNamespace" { ... }
 ```
 ```
 
 
@@ -87,9 +87,9 @@ that get parsed into a `u64` type inside the VM. In the future this
 could be extended with signed integers, and strings.
 could be extended with signed integers, and strings.
 
 
 
 
-### `.contract`
+### `.witness`
 
 
-The `.contract` section holds the circuit witness values in the form
+The `.witness` section holds the circuit witness values in the form
 of `WITNESS_TYPE`. Their stack index is incremented for each witness
 of `WITNESS_TYPE`. Their stack index is incremented for each witness
 as they're kept in order like in the source file. The witnesses
 as they're kept in order like in the source file. The witnesses
 that are of the same type as the circuit itself (typically `Base`)
 that are of the same type as the circuit itself (typically `Base`)

+ 1 - 1
example/simple.zk

@@ -3,7 +3,7 @@ constant "Simple" {
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 }
 }
 
 
-contract "Simple" {
+witness "Simple" {
 	Base value,
 	Base value,
 	Scalar value_blind,
 	Scalar value_blind,
 }
 }

+ 1 - 1
proof/arithmetic.zk

@@ -1,6 +1,6 @@
 constant "Arith" {}
 constant "Arith" {}
 
 
-contract "Arith" {
+witness "Arith" {
     Base a,
     Base a,
     Base b,
     Base b,
 }
 }

+ 1 - 1
proof/burn.zk

@@ -4,7 +4,7 @@ constant "Burn" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Burn" {
+witness "Burn" {
 	Base secret,
 	Base secret,
 	Base serial,
 	Base serial,
 	Base value,
 	Base value,

+ 1 - 1
proof/deploy_contract.zk

@@ -2,7 +2,7 @@ constant "DeployContract" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "DeployContract" {
+witness "DeployContract" {
 	# Amount of bytes to store on-chain
 	# Amount of bytes to store on-chain
 	Base bytes,
 	Base bytes,
 	# Deploy key used for signing and contract reference
 	# Deploy key used for signing and contract reference

+ 1 - 1
proof/encrypt.zk

@@ -7,7 +7,7 @@
 
 
 constant "Encrypt" {}
 constant "Encrypt" {}
 
 
-contract "Encrypt" {
+witness "Encrypt" {
     # We are encrypting values to this public key
     # We are encrypting values to this public key
     EcNiPoint pubkey,
     EcNiPoint pubkey,
 
 

+ 1 - 1
proof/inclusion_proof.zk

@@ -1,7 +1,7 @@
 constant "InclusionProof" {
 constant "InclusionProof" {
 }
 }
 
 
-contract "InclusionProof" {
+witness "InclusionProof" {
 	Base leaf,
 	Base leaf,
 	Uint32 leaf_pos,
 	Uint32 leaf_pos,
 	MerklePath path,
 	MerklePath path,

+ 1 - 1
proof/lead.zk

@@ -4,7 +4,7 @@ constant "Lead" {
          EcFixedPointBase NULLIFIER_K,
          EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Lead" {
+witness "Lead" {
          MerklePath c1_cm_path,
          MerklePath c1_cm_path,
          Uint32 c1_cm_pos,
          Uint32 c1_cm_pos,
          Uint32 c1_sk_pos,
          Uint32 c1_sk_pos,

+ 1 - 1
proof/mint.zk

@@ -4,7 +4,7 @@ constant "Mint" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Mint" {
+witness "Mint" {
 	Base pub_x,
 	Base pub_x,
 	Base pub_y,
 	Base pub_y,
 	Base value,
 	Base value,

+ 1 - 1
proof/opcodes.zk

@@ -4,7 +4,7 @@ constant "Opcodes" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Opcodes" {
+witness "Opcodes" {
 	Base value,
 	Base value,
 	Scalar value_blind,
 	Scalar value_blind,
 
 

+ 1 - 1
proof/tx.zk

@@ -4,7 +4,7 @@ constant "tx" {
          EcFixedPointBase NULLIFIER_K,
          EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "tx" {
+witness "tx" {
          # coin (1) witnesses
          # coin (1) witnesses
          Base root,
          Base root,
          Base c1_root_sk,
          Base c1_root_sk,

+ 1 - 1
proof/voting.zk

@@ -4,7 +4,7 @@ constant "Vote" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Vote" {
+witness "Vote" {
 	Base process_id_0,
 	Base process_id_0,
 	Base process_id_1,
 	Base process_id_1,
 	Base secret_key,
 	Base secret_key,

+ 1 - 1
script/research/rln/signal.zk

@@ -1,6 +1,6 @@
 constant "RlnSignal" {}
 constant "RlnSignal" {}
 
 
-contract "RlnSignal" {
+witness "RlnSignal" {
 	Base secret_key,
 	Base secret_key,
 	MerklePath identity_path,
 	MerklePath identity_path,
 	Uint32 identity_leaf_pos,
 	Uint32 identity_leaf_pos,

+ 1 - 1
script/research/rln/slash.zk

@@ -1,6 +1,6 @@
 constant "RlnSlash" {}
 constant "RlnSlash" {}
 
 
-contract "RlnSlash" {
+witness "RlnSlash" {
 	Base secret_key,
 	Base secret_key,
 	MerklePath identity_path,
 	MerklePath identity_path,
 	Uint32 identity_leaf_pos,
 	Uint32 identity_leaf_pos,

+ 1 - 1
src/contract/consensus/proof/reward_v1.zk

@@ -3,7 +3,7 @@ constant "Reward_V1" {
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 }
 }
 
 
-contract "Reward_V1" {
+witness "Reward_V1" {
 	# Burnt coin
 	# Burnt coin
 	Base coin,
 	Base coin,
 	# Burnt coin secret key
 	# Burnt coin secret key

+ 1 - 1
src/contract/dao/proof/dao-exec.zk

@@ -3,7 +3,7 @@ constant "DaoExec" {
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 }
 }
 
 
-contract "DaoExec" {
+witness "DaoExec" {
 	# Proposal parameters
 	# Proposal parameters
 	Base proposal_dest_x,
 	Base proposal_dest_x,
 	Base proposal_dest_y,
 	Base proposal_dest_y,

+ 1 - 1
src/contract/dao/proof/dao-mint.zk

@@ -3,7 +3,7 @@ constant "DaoMint" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "DaoMint" {
+witness "DaoMint" {
 	Base dao_proposer_limit,
 	Base dao_proposer_limit,
 	Base dao_quorum,
 	Base dao_quorum,
 	Base dao_approval_ratio_quot,
 	Base dao_approval_ratio_quot,

+ 1 - 1
src/contract/dao/proof/dao-propose-burn.zk

@@ -4,7 +4,7 @@ constant "DaoProposeInput" {
 	EcFixedPointShort VALUE_COMMIT_VALUE,
 	EcFixedPointShort VALUE_COMMIT_VALUE,
 }
 }
 
 
-contract "DaoProposeInput" {
+witness "DaoProposeInput" {
 	Base secret,
 	Base secret,
 	Base serial,
 	Base serial,
 	Base spend_hook,
 	Base spend_hook,

+ 1 - 1
src/contract/dao/proof/dao-propose-main.zk

@@ -3,7 +3,7 @@ constant "DaoProposeMain" {
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 	EcFixedPoint VALUE_COMMIT_RANDOM,
 }
 }
 
 
-contract "DaoProposeMain" {
+witness "DaoProposeMain" {
 	# Proposers total number of governance tokens
 	# Proposers total number of governance tokens
 	Base total_funds,
 	Base total_funds,
 	Scalar total_funds_blind,
 	Scalar total_funds_blind,

+ 1 - 1
src/contract/dao/proof/dao-vote-burn.zk

@@ -4,7 +4,7 @@ constant "DaoVoteInput" {
 	EcFixedPointShort VALUE_COMMIT_VALUE,
 	EcFixedPointShort VALUE_COMMIT_VALUE,
 }
 }
 
 
-contract "DaoVoteInput" {
+witness "DaoVoteInput" {
 	Base secret,
 	Base secret,
 	Base serial,
 	Base serial,
 	Base spend_hook,
 	Base spend_hook,

+ 1 - 1
src/contract/dao/proof/dao-vote-main.zk

@@ -3,7 +3,7 @@ constant "DaoVoteMain" {
 	EcFixedPointShort VALUE_COMMIT_VALUE,
 	EcFixedPointShort VALUE_COMMIT_VALUE,
 }
 }
 
 
-contract "DaoVoteMain" {
+witness "DaoVoteMain" {
 	# Proposal parameters
 	# Proposal parameters
 	Base proposal_dest_x,
 	Base proposal_dest_x,
 	Base proposal_dest_y,
 	Base proposal_dest_y,

+ 1 - 1
src/contract/money/proof/burn_v1.zk

@@ -4,7 +4,7 @@ constant "Burn_V1" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Burn_V1" {
+witness "Burn_V1" {
 	# The value of this coin
 	# The value of this coin
 	Base value,
 	Base value,
 	# The token ID
 	# The token ID

+ 1 - 1
src/contract/money/proof/lead_burn_v1.zk

@@ -4,7 +4,7 @@ constant "Lead_Burn_V1" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Lead_Burn_V1" {
+witness "Lead_Burn_V1" {
 	MerklePath c1_cm_path,
 	MerklePath c1_cm_path,
 	Uint32 c1_cm_pos,
 	Uint32 c1_cm_pos,
 	Uint32 c1_sk_pos,
 	Uint32 c1_sk_pos,

+ 1 - 1
src/contract/money/proof/lead_mint_v1.zk

@@ -4,7 +4,7 @@ constant "Lead_Mint_V1" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Lead_Mint_V1" {
+witness "Lead_Mint_V1" {
 	Base c1_sk,
 	Base c1_sk,
 	Base c1_sk_root,
 	Base c1_sk_root,
 	Base c1_slot,
 	Base c1_slot,

+ 1 - 1
src/contract/money/proof/mint_v1.zk

@@ -4,7 +4,7 @@ constant "Mint_V1" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "Mint_V1" {
+witness "Mint_V1" {
 	# X coordinate for public key
 	# X coordinate for public key
 	Base pub_x,
 	Base pub_x,
 	# Y coordinate for public key
 	# Y coordinate for public key

+ 1 - 1
src/contract/money/proof/token_freeze_v1.zk

@@ -2,7 +2,7 @@ constant "TokenFreeze_V1" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "TokenFreeze_V1" {
+witness "TokenFreeze_V1" {
 	# Token mint authority secret
 	# Token mint authority secret
 	Base mint_authority,
 	Base mint_authority,
 }
 }

+ 1 - 1
src/contract/money/proof/token_mint_v1.zk

@@ -5,7 +5,7 @@ constant "TokenMint_V1" {
 	EcFixedPointBase NULLIFIER_K,
 	EcFixedPointBase NULLIFIER_K,
 }
 }
 
 
-contract "TokenMint_V1" {
+witness "TokenMint_V1" {
 	# Token mint authority secret
 	# Token mint authority secret
 	Base mint_authority,
 	Base mint_authority,
 	# Token supply
 	# Token supply

+ 2 - 2
src/zkas/compiler.rs

@@ -92,9 +92,9 @@ impl Compiler {
             bincode.extend_from_slice(&serialize(&i.name));
             bincode.extend_from_slice(&serialize(&i.name));
         }
         }
 
 
-        // In the .contract section, we write all our witness types, on the stack
+        // In the .witness section, we write all our witness types, on the stack
         // they're in order of appearance.
         // they're in order of appearance.
-        bincode.extend_from_slice(b".contract");
+        bincode.extend_from_slice(b".witness");
         for i in &self.witnesses {
         for i in &self.witnesses {
             tmp_stack.push(i.name.as_str());
             tmp_stack.push(i.name.as_str());
             bincode.push(i.typ as u8);
             bincode.push(i.typ as u8);

+ 11 - 11
src/zkas/decoder.rs

@@ -46,7 +46,7 @@ impl ZkBinary {
 
 
         let _binary_version = &bytes[4];
         let _binary_version = &bytes[4];
 
 
-        // After the binary version, we're supposed to have the contract namespace
+        // After the binary version, we're supposed to have the witness namespace
         let (namespace, _) = deserialize_partial(&bytes[5..])?;
         let (namespace, _) = deserialize_partial(&bytes[5..])?;
 
 
         let constants_offset = match find_subslice(bytes, b".constant") {
         let constants_offset = match find_subslice(bytes, b".constant") {
@@ -59,9 +59,9 @@ impl ZkBinary {
             None => return Err(ZkasErr("Could not find .literal section".to_string())),
             None => return Err(ZkasErr("Could not find .literal section".to_string())),
         };
         };
 
 
-        let contract_offset = match find_subslice(bytes, b".contract") {
+        let witness_offset = match find_subslice(bytes, b".witness") {
             Some(v) => v,
             Some(v) => v,
-            None => return Err(ZkasErr("Could not find .contract section".to_string())),
+            None => return Err(ZkasErr("Could not find .witness section".to_string())),
         };
         };
 
 
         let circuit_offset = match find_subslice(bytes, b".circuit") {
         let circuit_offset = match find_subslice(bytes, b".circuit") {
@@ -78,12 +78,12 @@ impl ZkBinary {
             return Err(ZkasErr(".literal section appeared before .constant".to_string()))
             return Err(ZkasErr(".literal section appeared before .constant".to_string()))
         }
         }
 
 
-        if literals_offset > contract_offset {
-            return Err(ZkasErr(".contract section appeared before .literal".to_string()))
+        if literals_offset > witness_offset {
+            return Err(ZkasErr(".witness section appeared before .literal".to_string()))
         }
         }
 
 
-        if contract_offset > circuit_offset {
-            return Err(ZkasErr(".circuit section appeared before .contract".to_string()))
+        if witness_offset > circuit_offset {
+            return Err(ZkasErr(".circuit section appeared before .witness".to_string()))
         }
         }
 
 
         if circuit_offset > debug_offset {
         if circuit_offset > debug_offset {
@@ -91,13 +91,13 @@ impl ZkBinary {
         }
         }
 
 
         let constants_section = &bytes[constants_offset + b".constant".len()..literals_offset];
         let constants_section = &bytes[constants_offset + b".constant".len()..literals_offset];
-        let literals_section = &bytes[literals_offset + b".literal".len()..contract_offset];
-        let contract_section = &bytes[contract_offset + b".contract".len()..circuit_offset];
+        let literals_section = &bytes[literals_offset + b".literal".len()..witness_offset];
+        let witness_section = &bytes[witness_offset + b".witness".len()..circuit_offset];
         let circuit_section = &bytes[circuit_offset + b".circuit".len()..debug_offset];
         let circuit_section = &bytes[circuit_offset + b".circuit".len()..debug_offset];
 
 
         let constants = ZkBinary::parse_constants(constants_section)?;
         let constants = ZkBinary::parse_constants(constants_section)?;
         let literals = ZkBinary::parse_literals(literals_section)?;
         let literals = ZkBinary::parse_literals(literals_section)?;
-        let witnesses = ZkBinary::parse_contract(contract_section)?;
+        let witnesses = ZkBinary::parse_witness(witness_section)?;
         let opcodes = ZkBinary::parse_circuit(circuit_section)?;
         let opcodes = ZkBinary::parse_circuit(circuit_section)?;
 
 
         // TODO: Debug info
         // TODO: Debug info
@@ -153,7 +153,7 @@ impl ZkBinary {
         Ok(literals)
         Ok(literals)
     }
     }
 
 
-    fn parse_contract(bytes: &[u8]) -> Result<Vec<VarType>> {
+    fn parse_witness(bytes: &[u8]) -> Result<Vec<VarType>> {
         let mut witnesses = vec![];
         let mut witnesses = vec![];
 
 
         let mut iter_offset = 0;
         let mut iter_offset = 0;

+ 30 - 30
src/zkas/parser.rs

@@ -30,10 +30,10 @@ 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; 3] = ["constant", "contract", "circuit"];
+const KEYWORDS: [&str; 3] = ["constant", "witness", "circuit"];
 
 
 /// Forbidden namespaces
 /// Forbidden namespaces
-const NOPE_NS: [&str; 4] = [".constant", ".literal", ".contract", ".circuit"];
+const NOPE_NS: [&str; 4] = [".constant", ".literal", ".witness", ".circuit"];
 
 
 /// Valid EcFixedPoint constant names supported by the VM.
 /// Valid EcFixedPoint constant names supported by the VM.
 const VALID_ECFIXEDPOINT: [&str; 1] = ["VALUE_COMMIT_RANDOM"];
 const VALID_ECFIXEDPOINT: [&str; 1] = ["VALUE_COMMIT_RANDOM"];
@@ -63,25 +63,25 @@ impl Parser {
         // We use these to keep state while parsing.
         // We use these to keep state while parsing.
         let mut namespace = None;
         let mut namespace = None;
         let (mut declaring_constant, mut declared_constant) = (false, false);
         let (mut declaring_constant, mut declared_constant) = (false, false);
-        let (mut declaring_contract, mut declared_contract) = (false, false);
+        let (mut declaring_witness, mut declared_witness) = (false, false);
         let (mut declaring_circuit, mut declared_circuit) = (false, false);
         let (mut declaring_circuit, mut declared_circuit) = (false, false);
 
 
         // The tokens gathered from each of the sections
         // The tokens gathered from each of the sections
         let mut constant_tokens = vec![];
         let mut constant_tokens = vec![];
-        let mut contract_tokens = vec![];
+        let mut witness_tokens = vec![];
         let mut circuit_tokens = vec![];
         let mut circuit_tokens = vec![];
 
 
         // Tokens belonging to the current statement
         // Tokens belonging to the current statement
         let mut circuit_stmt = vec![];
         let mut circuit_stmt = vec![];
         // All completed statements are pushed here
         // All completed statements are pushed here
         let mut circuit_stmts = vec![];
         let mut circuit_stmts = vec![];
-        // Contains constant and contract sections
+        // Contains constant and witness sections
         let mut ast_inner = IndexMap::new();
         let mut ast_inner = IndexMap::new();
         let mut ast = IndexMap::new();
         let mut ast = IndexMap::new();
 
 
         if self.tokens[0].token_type != TokenType::Symbol {
         if self.tokens[0].token_type != TokenType::Symbol {
             self.error.abort(
             self.error.abort(
-                "Source file does not start with a section. Expected `constant/contract/circuit`.",
+                "Source file does not start with a section. Expected `constant/witness/circuit`.",
                 0,
                 0,
                 0,
                 0,
             );
             );
@@ -89,7 +89,7 @@ impl Parser {
 
 
         let mut iter = self.tokens.iter();
         let mut iter = self.tokens.iter();
         while let Some(t) = iter.next() {
         while let Some(t) = iter.next() {
-            // Sections "constant", "contract", and "circuit" are
+            // Sections "constant", "witness", and "circuit" are
             // the sections we must be declaring in our source code.
             // the sections we must be declaring in our source code.
             // When we find one, we'll take all the tokens found in
             // When we find one, we'll take all the tokens found in
             // the section and place them in their respective vec.
             // the section and place them in their respective vec.
@@ -97,7 +97,7 @@ impl Parser {
             // the sections are closed off with braces. This should
             // the sections are closed off with braces. This should
             // be revisited later when we decide to add other lang
             // be revisited later when we decide to add other lang
             // functionality that also depends on using braces.
             // functionality that also depends on using braces.
-            if !declaring_constant && !declaring_contract && !declaring_circuit {
+            if !declaring_constant && !declaring_witness && !declaring_circuit {
                 //
                 //
                 // We use this macro to avoid code repetition in the following
                 // We use this macro to avoid code repetition in the following
                 // match statement for soaking up the section tokens.
                 // match statement for soaking up the section tokens.
@@ -127,9 +127,9 @@ impl Parser {
                         declaring_constant = true;
                         declaring_constant = true;
                         absorb_inner_tokens!(constant_tokens);
                         absorb_inner_tokens!(constant_tokens);
                     }
                     }
-                    "contract" => {
-                        declaring_contract = true;
-                        absorb_inner_tokens!(contract_tokens);
+                    "witness" => {
+                        declaring_witness = true;
+                        absorb_inner_tokens!(witness_tokens);
                     }
                     }
                     "circuit" => {
                     "circuit" => {
                         declaring_circuit = true;
                         declaring_circuit = true;
@@ -210,19 +210,19 @@ impl Parser {
                 declared_constant = true;
                 declared_constant = true;
             }
             }
 
 
-            // Parse the contract section into the AST.
-            if declaring_contract {
-                if declared_contract {
-                    self.error.abort("Duplicate `contract` section found.", t.line, t.column);
+            // Parse the witness section into the AST.
+            if declaring_witness {
+                if declared_witness {
+                    self.error.abort("Duplicate `witness` section found.", t.line, t.column);
                 }
                 }
 
 
-                self.check_section_structure("contract", contract_tokens.clone());
-                check_namespace!(contract_tokens);
+                self.check_section_structure("witness", witness_tokens.clone());
+                check_namespace!(witness_tokens);
 
 
                 let mut witnesses_map = IndexMap::new();
                 let mut witnesses_map = IndexMap::new();
                 // This is everything between the braces: { ... }
                 // This is everything between the braces: { ... }
-                let mut contract_inner = contract_tokens[2..contract_tokens.len() - 1].iter();
-                while let Some((typ, name, comma)) = contract_inner.next_tuple() {
+                let mut witness_inner = witness_tokens[2..witness_tokens.len() - 1].iter();
+                while let Some((typ, name, comma)) = witness_inner.next_tuple() {
                     if comma.token_type != TokenType::Comma {
                     if comma.token_type != TokenType::Comma {
                         self.error.abort("Separator is not a comma.", comma.line, comma.column);
                         self.error.abort("Separator is not a comma.", comma.line, comma.column);
                     }
                     }
@@ -231,7 +231,7 @@ impl Parser {
                     if witnesses_map.contains_key(name.token.as_str()) {
                     if witnesses_map.contains_key(name.token.as_str()) {
                         self.error.abort(
                         self.error.abort(
                             &format!(
                             &format!(
-                                "Section `contract` already contains the token `{}`.",
+                                "Section `witness` already contains the token `{}`.",
                                 &name.token
                                 &name.token
                             ),
                             ),
                             name.line,
                             name.line,
@@ -242,13 +242,13 @@ impl Parser {
                     witnesses_map.insert(name.token.clone(), (name.clone(), typ.clone()));
                     witnesses_map.insert(name.token.clone(), (name.clone(), typ.clone()));
                 }
                 }
 
 
-                if contract_inner.next().is_some() {
-                    self.error.abort("Internal error, leftovers in 'contract' iterator", 0, 0);
+                if witness_inner.next().is_some() {
+                    self.error.abort("Internal error, leftovers in 'witness' iterator", 0, 0);
                 }
                 }
 
 
-                ast_inner.insert("contract".to_string(), witnesses_map);
-                declaring_contract = false;
-                declared_contract = true;
+                ast_inner.insert("witness".to_string(), witnesses_map);
+                declaring_witness = false;
+                declared_witness = true;
             }
             }
 
 
             // Parse the circuit section into the AST.
             // Parse the circuit section into the AST.
@@ -293,14 +293,14 @@ impl Parser {
         };
         };
 
 
         let witnesses = {
         let witnesses = {
-            let c = match ast.get(&ns).unwrap().get("contract") {
+            let c = match ast.get(&ns).unwrap().get("witness") {
                 Some(c) => c,
                 Some(c) => c,
                 None => {
                 None => {
-                    self.error.abort("Missing `contract` section in .zk source.", 0, 0);
+                    self.error.abort("Missing `witness` section in .zk source.", 0, 0);
                     unreachable!();
                     unreachable!();
                 }
                 }
             };
             };
-            self.parse_ast_contract(c)
+            self.parse_ast_witness(c)
         };
         };
 
 
         let statements = self.parse_ast_circuit(circuit_stmts);
         let statements = self.parse_ast_circuit(circuit_stmts);
@@ -338,7 +338,7 @@ impl Parser {
         }
         }
 
 
         match section {
         match section {
-            "constant" | "contract" => {
+            "constant" | "witness" => {
                 if tokens.len() == 3 {
                 if tokens.len() == 3 {
                     self.error.warn(&format!("{} section is empty.", section), 0, 0);
                     self.error.warn(&format!("{} section is empty.", section), 0, 0);
                 }
                 }
@@ -477,7 +477,7 @@ impl Parser {
         ret
         ret
     }
     }
 
 
-    fn parse_ast_contract(&self, ast: &IndexMap<String, (Token, Token)>) -> Vec<Witness> {
+    fn parse_ast_witness(&self, ast: &IndexMap<String, (Token, Token)>) -> Vec<Witness> {
         let mut ret = vec![];
         let mut ret = vec![];
 
 
         // k = name
         // k = name