Skip to content

Commit

Permalink
Upgrade to 2.9.1 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka authored Dec 2, 2024
1 parent 6bff030 commit 6d1d596
Show file tree
Hide file tree
Showing 34 changed files with 695 additions and 877 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.5"
scarb-version: "2.9.1"
- run: scarb --version
- run: scarb fmt --check
- run: scarb build
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "nightly"
scarb-version: "2.9.1"
- run: scarb --version
- run: scarb test
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ members = ["packages/*"]

[workspace.package]
description = "Bitcoin ZK client."
cairo-version = "2.8.5"
cairo-version = "2.9.1"
version = "0.1.0"
readme = "README.md"
repository = "https://github.com/keep-starknet-strange/raito"
license-file = "LICENSE"

[workspace.dependencies]
cairo_test = "2.8.5"
cairo_test = "2.9.1"
shinigami_engine = { git = "https://github.com/keep-starknet-strange/shinigami.git", rev = "3415ed6" }

[profile.cairo1-run.cairo]
Expand Down
18 changes: 8 additions & 10 deletions packages/client/src/test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ fn main(arguments: Array<felt252>) -> Array<felt252> {
let mut gas_before = get_available_gas();
let mut args = arguments.span();

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

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

Expand All @@ -59,7 +57,7 @@ fn main(arguments: Array<felt252>) -> Array<felt252> {
Result::Err(err) => {
println!("FAIL: gas_spent={} error='{}'", gas_before - get_available_gas(), err);
panic!();
}
},
}
};

Expand All @@ -68,7 +66,7 @@ fn main(arguments: Array<felt252>) -> Array<felt252> {
"FAIL: gas_spent={} error='expected chain state {:?}, actual {:?}'",
gas_before - get_available_gas(),
expected_chain_state,
chain_state
chain_state,
);
panic!();
}
Expand All @@ -84,7 +82,7 @@ fn main(arguments: Array<felt252>) -> Array<felt252> {
Result::Err(err) => {
println!("FAIL: gas_spent={} error='{:?}'", gas_before - get_available_gas(), err);
panic!();
}
},
}

state = state.add(utxo_set.leaves_to_add.span());
Expand All @@ -94,7 +92,7 @@ fn main(arguments: Array<felt252>) -> Array<felt252> {
"FAIL: gas_spent={} error='expected utreexo state {:?}, actual {:?}'",
gas_before - get_available_gas(),
expected_state,
state
state,
);
panic!();
}
Expand Down Expand Up @@ -123,7 +121,7 @@ impl ArgsSerde of Serde<Args> {
};
let execute_script: bool = Serde::deserialize(ref serialized).expect('execute_script');
Option::Some(
Args { chain_state, blocks, expected_chain_state, utreexo_args, execute_script, }
Args { chain_state, blocks, expected_chain_state, utreexo_args, execute_script },
)
}
}
152 changes: 76 additions & 76 deletions packages/consensus/src/codec.cairo

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions packages/consensus/src/types/block.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl BlockDisplay of Display<Block> {
fn fmt(self: @Block, ref f: Formatter) -> Result<(), Error> {
let data = match *self.data {
TransactionData::MerkleRoot(root) => format!("{}", root),
TransactionData::Transactions(txs) => format!("{}", txs.len())
TransactionData::Transactions(txs) => format!("{}", txs.len()),
};
let str: ByteArray = format!(" Block {{ header: {}, data: {} }}", *self.header, @data);
f.buffer.append(@str);
Expand All @@ -98,7 +98,7 @@ impl HeaderDisplay of Display<Header> {
*self.version,
*self.time,
*self.bits,
*self.nonce
*self.nonce,
);
f.buffer.append(@str);
Result::Ok(())
Expand All @@ -112,7 +112,7 @@ impl TransactionDataDisplay of Display<TransactionData> {
TransactionData::MerkleRoot(root) => f.buffer.append(@format!("MerkleRoot: {}", root)),
TransactionData::Transactions(txs) => f
.buffer
.append(@format!("Transactions: {}", txs.len()))
.append(@format!("Transactions: {}", txs.len())),
};
Result::Ok(())
}
Expand All @@ -133,7 +133,7 @@ mod tests {
.into();
// Block 170
let header = Header {
version: 1_u32, time: 1231731025_u32, bits: 0x1d00ffff_u32, nonce: 1889418792_u32
version: 1_u32, time: 1231731025_u32, bits: 0x1d00ffff_u32, nonce: 1889418792_u32,
};
let merkle_root: Digest =
0x7dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff_u256
Expand All @@ -158,7 +158,7 @@ mod tests {
.into();
// Block 170
let header = Header {
version: 1_u32, time: 1231731025_u32, bits: 0x1d00ffff_u32, nonce: 1889418792_u32
version: 1_u32, time: 1231731025_u32, bits: 0x1d00ffff_u32, nonce: 1889418792_u32,
};
let merkle_root: Digest =
0x6dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff_u256
Expand All @@ -182,7 +182,7 @@ mod tests {
.into();
// block 170
let header = Header {
version: 1_u32, time: 1231731025_u32, bits: 0x1d00ffff_u32, nonce: 1889418792_u32
version: 1_u32, time: 1231731025_u32, bits: 0x1d00ffff_u32, nonce: 1889418792_u32,
};
let merkle_root: Digest =
0x7dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff_u256
Expand Down
18 changes: 8 additions & 10 deletions packages/consensus/src/types/chain_state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::validation::{
difficulty::{validate_bits, adjust_difficulty}, coinbase::validate_coinbase,
timestamp::{validate_timestamp, next_prev_timestamps, compute_median_time_past},
work::{validate_proof_of_work, compute_total_work}, block::compute_and_validate_tx_data,
script::validate_scripts
script::validate_scripts,
};
use super::{block::{BlockHash, Block, TransactionData}, utxo_set::UtxoSet};
use utils::hash::Digest;
Expand Down Expand Up @@ -46,9 +46,7 @@ impl ChainStateDefault of Default<ChainState> {
.into(),
current_target: 0x00000000ffff0000000000000000000000000000000000000000000000000000_u256,
epoch_start_time: 1231006505,
prev_timestamps: [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1231006505
].span(),
prev_timestamps: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1231006505].span(),
}
}
}
Expand All @@ -57,7 +55,7 @@ impl ChainStateDefault of Default<ChainState> {
#[generate_trait]
pub impl BlockValidatorImpl of BlockValidator {
fn validate_and_apply(
self: ChainState, block: Block, ref utxo_set: UtxoSet, execute_script: bool
self: ChainState, block: Block, ref utxo_set: UtxoSet, execute_script: bool,
) -> Result<ChainState, ByteArray> {
let block_height = self.block_height + 1;

Expand All @@ -73,22 +71,22 @@ pub impl BlockValidatorImpl of BlockValidator {
TransactionData::MerkleRoot(root) => root,
TransactionData::Transactions(txs) => {
let (total_fees, txid_root, wtxid_root) = compute_and_validate_tx_data(
txs, block_height, block.header.time, median_time_past, ref utxo_set
txs, block_height, block.header.time, median_time_past, ref utxo_set,
)?;
validate_coinbase(txs[0], total_fees, block_height, wtxid_root)?;
if execute_script {
validate_scripts(@block.header, txs.slice(1, txs.len() - 1))?;
}
txid_root
}
},
};

let (current_target, epoch_start_time) = adjust_difficulty(
self.current_target,
self.epoch_start_time,
block_height,
prev_block_time,
block.header.time
block.header.time,
);
let total_work = compute_total_work(self.total_work, current_target);
let best_block_hash = block.header.hash(self.best_block_hash, txid_root);
Expand All @@ -104,7 +102,7 @@ pub impl BlockValidatorImpl of BlockValidator {
current_target,
epoch_start_time,
prev_timestamps,
}
},
)
}
}
Expand All @@ -130,7 +128,7 @@ impl ChainStateDisplay of Display<ChainState> {
*self.best_block_hash,
*self.current_target,
*self.epoch_start_time,
@prev_ts
@prev_ts,
);
f.buffer.append(@str);
Result::Ok(())
Expand Down
30 changes: 15 additions & 15 deletions packages/consensus/src/types/transaction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct OutPoint {
/// seconds.
pub median_time_past: u32,
/// Determines if the outpoint is a coinbase transaction.
pub is_coinbase: bool
pub is_coinbase: bool,
}


Expand Down Expand Up @@ -148,7 +148,7 @@ pub impl OutPointHashImpl of OutPointHashTrait {
/// `Default` trait implementation for `TxOut`.
impl TxOutDefault of Default<TxOut> {
fn default() -> TxOut {
TxOut { value: 0, pk_script: @"", cached: false, }
TxOut { value: 0, pk_script: @"", cached: false }
}
}

Expand All @@ -161,7 +161,7 @@ impl TransactionDisplay of Display<Transaction> {
*self.is_segwit,
(*self.inputs).len(),
(*self.outputs).len(),
*self.lock_time
*self.lock_time,
);
f.buffer.append(@str);
Result::Ok(())
Expand All @@ -176,7 +176,7 @@ impl TxInDisplay of Display<TxIn> {
*self.script,
*self.sequence,
*self.previous_output.txid,
(*self.witness).len()
(*self.witness).len(),
);
f.buffer.append(@str);
Result::Ok(())
Expand All @@ -200,7 +200,7 @@ impl OutPointDisplay of Display<OutPoint> {
*self.data,
*self.block_height,
*self.median_time_past,
*self.is_coinbase
*self.is_coinbase,
);
f.buffer.append(@str);
Result::Ok(())
Expand All @@ -214,7 +214,7 @@ impl TxOutDisplay of Display<TxOut> {
"TxOut {{ value: {}, pk_script: {}, cached: {} }}",
*self.value,
*self.pk_script,
*self.cached
*self.cached,
);
f.buffer.append(@str);
Result::Ok(())
Expand Down Expand Up @@ -260,7 +260,7 @@ mod tests {

#[derive(Debug, Drop, Default)]
pub struct HashState {
pub value: Array<felt252>
pub value: Array<felt252>,
}

impl HashStateImpl of HashStateTrait<HashState> {
Expand All @@ -279,13 +279,13 @@ mod tests {
pub fn test_outpoint_poseidon_hash_cb9() {
let mut coinbase_9_utxo = OutPoint {
txid: hex_to_hash_rev(
"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9"
"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9",
),
vout: 0,
data: TxOut {
value: 5000000000,
pk_script: @from_hex(
"410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac"
"410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac",
),
cached: false,
},
Expand All @@ -309,27 +309,27 @@ mod tests {
5,
9,
1231470988,
1
1,
];
assert_eq!(expected, state.value);

let hash = coinbase_9_utxo.hash();
assert_eq!(
761592244424273723796345514960638980240531938129162865626185984897576522513, hash
761592244424273723796345514960638980240531938129162865626185984897576522513, hash,
);
}

#[test]
pub fn test_outpoint_poseidon_hash_cb1() {
let mut coinbase_9_utxo = OutPoint {
txid: hex_to_hash_rev(
"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
),
vout: 0,
data: TxOut {
value: 5000000000,
pk_script: @from_hex(
"410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac"
"410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac",
),
cached: false,
},
Expand All @@ -353,13 +353,13 @@ mod tests {
5,
1,
1231006505,
1
1,
];
assert_eq!(expected, state.value);

let hash = coinbase_9_utxo.hash();
assert_eq!(
49459078824306138476779209834441505868925737545954320330266544605873965565, hash
49459078824306138476779209834441505868925737545954320330266544605873965565, hash,
);
}
}
12 changes: 6 additions & 6 deletions packages/consensus/src/types/utxo_set.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mod tests {
fn dummy_unspendable_outpoint(vout: u32, cached: bool) -> OutPoint {
OutPoint {
txid: hex_to_hash_rev(
"0000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000",
),
vout,
data: TxOut {
Expand All @@ -178,7 +178,7 @@ mod tests {
fn dummy_outpoint(vout: u32, cached: bool) -> OutPoint {
OutPoint {
txid: hex_to_hash_rev(
"0000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000",
),
vout,
data: TxOut {
Expand All @@ -196,19 +196,19 @@ mod tests {
fn get_outpoint() -> OutPoint {
OutPoint {
txid: hex_to_hash_rev(
"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9"
"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9",
),
vout: 0,
data: TxOut {
value: 5000000000,
pk_script: @from_hex(
"410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac"
"410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac",
),
cached: false
cached: false,
},
block_height: 9,
median_time_past: 1231470988,
is_coinbase: true
is_coinbase: true,
}
}

Expand Down
Loading

0 comments on commit 6d1d596

Please sign in to comment.