Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACE backend: a code generator from AirScript to the ACE chiplet of Miden's recursive verifier #370

Draft
wants to merge 142 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
4d83841
fix: small tweaks to parser test helpers
bitwalker Jul 21, 2023
451119b
fix: incorrect propagation of constraint flag during inlining
bitwalker Jul 21, 2023
2ea09c6
chore: update create versions to v0.4.0
bobbinth Jul 25, 2023
5427353
feat: use a block syntax for declarations and statements blocks (#350)
AurelienFT Apr 21, 2024
e73ee03
docs: define random values in examples when they are used (#349)
AurelienFT Apr 22, 2024
b4a81e3
feat: add support for functions
bitwalker Oct 9, 2023
9c6a3ee
feat: support more expressive syntax in ast
bitwalker Jun 20, 2024
f266e4b
ci: update to 1.78, use explicit toolchain
bitwalker Jun 21, 2024
d70cd76
fix: a couple clippy warnings
bitwalker Jun 21, 2024
bc0e12e
chore: remove leftover todo
bitwalker Aug 9, 2024
0f5feff
chore: fix new clippy warnings in 1.80
bitwalker Aug 9, 2024
2ed3288
refactor: eliminate exponentiations in the IR (#352)
Leo-Besancon Aug 9, 2024
ea582d4
feat: use semicolons as statement terminators (#353)
sydhds Aug 12, 2024
433711c
feat(parser): add comma for case statement
sydhds Aug 19, 2024
2cadf30
feat: use semicolons as statement terminators (#353)
sydhds Aug 12, 2024
450dd7c
feat: support named constants in ranges
bitwalker Aug 15, 2024
eb8686b
feat: add error handling to range conversion
Leo-Besancon Aug 22, 2024
b8bae19
chore: refactor, add comments and remove unused code
Leo-Besancon Aug 21, 2024
f312232
test: add constant_in_range test
Leo-Besancon Aug 13, 2024
e619913
docs: add constant in range example
Leo-Besancon Aug 21, 2024
0a7796c
fix: fix example and update documentation following #353
Leo-Besancon Aug 21, 2024
13f34f6
Merge branch 'next' into allow-named-constants-range-notation
Leo-Besancon Aug 22, 2024
e9ad231
Merge pull request #356 from massalabs/add-case-comma
bitwalker Sep 4, 2024
900a80a
Merge pull request #355 from massalabs/allow-named-constants-range-no…
bitwalker Sep 18, 2024
24e687a
feat - move AlgebraicGraph from ir to codegen/air
Leo-Besancon Sep 23, 2024
92952bd
Base IR graph, to improve
Leo-Besancon Sep 26, 2024
f4880ab
Make base IR structure (passes / translation from AST..)
Leo-Besancon Sep 27, 2024
33da4a3
Additional structure (MIR > AIR lowering), added TODO MIR comments
Leo-Besancon Sep 27, 2024
c036336
Add comments to TODOs
Leo-Besancon Sep 30, 2024
d018fd6
Add typed nodes in the Mir
Leo-Besancon Oct 9, 2024
5047968
Update MirValues to account for all case of binding in the AST
Leo-Besancon Oct 11, 2024
f34d16c
Add type for new elements
Leo-Besancon Oct 11, 2024
a615a8b
Add function variable node type
Leo-Besancon Oct 11, 2024
1af3508
Update value.rs
Leo-Besancon Oct 11, 2024
e4ce487
Implement some elements for lowering from AST to MIR
Leo-Besancon Oct 15, 2024
7b554ba
Inlining unit test structure
Soulthym Oct 11, 2024
18c1870
MirType:
Soulthym Oct 11, 2024
21dc897
Add human readable serialization to MirGraph
Soulthym Oct 15, 2024
7c180c9
Make IR test pass
Leo-Besancon Oct 16, 2024
6e58c2a
Merge remote-tracking branch 'origin/thy-ir-inlining' into leo_loweri…
Leo-Besancon Oct 16, 2024
e8fa708
Fix conflict Option<>
Leo-Besancon Oct 16, 2024
b0df63d
fix Migraph pretty printer counters not being shared between recursions
Soulthym Oct 17, 2024
6e1ddc4
Merge branch 'thy-ir-inlining' into feat-implement-ir
Soulthym Oct 17, 2024
6ca0349
Reworked use_list, reworked placeholder mechanic + fmt
Leo-Besancon Oct 17, 2024
ee7f04d
Add placeholder type to avoid issues with Constant(0)
Leo-Besancon Oct 17, 2024
9a2f4f8
MirGraph pretty printer: add call support + track func indexes
Soulthym Oct 17, 2024
1d7ca53
Inlining test: complete Input
Soulthym Oct 17, 2024
33e022d
cargo fmt + clippy
Leo-Besancon Oct 17, 2024
7cadc6f
Fix double Enf in cas of Bindary::Eq
Leo-Besancon Oct 18, 2024
65db04c
improve MirGraph pretty printer
Soulthym Oct 18, 2024
b7834cb
Add root management to differentiate between dead nodes and root nodes
Leo-Besancon Oct 22, 2024
65e0bc6
Add functions tests in MIR
Leo-Besancon Oct 22, 2024
04ff191
Inlining 1/2: replace call(func, args) site by func.body
Soulthym Oct 17, 2024
2876cd8
Inlining 2/2: swap variables for arg values in inlined body
Soulthym Oct 22, 2024
a57a3b0
cargo fmt + clippy
Soulthym Oct 22, 2024
4804834
Add helpers to insert nodes for each operation
Leo-Besancon Nov 5, 2024
35dd907
Generic visitor
Soulthym Nov 6, 2024
03744ad
expose roots and graph to visitor
Soulthym Nov 6, 2024
64cf047
inlining with generic visitor
Soulthym Nov 6, 2024
a999882
implement post order visitor
Soulthym Nov 7, 2024
9176471
fix missing visit of stored nodes
Soulthym Nov 8, 2024
ac51b88
Rename VisitOrder::DepthFirst to Manual
Soulthym Nov 8, 2024
f60e664
Add unrolling and lowering
Leo-Besancon Nov 14, 2024
e9f1bd7
rework Operation: base structure
Soulthym Oct 31, 2024
4910417
fix ir2 module structure
Soulthym Nov 4, 2024
9e43103
implement Sub and Mul
Soulthym Nov 4, 2024
78ab06d
make Operands dyn Value
Soulthym Nov 5, 2024
f066d6a
blanket migration for degree and trace
Soulthym Nov 6, 2024
103f453
added Eq, Clone and Debug support to Value and Operations
Soulthym Nov 13, 2024
d130f97
convert MirValue to the new structure
Soulthym Nov 13, 2024
987aa35
ir2: new graph structure based on enums
Soulthym Nov 19, 2024
a76e357
Split graph module, and several improvements to the graph datastructure
Soulthym Nov 21, 2024
cbd6620
fix builder pattern duplication and split+rename NodeType
Soulthym Nov 26, 2024
858d012
replace asserts by expects
Soulthym Nov 27, 2024
750ecf6
Scope with unique insertions
Soulthym Nov 27, 2024
345cbe7
IsNode derive macro
Soulthym Nov 29, 2024
002dfa5
fix module name
Soulthym Nov 29, 2024
2f1bc62
Merge pull request #3 from massalabs/thy-rework-ir
Soulthym Nov 29, 2024
ced1630
swap-ir-impl starting point (#4)
Soulthym Feb 5, 2025
40c478b
refactor: Remove test file duplication for codegen
Leo-Besancon Feb 5, 2025
bc49b4f
refactor: Remove test file duplication for air
Leo-Besancon Feb 5, 2025
9c8bbfd
remove unused Leaf
Soulthym Feb 5, 2025
b19b1c6
refactor: cleanup MIR module of useless structs
Leo-Besancon Feb 5, 2025
7711db5
refactor: Improve constant prop & value numbering placeholders
Leo-Besancon Feb 5, 2025
0bd41a1
docs: Add documentation to visitor, clean up mir passes mod.rs
Leo-Besancon Feb 5, 2025
4617ad8
refactor: Update root modules and MIR / AIR README.md
Leo-Besancon Feb 6, 2025
2f2149f
chore: fix docs format
Leo-Besancon Feb 6, 2025
a7c918d
docs: document all MIR Op variants
Leo-Besancon Feb 6, 2025
7d7f069
chore: cargo fmt fix + add Mir struct documentation
Leo-Besancon Feb 6, 2025
deec91a
refactor: Sanity check in graph, and add documentation for Mir graph …
Leo-Besancon Feb 6, 2025
471b15c
Add various MIR documentation (#9)
Leo-Besancon Feb 6, 2025
6769e03
chore: update toolchain and clippy fixes
Leo-Besancon Feb 21, 2025
8e6949d
Merge pull request #359 from massalabs/feat-implement-ir
bitwalker Mar 7, 2025
5f96b39
ace
paracetamolo Feb 28, 2025
3ab8c9a
serialization
paracetamolo Feb 27, 2025
bdea732
serialization of constants
paracetamolo Mar 5, 2025
9ae3b8d
test before
paracetamolo Mar 12, 2025
a058a8c
refactor
paracetamolo Mar 12, 2025
4041f20
dedup circuit
paracetamolo Mar 13, 2025
73ff34a
eval
paracetamolo Mar 13, 2025
58b4970
fix iterator
paracetamolo Mar 14, 2025
91dedd2
periodic
paracetamolo Mar 13, 2025
f8fa8bb
dedup normalize
paracetamolo Mar 14, 2025
de77797
0 1
paracetamolo Mar 14, 2025
6b2ac96
sort add mul
paracetamolo Mar 14, 2025
e7e7314
linear comb
paracetamolo Mar 14, 2025
eb11f3d
factor out circuit
paracetamolo Mar 14, 2025
5c74785
unify iterators
paracetamolo Mar 14, 2025
4569f80
move serialization
paracetamolo Mar 17, 2025
1433768
comparison
paracetamolo Mar 17, 2025
9915b8a
move circuit
paracetamolo Mar 17, 2025
289e0cd
ser
paracetamolo Mar 17, 2025
2372f52
k
paracetamolo Mar 17, 2025
a06cd13
k
paracetamolo Mar 17, 2025
3266d5c
k
paracetamolo Mar 17, 2025
68d5e4c
k
paracetamolo Mar 17, 2025
fa49924
k
paracetamolo Mar 17, 2025
ea6748f
k
paracetamolo Mar 17, 2025
ea9918f
refact
paracetamolo Mar 17, 2025
f1dd7fe
ser
paracetamolo Mar 17, 2025
6767e23
k
paracetamolo Mar 17, 2025
e991a43
k
paracetamolo Mar 17, 2025
0c3b604
eval
paracetamolo Mar 17, 2025
2cb71d3
optimize append
paracetamolo Mar 17, 2025
848f29d
eval felt
paracetamolo Mar 17, 2025
f224079
k
paracetamolo Mar 18, 2025
c8f4c5d
last input
paracetamolo Mar 18, 2025
ae44a51
test numerator
paracetamolo Mar 18, 2025
a8e880e
k
paracetamolo Mar 18, 2025
dbe996e
k
paracetamolo Mar 18, 2025
6b58346
k
paracetamolo Mar 19, 2025
8ca61f2
k
paracetamolo Mar 19, 2025
90b8ff2
k
paracetamolo Mar 20, 2025
a473bfb
k
paracetamolo Mar 20, 2025
2659169
k
paracetamolo Mar 20, 2025
1b34bd5
k
paracetamolo Mar 20, 2025
e34c762
k
paracetamolo Mar 20, 2025
e45391f
k
paracetamolo Mar 20, 2025
f45db06
k
paracetamolo Mar 20, 2025
d0fb504
k
paracetamolo Mar 20, 2025
f54c6a6
k
paracetamolo Mar 20, 2025
db52fa0
k
paracetamolo Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- main
pull_request:
types: [opened, repoened, synchronize]
types: [opened, reopened, synchronize]

jobs:
test:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
**/target/

# Remove system config files generated by mac os
**/.DS_Store
Expand All @@ -17,4 +17,4 @@ Cargo.lock

# Ignore examples codegen generated files
**/examples/*.rs
**/examples/*.masm
**/examples/*.masm
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## 0.4.0 (TBD)

## 0.3.0 (2023-07-12)

- Added support for library modules.
Expand Down
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
[workspace]
members = [
"air-script",
"parser",
"pass",
"ir",
"codegen/masm",
"codegen/winterfell",
"air-script",
"parser",
"pass",
"mir",
"air",
"codegen/masm",
"codegen/winterfell",
"codegen/ace",
]
resolver = "2"

[workspace.package]
edition = "2021"
rust-version = "1.78"
17 changes: 9 additions & 8 deletions air-script/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "air-script"
version = "0.3.0"
version = "0.4.0"
description = "AirScript language compiler"
authors = ["miden contributors"]
readme = "README.md"
Expand All @@ -9,20 +9,21 @@ repository = "https://github.com/0xPolygonMiden/air-script"
documentation = "https://0xpolygonmiden.github.io/air-script/"
categories = ["compilers", "cryptography"]
keywords = ["air", "stark", "zero-knowledge", "zkp"]
edition = "2021"
rust-version = "1.67"
edition.workspace = true
rust-version.workspace = true

[[bin]]
name = "airc"
path = "src/main.rs"

[dependencies]
air-ir = { package = "air-ir", path = "../ir", version = "0.3" }
air-parser = { package = "air-parser", path = "../parser", version = "0.3" }
mir = { package = "mir", path = "../mir", version = "0.4" }
air-ir = { package = "air-ir", path = "../air", version = "0.4" }
air-parser = { package = "air-parser", path = "../parser", version = "0.4" }
air-pass = { package = "air-pass", path = "../pass", version = "0.1" }
air-codegen-masm = { package = "air-codegen-masm", path = "../codegen/masm", version = "0.1" }
air-codegen-winter = { package = "air-codegen-winter", path = "../codegen/winterfell", version = "0.3" }
clap = {version = "4.2", features = ["derive"] }
air-codegen-masm = { package = "air-codegen-masm", path = "../codegen/masm", version = "0.4" }
air-codegen-winter = { package = "air-codegen-winter", path = "../codegen/winterfell", version = "0.4" }
clap = { version = "4.2", features = ["derive"] }
env_logger = "0.10"
log = { version = "0.4", default-features = false }
miden-diagnostics = "0.1"
Expand Down
50 changes: 41 additions & 9 deletions air-script/src/cli/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ impl Target {
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum Pipeline {
WithMIR,
WithoutMIR,
}

#[derive(Args)]
pub struct Transpile {
Expand All @@ -40,28 +45,55 @@ pub struct Transpile {
help = "Defines the target language, defaults to Winterfell"
)]
target: Option<Target>,

#[arg(
short,
long,
help = "Defines the compilation pipeline (WithMIR or WithoutMIR), defaults to WithMIR"
)]
pipeline: Option<Pipeline>,
}

impl Transpile {
pub fn execute(&self) -> Result<(), String> {
println!("============================================================");
println!("Transpiling...");

let input_path = &self.input;

let codemap = Arc::new(CodeMap::new());
let emitter = Arc::new(DefaultEmitter::new(ColorChoice::Auto));
let diagnostics = DiagnosticsHandler::new(Default::default(), codemap.clone(), emitter);

let pipeline = self.pipeline.unwrap_or(Pipeline::WithMIR);
// Parse from file to internal representation
let air = air_parser::parse_file(&diagnostics, codemap, input_path)
.map_err(CompileError::Parse)
.and_then(|ast| {
let mut pipeline = air_parser::transforms::ConstantPropagation::new(&diagnostics)
.chain(air_parser::transforms::Inlining::new(&diagnostics))
.chain(air_ir::passes::AstToAir::new(&diagnostics));
pipeline.run(ast)
});
let air = match pipeline {
Pipeline::WithMIR => {
println!("Transpiling with Mir pipeline...");
air_parser::parse_file(&diagnostics, codemap, input_path)
.map_err(CompileError::Parse)
.and_then(|ast| {
let mut pipeline =
air_parser::transforms::ConstantPropagation::new(&diagnostics)
.chain(mir::passes::AstToMir::new(&diagnostics))
.chain(mir::passes::Inlining::new(&diagnostics))
.chain(mir::passes::Unrolling::new(&diagnostics))
.chain(air_ir::passes::MirToAir::new(&diagnostics));
pipeline.run(ast)
})
}
Pipeline::WithoutMIR => {
println!("Transpiling without Mir pipeline...");
air_parser::parse_file(&diagnostics, codemap, input_path)
.map_err(CompileError::Parse)
.and_then(|ast| {
let mut pipeline =
air_parser::transforms::ConstantPropagation::new(&diagnostics)
.chain(air_parser::transforms::Inlining::new(&diagnostics))
.chain(air_ir::passes::AstToAir::new(&diagnostics));
pipeline.run(ast)
})
}
};

match air {
Ok(air) => {
Expand Down
47 changes: 26 additions & 21 deletions air-script/tests/aux_trace/aux_trace.air
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
def AuxiliaryAir

trace_columns:
main: [a, b, c]
aux: [p0, p1]
trace_columns {
main: [a, b, c],
aux: [p0, p1],
}

public_inputs:
stack_inputs: [16]
public_inputs {
stack_inputs: [16],
}

random_values:
rand: [2]
random_values {
rand: [2],
}

boundary_constraints:
enf a.first = 1
enf b.first = 1
boundary_constraints {
enf a.first = 1;
enf b.first = 1;

enf p0.first = 1
enf p0.last = 1
enf p0.first = 1;
enf p0.last = 1;

# auxiliary boundary constraint with a random value
enf p1.first = $rand[0]
enf p1.last = 1

integrity_constraints:
enf a' = b + a * b * c
enf b' = c + a'
enf c = a + b
enf p1.first = $rand[0];
enf p1.last = 1;
}

integrity_constraints {
enf a' = b + a * b * c;
enf b' = c + a';
enf c = a + b;

# integrity constraints against the auxiliary trace with random values
enf p0' = p0 * (a + $rand[0] + b + $rand[1])
enf p1 = p1' * (c + $rand[0])
enf p0' = p0 * (a + $rand[0] + b + $rand[1]);
enf p1 = p1' * (c + $rand[0]);
}
22 changes: 13 additions & 9 deletions air-script/tests/binary/binary.air
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
def BinaryAir

trace_columns:
main: [a, b]
trace_columns {
main: [a, b],
}

public_inputs:
stack_inputs: [16]
public_inputs {
stack_inputs: [16],
}

boundary_constraints:
enf a.first = 0
boundary_constraints {
enf a.first = 0;
}

integrity_constraints:
enf a^2 - a = 0
enf b^2 - b = 0
integrity_constraints {
enf a^2 - a = 0;
enf b^2 - b = 0;
}
32 changes: 2 additions & 30 deletions air-script/tests/binary/binary.masm
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,11 @@ end # END PROC compute_integrity_constraint_divisor
# This procedure pushes 2 quadratic extension field elements to the stack
proc.compute_integrity_constraints
# integrity constraint 0 for main
padw mem_loadw.4294900000 movdn.3 movdn.3 drop drop
# push the accumulator to the stack
push.1 movdn.2 push.0 movdn.2
# => [b1, b0, r1, r0, ...]
# square 1 times
dup.1 dup.1 ext2mul
# multiply
dup.1 dup.1 movdn.5 movdn.5
# => [b1, b0, r1, r0, b1, b0, ...] (4 cycles)
ext2mul movdn.3 movdn.3
# => [b1, b0, r1', r0', ...] (5 cycles)
# clean stack
drop drop
# => [r1, r0, ...] (2 cycles)
padw mem_loadw.4294900000 movdn.3 movdn.3 drop drop ext2sub push.0 push.0 ext2sub
padw mem_loadw.4294900000 movdn.3 movdn.3 drop drop padw mem_loadw.4294900000 movdn.3 movdn.3 drop drop ext2mul padw mem_loadw.4294900000 movdn.3 movdn.3 drop drop ext2sub push.0 push.0 ext2sub
# Multiply by the composition coefficient
padw mem_loadw.4294900200 movdn.3 movdn.3 drop drop ext2mul
# integrity constraint 1 for main
padw mem_loadw.4294900001 movdn.3 movdn.3 drop drop
# push the accumulator to the stack
push.1 movdn.2 push.0 movdn.2
# => [b1, b0, r1, r0, ...]
# square 1 times
dup.1 dup.1 ext2mul
# multiply
dup.1 dup.1 movdn.5 movdn.5
# => [b1, b0, r1, r0, b1, b0, ...] (4 cycles)
ext2mul movdn.3 movdn.3
# => [b1, b0, r1', r0', ...] (5 cycles)
# clean stack
drop drop
# => [r1, r0, ...] (2 cycles)
padw mem_loadw.4294900001 movdn.3 movdn.3 drop drop ext2sub push.0 push.0 ext2sub
padw mem_loadw.4294900001 movdn.3 movdn.3 drop drop padw mem_loadw.4294900001 movdn.3 movdn.3 drop drop ext2mul padw mem_loadw.4294900001 movdn.3 movdn.3 drop drop ext2sub push.0 push.0 ext2sub
# Multiply by the composition coefficient
padw mem_loadw.4294900200 drop drop ext2mul
end # END PROC compute_integrity_constraints
Expand Down
4 changes: 2 additions & 2 deletions air-script/tests/binary/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl Air for BinaryAir {
fn evaluate_transition<E: FieldElement<BaseField = Felt>>(&self, frame: &EvaluationFrame<E>, periodic_values: &[E], result: &mut [E]) {
let main_current = frame.current();
let main_next = frame.next();
result[0] = main_current[0].exp(E::PositiveInteger::from(2_u64)) - main_current[0] - E::ZERO;
result[1] = main_current[1].exp(E::PositiveInteger::from(2_u64)) - main_current[1] - E::ZERO;
result[0] = main_current[0] * main_current[0] - main_current[0] - E::ZERO;
result[1] = main_current[1] * main_current[1] - main_current[1] - E::ZERO;
}

fn evaluate_aux_transition<F, E>(&self, main_frame: &EvaluationFrame<F>, aux_frame: &EvaluationFrame<E>, _periodic_values: &[F], aux_rand_elements: &AuxTraceRandElements<E>, result: &mut [E])
Expand Down
Loading
Loading