Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Mar 1, 2024
1 parent 62aae1f commit f438ed0
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 18 deletions.
2 changes: 1 addition & 1 deletion boxes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM aztecprotocol/noir-projects as noir-projects
# We need yarn. Start fresh container.
FROM node:18.19.0
RUN apt update && apt install netcat-openbsd
RUN npx -y playwright@1.41.1 install --with-deps
RUN npx -y playwright@1.42.0 install --with-deps
COPY --from=aztec /usr/src /usr/src
COPY --from=noir /usr/src/noir/noir-repo/target/release/nargo /usr/src/noir/noir-repo/target/release/nargo
COPY --from=noir-projects /usr/src/noir-projects/aztec-nr /usr/src/noir-projects/aztec-nr
Expand Down
6 changes: 5 additions & 1 deletion boxes/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
"yup": "^1.2.0"
},
"devDependencies": {
<<<<<<< Updated upstream:boxes/react/package.json
=======
"@playwright/test": "1.42.0",
>>>>>>> Stashed changes:boxes/boxes/react/package.json
"@types/jest": "^29.5.0",
"@types/node": "^20.11.21",
"@types/node": "^20.5.9",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion boxes/react/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
testDir: './tests',
testMatch: '**.spec.ts',
fullyParallel: true,
retries: process.env.CI ? 3 : 0,
retries: 3,
workers: process.env.CI ? 1 : 3,
reporter: 'list',
use: {
Expand Down
2 changes: 1 addition & 1 deletion boxes/vanilla-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@aztec/aztec.js": "latest"
},
"devDependencies": {
"@playwright/test": "^1.41.2",
"@playwright/test": "1.42.0",
"@types/node": "^20.11.17",
"copy-webpack-plugin": "^11.0.0",
"html-webpack-plugin": "^5.6.0",
Expand Down
2 changes: 1 addition & 1 deletion boxes/vanilla-js/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
retries: process.env.CI ? 3 : 1,
retries: 3,
workers: process.env.CI ? 1 : 3,
reporter: 'list',
use: {
Expand Down
79 changes: 76 additions & 3 deletions boxes/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,58 @@ __metadata:
languageName: node
linkType: soft

"@aztec/react@workspace:boxes/react":
version: 0.0.0-use.local
resolution: "@aztec/react@workspace:boxes/react"
dependencies:
"@aztec/accounts": "npm:latest"
"@aztec/aztec.js": "npm:latest"
"@playwright/test": "npm:1.42.0"
"@types/jest": "npm:^29.5.0"
"@types/node": "npm:^20.11.21"
"@types/react": "npm:^18.2.15"
"@types/react-dom": "npm:^18.2.7"
"@typescript-eslint/eslint-plugin": "npm:^6.0.0"
"@typescript-eslint/parser": "npm:^6.0.0"
autoprefixer: "npm:^10.4.15"
classnames: "npm:^2.3.2"
copy-webpack-plugin: "npm:^11.0.0"
css-loader: "npm:^6.8.1"
eslint: "npm:^8.21.0"
eslint-config-prettier: "npm:^9.0.0"
eslint-import-resolver-typescript: "npm:^3.5.5"
eslint-plugin-import: "npm:^2.27.5"
eslint-plugin-prettier: "npm:^5.0.1"
eslint-plugin-react-hooks: "npm:^4.6.0"
eslint-plugin-react-refresh: "npm:^0.4.3"
formik: "npm:^2.4.3"
html-webpack-plugin: "npm:^5.6.0"
jest: "npm:^29.6.4"
node-sass: "npm:^9.0.0"
postcss: "npm:^8.4.29"
postcss-loader: "npm:^7.3.3"
prettier: "npm:^3.1.1"
react: "npm:^18.2.0"
react-dom: "npm:^18.2.0"
react-toastify: "npm:^10.0.4"
resolve-typescript-plugin: "npm:^2.0.1"
sass-loader: "npm:^13.3.2"
serve: "npm:^14.2.1"
stream-browserify: "npm:^3.0.0"
style-loader: "npm:^3.3.3"
ts-jest: "npm:^29.1.0"
ts-loader: "npm:^9.4.4"
ts-node: "npm:^10.9.1"
tty-browserify: "npm:^0.0.1"
typescript: "npm:^5.0.4"
util: "npm:^0.12.5"
webpack: "npm:^5.88.2"
webpack-cli: "npm:^5.1.4"
webpack-dev-server: "npm:^4.15.1"
yup: "npm:^1.2.0"
languageName: unknown
linkType: soft

"@aztec/types@portal:../yarn-project/types::locator=create-aztec-app%40workspace%3A.":
version: 0.0.0-use.local
resolution: "@aztec/types@portal:../yarn-project/types::locator=create-aztec-app%40workspace%3A."
Expand All @@ -243,6 +295,27 @@ __metadata:
languageName: node
linkType: soft

"@aztec/vanilla@workspace:boxes/vanilla":
version: 0.0.0-use.local
resolution: "@aztec/vanilla@workspace:boxes/vanilla"
dependencies:
"@aztec/accounts": "npm:latest"
"@aztec/aztec.js": "npm:latest"
"@playwright/test": "npm:1.42.0"
"@types/node": "npm:^20.11.17"
copy-webpack-plugin: "npm:^11.0.0"
html-webpack-plugin: "npm:^5.6.0"
stream-browserify: "npm:^3.0.0"
ts-loader: "npm:^9.5.1"
tty-browserify: "npm:^0.0.1"
typescript: "npm:^5.0.4"
util: "npm:^0.12.5"
webpack: "npm:^5.90.1"
webpack-cli: "npm:^5.1.4"
webpack-dev-server: "npm:^4.15.1"
languageName: unknown
linkType: soft

"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.23.5":
version: 7.23.5
resolution: "@babel/code-frame@npm:7.23.5"
Expand Down Expand Up @@ -1272,9 +1345,9 @@ __metadata:
languageName: node
linkType: hard

"@playwright/test@npm:^1.41.2":
version: 1.41.2
resolution: "@playwright/test@npm:1.41.2"
"@playwright/test@npm:1.42.0":
version: 1.42.0
resolution: "@playwright/test@npm:1.42.0"
dependencies:
playwright: "npm:1.41.2"
bin:
Expand Down
1 change: 1 addition & 0 deletions docs/deploy_netlify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ else

# Regular deploy if the argument is not "master" and docs changed
DEPLOY_OUTPUT=$(netlify deploy --site aztec-docs-dev)
echo "$DEPLOY_OUTPUT"
UNIQUE_DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -E "https://.*aztec-docs-dev.netlify.app" | awk '{print $4}')
echo "Unique deploy URL: $UNIQUE_DEPLOY_URL"

Expand Down
105 changes: 95 additions & 10 deletions noir/noir-repo/aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum AztecMacroError {
UnsupportedStorageType { span: Option<Span>, typ: UnresolvedTypeData },
CouldNotAssignStorageSlots { secondary_message: Option<String> },
EventError { span: Span, message: String },
UnsupportedAttributes { span: Span, secondary_message: Option<String> },
}

impl From<AztecMacroError> for MacroError {
Expand Down Expand Up @@ -114,6 +115,11 @@ impl From<AztecMacroError> for MacroError {
secondary_message: None,
span: Some(span),
},
AztecMacroError::UnsupportedAttributes { span, secondary_message } => MacroError {
primary_message: "Unsupported attributes in contract function".to_string(),
secondary_message,
span: Some(span),
},
}
}
}
Expand Down Expand Up @@ -430,22 +436,43 @@ fn transform_module(
}

for func in module.functions.iter_mut() {
let mut is_private = false;
let mut is_public = false;
let mut is_public_vm = false;
let mut is_initializer = false;
let mut skip_init_check = true; // Default to true once we're confident that the approach works

for secondary_attribute in func.def.attributes.secondary.clone() {
let crate_graph = &context.crate_graph[crate_id];
if is_custom_attribute(&secondary_attribute, "aztec(private)") {
transform_function("Private", func, storage_defined)
.map_err(|err| (err, crate_graph.root_file_id))?;
has_transformed_module = true;
is_private = true;
} else if is_custom_attribute(&secondary_attribute, "aztec(initializer)") {
is_initializer = true;
} else if is_custom_attribute(&secondary_attribute, "aztec(initcheck)") {
skip_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(public)") {
transform_function("Public", func, storage_defined)
.map_err(|err| (err, crate_graph.root_file_id))?;
has_transformed_module = true;
is_public = true;
} else if is_custom_attribute(&secondary_attribute, "aztec(public-vm)") {
transform_vm_function(func, storage_defined)
.map_err(|err| (err, crate_graph.root_file_id))?;
has_transformed_module = true;
is_public_vm = true;
}
}

// Apply transformations to the function based on collected attributes
if is_private || is_public {
transform_function(
if is_private { "Private" } else { "Public" },
func,
storage_defined,
is_initializer,
skip_init_check,
)
.map_err(|err| (err, crate_graph.root_file_id))?;
has_transformed_module = true;
} else if is_public_vm {
transform_vm_function(func, storage_defined)
.map_err(|err| (err, crate_graph.root_file_id))?;
has_transformed_module = true;
}

// Add the storage struct to the beginning of the function if it is unconstrained in an aztec contract
if storage_defined && func.def.is_unconstrained {
transform_unconstrained(func);
Expand Down Expand Up @@ -627,11 +654,28 @@ fn transform_function(
ty: &str,
func: &mut NoirFunction,
storage_defined: bool,
is_initializer: bool,
skip_init_check: bool,
) -> Result<(), AztecMacroError> {
let context_name = format!("{}Context", ty);
let inputs_name = format!("{}ContextInputs", ty);
let return_type_name = format!("{}CircuitPublicInputs", ty);

// Add initialization check
if !skip_init_check {
if ty == "Public" {
let error = AztecMacroError::UnsupportedAttributes {
span: func.def.name.span(),
secondary_message: Some(
"public functions do not yet support initialization check".to_owned(),
),
};
return Err(error);
}
let init_check = create_init_check();
func.def.body.0.insert(0, init_check);
}

// Add access to the storage struct
if storage_defined {
let storage_def = abstract_storage(&ty.to_lowercase(), false);
Expand All @@ -655,6 +699,21 @@ fn transform_function(
func.def.body.0.push(return_values);
}

// Before returning mark the contract as initialized
if is_initializer {
if ty == "Public" {
let error = AztecMacroError::UnsupportedAttributes {
span: func.def.name.span(),
secondary_message: Some(
"public functions cannot yet be used as initializers".to_owned(),
),
};
return Err(error);
}
let mark_initialized = create_mark_as_initialized();
func.def.body.0.push(mark_initialized);
}

// Push the finish method call to the end of the function
let finish_def = create_context_finish();
func.def.body.0.push(finish_def);
Expand Down Expand Up @@ -1091,6 +1150,32 @@ fn create_inputs(ty: &str) -> Param {
Param { pattern: context_pattern, typ: context_type, visibility, span: Span::default() }
}

/// Creates an initialization check to ensure that the contract has been initialized, meant to
/// be injected as the first statement of any function after the context has been created.
///
/// ```noir
/// assert_is_initialized(&mut context);
/// ```
fn create_init_check() -> Statement {
make_statement(StatementKind::Expression(call(
variable_path(chained_path!("aztec", "initializer", "assert_is_initialized")),
vec![mutable_reference("context")],
)))
}

/// Creates a call to mark_as_initialized which emits the initialization nullifier, meant to
/// be injected as the last statement before returning in a constructor.
///
/// ```noir
/// mark_as_initialized(&mut context);
/// ```
fn create_mark_as_initialized() -> Statement {
make_statement(StatementKind::Expression(call(
variable_path(chained_path!("aztec", "initializer", "mark_as_initialized")),
vec![mutable_reference("context")],
)))
}

/// Creates the private context object to be accessed within the function, the parameters need to be extracted to be
/// appended into the args hash object.
///
Expand Down

0 comments on commit f438ed0

Please sign in to comment.