Skip to content

Commit

Permalink
Edit JSON Abi to include whether a function is open
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Mar 27, 2023
1 parent ce44ef3 commit 15e4950
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 3 additions & 23 deletions crates/noirc_driver/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
use std::collections::BTreeMap;

use noirc_frontend::ContractVisibility;

use crate::CompiledProgram;

/// ContractFunctionType describes the types
/// smart contract functions that are allowed.
///
/// Note:
/// - All Noir programs in the non-contract context
/// can be seen as `Secret`.
/// - It may be possible to have `unconstrained`
/// functions in regular Noir programs. For now
/// we leave it as a property of only contract functions.
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ContractFunctionType {
/// This function will be executed in a private
/// context.
Secret,
/// This function will be executed in a public
/// context.
Public,
/// A function which is non-deterministic
/// and does not require any constraints.
Unconstrained,
}
/// Each function in the contract will be compiled
/// as a separate noir program.
///
Expand All @@ -32,7 +12,7 @@ pub enum ContractFunctionType {
/// One of these being a function type.
#[derive(serde::Serialize, serde::Deserialize)]
pub struct ContractFunction {
pub func_type: ContractFunctionType,
pub func_type: ContractVisibility,
pub function: CompiledProgram,
}

Expand Down
10 changes: 5 additions & 5 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ impl Driver {
contract: Contract,
options: &CompileOptions,
) -> Result<CompiledContract, ReportedError> {
let functions = try_btree_map(&contract.functions, |function| {
let function_name = self.function_name(*function).to_owned();
let function = self.compile_no_check(options, *function)?;
let func_type = contract::ContractFunctionType::Secret;
// Note: currently we mark all of the contract methods as secret as we do not support public functions.
let functions = try_btree_map(&contract.functions, |function_id| {
let function_name = self.function_name(*function_id).to_owned();
let function = self.compile_no_check(options, *function_id)?;
let func_type =
self.context.def_interner.function_meta(function_id).contract_visibility;
Ok((function_name, ContractFunction { func_type, function }))
})?;

Expand Down
3 changes: 2 additions & 1 deletion crates/noirc_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ iter-extended.workspace = true
chumsky.workspace = true
thiserror.workspace = true
smol_str.workspace = true
serde.workspace = true
rustc-hash = "1.1.0"

[dev-dependencies]
strum = "0.24"
strum_macros = "0.24"
strum_macros = "0.24"
23 changes: 18 additions & 5 deletions crates/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,26 @@ pub struct FunctionDefinition {
pub return_visibility: noirc_abi::AbiVisibility,
}

/// The visibility a function has in the contract it is defined within.
/// If the function is not defined within a contract, this should always be 'Secret'.
/// Likewise, if a function does not specify its visibility, it defaults to 'Secret'.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
/// ContractFunctionType describes the types
/// smart contract functions that are allowed.
///
/// Note:
/// - All Noir programs in the non-contract context
/// can be seen as `Secret`.
/// - It may be possible to have `unconstrained`
/// functions in regular Noir programs. For now
/// we leave it as a property of only contract functions.
#[derive(serde::Serialize, serde::Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ContractVisibility {
Open,
/// This function will be executed in a private
/// context.
Secret,
/// This function will be executed in a public
/// context.
Open,
/// A function which is non-deterministic
/// and does not require any constraints.
Unconstrained,
}

Expand Down

0 comments on commit 15e4950

Please sign in to comment.