Skip to content

Commit fa84636

Browse files
committed
Merge #264: Add imports functionality
8b12ac6 fix: internal error inside resolution.rs and add error tests (Sdoba16) da1240a test: add functional tests (Sdoba16) 7df36e7 feat: add `--dep` flag and connect driver to overall execution flow, add examples (LesterEvSe) 857cc5a feat: change ast.rs to match the functionality of the driver (LesterEvSe) fda737f fix: resolution data structure and alias architecture (LesterEvSe) 260d844 feat: add and test import aliases (LesterEvSe) 8300fe5 feat: add linearize and build functionality to the driver, fix `Error` enum a bit (LesterEvSe) f5999f2 feat: Added linearization algorithm (Sdoba16) 056a359 feat: implement `DependencyGraph` inside `driver.rs` file and change parse trait to the `SourceFile` (LesterEvSe) e2604f3 feat: add data structure for dependency resolution (LesterEvSe) 2064542 feat: add `SourceFile` to the `RichError` and change the `ErrorCollector` (LesterEvSe) 80ae099 feat: add import errors (LesterEvSe) 3c7d4c3 feat: implement resolution.rs utils (LesterEvSe) 7ddeed2 feat: add pub and use keywords and parse them (LesterEvSe) Pull request description: ## Motivation (copied from #258) The main goal of this PR is to enable an analogue of the OpenZeppelin library to exist in the SimplicityHL ecosystem. By introducing official compiler support for imports, we significantly increase code reusability and speed up application development. For projects heavily focused on security, this also allows developers to eventually "flatten" the code and audit all functions without external dependencies. ## Checklist - [x] **Visibility:** Added `pub` and `pub use` to control local scope versus re-exporting. - [x] **Import Syntax:** Implemented parsing and resolution for `use m::name;` and explicit aliasing (`as`). - [x] **Collision Handling:** Enforced strict errors for local scope collisions, utilizing linearization for resolving re-export conflicts. - [x] **Transitive Dependencies**: Add support for libraries importing other libraries. - [x] **Documentation:** Сode comments are updated accordingly. - [x] **Quality Assurance:** Code is formatted, all tests pass, and CI shows no errors. Related PRs (in order of the merge): #260, #256, #265, #266, #269, #278, #279, #280, #283, #287, #284, #289 ACKs for top commit: KyrylR: ACK 8b12ac6; code review and test runs (see #260, #256, #265, #266, #269, #278, #279, #280, #283, #287, #284, #289) delta1: ACK 8b12ac6; tested locally Tree-SHA512: bec0d7437279dd45810cd8b13b48ba3921739d8c38f61d2f61401e419b32a2f4b31328df2c5596375fe8c69cabadc3e931a639ad833fe446918d1360091a447f
2 parents 543439b + 8b12ac6 commit fa84636

64 files changed

Lines changed: 4010 additions & 181 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions

doc/architecture.md

Lines changed: 77 additions & 0 deletions

examples/multiple_deps/main.simf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use merkle::build_root::{get_root, hash as and_hash};
2+
use base_math::simple_op::hash as or_hash;
3+
4+
pub fn get_block_value_hash(prev_hash: u32, tx1: u32, tx2: u32) -> u32 {
5+
let root: u32 = get_root(tx1, tx2);
6+
or_hash(prev_hash, root)
7+
}
8+
9+
fn main() {
10+
let block_val_hash: u32 = get_block_value_hash(5, 10, 20);
11+
assert!(jet::eq_32(block_val_hash, 27));
12+
13+
let first_value: u32 = 15;
14+
let second_value: u32 = 22;
15+
assert!(jet::eq_32(and_hash(first_value, second_value), 6));
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn hash(x: u32, y: u32) -> u32 {
2+
jet::xor_32(x, y)
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use math::simple_op::hash as temp_hash;
2+
3+
pub fn get_root(tx1: u32, tx2: u32) -> u32 {
4+
temp_hash(tx1, tx2)
5+
}
6+
7+
pub fn hash(tx1: u32, tx2: u32) -> u32 {
8+
jet::and_32(tx1, tx2)
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn sha256(data: u32) -> u256 {
2+
let ctx: Ctx8 = jet::sha_256_ctx_8_init();
3+
let ctx: Ctx8 = jet::sha_256_ctx_8_add_4(ctx, data);
4+
jet::sha_256_ctx_8_finalize(ctx)
5+
}

examples/simple_multidep/main.simf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use math::arithmetic::add;
2+
use crypto::hashes::sha256;
3+
4+
fn main() {
5+
let sum: u32 = add(2, 3);
6+
let hash: u256 = sha256(sum);
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub fn add(a: u32, b: u32) -> u32 {
2+
let (_, res): (bool, u32) = jet::add_32(a, b);
3+
res
4+
}

examples/single_dep/main.simf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub use temp::constants::utils::two as smth;
2+
use temp::funcs::{get_five, Smth};
3+
4+
fn seven() -> u32 {
5+
7
6+
}
7+
8+
fn main() {
9+
let (_, temp): (bool, u32) = jet::add_32(smth(), get_five());
10+
assert!(jet::eq_32(temp, seven()));
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub use temp::funcs::Smth;
2+
3+
pub fn two() -> Smth {
4+
2
5+
}

0 commit comments

Comments
 (0)