Skip to content

Commit

Permalink
Merge branch 'main' into feat/236-batch-deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Oct 17, 2024
2 parents cee2d63 + 2c5d674 commit 62f7128
Show file tree
Hide file tree
Showing 81 changed files with 956,034 additions and 787 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.4"
- run: scarb --version
- run: scarb fmt --check
- run: scarb build
5 changes: 4 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.4"
- run: scarb --version
- run: scarb test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ __pycache__
.client_cache/
.utxo_data/
.timestamps_data/
.arguments*.json

corelib
*.svg
*.txt
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.8.2
scarb 2.8.4
36 changes: 36 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,45 @@ dependencies = [
name = "consensus"
version = "0.1.0"
dependencies = [
"shinigami_engine",
"utils",
]

[[package]]
name = "ripemd160"
version = "0.1.0"
source = "git+https://github.com/j1mbo64/ripemd160_cairo.git#cdc5ab58b0acc64db87e0b03851fb18213977dc8"

[[package]]
name = "sha1"
version = "0.1.0"
source = "git+https://github.com/j1mbo64/sha1_cairo.git#280b4c64ae457fdc4bd7cd807efd17e8dced654e"

[[package]]
name = "shinigami_compiler"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/shinigami.git?rev=9e7692d#9e7692d34fb2ff7e862488b0921ba6c72de8602f"
dependencies = [
"shinigami_engine",
"shinigami_utils",
]

[[package]]
name = "shinigami_engine"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/shinigami.git?rev=9e7692d#9e7692d34fb2ff7e862488b0921ba6c72de8602f"
dependencies = [
"ripemd160",
"sha1",
"shinigami_compiler",
"shinigami_utils",
]

[[package]]
name = "shinigami_utils"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/shinigami.git?rev=9e7692d#9e7692d34fb2ff7e862488b0921ba6c72de8602f"

[[package]]
name = "utils"
version = "0.1.0"
Expand Down
7 changes: 7 additions & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ license-file = "LICENSE"

[workspace.dependencies]
cairo_test = "2.8.0"
shinigami_engine = { git = "https://github.com/keep-starknet-strange/shinigami.git", rev = "9e7692d" }

[profile.cairo1-run.cairo]
# https://github.com/lambdaclass/cairo-vm/issues/1745
enable-gas = false
# https://github.com/software-mansion/scarb/blob/4d91be7a7dbfeb24327e3ba21c62fbac43a2105a/scarb/src/compiler/compilers/lib.rs#L154
sierra-replace-ids = true
5 changes: 4 additions & 1 deletion _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ extend-exclude = [
]

[default.extend-words]
Pn = "Pn"
Pn = "Pn"

[default]
extend-ignore-re = ["(?Rm)^.*(#|//)\\s*spellchecker:disable-line$"]
3 changes: 0 additions & 3 deletions packages/client/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
mod main;
// TODO: scarb cairo-run should support "features" argument
// so that we can conditionally compile this module
mod test;
33 changes: 0 additions & 33 deletions packages/client/src/main.cairo

This file was deleted.

44 changes: 18 additions & 26 deletions packages/client/src/test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -35,73 +35,65 @@ struct UtreexoArgs {
/// Receives arguments in a serialized format (Cairo serde).
/// Panics in case of a validation error or chain state mismatch.
/// Prints result to the stdout.
fn test(mut arguments: Span<felt252>) {
pub(crate) fn main(mut arguments: Span<felt252>, execute_script: bool) {
let mut gas_before = get_available_gas();

let Args { mut chain_state, blocks, expected_chain_state, utreexo_args } = Serde::deserialize(
ref arguments
)
.expect('Failed to deserialize');

let mut utxo_set: UtxoSet = Default::default();
let mut gas_before = get_available_gas();

for block in blocks {
let height = chain_state.block_height + 1;
match chain_state.validate_and_apply(block, ref utxo_set) {
Result::Ok(new_chain_state) => {
chain_state = new_chain_state;
let gas_after = get_available_gas();
println!("OK: block={} gas_spent={}", height, gas_before - gas_after);
gas_before = gas_after;
},
match chain_state.validate_and_apply(block, ref utxo_set, execute_script) {
Result::Ok(new_chain_state) => { chain_state = new_chain_state; },
Result::Err(err) => {
let gas_after = get_available_gas();
println!(
"FAIL: block={} gas_spent={} error='{}'", height, gas_before - gas_after, err
);
println!("FAIL: gas_spent={} error='{}'", gas_before - get_available_gas(), err);
panic!();
}
}
};

if chain_state != expected_chain_state {
println!(
"FAIL: block={} error='expected chain state {:?}, actual {:?}'",
chain_state.block_height,
"FAIL: gas_spent={} error='expected chain state {:?}, actual {:?}'",
gas_before - get_available_gas(),
expected_chain_state,
chain_state
);
panic!();
}

if let Result::Err(err) = utxo_set.finalize() {
println!("FAIL: error='{}'", err);
println!("FAIL: gas_spent={} error='{}'", gas_before - get_available_gas(), err);
panic!();
}

if let Option::Some(UtreexoArgs { mut state, proofs, expected_state }) = utreexo_args {
match state
.validate_and_apply(
utxo_set.leaves_to_add.span(), utxo_set.leaves_to_delete.span(), proofs.span()
utxo_set.leaves_to_add.span(), utxo_set.leaves_to_delete.span(), proofs.span(),
) {
Result::Ok(new_state) => {
state = new_state;
let gas_after = get_available_gas();
println!("OK: gas_spent={}", gas_before - gas_after);
},
Result::Ok(new_state) => { state = new_state; },
Result::Err(err) => {
let gas_after = get_available_gas();
println!("FAIL: gas_spent={} error='{:?}'", gas_before - gas_after, err);
println!("FAIL: gas_spent={} error='{:?}'", gas_before - get_available_gas(), err);
panic!();
}
}

if state != expected_state {
println!(
"FAIL: error='expected utreexo state {:?}, actual {:?}'", expected_state, state
"FAIL: gas_spent={} error='expected utreexo state {:?}, actual {:?}'",
gas_before - get_available_gas(),
expected_state,
state
);
panic!();
}
}

println!("OK: gas_spent={}", gas_before - get_available_gas());
}

/// Workaround for handling missing `utreexo_args` field.
Expand Down
Loading

0 comments on commit 62f7128

Please sign in to comment.