@aztec/aztec 0.0.1-commit.381b1a9 → 0.0.1-commit.3a4ae741b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dest/cli/aztec_start_action.d.ts +1 -1
  2. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  3. package/dest/cli/aztec_start_action.js +5 -1
  4. package/dest/cli/aztec_start_options.js +1 -1
  5. package/dest/cli/cli.js +3 -3
  6. package/dest/cli/cmds/compile.d.ts +1 -1
  7. package/dest/cli/cmds/compile.d.ts.map +1 -1
  8. package/dest/cli/cmds/compile.js +99 -1
  9. package/dest/cli/cmds/profile_flamegraph.d.ts +1 -1
  10. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -1
  11. package/dest/cli/cmds/profile_flamegraph.js +2 -1
  12. package/dest/cli/cmds/profile_gates.d.ts +1 -1
  13. package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
  14. package/dest/cli/cmds/profile_gates.js +2 -1
  15. package/dest/cli/cmds/start_archiver.d.ts +2 -2
  16. package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
  17. package/dest/cli/cmds/start_archiver.js +1 -1
  18. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  19. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  20. package/dest/cli/cmds/utils/needs_recompile.js +134 -0
  21. package/dest/cli/util.js +3 -3
  22. package/dest/testing/anvil_test_watcher.js +1 -1
  23. package/dest/testing/cheat_codes.js +1 -1
  24. package/package.json +34 -34
  25. package/scripts/add_crate.sh +102 -0
  26. package/scripts/aztec.sh +4 -2
  27. package/scripts/init.sh +23 -19
  28. package/scripts/new.sh +48 -24
  29. package/scripts/setup_workspace.sh +68 -0
  30. package/src/cli/aztec_start_action.ts +2 -1
  31. package/src/cli/aztec_start_options.ts +1 -1
  32. package/src/cli/cli.ts +3 -3
  33. package/src/cli/cmds/compile.ts +112 -1
  34. package/src/cli/cmds/profile_flamegraph.ts +2 -1
  35. package/src/cli/cmds/profile_gates.ts +2 -1
  36. package/src/cli/cmds/start_archiver.ts +1 -1
  37. package/src/cli/cmds/utils/needs_recompile.ts +151 -0
  38. package/src/cli/util.ts +2 -2
  39. package/src/testing/anvil_test_watcher.ts +1 -1
  40. package/src/testing/cheat_codes.ts +1 -1
  41. package/scripts/setup_project.sh +0 -31
@@ -0,0 +1,151 @@
1
+ import TOML from '@iarna/toml';
2
+ import { readFile, readdir, stat } from 'fs/promises';
3
+ import { join, resolve } from 'path';
4
+
5
+ /**
6
+ * Returns true if recompilation is needed: either no artifacts exist in target/ or any .nr or Nargo.toml source file
7
+ * (including path-based dependencies) is newer than the oldest artifact. We compare against the oldest artifact so
8
+ * that a source change between the oldest and newest compilation (e.g. in a multi-contract workspace) still triggers
9
+ * a recompile.
10
+ *
11
+ * Note: The above implies that if there is a random json file in the target dir we would be always recompiling.
12
+ */
13
+ export async function needsRecompile(): Promise<boolean> {
14
+ const oldestArtifactMs = await getOldestArtifactModificationTime('target');
15
+ if (oldestArtifactMs === undefined) {
16
+ return true;
17
+ }
18
+
19
+ const crateDirs = await collectCrateDirs('.');
20
+ return hasNewerSourceFile(crateDirs, oldestArtifactMs);
21
+ }
22
+
23
+ /**
24
+ * Returns the last modification time (timestamp in ms) of the oldest .json artifact in targetDir, or undefined if
25
+ * none exist.
26
+ */
27
+ async function getOldestArtifactModificationTime(targetDir: string): Promise<number | undefined> {
28
+ let entries: string[];
29
+ try {
30
+ entries = (await readdir(targetDir)).filter(f => f.endsWith('.json'));
31
+ } catch (err: any) {
32
+ if (err?.code === 'ENOENT') {
33
+ return undefined;
34
+ }
35
+ throw err;
36
+ }
37
+
38
+ if (entries.length === 0) {
39
+ return undefined;
40
+ }
41
+
42
+ let oldest = Infinity;
43
+ for (const entry of entries) {
44
+ const s = await stat(join(targetDir, entry));
45
+ if (s.mtimeMs < oldest) {
46
+ oldest = s.mtimeMs;
47
+ }
48
+ }
49
+ return oldest;
50
+ }
51
+
52
+ /**
53
+ * Recursively collects crate directories starting from startCrateDir by following path-based dependencies declared in
54
+ * Nargo.toml files. Git-based deps are ignored (they only change when Nargo.toml itself is modified since the deps are
55
+ * tagged).
56
+ */
57
+ async function collectCrateDirs(startCrateDir: string): Promise<string[]> {
58
+ // We have a set of visited dirs we check against when entering a new dir because we could stumble upon a directory
59
+ // multiple times in case multiple deps shared a dep (e.g. dep A and dep B both sharing dep C).
60
+ const visited = new Set<string>();
61
+
62
+ async function visit(crateDir: string): Promise<void> {
63
+ const absDir = resolve(crateDir);
64
+ if (visited.has(absDir)) {
65
+ return;
66
+ }
67
+ visited.add(absDir);
68
+
69
+ // Every dep is its own crate and every crate needs to have Nargo.toml defined in the root so we try to load it and
70
+ // error out if it's not the case.
71
+ const tomlPath = join(absDir, 'Nargo.toml');
72
+ const content = await readFile(tomlPath, 'utf-8').catch(() => {
73
+ throw new Error(`Incorrectly defined dependency. Nargo.toml not found in ${absDir}`);
74
+ });
75
+
76
+ const parsed = TOML.parse(content) as Record<string, any>;
77
+
78
+ const members = (parsed.workspace as Record<string, any>)?.members as string[] | undefined;
79
+
80
+ // A Nargo.toml is either a workspace root (has workspace.members) or a single crate (has dependencies).
81
+ if (Array.isArray(members)) {
82
+ // The crate is a workspace root and has members defined so we visit the members
83
+ for (const member of members) {
84
+ const memberPath = resolve(absDir, member);
85
+ await visit(memberPath);
86
+ }
87
+ } else {
88
+ // The crate is not a workspace root so we check for dependencies
89
+ const deps = (parsed.dependencies as Record<string, any>) ?? {};
90
+ for (const dep of Object.values(deps)) {
91
+ if (dep && typeof dep === 'object' && typeof dep.path === 'string') {
92
+ const depPath = resolve(absDir, dep.path);
93
+ const s = await stat(depPath);
94
+ if (!s.isDirectory()) {
95
+ throw new Error(
96
+ `Dependency path "${dep.path}" in ${tomlPath} resolves to ${depPath} which is not a directory`,
97
+ );
98
+ }
99
+ await visit(depPath);
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ await visit(startCrateDir);
106
+ return [...visited];
107
+ }
108
+
109
+ /**
110
+ * Walks crate dirs looking for .nr and Nargo.toml files newer than thresholdMs. Short-circuits on the first match.
111
+ */
112
+ async function hasNewerSourceFile(crateDirs: string[], thresholdMs: number): Promise<boolean> {
113
+ // Returns true if it find a new file than thresholdMs, false otherwise
114
+ async function walkForNewer(dir: string): Promise<boolean> {
115
+ let entries;
116
+ try {
117
+ entries = await readdir(dir, { withFileTypes: true });
118
+ } catch {
119
+ return false;
120
+ }
121
+
122
+ // We iterate over the entries in the dir
123
+ for (const entry of entries) {
124
+ const fullPath = join(dir, entry.name);
125
+ if (entry.isDirectory()) {
126
+ // If the entry is a dir and it's not called `target` we recursively enter it
127
+ if (entry.name === 'target') {
128
+ continue;
129
+ }
130
+ if (await walkForNewer(fullPath)) {
131
+ return true;
132
+ }
133
+ } else if (entry.name === 'Nargo.toml' || entry.name.endsWith('.nr')) {
134
+ // The entry is a Nargo.toml file or *.nr file so we check the timestamp
135
+ const s = await stat(fullPath);
136
+ if (s.mtimeMs > thresholdMs) {
137
+ return true;
138
+ }
139
+ }
140
+ }
141
+ return false;
142
+ }
143
+
144
+ // We search through the crate dirs
145
+ for (const dir of crateDirs) {
146
+ if (await walkForNewer(dir)) {
147
+ return true;
148
+ }
149
+ }
150
+ return false;
151
+ }
package/src/cli/util.ts CHANGED
@@ -272,7 +272,7 @@ export async function preloadCrsDataForVerifying(
272
272
  ): Promise<void> {
273
273
  if (realProofs) {
274
274
  const { Crs, GrumpkinCrs } = await import('@aztec/bb.js');
275
- await Promise.all([Crs.new(2 ** 1, undefined, log), GrumpkinCrs.new(2 ** 16 + 1, undefined, log)]);
275
+ await Promise.all([Crs.new(2 ** 1, undefined, log), GrumpkinCrs.new(2 ** 16, undefined, log)]);
276
276
  }
277
277
  }
278
278
 
@@ -287,7 +287,7 @@ export async function preloadCrsDataForServerSideProving(
287
287
  ): Promise<void> {
288
288
  if (realProofs) {
289
289
  const { Crs, GrumpkinCrs } = await import('@aztec/bb.js');
290
- await Promise.all([Crs.new(2 ** 25 + 1, undefined, log), GrumpkinCrs.new(2 ** 18 + 1, undefined, log)]);
290
+ await Promise.all([Crs.new(2 ** 25, undefined, log), GrumpkinCrs.new(2 ** 18, undefined, log)]);
291
291
  }
292
292
  }
293
293
 
@@ -130,7 +130,7 @@ export class AnvilTestWatcher {
130
130
  return;
131
131
  }
132
132
 
133
- const l1Time = (await this.cheatcodes.timestamp()) * 1000;
133
+ const l1Time = (await this.cheatcodes.lastBlockTimestamp()) * 1000;
134
134
  const wallTime = this.dateProvider.now();
135
135
  if (l1Time > wallTime) {
136
136
  this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
@@ -72,7 +72,7 @@ export class CheatCodes {
72
72
  * @param duration - The duration to advance time by (in seconds)
73
73
  */
74
74
  async warpL2TimeAtLeastBy(sequencerClient: SequencerClient, node: AztecNode, duration: bigint | number) {
75
- const currentTimestamp = await this.eth.timestamp();
75
+ const currentTimestamp = await this.eth.lastBlockTimestamp();
76
76
  const targetTimestamp = BigInt(currentTimestamp) + BigInt(duration);
77
77
  await this.warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp);
78
78
  }
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- # Get the actual aztec version for the git tag.
5
- AZTEC_VERSION=$(jq -r '.version' $(dirname $0)/../package.json)
6
- NARGO_TOML_PATH="Nargo.toml"
7
- MAIN_NR_PATH="src/main.nr"
8
-
9
- if [ ! -f "$NARGO_TOML_PATH" ]; then
10
- >&2 echo "Warning: Could not find Nargo.toml at $NARGO_TOML_PATH to add aztec dependency"
11
- exit 1
12
- fi
13
-
14
- if [ ! -f "$MAIN_NR_PATH" ]; then
15
- >&2 echo "Warning: Could not find main.nr at $MAIN_NR_PATH"
16
- exit 1
17
- fi
18
-
19
- # Add aztec dependency to Nargo.toml
20
- echo "" >> "$NARGO_TOML_PATH"
21
- echo "aztec = { git=\"https://github.com/AztecProtocol/aztec-nr\", tag=\"v${AZTEC_VERSION}\", directory=\"aztec\" }" >> "$NARGO_TOML_PATH"
22
- echo "Added aztec dependency (v${AZTEC_VERSION}) to Nargo.toml"
23
-
24
- # Replace the contents of main.nr with the Aztec contract template
25
- cat > "$MAIN_NR_PATH" << 'EOF'
26
- use aztec::macros::aztec;
27
-
28
- #[aztec]
29
- contract Main {}
30
- EOF
31
- echo "Created main.nr with Aztec contract template"