diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0db472ff..30af6153 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ee30816f..aab7a776 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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 diff --git a/Scarb.toml b/Scarb.toml index aaaa2028..7975d43d 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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] diff --git a/packages/client/src/test.cairo b/packages/client/src/test.cairo index 5607dde0..87cde83d 100644 --- a/packages/client/src/test.cairo +++ b/packages/client/src/test.cairo @@ -45,11 +45,9 @@ fn main(arguments: Array) -> Array { 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(); @@ -59,7 +57,7 @@ fn main(arguments: Array) -> Array { Result::Err(err) => { println!("FAIL: gas_spent={} error='{}'", gas_before - get_available_gas(), err); panic!(); - } + }, } }; @@ -68,7 +66,7 @@ fn main(arguments: Array) -> Array { "FAIL: gas_spent={} error='expected chain state {:?}, actual {:?}'", gas_before - get_available_gas(), expected_chain_state, - chain_state + chain_state, ); panic!(); } @@ -84,7 +82,7 @@ fn main(arguments: Array) -> Array { Result::Err(err) => { println!("FAIL: gas_spent={} error='{:?}'", gas_before - get_available_gas(), err); panic!(); - } + }, } state = state.add(utxo_set.leaves_to_add.span()); @@ -94,7 +92,7 @@ fn main(arguments: Array) -> Array { "FAIL: gas_spent={} error='expected utreexo state {:?}, actual {:?}'", gas_before - get_available_gas(), expected_state, - state + state, ); panic!(); } @@ -123,7 +121,7 @@ impl ArgsSerde of Serde { }; 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 }, ) } } diff --git a/packages/consensus/src/codec.cairo b/packages/consensus/src/codec.cairo index 03cf9e0a..7f9d700e 100644 --- a/packages/consensus/src/codec.cairo +++ b/packages/consensus/src/codec.cairo @@ -11,7 +11,7 @@ pub trait Encode { /// Encodes using Bitcoin codec and returns a `WordArray`. fn encode( - self: @T + self: @T, ) -> WordArray { let mut dest: WordArray = Default::default(); Self::encode_to(self, ref dest); @@ -209,7 +209,7 @@ mod tests { let txout = @TxOut { value: 5000000000_u64, pk_script: @from_hex( - "4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac" + "4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac", ), cached: false, }; @@ -217,7 +217,7 @@ mod tests { let bytes = txout.encode(); let expected = words_from_hex( - "00f2052a01000000434104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac" + "00f2052a01000000434104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac", ); assert_eq!(bytes, expected); } @@ -227,7 +227,7 @@ mod tests { // Block 170 coinbase tx b1fea52486ce0c62bb442b530a3f0132b826c74e473d1f2c220bfa78111c5082 let outpoint = OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 4294967295_u32, data: Default::default(), @@ -238,7 +238,7 @@ mod tests { let bytes = outpoint.encode(); let expected = words_from_hex( - "0000000000000000000000000000000000000000000000000000000000000000ffffffff" + "0000000000000000000000000000000000000000000000000000000000000000ffffffff", ); assert_eq!(bytes, expected); } @@ -248,7 +248,7 @@ mod tests { //Block 170 tx f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16 let outpoint = OutPoint { txid: hex_to_hash_rev( - "0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9" + "0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9", ), vout: 0_u32, data: Default::default(), @@ -259,7 +259,7 @@ mod tests { let bytes = outpoint.encode(); let expected = words_from_hex( - "c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd370400000000" + "c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd370400000000", ); assert_eq!(bytes, expected); } @@ -272,7 +272,7 @@ mod tests { sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 4294967295, data: Default::default(), @@ -280,12 +280,12 @@ mod tests { median_time_past: Default::default(), is_coinbase: false, }, - witness: array![].span() + witness: array![].span(), }; let bytes = txin.encode(); let expected = words_from_hex( - "0000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0102ffffffff" + "0000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0102ffffffff", ); assert_eq!(bytes, expected); } @@ -296,12 +296,12 @@ mod tests { // input 2 let txin = @TxIn { script: @from_hex( - "493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028" + "493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028", ), sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "66ce602f26ae00d128ea83e5afddf8c1cd226b7148322bb090779199f63f9ff5" + "66ce602f26ae00d128ea83e5afddf8c1cd226b7148322bb090779199f63f9ff5", ), vout: 1_u32, data: Default::default(), @@ -309,12 +309,12 @@ mod tests { median_time_past: Default::default(), is_coinbase: false, }, - witness: array![].span() + witness: array![].span(), }; let bytes = txin.encode(); let expected = words_from_hex( - "f59f3ff699917790b02b3248716b22cdc1f8ddafe583ea28d100ae262f60ce66010000008c493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028ffffffff" + "f59f3ff699917790b02b3248716b22cdc1f8ddafe583ea28d100ae262f60ce66010000008c493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028ffffffff", ); assert_eq!(bytes, expected); } @@ -328,12 +328,12 @@ mod tests { inputs: array![ TxIn { script: @from_hex( - "493046022100838b5bd094d57898d359569af330312e2dd99f8a1db7add92dc1704808625dbf022100978160771ea1e3ffe014e1fa7559f0bb5ffd32f6b63f19225bf3be110c2f2d65014104c273b18442afb2263698a09da205bb7a18f23037f9c285fc789874fe012ac32b40a18f12191a0015f2506b5a395d9845005b90a34a813715e9cc5dbf8024ca18" + "493046022100838b5bd094d57898d359569af330312e2dd99f8a1db7add92dc1704808625dbf022100978160771ea1e3ffe014e1fa7559f0bb5ffd32f6b63f19225bf3be110c2f2d65014104c273b18442afb2263698a09da205bb7a18f23037f9c285fc789874fe012ac32b40a18f12191a0015f2506b5a395d9845005b90a34a813715e9cc5dbf8024ca18", ), sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "b8a75476112bb2322af0331646100fe44f26fee85f452001589f6d9672b763a7" + "b8a75476112bb2322af0331646100fe44f26fee85f452001589f6d9672b763a7", ), vout: 0_u32, data: Default::default(), @@ -341,16 +341,16 @@ mod tests { median_time_past: Default::default(), is_coinbase: false, }, - witness: array![].span() + witness: array![].span(), }, TxIn { script: @from_hex( - "48304502200b2ff9ed1689c9403b4bf0aca89fa4a53004c2c6ad66b4df25ae8361eef172cc022100c8f5fcd4eeb02762d9b40de1013ad7283042585caec8e60be873689de8e29a4a014104cdadb5199b0d9d356ae03fbf891f28d761547d79a0c5dae24998fa84a147e39f27ce03cd8efd8bd27e9dffc78744d66b2942b76801f79ae4028028e7122a3bb1" + "48304502200b2ff9ed1689c9403b4bf0aca89fa4a53004c2c6ad66b4df25ae8361eef172cc022100c8f5fcd4eeb02762d9b40de1013ad7283042585caec8e60be873689de8e29a4a014104cdadb5199b0d9d356ae03fbf891f28d761547d79a0c5dae24998fa84a147e39f27ce03cd8efd8bd27e9dffc78744d66b2942b76801f79ae4028028e7122a3bb1", ), sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "a7ed5e908fa1951c912fd39cd72a37410ca78fc75de65180b8568a622f4e3a97" + "a7ed5e908fa1951c912fd39cd72a37410ca78fc75de65180b8568a622f4e3a97", ), vout: 1_u32, data: Default::default(), @@ -358,16 +358,16 @@ mod tests { median_time_past: Default::default(), is_coinbase: false, }, - witness: array![].span() + witness: array![].span(), }, TxIn { script: @from_hex( - "493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028" + "493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028", ), sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "66ce602f26ae00d128ea83e5afddf8c1cd226b7148322bb090779199f63f9ff5" + "66ce602f26ae00d128ea83e5afddf8c1cd226b7148322bb090779199f63f9ff5", ), vout: 1_u32, data: Default::default(), @@ -375,8 +375,8 @@ mod tests { median_time_past: Default::default(), is_coinbase: false, }, - witness: array![].span() - } + witness: array![].span(), + }, ] .span(), outputs: array![ @@ -389,16 +389,16 @@ mod tests { value: 111950000_u64, pk_script: @from_hex("76a914ef48d8584b96d95992a664d524e52007b036754188ac"), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_encoded = tx.encode(); let wtx_encoded = tx.encode_with_witness(tx_encoded.span()); let tx_encoded_expect = words_from_hex( - "0100000003a763b772966d9f580120455fe8fe264fe40f10461633f02a32b22b117654a7b8000000008c493046022100838b5bd094d57898d359569af330312e2dd99f8a1db7add92dc1704808625dbf022100978160771ea1e3ffe014e1fa7559f0bb5ffd32f6b63f19225bf3be110c2f2d65014104c273b18442afb2263698a09da205bb7a18f23037f9c285fc789874fe012ac32b40a18f12191a0015f2506b5a395d9845005b90a34a813715e9cc5dbf8024ca18ffffffff973a4e2f628a56b88051e65dc78fa70c41372ad79cd32f911c95a18f905eeda7010000008b48304502200b2ff9ed1689c9403b4bf0aca89fa4a53004c2c6ad66b4df25ae8361eef172cc022100c8f5fcd4eeb02762d9b40de1013ad7283042585caec8e60be873689de8e29a4a014104cdadb5199b0d9d356ae03fbf891f28d761547d79a0c5dae24998fa84a147e39f27ce03cd8efd8bd27e9dffc78744d66b2942b76801f79ae4028028e7122a3bb1fffffffff59f3ff699917790b02b3248716b22cdc1f8ddafe583ea28d100ae262f60ce66010000008c493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028ffffffff0290051000000000001976a914bafe7b8f25824ff18f698d2878d50c6fc43dd1d088acb038ac06000000001976a914ef48d8584b96d95992a664d524e52007b036754188ac00000000" + "0100000003a763b772966d9f580120455fe8fe264fe40f10461633f02a32b22b117654a7b8000000008c493046022100838b5bd094d57898d359569af330312e2dd99f8a1db7add92dc1704808625dbf022100978160771ea1e3ffe014e1fa7559f0bb5ffd32f6b63f19225bf3be110c2f2d65014104c273b18442afb2263698a09da205bb7a18f23037f9c285fc789874fe012ac32b40a18f12191a0015f2506b5a395d9845005b90a34a813715e9cc5dbf8024ca18ffffffff973a4e2f628a56b88051e65dc78fa70c41372ad79cd32f911c95a18f905eeda7010000008b48304502200b2ff9ed1689c9403b4bf0aca89fa4a53004c2c6ad66b4df25ae8361eef172cc022100c8f5fcd4eeb02762d9b40de1013ad7283042585caec8e60be873689de8e29a4a014104cdadb5199b0d9d356ae03fbf891f28d761547d79a0c5dae24998fa84a147e39f27ce03cd8efd8bd27e9dffc78744d66b2942b76801f79ae4028028e7122a3bb1fffffffff59f3ff699917790b02b3248716b22cdc1f8ddafe583ea28d100ae262f60ce66010000008c493046022100f814323e8be180dd90d063adb8f94b31801fb68ce97eb1acb32970a390bfa72f02210085ed8af17e90e2415d400d7cb08311535243d55461be9982bb3408271aa954aa0141045d21d60c22da05383ef130e3fc314b28c7dd378c762931f8c85e5e708d97b9779d83135a8c3cfe202f435e2781c99329043080627c5eb71f73be103fe45c2028ffffffff0290051000000000001976a914bafe7b8f25824ff18f698d2878d50c6fc43dd1d088acb038ac06000000001976a914ef48d8584b96d95992a664d524e52007b036754188ac00000000", ); assert_eq!(tx_encoded, tx_encoded_expect); assert_eq!(wtx_encoded, tx_encoded_expect); @@ -414,19 +414,19 @@ mod tests { inputs: array![ TxIn { script: @from_hex( - "493046022100ebbd4f6b412cafa26c6484ec9a16704177964f2570f0867de633cb3f3b48f3520221008211917fee214c506686a7bba3414b9cbbc33769c06ce49f29197ac863c8bee1014104b13bab6066a13e3d672a0b11447659f1986888c9e5cbf9ee6c57283ccf5662c5eeeefc02ad3c38141b6872ab46429f784802892dea1306c909754b3fcb1f1d0c" + "493046022100ebbd4f6b412cafa26c6484ec9a16704177964f2570f0867de633cb3f3b48f3520221008211917fee214c506686a7bba3414b9cbbc33769c06ce49f29197ac863c8bee1014104b13bab6066a13e3d672a0b11447659f1986888c9e5cbf9ee6c57283ccf5662c5eeeefc02ad3c38141b6872ab46429f784802892dea1306c909754b3fcb1f1d0c", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "cf37895a05d18f4f3fa0a7fb1b4e74763fc9d287d929b5ae1a7cec789f28fd07" + "cf37895a05d18f4f3fa0a7fb1b4e74763fc9d287d929b5ae1a7cec789f28fd07", ), vout: 1_u32, data: TxOut { value: 62000000_u64, pk_script: @from_hex( - "76a9142ae88d06a952e6acc52310dcb59e55fd1686862088ac" + "76a9142ae88d06a952e6acc52310dcb59e55fd1686862088ac", ), cached: false, }, @@ -437,19 +437,19 @@ mod tests { }, TxIn { script: @from_hex( - "483045022100b61a58bc0a99fe55445a44f9a77b2a97a946283f34db3b26fcae24ea8750b6cc02204faf7572c8504b129a699250fdb90f9524a875052a49fb464bcc381f9a1a31af0141045327413c7cec34e5b3cee5e186221ffaab3e808bc9564cf8f110ee9bf4c270a6df410d98705867220e4cbfdde4a42e27288171416935655667c48a3acba08c25" + "483045022100b61a58bc0a99fe55445a44f9a77b2a97a946283f34db3b26fcae24ea8750b6cc02204faf7572c8504b129a699250fdb90f9524a875052a49fb464bcc381f9a1a31af0141045327413c7cec34e5b3cee5e186221ffaab3e808bc9564cf8f110ee9bf4c270a6df410d98705867220e4cbfdde4a42e27288171416935655667c48a3acba08c25", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "e69026f2413fffc021cd3e3018f7eaeda4db0ad11c8b80c61f4fd77df0265bde" + "e69026f2413fffc021cd3e3018f7eaeda4db0ad11c8b80c61f4fd77df0265bde", ), vout: 1_u32, data: TxOut { value: 26900000_u64, pk_script: @from_hex( - "76a9143f29bb456435e26b45b195e865d102ee90301ace88ac" + "76a9143f29bb456435e26b45b195e865d102ee90301ace88ac", ), cached: false, }, @@ -460,19 +460,19 @@ mod tests { }, TxIn { script: @from_hex( - "483045022100f3fe3bb13a02d226c7876f5f20618e4752e65fdb52fed9558bc280f1196dc6d202205c8bae389dd40524bbd6b890c989b32f476ba8a555ff052c00e469fcf18100730141041dd42c00f540555c3785748f9acacff422ec8c403f080f16a12b69681a8cf3d4ddd0f7b767b60a9ce2809c52b7f2e3100cf82857eb597226a4281ebd99fec983" + "483045022100f3fe3bb13a02d226c7876f5f20618e4752e65fdb52fed9558bc280f1196dc6d202205c8bae389dd40524bbd6b890c989b32f476ba8a555ff052c00e469fcf18100730141041dd42c00f540555c3785748f9acacff422ec8c403f080f16a12b69681a8cf3d4ddd0f7b767b60a9ce2809c52b7f2e3100cf82857eb597226a4281ebd99fec983", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "116ffc273e21fa84f92738b059aa2f895fc34963724decdee8600d4d49b2ea75" + "116ffc273e21fa84f92738b059aa2f895fc34963724decdee8600d4d49b2ea75", ), vout: 1_u32, data: TxOut { value: 501999999_u64, pk_script: @from_hex( - "76a91424ae3a8e9b07f92f0eeb8fc47809b20c3cca41d388ac" + "76a91424ae3a8e9b07f92f0eeb8fc47809b20c3cca41d388ac", ), cached: false, }, @@ -483,19 +483,19 @@ mod tests { }, TxIn { script: @from_hex( - "48304502203edc1344854875d946fa88991249e043e112e2a4716c6758658e4053d96d13d5022100c6388938893200b95c6f0ff718cb875df01b25aead54e6bcaf15ecc4f22bfdd10141047ce313f56017f2b0bf12619a4b3d06ea3926b68b005c6f4b77d05711bc750bc423f22c5bd639265a699f24483d56566efdf86941fda31f741da8e73aa75674a6" + "48304502203edc1344854875d946fa88991249e043e112e2a4716c6758658e4053d96d13d5022100c6388938893200b95c6f0ff718cb875df01b25aead54e6bcaf15ecc4f22bfdd10141047ce313f56017f2b0bf12619a4b3d06ea3926b68b005c6f4b77d05711bc750bc423f22c5bd639265a699f24483d56566efdf86941fda31f741da8e73aa75674a6", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "a6f7299d3b1412921b3a2335b345c96462421b37b4c0d519c66a591027d4b44c" + "a6f7299d3b1412921b3a2335b345c96462421b37b4c0d519c66a591027d4b44c", ), vout: 1_u32, data: TxOut { value: 1226409352_u64, pk_script: @from_hex( - "76a9142ac56f52fa8217b501e471db987140da7534509d88ac" + "76a9142ac56f52fa8217b501e471db987140da7534509d88ac", ), cached: false, }, @@ -506,19 +506,19 @@ mod tests { }, TxIn { script: @from_hex( - "483045022031e8a1071c3ffb7642156ef6b23db33f8fb74034ed365f161f87721e2267bdc3022100b3b64ecba04459f7b378ad569315e3750eee1debe9520e54b4cd84c49115e586014104ee1a3b5815a9b2f641f013e6ad0b45b297093ef2e61754f6513cb9d565fe90f57488452cf8d467ce429344b53177d53903d9cd20ac56c7bb94b9932c0fc44873" + "483045022031e8a1071c3ffb7642156ef6b23db33f8fb74034ed365f161f87721e2267bdc3022100b3b64ecba04459f7b378ad569315e3750eee1debe9520e54b4cd84c49115e586014104ee1a3b5815a9b2f641f013e6ad0b45b297093ef2e61754f6513cb9d565fe90f57488452cf8d467ce429344b53177d53903d9cd20ac56c7bb94b9932c0fc44873", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "9e5a36dc05bbe1f0c8006293b73d983cdcc24e84d4d88dd1d91cb5bb93fefa0f" + "9e5a36dc05bbe1f0c8006293b73d983cdcc24e84d4d88dd1d91cb5bb93fefa0f", ), vout: 0_u32, data: TxOut { value: 2507265606_u64, pk_script: @from_hex( - "76a914685dd14a99d59e85413a7786b55574de0aca508b88ac" + "76a914685dd14a99d59e85413a7786b55574de0aca508b88ac", ), cached: false, }, @@ -529,19 +529,19 @@ mod tests { }, TxIn { script: @from_hex( - "49304602210097542b50d8c59dc36103409bbe8a3b127b71ef54cde7cc6b86dfb347b5fc2593022100b0feb2951ea9bd21e70d382513bb5230ea598ba1ad27b16ace79731e286aef42014104190af8345785f062b8f91730c5f1aa0527a540859c2d5bbf8b0e15553c6c596308fb02a4c617baaa81ef970bbb6b5267ecdac860a89a5c84f55c6cc0c242b197" + "49304602210097542b50d8c59dc36103409bbe8a3b127b71ef54cde7cc6b86dfb347b5fc2593022100b0feb2951ea9bd21e70d382513bb5230ea598ba1ad27b16ace79731e286aef42014104190af8345785f062b8f91730c5f1aa0527a540859c2d5bbf8b0e15553c6c596308fb02a4c617baaa81ef970bbb6b5267ecdac860a89a5c84f55c6cc0c242b197", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "10ee2df74adce2d1727194e0cc1c0006978a38225d9068ea86dae6603cbdc26a" + "10ee2df74adce2d1727194e0cc1c0006978a38225d9068ea86dae6603cbdc26a", ), vout: 1_u32, data: TxOut { value: 568878428_u64, pk_script: @from_hex( - "76a9146dc21dd3563ce54c0da31174d05f3492af934c1e88ac" + "76a9146dc21dd3563ce54c0da31174d05f3492af934c1e88ac", ), cached: false, }, @@ -552,19 +552,19 @@ mod tests { }, TxIn { script: @from_hex( - "4830450220788dfeb9abbbee831f80fa96421e215ee1d7cf173492fd064756fc881f6b9a2d022100a20ce16d007ca199674cadff4b29c0da7c644efb3e8238045d37848e9d45d7c3014104afdd6ae6cc3df689e7e9bced930cdac7fc7099da002d0fe6ad376dc69159664bb2ef4de657b1f96eeb4f5bd80a0b2f01fcd7fe8dd0eb8d7539c2e985d87ef18f" + "4830450220788dfeb9abbbee831f80fa96421e215ee1d7cf173492fd064756fc881f6b9a2d022100a20ce16d007ca199674cadff4b29c0da7c644efb3e8238045d37848e9d45d7c3014104afdd6ae6cc3df689e7e9bced930cdac7fc7099da002d0fe6ad376dc69159664bb2ef4de657b1f96eeb4f5bd80a0b2f01fcd7fe8dd0eb8d7539c2e985d87ef18f", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "ce8f4c5729351528ee52ee56d4bc85269cbc173b40ee04882e8fc66ce15fd80b" + "ce8f4c5729351528ee52ee56d4bc85269cbc173b40ee04882e8fc66ce15fd80b", ), vout: 1_u32, data: TxOut { value: 497295999_u64, pk_script: @from_hex( - "76a91430abfd2f1003084643240c3fa453886db43ea59888ac" + "76a91430abfd2f1003084643240c3fa453886db43ea59888ac", ), cached: false, }, @@ -575,19 +575,19 @@ mod tests { }, TxIn { script: @from_hex( - "483045022100d08ff8ae18a308718e58955525e57f5482409769b72366c04657c5687a15947802206c77aa5472d324921a3bc58821dd0debc1fb41674fe45ae19bd655be6e6b867a0141042825c68ba0a68b07c64afd202f5eefd7cf587ded6a1b80b16606d27157634642e01ecc67e6f072e5feadfd23a9a4222407e3a10068f8745b1296fa905e80c091" + "483045022100d08ff8ae18a308718e58955525e57f5482409769b72366c04657c5687a15947802206c77aa5472d324921a3bc58821dd0debc1fb41674fe45ae19bd655be6e6b867a0141042825c68ba0a68b07c64afd202f5eefd7cf587ded6a1b80b16606d27157634642e01ecc67e6f072e5feadfd23a9a4222407e3a10068f8745b1296fa905e80c091", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "5d22c46efffbba9d1e0e8b2e94b0933a4e71e2e2ed3ab642ea8eba957cb036c9" + "5d22c46efffbba9d1e0e8b2e94b0933a4e71e2e2ed3ab642ea8eba957cb036c9", ), vout: 1_u32, data: TxOut { value: 4756000000_u64, pk_script: @from_hex( - "76a91419b159563b79c8b0bf041de7b04d56bc099c3aa288ac" + "76a91419b159563b79c8b0bf041de7b04d56bc099c3aa288ac", ), cached: false, }, @@ -617,7 +617,7 @@ mod tests { let wtx_encoded = tx.encode_with_witness(tx_encoded.span()); let tx_encoded_expect = words_from_hex( - "010000000807fd289f78ec7c1aaeb529d987d2c93f76744e1bfba7a03f4f8fd1055a8937cf010000008c493046022100ebbd4f6b412cafa26c6484ec9a16704177964f2570f0867de633cb3f3b48f3520221008211917fee214c506686a7bba3414b9cbbc33769c06ce49f29197ac863c8bee1014104b13bab6066a13e3d672a0b11447659f1986888c9e5cbf9ee6c57283ccf5662c5eeeefc02ad3c38141b6872ab46429f784802892dea1306c909754b3fcb1f1d0cffffffffde5b26f07dd74f1fc6808b1cd10adba4edeaf718303ecd21c0ff3f41f22690e6010000008b483045022100b61a58bc0a99fe55445a44f9a77b2a97a946283f34db3b26fcae24ea8750b6cc02204faf7572c8504b129a699250fdb90f9524a875052a49fb464bcc381f9a1a31af0141045327413c7cec34e5b3cee5e186221ffaab3e808bc9564cf8f110ee9bf4c270a6df410d98705867220e4cbfdde4a42e27288171416935655667c48a3acba08c25ffffffff75eab2494d0d60e8deec4d726349c35f892faa59b03827f984fa213e27fc6f11010000008b483045022100f3fe3bb13a02d226c7876f5f20618e4752e65fdb52fed9558bc280f1196dc6d202205c8bae389dd40524bbd6b890c989b32f476ba8a555ff052c00e469fcf18100730141041dd42c00f540555c3785748f9acacff422ec8c403f080f16a12b69681a8cf3d4ddd0f7b767b60a9ce2809c52b7f2e3100cf82857eb597226a4281ebd99fec983ffffffff4cb4d42710596ac619d5c0b4371b426264c945b335233a1b9212143b9d29f7a6010000008b48304502203edc1344854875d946fa88991249e043e112e2a4716c6758658e4053d96d13d5022100c6388938893200b95c6f0ff718cb875df01b25aead54e6bcaf15ecc4f22bfdd10141047ce313f56017f2b0bf12619a4b3d06ea3926b68b005c6f4b77d05711bc750bc423f22c5bd639265a699f24483d56566efdf86941fda31f741da8e73aa75674a6ffffffff0ffafe93bbb51cd9d18dd8d4844ec2dc3c983db7936200c8f0e1bb05dc365a9e000000008b483045022031e8a1071c3ffb7642156ef6b23db33f8fb74034ed365f161f87721e2267bdc3022100b3b64ecba04459f7b378ad569315e3750eee1debe9520e54b4cd84c49115e586014104ee1a3b5815a9b2f641f013e6ad0b45b297093ef2e61754f6513cb9d565fe90f57488452cf8d467ce429344b53177d53903d9cd20ac56c7bb94b9932c0fc44873ffffffff6ac2bd3c60e6da86ea68905d22388a9706001ccce0947172d1e2dc4af72dee10010000008c49304602210097542b50d8c59dc36103409bbe8a3b127b71ef54cde7cc6b86dfb347b5fc2593022100b0feb2951ea9bd21e70d382513bb5230ea598ba1ad27b16ace79731e286aef42014104190af8345785f062b8f91730c5f1aa0527a540859c2d5bbf8b0e15553c6c596308fb02a4c617baaa81ef970bbb6b5267ecdac860a89a5c84f55c6cc0c242b197ffffffff0bd85fe16cc68f2e8804ee403b17bc9c2685bcd456ee52ee28153529574c8fce010000008b4830450220788dfeb9abbbee831f80fa96421e215ee1d7cf173492fd064756fc881f6b9a2d022100a20ce16d007ca199674cadff4b29c0da7c644efb3e8238045d37848e9d45d7c3014104afdd6ae6cc3df689e7e9bced930cdac7fc7099da002d0fe6ad376dc69159664bb2ef4de657b1f96eeb4f5bd80a0b2f01fcd7fe8dd0eb8d7539c2e985d87ef18fffffffffc936b07c95ba8eea42b63aede2e2714e3a93b0942e8b0e1e9dbafbff6ec4225d010000008b483045022100d08ff8ae18a308718e58955525e57f5482409769b72366c04657c5687a15947802206c77aa5472d324921a3bc58821dd0debc1fb41674fe45ae19bd655be6e6b867a0141042825c68ba0a68b07c64afd202f5eefd7cf587ded6a1b80b16606d27157634642e01ecc67e6f072e5feadfd23a9a4222407e3a10068f8745b1296fa905e80c091ffffffff0200e40b54020000001976a914552362dca64805372f3a1c1bfbe190bd148569a188acca37bf08000000001976a9140b0a49a0f4db52c7aa4cc913cebc49b26500d78288ac00000000" + "010000000807fd289f78ec7c1aaeb529d987d2c93f76744e1bfba7a03f4f8fd1055a8937cf010000008c493046022100ebbd4f6b412cafa26c6484ec9a16704177964f2570f0867de633cb3f3b48f3520221008211917fee214c506686a7bba3414b9cbbc33769c06ce49f29197ac863c8bee1014104b13bab6066a13e3d672a0b11447659f1986888c9e5cbf9ee6c57283ccf5662c5eeeefc02ad3c38141b6872ab46429f784802892dea1306c909754b3fcb1f1d0cffffffffde5b26f07dd74f1fc6808b1cd10adba4edeaf718303ecd21c0ff3f41f22690e6010000008b483045022100b61a58bc0a99fe55445a44f9a77b2a97a946283f34db3b26fcae24ea8750b6cc02204faf7572c8504b129a699250fdb90f9524a875052a49fb464bcc381f9a1a31af0141045327413c7cec34e5b3cee5e186221ffaab3e808bc9564cf8f110ee9bf4c270a6df410d98705867220e4cbfdde4a42e27288171416935655667c48a3acba08c25ffffffff75eab2494d0d60e8deec4d726349c35f892faa59b03827f984fa213e27fc6f11010000008b483045022100f3fe3bb13a02d226c7876f5f20618e4752e65fdb52fed9558bc280f1196dc6d202205c8bae389dd40524bbd6b890c989b32f476ba8a555ff052c00e469fcf18100730141041dd42c00f540555c3785748f9acacff422ec8c403f080f16a12b69681a8cf3d4ddd0f7b767b60a9ce2809c52b7f2e3100cf82857eb597226a4281ebd99fec983ffffffff4cb4d42710596ac619d5c0b4371b426264c945b335233a1b9212143b9d29f7a6010000008b48304502203edc1344854875d946fa88991249e043e112e2a4716c6758658e4053d96d13d5022100c6388938893200b95c6f0ff718cb875df01b25aead54e6bcaf15ecc4f22bfdd10141047ce313f56017f2b0bf12619a4b3d06ea3926b68b005c6f4b77d05711bc750bc423f22c5bd639265a699f24483d56566efdf86941fda31f741da8e73aa75674a6ffffffff0ffafe93bbb51cd9d18dd8d4844ec2dc3c983db7936200c8f0e1bb05dc365a9e000000008b483045022031e8a1071c3ffb7642156ef6b23db33f8fb74034ed365f161f87721e2267bdc3022100b3b64ecba04459f7b378ad569315e3750eee1debe9520e54b4cd84c49115e586014104ee1a3b5815a9b2f641f013e6ad0b45b297093ef2e61754f6513cb9d565fe90f57488452cf8d467ce429344b53177d53903d9cd20ac56c7bb94b9932c0fc44873ffffffff6ac2bd3c60e6da86ea68905d22388a9706001ccce0947172d1e2dc4af72dee10010000008c49304602210097542b50d8c59dc36103409bbe8a3b127b71ef54cde7cc6b86dfb347b5fc2593022100b0feb2951ea9bd21e70d382513bb5230ea598ba1ad27b16ace79731e286aef42014104190af8345785f062b8f91730c5f1aa0527a540859c2d5bbf8b0e15553c6c596308fb02a4c617baaa81ef970bbb6b5267ecdac860a89a5c84f55c6cc0c242b197ffffffff0bd85fe16cc68f2e8804ee403b17bc9c2685bcd456ee52ee28153529574c8fce010000008b4830450220788dfeb9abbbee831f80fa96421e215ee1d7cf173492fd064756fc881f6b9a2d022100a20ce16d007ca199674cadff4b29c0da7c644efb3e8238045d37848e9d45d7c3014104afdd6ae6cc3df689e7e9bced930cdac7fc7099da002d0fe6ad376dc69159664bb2ef4de657b1f96eeb4f5bd80a0b2f01fcd7fe8dd0eb8d7539c2e985d87ef18fffffffffc936b07c95ba8eea42b63aede2e2714e3a93b0942e8b0e1e9dbafbff6ec4225d010000008b483045022100d08ff8ae18a308718e58955525e57f5482409769b72366c04657c5687a15947802206c77aa5472d324921a3bc58821dd0debc1fb41674fe45ae19bd655be6e6b867a0141042825c68ba0a68b07c64afd202f5eefd7cf587ded6a1b80b16606d27157634642e01ecc67e6f072e5feadfd23a9a4222407e3a10068f8745b1296fa905e80c091ffffffff0200e40b54020000001976a914552362dca64805372f3a1c1bfbe190bd148569a188acca37bf08000000001976a9140b0a49a0f4db52c7aa4cc913cebc49b26500d78288ac00000000", ); assert_eq!(tx_encoded, tx_encoded_expect); @@ -634,19 +634,19 @@ mod tests { inputs: array![ TxIn { script: @from_hex( - "47304402203c31af8b4ad8e035aac5a7b2bcda81c26a5a2ce791df00bbf207aabceff246410220545e269decc8c777beccda949118028a9fa3a2a5452414ee3ff21068db18fcab0141047a38fd20560d9e258b11bf6d71fec9f049a4786d0374bc858317848ad32970337ab61ae3bd3c0296d7dce49d7ad0fb46ba0f0743960ea3324a57699a997e5ad9" + "47304402203c31af8b4ad8e035aac5a7b2bcda81c26a5a2ce791df00bbf207aabceff246410220545e269decc8c777beccda949118028a9fa3a2a5452414ee3ff21068db18fcab0141047a38fd20560d9e258b11bf6d71fec9f049a4786d0374bc858317848ad32970337ab61ae3bd3c0296d7dce49d7ad0fb46ba0f0743960ea3324a57699a997e5ad9", ), sequence: 4294967295, witness: array![].span(), previous_output: OutPoint { txid: hex_to_hash_rev( - "027f3d5cda9b0e8c45654d603d1ce2babbbbeb1198378804de654f253ea7531d" + "027f3d5cda9b0e8c45654d603d1ce2babbbbeb1198378804de654f253ea7531d", ), vout: 1_u32, data: TxOut { value: 8010539842_u64, pk_script: @from_hex( - "76a9146e9470910291611d311ab76b89a878fead10594788ac" + "76a9146e9470910291611d311ab76b89a878fead10594788ac", ), cached: false, }, @@ -725,7 +725,7 @@ mod tests { let tx_encoded = tx.encode(); let wtx_encoded = tx.encode_with_witness(tx_encoded.span()); let tx_encoded_expect = words_from_hex( - "01000000011d53a73e254f65de0488379811ebbbbbbae21c3d604d65458c0e9bda5c3d7f02010000008a47304402203c31af8b4ad8e035aac5a7b2bcda81c26a5a2ce791df00bbf207aabceff246410220545e269decc8c777beccda949118028a9fa3a2a5452414ee3ff21068db18fcab0141047a38fd20560d9e258b11bf6d71fec9f049a4786d0374bc858317848ad32970337ab61ae3bd3c0296d7dce49d7ad0fb46ba0f0743960ea3324a57699a997e5ad9ffffffff0c00e1f505000000001976a91406f1b6716309948fa3b07b0a6b66804fdfd6873188ac00e1f505000000001976a91406f1b670791f9256bffc898f474271c22f4bb94988ac00e1f505000000001976a91406f1b6703d3f56427bfcfd372f952d50d04b64bd88ac00e1f505000000001976a91406f1b66ffe49df7fce684df16c62f59dc9adbd3f88ac00e1f505000000001976a91406f1b66fc9e59a7b4554cf2e6094032cd9ee45c488ac00e1f505000000001976a91406f1b66fd59a34755c37a8f701f43e937cdbeb1388ac00e1f505000000001976a91406f1b66fb6c0e253f24c74d3ed972ff447ca285c88ac00e1f505000000001976a91406f1b66f8567c6e527fc89b4d664069d20b0969388ac00e1f505000000001976a91406f1b66f6d8af8b3e984e5d807c0e1dd6964796288ac00e1f505000000001976a91406f1b66f5a691ff3169702d615b77d0af1451e7788ac404b4c00000000001976a91406f1b66e25393fabd2b23a237e4bdfd4c2c35fac88ac62878ea1010000001976a9146e9470910291611d311ab76b89a878fead10594788ac00000000" + "01000000011d53a73e254f65de0488379811ebbbbbbae21c3d604d65458c0e9bda5c3d7f02010000008a47304402203c31af8b4ad8e035aac5a7b2bcda81c26a5a2ce791df00bbf207aabceff246410220545e269decc8c777beccda949118028a9fa3a2a5452414ee3ff21068db18fcab0141047a38fd20560d9e258b11bf6d71fec9f049a4786d0374bc858317848ad32970337ab61ae3bd3c0296d7dce49d7ad0fb46ba0f0743960ea3324a57699a997e5ad9ffffffff0c00e1f505000000001976a91406f1b6716309948fa3b07b0a6b66804fdfd6873188ac00e1f505000000001976a91406f1b670791f9256bffc898f474271c22f4bb94988ac00e1f505000000001976a91406f1b6703d3f56427bfcfd372f952d50d04b64bd88ac00e1f505000000001976a91406f1b66ffe49df7fce684df16c62f59dc9adbd3f88ac00e1f505000000001976a91406f1b66fc9e59a7b4554cf2e6094032cd9ee45c488ac00e1f505000000001976a91406f1b66fd59a34755c37a8f701f43e937cdbeb1388ac00e1f505000000001976a91406f1b66fb6c0e253f24c74d3ed972ff447ca285c88ac00e1f505000000001976a91406f1b66f8567c6e527fc89b4d664069d20b0969388ac00e1f505000000001976a91406f1b66f6d8af8b3e984e5d807c0e1dd6964796288ac00e1f505000000001976a91406f1b66f5a691ff3169702d615b77d0af1451e7788ac404b4c00000000001976a91406f1b66e25393fabd2b23a237e4bdfd4c2c35fac88ac62878ea1010000001976a9146e9470910291611d311ab76b89a878fead10594788ac00000000", ); assert_eq!(tx_encoded, tx_encoded_expect); @@ -744,7 +744,7 @@ mod tests { sequence: 0xfffffffd, previous_output: OutPoint { txid: hex_to_hash_rev( - "39cc1562b197182429bc1ea312c9e30f1257be6d5159fcd7b375139d3c3fe63c" + "39cc1562b197182429bc1ea312c9e30f1257be6d5159fcd7b375139d3c3fe63c", ), vout: 0x0, data: Default::default(), @@ -754,11 +754,11 @@ mod tests { }, witness: array![ from_hex( - "30440220537f470c1a18dc1a9d233c0b6af1d2ce18a07f3b244e4d9d54e0e60c34c55e67022058169cd11ac42374cda217d6e28143abd0e79549f7b84acc6542817466dc9b3001" + "30440220537f470c1a18dc1a9d233c0b6af1d2ce18a07f3b244e4d9d54e0e60c34c55e67022058169cd11ac42374cda217d6e28143abd0e79549f7b84acc6542817466dc9b3001", ), from_hex( - "0301c1768b48843933bd7f0e8782716e8439fc44723d3745feefde2d57b761f503" - ) + "0301c1768b48843933bd7f0e8782716e8439fc44723d3745feefde2d57b761f503", + ), ] .span(), }, @@ -784,10 +784,10 @@ mod tests { let wtx_encoded = tx.encode_with_witness(tx_encoded.span()); let tx_encoded_expect = words_from_hex( - "02000000013ce63f3c9d1375b3d7fc59516dbe57120fe3c912a31ebc29241897b16215cc390000000000fdffffff020f900100000000001976a914998db5e1126bc3a5e04109fbf253a7900462410e88acd9bd150000000000160014579bf4f06510c8683f2451262b6685b00012e46f3f600a00" + "02000000013ce63f3c9d1375b3d7fc59516dbe57120fe3c912a31ebc29241897b16215cc390000000000fdffffff020f900100000000001976a914998db5e1126bc3a5e04109fbf253a7900462410e88acd9bd150000000000160014579bf4f06510c8683f2451262b6685b00012e46f3f600a00", ); let wtx_encoded_expect = words_from_hex( - "020000000001013ce63f3c9d1375b3d7fc59516dbe57120fe3c912a31ebc29241897b16215cc390000000000fdffffff020f900100000000001976a914998db5e1126bc3a5e04109fbf253a7900462410e88acd9bd150000000000160014579bf4f06510c8683f2451262b6685b00012e46f024730440220537f470c1a18dc1a9d233c0b6af1d2ce18a07f3b244e4d9d54e0e60c34c55e67022058169cd11ac42374cda217d6e28143abd0e79549f7b84acc6542817466dc9b3001210301c1768b48843933bd7f0e8782716e8439fc44723d3745feefde2d57b761f5033f600a00" + "020000000001013ce63f3c9d1375b3d7fc59516dbe57120fe3c912a31ebc29241897b16215cc390000000000fdffffff020f900100000000001976a914998db5e1126bc3a5e04109fbf253a7900462410e88acd9bd150000000000160014579bf4f06510c8683f2451262b6685b00012e46f024730440220537f470c1a18dc1a9d233c0b6af1d2ce18a07f3b244e4d9d54e0e60c34c55e67022058169cd11ac42374cda217d6e28143abd0e79549f7b84acc6542817466dc9b3001210301c1768b48843933bd7f0e8782716e8439fc44723d3745feefde2d57b761f5033f600a00", ); let total_weight = 3 * tx_encoded.byte_len() + wtx_encoded.byte_len(); @@ -809,7 +809,7 @@ mod tests { sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "db2448ca5ab8fa4243cb0b3256fb0a629d8e42f9be1056bf1177c9d1be9f996f" + "db2448ca5ab8fa4243cb0b3256fb0a629d8e42f9be1056bf1177c9d1be9f996f", ), vout: 0_u32, data: Default::default(), @@ -819,10 +819,10 @@ mod tests { }, witness: array![ from_hex( - "3045022100e79c80ee315b6ef4e29f9bd5776b14d50c2c23a378cde2407b8adc907352ecf902200a4b2d2b5db31883e78e84f5d81f0fcc7e5fa54c5a0dc98335cd58efed3c4f1901" + "3045022100e79c80ee315b6ef4e29f9bd5776b14d50c2c23a378cde2407b8adc907352ecf902200a4b2d2b5db31883e78e84f5d81f0fcc7e5fa54c5a0dc98335cd58efed3c4f1901", ), from_hex( - "03e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa" + "03e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa", ), ] .span(), @@ -832,7 +832,7 @@ mod tests { sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "1c3f37e7b248c24e17c69202c22f78f027be62e0bcea1a91c664df467c4d2d7b" + "1c3f37e7b248c24e17c69202c22f78f027be62e0bcea1a91c664df467c4d2d7b", ), vout: 1_u32, data: Default::default(), @@ -842,10 +842,10 @@ mod tests { }, witness: array![ from_hex( - "3044022065bb4676eb5bebb69241ebdd121dbef5d8e468e7b0af96576d62a38be7af83b70220604dacc80a67fd0511da9cfaeeb72b0ab58c255e712a209325902f50e60ad0bb01" + "3044022065bb4676eb5bebb69241ebdd121dbef5d8e468e7b0af96576d62a38be7af83b70220604dacc80a67fd0511da9cfaeeb72b0ab58c255e712a209325902f50e60ad0bb01", ), from_hex( - "03e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa" + "03e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa", ), ] .span(), @@ -871,10 +871,10 @@ mod tests { let wtx_encoded = tx.encode_with_witness(tx_encoded.span()); let tx_encoded_expect = words_from_hex( - "02000000026f999fbed1c97711bf5610bef9428e9d620afb56320bcb4342fab85aca4824db0000000000ffffffff7b2d4d7c46df64c6911aeabce062be27f0782fc20292c6174ec248b2e7373f1c0100000000ffffffff027cfa0400000000001600148812478461956e68872e7f3e8782d5ecb58b9ec15453010000000000160014857f3f59abc3998e771f07d8f06d3ec6eb5d2da200000000" + "02000000026f999fbed1c97711bf5610bef9428e9d620afb56320bcb4342fab85aca4824db0000000000ffffffff7b2d4d7c46df64c6911aeabce062be27f0782fc20292c6174ec248b2e7373f1c0100000000ffffffff027cfa0400000000001600148812478461956e68872e7f3e8782d5ecb58b9ec15453010000000000160014857f3f59abc3998e771f07d8f06d3ec6eb5d2da200000000", ); let wtx_encoded_expect = words_from_hex( - "020000000001026f999fbed1c97711bf5610bef9428e9d620afb56320bcb4342fab85aca4824db0000000000ffffffff7b2d4d7c46df64c6911aeabce062be27f0782fc20292c6174ec248b2e7373f1c0100000000ffffffff027cfa0400000000001600148812478461956e68872e7f3e8782d5ecb58b9ec15453010000000000160014857f3f59abc3998e771f07d8f06d3ec6eb5d2da202483045022100e79c80ee315b6ef4e29f9bd5776b14d50c2c23a378cde2407b8adc907352ecf902200a4b2d2b5db31883e78e84f5d81f0fcc7e5fa54c5a0dc98335cd58efed3c4f19012103e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa02473044022065bb4676eb5bebb69241ebdd121dbef5d8e468e7b0af96576d62a38be7af83b70220604dacc80a67fd0511da9cfaeeb72b0ab58c255e712a209325902f50e60ad0bb012103e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa00000000" + "020000000001026f999fbed1c97711bf5610bef9428e9d620afb56320bcb4342fab85aca4824db0000000000ffffffff7b2d4d7c46df64c6911aeabce062be27f0782fc20292c6174ec248b2e7373f1c0100000000ffffffff027cfa0400000000001600148812478461956e68872e7f3e8782d5ecb58b9ec15453010000000000160014857f3f59abc3998e771f07d8f06d3ec6eb5d2da202483045022100e79c80ee315b6ef4e29f9bd5776b14d50c2c23a378cde2407b8adc907352ecf902200a4b2d2b5db31883e78e84f5d81f0fcc7e5fa54c5a0dc98335cd58efed3c4f19012103e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa02473044022065bb4676eb5bebb69241ebdd121dbef5d8e468e7b0af96576d62a38be7af83b70220604dacc80a67fd0511da9cfaeeb72b0ab58c255e712a209325902f50e60ad0bb012103e5d541eed7ccea6f94324bdcce27427c0e20b626bb9f2d2cbe2e81f22ae4aafa00000000", ); let total_weight = 3 * tx_encoded.byte_len() + wtx_encoded.byte_len(); @@ -895,7 +895,7 @@ mod tests { sequence: 0xfffffffd, previous_output: OutPoint { txid: hex_to_hash_rev( - "89d8ddef7821789e8ea407ebfe3dd290be403d5fa9174acc544d414eb2fd8a43" + "89d8ddef7821789e8ea407ebfe3dd290be403d5fa9174acc544d414eb2fd8a43", ), vout: 1, data: Default::default(), @@ -905,11 +905,11 @@ mod tests { }, witness: array![ from_hex( - "30440220200254b765f25126334b8de16ee4badf57315c047243942340c16cffd9b11196022074a9476633f093f229456ad904a9d97e26c271fc4f01d0501dec008e4aae71c201" + "30440220200254b765f25126334b8de16ee4badf57315c047243942340c16cffd9b11196022074a9476633f093f229456ad904a9d97e26c271fc4f01d0501dec008e4aae71c201", ), from_hex( - "02c37a3c5b21a5991d3d7b1e203be195be07104a1a19e5c2ed82329a56b4312130" - ) + "02c37a3c5b21a5991d3d7b1e203be195be07104a1a19e5c2ed82329a56b4312130", + ), ] .span(), }, @@ -935,10 +935,10 @@ mod tests { let wtx_encoded = tx.encode_with_witness(tx_encoded.span()); let tx_encoded_expect = words_from_hex( - "0100000001438afdb24e414d54cc4a17a95f3d40be90d23dfeeb07a48e9e782178efddd8890100000000fdffffff020db9a60000000000160014b549d227c9edd758288112fe3573c1f85240166880a81201000000001976a914ae28f233464e6da03c052155119a413d13f3380188ac00000000" + "0100000001438afdb24e414d54cc4a17a95f3d40be90d23dfeeb07a48e9e782178efddd8890100000000fdffffff020db9a60000000000160014b549d227c9edd758288112fe3573c1f85240166880a81201000000001976a914ae28f233464e6da03c052155119a413d13f3380188ac00000000", ); let wtx_encoded_expect = words_from_hex( - "01000000000101438afdb24e414d54cc4a17a95f3d40be90d23dfeeb07a48e9e782178efddd8890100000000fdffffff020db9a60000000000160014b549d227c9edd758288112fe3573c1f85240166880a81201000000001976a914ae28f233464e6da03c052155119a413d13f3380188ac024730440220200254b765f25126334b8de16ee4badf57315c047243942340c16cffd9b11196022074a9476633f093f229456ad904a9d97e26c271fc4f01d0501dec008e4aae71c2012102c37a3c5b21a5991d3d7b1e203be195be07104a1a19e5c2ed82329a56b431213000000000" + "01000000000101438afdb24e414d54cc4a17a95f3d40be90d23dfeeb07a48e9e782178efddd8890100000000fdffffff020db9a60000000000160014b549d227c9edd758288112fe3573c1f85240166880a81201000000001976a914ae28f233464e6da03c052155119a413d13f3380188ac024730440220200254b765f25126334b8de16ee4badf57315c047243942340c16cffd9b11196022074a9476633f093f229456ad904a9d97e26c271fc4f01d0501dec008e4aae71c2012102c37a3c5b21a5991d3d7b1e203be195be07104a1a19e5c2ed82329a56b431213000000000", ); let total_weight = 3 * tx_encoded.byte_len() + wtx_encoded.byte_len(); diff --git a/packages/consensus/src/types/block.cairo b/packages/consensus/src/types/block.cairo index a2ac02ad..549246ab 100644 --- a/packages/consensus/src/types/block.cairo +++ b/packages/consensus/src/types/block.cairo @@ -82,7 +82,7 @@ impl BlockDisplay of Display { 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); @@ -98,7 +98,7 @@ impl HeaderDisplay of Display
{ *self.version, *self.time, *self.bits, - *self.nonce + *self.nonce, ); f.buffer.append(@str); Result::Ok(()) @@ -112,7 +112,7 @@ impl TransactionDataDisplay of Display { 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(()) } @@ -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 @@ -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 @@ -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 diff --git a/packages/consensus/src/types/chain_state.cairo b/packages/consensus/src/types/chain_state.cairo index e31a5e17..4022fe52 100644 --- a/packages/consensus/src/types/chain_state.cairo +++ b/packages/consensus/src/types/chain_state.cairo @@ -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; @@ -46,9 +46,7 @@ impl ChainStateDefault of Default { .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(), } } } @@ -57,7 +55,7 @@ impl ChainStateDefault of Default { #[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 { let block_height = self.block_height + 1; @@ -73,14 +71,14 @@ 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( @@ -88,7 +86,7 @@ pub impl BlockValidatorImpl of BlockValidator { 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); @@ -104,7 +102,7 @@ pub impl BlockValidatorImpl of BlockValidator { current_target, epoch_start_time, prev_timestamps, - } + }, ) } } @@ -130,7 +128,7 @@ impl ChainStateDisplay of Display { *self.best_block_hash, *self.current_target, *self.epoch_start_time, - @prev_ts + @prev_ts, ); f.buffer.append(@str); Result::Ok(()) diff --git a/packages/consensus/src/types/transaction.cairo b/packages/consensus/src/types/transaction.cairo index d18eea74..90e47be8 100644 --- a/packages/consensus/src/types/transaction.cairo +++ b/packages/consensus/src/types/transaction.cairo @@ -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, } @@ -148,7 +148,7 @@ pub impl OutPointHashImpl of OutPointHashTrait { /// `Default` trait implementation for `TxOut`. impl TxOutDefault of Default { fn default() -> TxOut { - TxOut { value: 0, pk_script: @"", cached: false, } + TxOut { value: 0, pk_script: @"", cached: false } } } @@ -161,7 +161,7 @@ impl TransactionDisplay of Display { *self.is_segwit, (*self.inputs).len(), (*self.outputs).len(), - *self.lock_time + *self.lock_time, ); f.buffer.append(@str); Result::Ok(()) @@ -176,7 +176,7 @@ impl TxInDisplay of Display { *self.script, *self.sequence, *self.previous_output.txid, - (*self.witness).len() + (*self.witness).len(), ); f.buffer.append(@str); Result::Ok(()) @@ -200,7 +200,7 @@ impl OutPointDisplay of Display { *self.data, *self.block_height, *self.median_time_past, - *self.is_coinbase + *self.is_coinbase, ); f.buffer.append(@str); Result::Ok(()) @@ -214,7 +214,7 @@ impl TxOutDisplay of Display { "TxOut {{ value: {}, pk_script: {}, cached: {} }}", *self.value, *self.pk_script, - *self.cached + *self.cached, ); f.buffer.append(@str); Result::Ok(()) @@ -260,7 +260,7 @@ mod tests { #[derive(Debug, Drop, Default)] pub struct HashState { - pub value: Array + pub value: Array, } impl HashStateImpl of HashStateTrait { @@ -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, }, @@ -309,13 +309,13 @@ mod tests { 5, 9, 1231470988, - 1 + 1, ]; assert_eq!(expected, state.value); let hash = coinbase_9_utxo.hash(); assert_eq!( - 761592244424273723796345514960638980240531938129162865626185984897576522513, hash + 761592244424273723796345514960638980240531938129162865626185984897576522513, hash, ); } @@ -323,13 +323,13 @@ mod tests { 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, }, @@ -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, ); } } diff --git a/packages/consensus/src/types/utxo_set.cairo b/packages/consensus/src/types/utxo_set.cairo index 3537fa70..71b77de6 100644 --- a/packages/consensus/src/types/utxo_set.cairo +++ b/packages/consensus/src/types/utxo_set.cairo @@ -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 { @@ -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 { @@ -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, } } diff --git a/packages/consensus/src/validation/block.cairo b/packages/consensus/src/validation/block.cairo index 04314b83..818cc53d 100644 --- a/packages/consensus/src/validation/block.cairo +++ b/packages/consensus/src/validation/block.cairo @@ -5,7 +5,7 @@ use crate::types::utxo_set::{UtxoSet, UtxoSetTrait}; use crate::types::transaction::{OutPoint, Transaction}; use crate::codec::{Encode, TransactionCodec}; use crate::validation::{coinbase::is_coinbase_txid_duplicated, transaction::validate_transaction}; -use utils::{hash::Digest, merkle_tree::merkle_root, double_sha256::double_sha256_word_array,}; +use utils::{hash::Digest, merkle_tree::merkle_root, double_sha256::double_sha256_word_array}; use utils::word_array::WordArrayTrait; const MAX_BLOCK_WEIGHT_LEGACY: usize = 1_000_000; @@ -18,8 +18,8 @@ pub fn validate_block_weight(weight: usize) -> Result<(), ByteArray> { if (weight > MAX_BLOCK_WEIGHT) { return Result::Err( format!( - "[validate_weight] block weight {weight} exceeds the limit {MAX_BLOCK_WEIGHT} for segwit blocks" - ) + "[validate_weight] block weight {weight} exceeds the limit {MAX_BLOCK_WEIGHT} for segwit blocks", + ), ); } @@ -36,7 +36,7 @@ pub fn compute_and_validate_tx_data( block_height: u32, block_time: u32, median_time_past: u32, - ref utxo_set: UtxoSet + ref utxo_set: UtxoSet, ) -> Result<(u64, Digest, Digest), ByteArray> { let mut txids: Array = array![]; let mut wtxids: Array = array![]; @@ -84,33 +84,27 @@ pub fn compute_and_validate_tx_data( } let mut vout = 0; - for output in *tx - .outputs { - let outpoint = OutPoint { - txid, - vout, - data: *output, - block_height, - median_time_past, - is_coinbase: true, - }; - inner_result = utxo_set.add(outpoint); - if inner_result.is_err() { - break; - } - vout += 1; + for output in *tx.outputs { + let outpoint = OutPoint { + txid, vout, data: *output, block_height, median_time_past, is_coinbase: true, }; + inner_result = utxo_set.add(outpoint); + if inner_result.is_err() { + break; + } + vout += 1; + }; is_coinbase = false; } else { let fee = match validate_transaction( - tx, block_height, block_time, median_time_past, txid, ref utxo_set + tx, block_height, block_time, median_time_past, txid, ref utxo_set, ) { Result::Ok(fee) => fee, Result::Err(err) => { inner_result = Result::Err(err); break; - } + }, }; total_fee += fee; } diff --git a/packages/consensus/src/validation/coinbase.cairo b/packages/consensus/src/validation/coinbase.cairo index fd5f1889..e096d136 100644 --- a/packages/consensus/src/validation/coinbase.cairo +++ b/packages/consensus/src/validation/coinbase.cairo @@ -137,7 +137,7 @@ fn calculate_wtxid_commitment(wtxid_root: Digest) -> Digest { /// validates segwit output (BIP-141). fn validate_coinbase_outputs( - mut outputs: Span, wtxid_commitment: Digest + mut outputs: Span, wtxid_commitment: Digest, ) -> Result<(), ByteArray> { let mut is_wtxid_commitment_present: bool = false; @@ -271,7 +271,7 @@ mod tests { previous_output: OutPoint { txid: 0_u256.into(), vout: 0xffffffff_u32, - data: TxOut { value: 0_64, ..Default::default(), }, + data: TxOut { value: 0_64, ..Default::default() }, block_height: Default::default(), median_time_past: Default::default(), is_coinbase: false, @@ -284,20 +284,20 @@ mod tests { previous_output: OutPoint { txid: 0_u256.into(), vout: 0xffffffff_u32, - data: TxOut { value: 0_64, ..Default::default(), }, + data: TxOut { value: 0_64, ..Default::default() }, block_height: Default::default(), median_time_past: Default::default(), is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ - TxOut { value: 5000000000_u64, pk_script: @from_hex(""), cached: false, } + TxOut { value: 5000000000_u64, pk_script: @from_hex(""), cached: false }, ] .span(), - lock_time: 0 + lock_time: 0, }; let total_fees = 5000000000_u64; let block_height = 1; @@ -313,7 +313,7 @@ mod tests { previous_output: OutPoint { txid: 0_u256.into(), vout: 0x1_u32, - data: TxOut { value: 0_64, ..Default::default(), }, + data: TxOut { value: 0_64, ..Default::default() }, block_height: Default::default(), median_time_past: Default::default(), is_coinbase: false, @@ -332,7 +332,7 @@ mod tests { previous_output: OutPoint { txid: 0x2_u256.into(), vout: 0xFFFFFFFF_u32, - data: TxOut { value: 0_64, ..Default::default(), }, + data: TxOut { value: 0_64, ..Default::default() }, block_height: Default::default(), median_time_past: Default::default(), is_coinbase: false, @@ -355,20 +355,20 @@ mod tests { previous_output: OutPoint { txid: 0_u256.into(), vout: 0xffffffff_u32, - data: TxOut { value: 0_64, ..Default::default(), }, + data: TxOut { value: 0_64, ..Default::default() }, block_height: Default::default(), median_time_past: Default::default(), is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ - TxOut { value: 5000000000_u64, pk_script: @from_hex(""), cached: false, } + TxOut { value: 5000000000_u64, pk_script: @from_hex(""), cached: false }, ] .span(), - lock_time: 0 + lock_time: 0, }; let total_fees = 0_u64; @@ -385,29 +385,31 @@ mod tests { inputs: array![ TxIn { script: @from_hex( - "03f3110d04e202bb667c204d41524120506f6f6c207c204d61646520696e2055534120f09f87baf09f87b8207c2028763033313932342976649b3c094f135bf4b83108c14ea85f129c98e20e0000000000ffffffff" + "03f3110d04e202bb667c204d41524120506f6f6c207c204d61646520696e2055534120f09f87baf09f87b8207c2028763033313932342976649b3c094f135bf4b83108c14ea85f129c98e20e0000000000ffffffff", ), sequence: 4294967295, previous_output: OutPoint { txid: 0_u256.into(), vout: 0xffffffff_u32, - data: TxOut { value: 0_64, ..Default::default(), }, + data: TxOut { value: 0_64, ..Default::default() }, block_height: Default::default(), median_time_past: Default::default(), is_coinbase: false, }, witness: array![ - from_hex("0000000000000000000000000000000000000000000000000000000000000000") + from_hex( + "0000000000000000000000000000000000000000000000000000000000000000", + ), ] .span(), - } + }, ] .span(), outputs: array![ - TxOut { value: 5000000000_u64, pk_script: @from_hex(""), cached: false, } + TxOut { value: 5000000000_u64, pk_script: @from_hex(""), cached: false }, ] .span(), - lock_time: 0 + lock_time: 0, }; let total_fees = 5000000000_u64; @@ -434,20 +436,20 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ TxOut { value: 5000000000_u64, pk_script: @from_hex( - "4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac" + "4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac", ), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let total_fees = 0_u64; let block_height = 170; @@ -464,7 +466,7 @@ mod tests { #[test] fn test_validate_coinbase_BIP_34_sig_script_greater_than_100() { let script = from_hex( - "4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac" + "4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac4104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac", ); validate_coinbase_sig_script(@script, 856563).unwrap_err(); } @@ -472,7 +474,7 @@ mod tests { #[test] fn test_validate_coinbase_BIP_34_sig_script_with_wrong_block_height() { let script = from_hex( - "03aa68060004c345815704451c591c0c60ef5b577b690000000000000a2020202020200a2f72657365727665642f" + "03aa68060004c345815704451c591c0c60ef5b577b690000000000000a2020202020200a2f72657365727665642f", ); validate_coinbase_sig_script(@script, 856563).unwrap_err(); } @@ -480,7 +482,7 @@ mod tests { #[test] fn test_validate_coinbase_BIP_34_sig_script_with_Invalid_number_of_bytes() { let script = from_hex( - "04aa68060004c345815704451c591c0c60ef5b577b690000000000000a2020202020200a2f72657365727665642f" + "04aa68060004c345815704451c591c0c60ef5b577b690000000000000a2020202020200a2f72657365727665642f", ); validate_coinbase_sig_script(@script, 856563).unwrap_err(); } @@ -488,7 +490,7 @@ mod tests { #[test] fn test_validate_coinbase_BIP_34_sig_script() { let script = from_hex( - "03aa68060004c345815704451c591c0c60ef5b577b690000000000000a2020202020200a2f72657365727665642f" + "03aa68060004c345815704451c591c0c60ef5b577b690000000000000a2020202020200a2f72657365727665642f", ); validate_coinbase_sig_script(@script, 420_010).unwrap(); } @@ -503,7 +505,7 @@ mod tests { fn test_validate_coinbase_witness_with_more_than_one_element() { let witness = array![ from_hex("0000000000000000000000000000000000000000000000000000000000000000"), - from_hex("0000000000000000000000000000000000000000000000000000000000000000") + from_hex("0000000000000000000000000000000000000000000000000000000000000000"), ] .span(); validate_coinbase_witness(witness).unwrap_err(); @@ -512,7 +514,7 @@ mod tests { #[test] fn test_validate_coinbase_witness_with_wrong_witness() { let witness = array![ - from_hex("400d00000000e000000000000000000000000e00000000000000000000000000") + from_hex("400d00000000e000000000000000000000000e00000000000000000000000000"), ] .span(); validate_coinbase_witness(witness).unwrap_err(); @@ -521,7 +523,7 @@ mod tests { #[test] fn test_validate_coinbase_witness() { let witness = array![ - from_hex("0000000000000000000000000000000000000000000000000000000000000000") + from_hex("0000000000000000000000000000000000000000000000000000000000000000"), ] .span(); validate_coinbase_witness(witness).unwrap(); @@ -533,31 +535,25 @@ mod tests { TxOut { value: 625107042, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000", ), - cached: false + cached: false, }, TxOut { value: 0_u64, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000", ), - cached: false - } + cached: false, + }, ] .span(); let wtxid_commitment = Digest { value: [ - 0x10109f4b, - 0x82aa3ed7, - 0xec9d02a2, - 0xa9024647, - 0x8b3308c8, - 0xb85daf62, - 0xfe501d58, - 0xd05727a4 - ] + 0x10109f4b, 0x82aa3ed7, 0xec9d02a2, 0xa9024647, 0x8b3308c8, 0xb85daf62, 0xfe501d58, + 0xd05727a4, + ], }; validate_coinbase_outputs(outputs, wtxid_commitment).unwrap_err(); @@ -569,36 +565,36 @@ mod tests { TxOut { value: 625107042, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000", ), - cached: false + cached: false, }, TxOut { value: 0_u64, pk_script: @from_hex( - "6a24aa21a9ed6502e8637ba29cd8a820021915339c7341223d571e5e8d66edd83786d387e715" + "6a24aa21a9ed6502e8637ba29cd8a820021915339c7341223d571e5e8d66edd83786d387e715", ), - cached: false + cached: false, }, TxOut { value: 0_u64, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000", ), - cached: false + cached: false, }, TxOut { value: 0_u64, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000", ), - cached: false - } + cached: false, + }, ] .span(); let wtxid_commitment: Digest = hex_to_hash_rev( - "15e787d38637d8ed668d5e1e573d2241739c3315190220a8d89ca27b63e80265" + "15e787d38637d8ed668d5e1e573d2241739c3315190220a8d89ca27b63e80265", ); validate_coinbase_outputs(outputs, wtxid_commitment).unwrap(); @@ -607,15 +603,15 @@ mod tests { #[test] fn test_calculate_wtxid_commitment() { let witness_root_hash: Digest = hex_to_hash_rev( - "f2db1fa411685843d0b5ece37cacb7df882a64f13a68df1d2aaa8c8a869aeedb" + "f2db1fa411685843d0b5ece37cacb7df882a64f13a68df1d2aaa8c8a869aeedb", ); let expected_wtxid_commitment = from_hex( - "6502e8637ba29cd8a820021915339c7341223d571e5e8d66edd83786d387e715" + "6502e8637ba29cd8a820021915339c7341223d571e5e8d66edd83786d387e715", ); assert_eq!( - (calculate_wtxid_commitment(witness_root_hash)).into(), expected_wtxid_commitment + (calculate_wtxid_commitment(witness_root_hash)).into(), expected_wtxid_commitment, ); } @@ -627,7 +623,7 @@ mod tests { inputs: array![ TxIn { script: @from_hex( - "0320a107046f0a385a632f4254432e434f4d2ffabe6d6dbdd0ee86f9a1badfd0aa1b3c9dac8d90840cf973f7b2590d6c9adde1a6e0974a010000000000000001283da9a172020000000000" + "0320a107046f0a385a632f4254432e434f4d2ffabe6d6dbdd0ee86f9a1badfd0aa1b3c9dac8d90840cf973f7b2590d6c9adde1a6e0974a010000000000000001283da9a172020000000000", ), sequence: 4294967295, previous_output: OutPoint { @@ -639,51 +635,53 @@ mod tests { is_coinbase: false, }, witness: array![ - from_hex("0000000000000000000000000000000000000000000000000000000000000000") + from_hex( + "0000000000000000000000000000000000000000000000000000000000000000", + ), ] .span(), - } + }, ] .span(), outputs: array![ TxOut { value: 0_u64, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), cached: false, }, TxOut { value: 0_u64, pk_script: @from_hex( - "6a24aa21a9ed6502e8637ba29cd8a820021915339c7341223d571e5e8d66edd83786d387e715" + "6a24aa21a9ed6502e8637ba29cd8a820021915339c7341223d571e5e8d66edd83786d387e715", ), cached: false, }, TxOut { value: 0_u64, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), cached: false, }, TxOut { value: 0_u64, pk_script: @from_hex( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let total_fees = 0_u64; let block_height = 500_000; let wtxid_root_hash: Digest = hex_to_hash_rev( - "f2db1fa411685843d0b5ece37cacb7df882a64f13a68df1d2aaa8c8a869aeedb" + "f2db1fa411685843d0b5ece37cacb7df882a64f13a68df1d2aaa8c8a869aeedb", ); validate_coinbase(@tx, total_fees, block_height, wtxid_root_hash).unwrap(); diff --git a/packages/consensus/src/validation/difficulty.cairo b/packages/consensus/src/validation/difficulty.cairo index 85fe48e4..15f829c4 100644 --- a/packages/consensus/src/validation/difficulty.cairo +++ b/packages/consensus/src/validation/difficulty.cairo @@ -36,7 +36,7 @@ pub fn adjust_difficulty( epoch_start_time: u32, block_height: u32, prev_block_time: u32, - block_time: u32 + block_time: u32, ) -> (u256, u32) { if block_height % BLOCKS_PER_EPOCH == 0 { let mut time_span = prev_block_time - epoch_start_time; @@ -127,12 +127,12 @@ fn bits_to_target(bits: u32) -> Result { }, 15 => { return Result::Ok( - u256 { low: (mantissa.into() * 0x1000000000000000000000000), high: 0 } + u256 { low: (mantissa.into() * 0x1000000000000000000000000), high: 0 }, ); }, 16 => { return Result::Ok( - u256 { low: (mantissa.into() * 0x100000000000000000000000000), high: 0 } + u256 { low: (mantissa.into() * 0x100000000000000000000000000), high: 0 }, ); }, // Here we don't know @@ -185,11 +185,11 @@ mod tests { let block_height: u32 = 2016; let (new_target, new_epoch_start_time) = adjust_difficulty( - current_target, epoch_start_time, block_height, prev_block_time, block_time + current_target, epoch_start_time, block_height, prev_block_time, block_time, ); assert_eq!( - new_target, 0x00000000ffff0000000000000000000000000000000000000000000000000000_u256 + new_target, 0x00000000ffff0000000000000000000000000000000000000000000000000000_u256, ); assert_eq!(new_epoch_start_time, 1233063531); } @@ -207,11 +207,11 @@ mod tests { let block_height: u32 = 2017; let (new_target, new_epoch_start_time) = adjust_difficulty( - current_target, epoch_start_time, block_height, prev_block_time, block_time + current_target, epoch_start_time, block_height, prev_block_time, block_time, ); assert_eq!( - new_target, 0x00000000ffff0000000000000000000000000000000000000000000000000000_u256 + new_target, 0x00000000ffff0000000000000000000000000000000000000000000000000000_u256, ); assert_eq!(new_epoch_start_time, 1233063531); } @@ -229,11 +229,11 @@ mod tests { let block_height: u32 = 32256; let (new_target, new_epoch_start_time) = adjust_difficulty( - current_target, epoch_start_time, block_height, prev_block_time, block_time + current_target, epoch_start_time, block_height, prev_block_time, block_time, ); assert_eq!( - new_target, 0x00000000d86a0000000000000000000000000000000000000000000000000000_u256 + new_target, 0x00000000d86a0000000000000000000000000000000000000000000000000000_u256, ); assert_eq!(new_epoch_start_time, 1262153464); } @@ -251,11 +251,11 @@ mod tests { let block_height: u32 = 56448; let (new_target, new_epoch_start_time) = adjust_difficulty( - current_target, epoch_start_time, block_height, prev_block_time, block_time + current_target, epoch_start_time, block_height, prev_block_time, block_time, ); assert_eq!( - new_target, 0x00000000159c2400000000000000000000000000000000000000000000000000_u256 + new_target, 0x00000000159c2400000000000000000000000000000000000000000000000000_u256, ); assert_eq!(new_epoch_start_time, 1274278435); } @@ -287,7 +287,7 @@ mod tests { assert!(result.is_ok(), "Should be valid"); assert!( result.unwrap() == 0x1bc330000000000000000000000000000000000000000000_u256, - "Incorrect target for 0x181bc330" + "Incorrect target for 0x181bc330", ); } @@ -312,7 +312,7 @@ mod tests { assert!( result .unwrap() == 0x00000000ffff0000000000000000000000000000000000000000000000000000_u256, - "Incorrect target for 0x1d00ffff" + "Incorrect target for 0x1d00ffff", ); } @@ -323,7 +323,7 @@ mod tests { assert!( result .unwrap() == 0x000000000d314200000000000000000000000000000000000000000000000000_u256, - "Incorrect target for 0x1c0d3142" + "Incorrect target for 0x1c0d3142", ); } @@ -334,7 +334,7 @@ mod tests { assert!( result .unwrap() == 0x00000000000000000007a4290000000000000000000000000000000000000000_u256, - "Incorrect target for 0x1707a429" + "Incorrect target for 0x1707a429", ); } @@ -342,7 +342,7 @@ mod tests { fn test_bits_to_target_bounds() { // MSB is 0x80 assert_eq!( - bits_to_target(0x03800000).unwrap_err(), "Target cannot have most significant bit set" + bits_to_target(0x03800000).unwrap_err(), "Target cannot have most significant bit set", ); // Exponent is 33 assert_eq!(bits_to_target(0x2100aa00).unwrap_err(), "Target size cannot exceed 32 bytes"); @@ -362,21 +362,21 @@ mod tests { assert_eq!(reduce_target_precision(0x800001), 0x800000); assert_eq!( reduce_target_precision( - 0x00000000FFFF0000000000000000000000000000000000000000000000000000 + 0x00000000FFFF0000000000000000000000000000000000000000000000000000, ), - 0x00000000FFFF0000000000000000000000000000000000000000000000000000 + 0x00000000FFFF0000000000000000000000000000000000000000000000000000, ); assert_eq!( reduce_target_precision( - 0x00000000FFFF0100000000000000000000000000000000000000000000000000 + 0x00000000FFFF0100000000000000000000000000000000000000000000000000, ), - 0x00000000FFFF0000000000000000000000000000000000000000000000000000 + 0x00000000FFFF0000000000000000000000000000000000000000000000000000, ); assert_eq!( reduce_target_precision( - 0x00000001FFFF0100000000000000000000000000000000000000000000000000 + 0x00000001FFFF0100000000000000000000000000000000000000000000000000, ), - 0x00000001FFFF0000000000000000000000000000000000000000000000000000 + 0x00000001FFFF0000000000000000000000000000000000000000000000000000, ); } } diff --git a/packages/consensus/src/validation/locktime.cairo b/packages/consensus/src/validation/locktime.cairo index eb2fecfa..e1f59152 100644 --- a/packages/consensus/src/validation/locktime.cairo +++ b/packages/consensus/src/validation/locktime.cairo @@ -29,7 +29,7 @@ pub fn is_input_final(sequence: u32) -> bool { /// /// https://learnmeabitcoin.com/technical/transaction/locktime/ pub fn validate_absolute_locktime( - lock_time: u32, block_height: u32, block_time: u32 + lock_time: u32, block_height: u32, block_time: u32, ) -> Result<(), ByteArray> { if lock_time < LOCKTIME_THRESHOLD { if lock_time < block_height { @@ -39,8 +39,8 @@ pub fn validate_absolute_locktime( format!( "Transaction locktime {} is not lesser than current block height {}", lock_time, - block_height - ) + block_height, + ), ); } } else if lock_time < block_time { @@ -50,8 +50,8 @@ pub fn validate_absolute_locktime( format!( "Transaction locktime {} is not lesser than current block time {}", lock_time, - block_time - ) + block_time, + ), ); } } @@ -61,7 +61,7 @@ pub fn validate_absolute_locktime( /// If relative locktime is enabled, ensure the input's locktime is respected. /// https://learnmeabitcoin.com/technical/transaction/input/sequence/ pub fn validate_relative_locktime( - input: @TxIn, block_height: u32, median_time_past: u32 + input: @TxIn, block_height: u32, median_time_past: u32, ) -> Result<(), ByteArray> { let sequence = *input.sequence; if sequence & SEQUENCE_LOCKTIME_DISABLE_FLAG != 0 { @@ -85,8 +85,8 @@ pub fn validate_relative_locktime( "Relative time-based lock time is not respected: current MTP: {}, outpoint MTP: {}, lock time: {} seconds", median_time_past, *input.previous_output.median_time_past, - lock_time - ) + lock_time, + ), ); } } else { @@ -97,8 +97,8 @@ pub fn validate_relative_locktime( "Relative block-based lock time is not respected: current height: {}, outpoint height: {}, lock time: {} blocks", block_height, *input.previous_output.block_height, - value - ) + value, + ), ); } } @@ -119,7 +119,7 @@ mod tests { sequence: 0xffffffff, // Final, relative locktime disabled previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -142,7 +142,7 @@ mod tests { sequence: 144, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 188442, ..Default::default() }, @@ -165,7 +165,7 @@ mod tests { sequence: 4194311, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 13671, ..Default::default() }, @@ -185,7 +185,7 @@ mod tests { sequence: 144, // Lower sequence number with locktime enabled (block-based locktime) previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 188442, ..Default::default() }, @@ -213,7 +213,7 @@ mod tests { sequence: 4194311, // Time-based relative locktime (0x400007 = SEQUENCE_LOCKTIME_TYPE_FLAG + value) previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 13671, ..Default::default() }, @@ -240,7 +240,7 @@ mod tests { sequence: 144, // Relative locktime enabled (no SEQUENCE_LOCKTIME_DISABLE_FLAG) previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, diff --git a/packages/consensus/src/validation/script.cairo b/packages/consensus/src/validation/script.cairo index e8df49ed..f0ad3000 100644 --- a/packages/consensus/src/validation/script.cairo +++ b/packages/consensus/src/validation/script.cairo @@ -7,7 +7,7 @@ use shinigami_engine::engine::EngineImpl; use shinigami_engine::hash_cache::HashCacheImpl; use shinigami_engine::flags::ScriptFlags; use shinigami_engine::transaction::{ - EngineTransactionInputTrait, EngineTransactionOutputTrait, EngineTransactionTrait + EngineTransactionInputTrait, EngineTransactionOutputTrait, EngineTransactionTrait, }; const BIP_16_BLOCK_HEIGHT: u32 = 173805; // Pay-to-Script-Hash (P2SH) @@ -66,7 +66,7 @@ impl EngineTransactionOutputDummyImpl of EngineTransactionOutputTrait { } } -impl EngineTransactionDummyImpl of EngineTransactionTrait { +impl EngineTransactionDummyImpl of EngineTransactionTrait { /// Returns the version of the given transaction. fn get_version(self: @Transaction) -> i32 { Into::::into(*self.version).try_into().unwrap() @@ -150,40 +150,38 @@ fn parse_short_string(short: felt252) -> ByteArray { fn validate_script(header: @Header, tx: @Transaction, tx_idx: u32) -> Result<(), ByteArray> { let cache = HashCacheImpl::new(tx); let mut result: Option = Option::None; - for input_idx in 0 - ..(*tx.inputs) - .len() { - let previous_output = *tx.inputs[input_idx].previous_output; - let mut engine = EngineImpl::new( - previous_output.data.pk_script, - tx, - input_idx, - script_flags(header, tx), - Into::::into(previous_output.data.value).try_into().unwrap(), - @cache - ) - .unwrap(); //TODO: handle error - - match engine.execute() { - Result::Ok(_) => { break; }, // TODO: verify this is correct - Result::Err(err) => { - result = - Option::Some( - format!( - "Script validation failed on tx_idx: {}, input_idx: {}: {}", - tx_idx, - input_idx, - parse_short_string(err) - ) - ); - break; - } - } - }; + for input_idx in 0..(*tx.inputs).len() { + let previous_output = *tx.inputs[input_idx].previous_output; + let mut engine = EngineImpl::new( + previous_output.data.pk_script, + tx, + input_idx, + script_flags(header, tx), + Into::::into(previous_output.data.value).try_into().unwrap(), + @cache, + ) + .unwrap(); //TODO: handle error + + match engine.execute() { + Result::Ok(_) => { break; }, // TODO: verify this is correct + Result::Err(err) => { + result = + Option::Some( + format!( + "Script validation failed on tx_idx: {}, input_idx: {}: {}", + tx_idx, + input_idx, + parse_short_string(err), + ), + ); + break; + }, + } + }; match result { Option::Some(err) => Result::Err(err), - Option::None => Result::Ok(()) + Option::None => Result::Ok(()), } } diff --git a/packages/consensus/src/validation/timestamp.cairo b/packages/consensus/src/validation/timestamp.cairo index 4657d57f..1d813725 100644 --- a/packages/consensus/src/validation/timestamp.cairo +++ b/packages/consensus/src/validation/timestamp.cairo @@ -46,7 +46,7 @@ pub fn validate_timestamp(median_time_past: u32, block_time: u32) -> Result<(), Result::Ok(()) } else { Result::Err( - format!("Median time past: {} >= block's timestamp: {}", median_time_past, block_time) + format!("Median time past: {} >= block's timestamp: {}", median_time_past, block_time), ) } } diff --git a/packages/consensus/src/validation/transaction.cairo b/packages/consensus/src/validation/transaction.cairo index b9528aed..63f9127b 100644 --- a/packages/consensus/src/validation/transaction.cairo +++ b/packages/consensus/src/validation/transaction.cairo @@ -3,7 +3,7 @@ use crate::types::transaction::{OutPoint, Transaction}; use crate::types::utxo_set::{UtxoSet, UtxoSetTrait}; use crate::validation::locktime::{ - is_input_final, validate_absolute_locktime, validate_relative_locktime + is_input_final, validate_absolute_locktime, validate_relative_locktime, }; use utils::hash::Digest; @@ -19,7 +19,7 @@ pub fn validate_transaction( block_time: u32, median_time_past: u32, txid: Digest, - ref utxo_set: UtxoSet + ref utxo_set: UtxoSet, ) -> Result { if (*tx.inputs).is_empty() { return Result::Err("transaction inputs are empty"); @@ -37,32 +37,31 @@ pub fn validate_transaction( // TODO: BIP68 enabled for tx with version >= 2 (is it critical?) - for input in *tx - .inputs { - // Ensure that the output is not yet spent and spends it - inner_result = utxo_set.spend(input.previous_output); + for input in *tx.inputs { + // Ensure that the output is not yet spent and spends it + inner_result = utxo_set.spend(input.previous_output); + if inner_result.is_err() { + break; + } + + if *input.previous_output.is_coinbase { + inner_result = + validate_coinbase_maturity(*input.previous_output.block_height, block_height); if inner_result.is_err() { break; } + } - if *input.previous_output.is_coinbase { - inner_result = - validate_coinbase_maturity(*input.previous_output.block_height, block_height); - if inner_result.is_err() { - break; - } - } - - if *tx.version >= 2 && !is_input_final(*input.sequence) { - inner_result = validate_relative_locktime(input, block_height, median_time_past); - if inner_result.is_err() { - break; - } - is_tx_final = false; + if *tx.version >= 2 && !is_input_final(*input.sequence) { + inner_result = validate_relative_locktime(input, block_height, median_time_past); + if inner_result.is_err() { + break; } + is_tx_final = false; + } - total_input_amount += *input.previous_output.data.value; - }; + total_input_amount += *input.previous_output.data.value; + }; if inner_result.is_err() { return Result::Err(inner_result.unwrap_err()); @@ -77,34 +76,33 @@ pub fn validate_transaction( let mut total_output_amount = 0; let mut vout = 0; - for output in *tx - .outputs { - // Add outpoint to the cache if the corresponding transaction output will be used - // as a transaction input in the same block(s), or add it to the utreexo otherwise - let outpoint = OutPoint { - txid, vout, data: *output, block_height, median_time_past, is_coinbase: false, - }; - - inner_result = utxo_set.add(outpoint); - if inner_result.is_err() { - break; - } - - total_output_amount += *output.value; - vout += 1; + for output in *tx.outputs { + // Add outpoint to the cache if the corresponding transaction output will be used + // as a transaction input in the same block(s), or add it to the utreexo otherwise + let outpoint = OutPoint { + txid, vout, data: *output, block_height, median_time_past, is_coinbase: false, }; + inner_result = utxo_set.add(outpoint); + if inner_result.is_err() { + break; + } + + total_output_amount += *output.value; + vout += 1; + }; + inner_result?; compute_transaction_fee(total_input_amount, total_output_amount) } /// Computes the transaction fee and ensures transaction fee is not negative. fn compute_transaction_fee( - total_input_amount: u64, total_output_amount: u64 + total_input_amount: u64, total_output_amount: u64, ) -> Result { if total_output_amount > total_input_amount { return Result::Err( - format!("Negative fee (output {total_output_amount} > input {total_input_amount})") + format!("Negative fee (output {total_output_amount} > input {total_input_amount})"), ); } @@ -119,7 +117,7 @@ fn validate_coinbase_maturity(output_height: u32, block_height: u32) -> Result<( "Output is not mature (output height: {}, current block height: {})", output_height, block_height, - ) + ), ); } else { return Result::Ok(()); @@ -152,12 +150,12 @@ mod tests { inputs: array![ TxIn { script: @from_hex( - "01091d8d76a82122082246acbb6cc51c839d9012ddaca46048de07ca8eec221518200241cdb85fab4815c6c624d6e932774f3fdf5fa2a1d3a1614951afb83269e1454e2002443047" + "01091d8d76a82122082246acbb6cc51c839d9012ddaca46048de07ca8eec221518200241cdb85fab4815c6c624d6e932774f3fdf5fa2a1d3a1614951afb83269e1454e2002443047", ), sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9" + "0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9", ), vout: 0x00000000, data: TxOut { value: 100, ..Default::default() }, @@ -166,20 +164,20 @@ mod tests { is_coinbase: true, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ TxOut { value: 90, pk_script: @from_hex( - "ac4cd86c7e4f702ac7d5debaf126068a3b30b7c1212c145fdfa754f59773b3aae71484a22f30718d37cd74f325229b15f7a2996bf0075f90131bf5c509fe621aae0441" + "ac4cd86c7e4f702ac7d5debaf126068a3b30b7c1212c145fdfa754f59773b3aae71484a22f30718d37cd74f325229b15f7a2996bf0075f90131bf5c509fe621aae0441", ), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -205,10 +203,10 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -230,7 +228,7 @@ mod tests { sequence: 0xffffffff, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -239,11 +237,11 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![].span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -265,7 +263,7 @@ mod tests { sequence: 0xfffffffe, // Absolute locktime previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -274,7 +272,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -282,7 +280,7 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), lock_time: 500000 // Block height locktime @@ -296,7 +294,7 @@ mod tests { let result = validate_transaction(@tx, 500000, 0, 0, txid, ref utxo_set); assert_eq!( result.unwrap_err().into(), - "Transaction locktime 500000 is not lesser than current block height 500000" + "Transaction locktime 500000 is not lesser than current block height 500000", ); utxo_set = Default::default(); @@ -318,7 +316,7 @@ mod tests { sequence: 0xfffffffe, // Not final previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -327,7 +325,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -335,7 +333,7 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), lock_time: 1600000000 // UNIX timestamp locktime @@ -349,7 +347,7 @@ mod tests { let result = validate_transaction(@tx, 0, 1600000000, 1600000000, txid, ref utxo_set); assert_eq!( result.unwrap_err().into(), - "Transaction locktime 1600000000 is not lesser than current block time 1600000000" + "Transaction locktime 1600000000 is not lesser than current block time 1600000000", ); utxo_set = Default::default(); @@ -370,7 +368,7 @@ mod tests { sequence: 0xffffffff, // Final previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -379,7 +377,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -387,7 +385,7 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), lock_time: 1600000000 // UNIX timestamp locktime @@ -419,7 +417,7 @@ mod tests { sequence: 0xffffffff, // Final previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -428,7 +426,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -436,7 +434,7 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), lock_time: 500000 // Block height locktime @@ -470,7 +468,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -479,7 +477,7 @@ mod tests { is_coinbase: true, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -487,10 +485,10 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -513,7 +511,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, ..Default::default() }, @@ -522,7 +520,7 @@ mod tests { is_coinbase: true, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -530,10 +528,10 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -557,7 +555,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: true }, @@ -566,7 +564,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -574,10 +572,10 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -601,7 +599,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: false }, @@ -610,7 +608,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -618,10 +616,10 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -648,7 +646,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: true }, @@ -657,7 +655,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -665,10 +663,10 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), - lock_time: 0 + lock_time: 0, }; let tx_words = tx.encode(); @@ -695,7 +693,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: false }, @@ -704,7 +702,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -712,7 +710,7 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: true, - } + }, ] .span(), lock_time: 0, @@ -751,7 +749,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: true }, @@ -766,7 +764,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: true }, @@ -775,7 +773,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -783,7 +781,7 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), lock_time: 0, @@ -814,7 +812,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: false }, @@ -829,7 +827,7 @@ mod tests { sequence: 0xfffffffe, previous_output: OutPoint { txid: hex_to_hash_rev( - "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000", ), vout: 0, data: TxOut { value: 100, pk_script: @from_hex(""), cached: false }, @@ -838,7 +836,7 @@ mod tests { is_coinbase: false, }, witness: array![].span(), - } + }, ] .span(), outputs: array![ @@ -846,7 +844,7 @@ mod tests { value: 50, pk_script: @from_hex("76a914000000000000000000000000000000000000000088ac"), cached: false, - } + }, ] .span(), lock_time: 0, diff --git a/packages/consensus/src/validation/work.cairo b/packages/consensus/src/validation/work.cairo index 0d2c32ba..2854b95a 100644 --- a/packages/consensus/src/validation/work.cairo +++ b/packages/consensus/src/validation/work.cairo @@ -11,8 +11,8 @@ pub fn validate_proof_of_work(target: u256, block_hash: Digest) -> Result<(), By format!( "Insufficient proof of work. Expected block hash {:?} to be less than or equal to {}", block_hash, - target - ) + target, + ), ) } } @@ -56,7 +56,7 @@ mod tests { // Block prev block hash is less than target let result = validate_proof_of_work( 0x00000000ffff0000000000000000000000000000000000000000000000000000_u256, - 0x000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55_u256.into() + 0x000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55_u256.into(), ); assert!(result.is_ok(), "Expect prev block hash lt target"); } diff --git a/packages/utils/src/bit_shifts.cairo b/packages/utils/src/bit_shifts.cairo index 5d801947..e6e5d9b3 100644 --- a/packages/utils/src/bit_shifts.cairo +++ b/packages/utils/src/bit_shifts.cairo @@ -39,7 +39,7 @@ pub fn fast_pow< +Drop, +PartialEq, >( - base: T, exp: U + base: T, exp: U, ) -> T { if exp == Zero::zero() { return One::one(); @@ -76,69 +76,15 @@ pub fn fast_pow< /// * If `exponent` is greater than 63 (out of the supported range) pub fn pow2(exponent: u32) -> u64 { let hardcoded_results: [u64; 64] = [ - 0x1, - 0x2, - 0x4, - 0x8, - 0x10, - 0x20, - 0x40, - 0x80, - 0x100, - 0x200, - 0x400, - 0x800, - 0x1000, - 0x2000, - 0x4000, - 0x8000, - 0x10000, - 0x20000, - 0x40000, - 0x80000, - 0x100000, - 0x200000, - 0x400000, - 0x800000, - 0x1000000, - 0x2000000, - 0x4000000, - 0x8000000, - 0x10000000, - 0x20000000, - 0x40000000, - 0x80000000, - 0x100000000, - 0x200000000, - 0x400000000, - 0x800000000, - 0x1000000000, - 0x2000000000, - 0x4000000000, - 0x8000000000, - 0x10000000000, - 0x20000000000, - 0x40000000000, - 0x80000000000, - 0x100000000000, - 0x200000000000, - 0x400000000000, - 0x800000000000, - 0x1000000000000, - 0x2000000000000, - 0x4000000000000, - 0x8000000000000, - 0x10000000000000, - 0x20000000000000, - 0x40000000000000, - 0x80000000000000, - 0x100000000000000, - 0x200000000000000, - 0x400000000000000, - 0x800000000000000, - 0x1000000000000000, - 0x2000000000000000, - 0x4000000000000000, + 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, + 0x4000, 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, 0x800000, + 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x100000000, 0x200000000, 0x400000000, 0x800000000, 0x1000000000, 0x2000000000, + 0x4000000000, 0x8000000000, 0x10000000000, 0x20000000000, 0x40000000000, 0x80000000000, + 0x100000000000, 0x200000000000, 0x400000000000, 0x800000000000, 0x1000000000000, + 0x2000000000000, 0x4000000000000, 0x8000000000000, 0x10000000000000, 0x20000000000000, + 0x40000000000000, 0x80000000000000, 0x100000000000000, 0x200000000000000, 0x400000000000000, + 0x800000000000000, 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000, ]; *hardcoded_results.span()[exponent] diff --git a/packages/utils/src/double_sha256.cairo b/packages/utils/src/double_sha256.cairo index 309e13b1..2c110c86 100644 --- a/packages/utils/src/double_sha256.cairo +++ b/packages/utils/src/double_sha256.cairo @@ -37,16 +37,16 @@ mod tests { // hashlib.sha256(sha256(b"bitcoin").digest()).hexdigest() assert_eq!( double_sha256_word_array(words_from_hex("626974636f696e")).into(), - from_hex("f1ef1bf105d788352c052453b15a913403be59b90ddf9f7c1f937edee8938dc5") + from_hex("f1ef1bf105d788352c052453b15a913403be59b90ddf9f7c1f937edee8938dc5"), ); // hashlib.sha256(sha256(bytes.fromhex("00000001000000020000000300000004000000050000000600000007")).digest()).hexdigest() assert_eq!( double_sha256_word_array( - words_from_hex("00000001000000020000000300000004000000050000000600000007") + words_from_hex("00000001000000020000000300000004000000050000000600000007"), ) .into(), - from_hex("489b8eeb4024cb77ab057616ebf7f8d4405aa0bd3ad5f42e6b4c20580e011ac4") + from_hex("489b8eeb4024cb77ab057616ebf7f8d4405aa0bd3ad5f42e6b4c20580e011ac4"), ); } @@ -56,7 +56,7 @@ mod tests { // 8)).digest()).hexdigest() assert_eq!( double_sha256_parent(@Digest { value: [1; 8] }, @Digest { value: [2; 8] }).into(), - from_hex("14a6e4a4caef969126944266724d11866b39b3390cee070b0aa4c9390cd77f47") + from_hex("14a6e4a4caef969126944266724d11866b39b3390cee070b0aa4c9390cd77f47"), ) } } diff --git a/packages/utils/src/hash.cairo b/packages/utils/src/hash.cairo index d38c7e19..a7e52c40 100644 --- a/packages/utils/src/hash.cairo +++ b/packages/utils/src/hash.cairo @@ -10,7 +10,7 @@ use core::to_byte_array::AppendFormattedToByteArray; /// Represented as an array of 4-byte words. #[derive(Copy, Drop, Debug, Default, Serde)] pub struct Digest { - pub value: [u32; 8] + pub value: [u32; 8], } #[generate_trait] @@ -88,15 +88,11 @@ pub impl U256IntoDigest of Into { Digest { value: [ - high_128_96.try_into().unwrap(), - high_96_64.try_into().unwrap(), - high_64_32.try_into().unwrap(), - high_32_0.try_into().unwrap(), - low_128_96.try_into().unwrap(), - low_96_64.try_into().unwrap(), - low_64_32.try_into().unwrap(), - low_32_0.try_into().unwrap(), - ] + high_128_96.try_into().unwrap(), high_96_64.try_into().unwrap(), + high_64_32.try_into().unwrap(), high_32_0.try_into().unwrap(), + low_128_96.try_into().unwrap(), low_96_64.try_into().unwrap(), + low_64_32.try_into().unwrap(), low_32_0.try_into().unwrap(), + ], } } } @@ -141,14 +137,8 @@ mod tests { let expected_hash = Digest { value: [ - 0xefcdab90, - 0x78563412, - 0xefcdab90, - 0x78563412, - 0x21436587, + 0xefcdab90, 0x78563412, 0xefcdab90, 0x78563412, 0x21436587, 0x09badcfe, 0x21436587, 0x09badcfe, - 0x21436587, - 0x09badcfe ], }; @@ -159,13 +149,7 @@ mod tests { fn test_hash_to_u256() { let hash_value = Digest { value: [ - 0xfedcba09, - 0x87654321, - 0xfedcba09, - 0x87654321, - 0x12345678, - 0x90abcdef, - 0x12345678, + 0xfedcba09, 0x87654321, 0xfedcba09, 0x87654321, 0x12345678, 0x90abcdef, 0x12345678, 0x90abcdef, ], }; @@ -184,13 +168,7 @@ mod tests { fn test_hash_to_u256_to_hash() { let hash_value = Digest { value: [ - 0xfedcba09, - 0x87654321, - 0xfedcba09, - 0x87654321, - 0x12345678, - 0x90abcdef, - 0x12345678, + 0xfedcba09, 0x87654321, 0xfedcba09, 0x87654321, 0x12345678, 0x90abcdef, 0x12345678, 0x90abcdef, ], }; @@ -218,21 +196,15 @@ mod tests { fn test_hash_into_bytearray() { let hash = Digest { value: [ - 0x12345678_u32, - 0x9abcdef0_u32, - 0x11223344_u32, - 0x55667788_u32, - 0xaabbccdd_u32, - 0xeeff0011_u32, - 0x22334455_u32, - 0x66778899_u32 - ] + 0x12345678_u32, 0x9abcdef0_u32, 0x11223344_u32, 0x55667788_u32, 0xaabbccdd_u32, + 0xeeff0011_u32, 0x22334455_u32, 0x66778899_u32, + ], }; let byte_array: ByteArray = hash.into(); let expected_byte_array = from_hex( - "123456789abcdef01122334455667788aabbccddeeff00112233445566778899" + "123456789abcdef01122334455667788aabbccddeeff00112233445566778899", ); assert_eq!(byte_array, expected_byte_array, "invalid results"); diff --git a/packages/utils/src/hex.cairo b/packages/utils/src/hex.cairo index 5b7ad3fd..a2ccc321 100644 --- a/packages/utils/src/hex.cairo +++ b/packages/utils/src/hex.cairo @@ -57,15 +57,9 @@ pub fn hex_to_hash_rev(hex_string: ByteArray) -> Digest { Digest { value: [ - *result[0], - *result[1], - *result[2], - *result[3], - *result[4], - *result[5], - *result[6], + *result[0], *result[1], *result[2], *result[3], *result[4], *result[5], *result[6], *result[7], - ] + ], } } @@ -105,15 +99,9 @@ mod tests { fn test_hex_to_hash_rev() { let hash: Digest = Digest { value: [ - 0x12345678_u32, - 0x9abcdef0_u32, - 0x11223344_u32, - 0x55667788_u32, - 0xaabbccdd_u32, - 0xeeff0011_u32, - 0x22334455_u32, - 0x66778899_u32 - ] + 0x12345678_u32, 0x9abcdef0_u32, 0x11223344_u32, 0x55667788_u32, 0xaabbccdd_u32, + 0xeeff0011_u32, 0x22334455_u32, 0x66778899_u32, + ], }; let hex = "99887766554433221100ffeeddccbbaa8877665544332211f0debc9a78563412"; assert_eq!(hash, hex_to_hash_rev(hex)); diff --git a/packages/utils/src/merkle_tree.cairo b/packages/utils/src/merkle_tree.cairo index 4d4e84a8..11b95a9a 100644 --- a/packages/utils/src/merkle_tree.cairo +++ b/packages/utils/src/merkle_tree.cairo @@ -43,7 +43,7 @@ mod tests { ]; let expected_merkle_root: Digest = hex_to_hash_rev( - "acd9825be8bece7782ec746a80b52f44d6a8af41c63dbab59b03e29558469682" + "acd9825be8bece7782ec746a80b52f44d6a8af41c63dbab59b03e29558469682", ); assert_eq!(merkle_root(txids.span()), expected_merkle_root); } @@ -57,7 +57,7 @@ mod tests { ]; let expected_merkle_root: Digest = hex_to_hash_rev( - "7dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff" + "7dac2c5666815c17a3b36427de37bb9d2e2c5ccec3f8633eb91a4205cb4c10ff", ); assert_eq!(merkle_root(txids.span()), expected_merkle_root); } @@ -71,7 +71,7 @@ mod tests { ]; let expected_merkle_root: Digest = hex_to_hash_rev( - "035dff4bfc62ff255ddac842dd31be4d28756b3625b0c4fecade7011f8dada20" + "035dff4bfc62ff255ddac842dd31be4d28756b3625b0c4fecade7011f8dada20", ); assert_eq!(merkle_root(txids.span()), expected_merkle_root); } @@ -82,11 +82,11 @@ mod tests { let mut txids: Array = array![ hex_to_hash_rev("5aa99d53575d34a8fe9324820606d90563ab37f246182911314df1e2570d6c80"), hex_to_hash_rev("9367940d1975aa9cc83f8118448ad94b6081e12ed0f7c968e375b2a283e78910"), - hex_to_hash_rev("b5f969b3d098c6ac87bb976eb0983259edb294892872d0aba0d47e66e1a5236f") + hex_to_hash_rev("b5f969b3d098c6ac87bb976eb0983259edb294892872d0aba0d47e66e1a5236f"), ]; let expected_merkle_root: Digest = hex_to_hash_rev( - "222ae86adb1f65c0458f53f4c4c5d70966e12f122ef00bfdf2eac04022865013" + "222ae86adb1f65c0458f53f4c4c5d70966e12f122ef00bfdf2eac04022865013", ); assert_eq!(merkle_root(txids.span()), expected_merkle_root); } @@ -98,11 +98,11 @@ mod tests { hex_to_hash_rev("32a46e3fcdb462c16de20e3fe88f988ff9174b7b68faa630040f938566f114e9"), hex_to_hash_rev("6af9fc350b15715a0b1892110523fb8d6b43b004b23d201670acf398371ed27d"), hex_to_hash_rev("4bcf8ebc578c4d577a1da75bca8e0fe3e884466b51391b34237d94bb4925d065"), - hex_to_hash_rev("93298aadb447909639ed4ae0aa608a6b7bb907991064bc6582839710555f453d") + hex_to_hash_rev("93298aadb447909639ed4ae0aa608a6b7bb907991064bc6582839710555f453d"), ]; let expected_merkle_root = hex_to_hash_rev( - "968bd407fe881936f5140e3794c85962db7e8614c1bb9894bb78b59e56be4555" + "968bd407fe881936f5140e3794c85962db7e8614c1bb9894bb78b59e56be4555", ); assert_eq!(merkle_root(txids.span()), expected_merkle_root); } @@ -132,7 +132,7 @@ mod tests { ]; let expected_merkle_root: Digest = hex_to_hash_rev( - "af77d9974359ae0699e62990b300d1e4663d03996176528bfa92aa24a65a45e1" + "af77d9974359ae0699e62990b300d1e4663d03996176528bfa92aa24a65a45e1", ); assert_eq!(merkle_root(txids.span()), expected_merkle_root); } @@ -178,7 +178,7 @@ mod tests { ]; let expected_merkle_root: Digest = hex_to_hash_rev( - "c78e335cb8908ecda32ff5dd44e9985099572692761f7809a400f60ec58d452c" + "c78e335cb8908ecda32ff5dd44e9985099572692761f7809a400f60ec58d452c", ); assert_eq!(merkle_root(txids.span()), expected_merkle_root); } diff --git a/packages/utils/src/sha256.cairo b/packages/utils/src/sha256.cairo index eecaef43..15481136 100644 --- a/packages/utils/src/sha256.cairo +++ b/packages/utils/src/sha256.cairo @@ -35,10 +35,8 @@ pub fn compute_sha256_byte_array(arr: @ByteArray) -> [u32; 8] { /// Cairo implementation of the corelib `compute_sha256_u32_array` function. pub fn compute_sha256_u32_array( - mut input: Array, last_input_word: u32, last_input_num_bytes: u32 - ) -> [ - u32 -; 8] { + mut input: Array, last_input_word: u32, last_input_num_bytes: u32, +) -> [u32; 8] { add_sha256_padding(ref input, last_input_word, last_input_num_bytes); let result = sha256_inner(input.span(), 0, k.span(), h.span()); @@ -267,79 +265,19 @@ fn ssig1(x: u32) -> u32 { result.try_into().unwrap() } -const h: [ - u32 - ; 8] = [ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 +const h: [u32; 8] = [ + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, ]; -const k: [ - u32 - ; 64] = [ - 0x428a2f98, - 0x71374491, - 0xb5c0fbcf, - 0xe9b5dba5, - 0x3956c25b, - 0x59f111f1, - 0x923f82a4, - 0xab1c5ed5, - 0xd807aa98, - 0x12835b01, - 0x243185be, - 0x550c7dc3, - 0x72be5d74, - 0x80deb1fe, - 0x9bdc06a7, - 0xc19bf174, - 0xe49b69c1, - 0xefbe4786, - 0x0fc19dc6, - 0x240ca1cc, - 0x2de92c6f, - 0x4a7484aa, - 0x5cb0a9dc, - 0x76f988da, - 0x983e5152, - 0xa831c66d, - 0xb00327c8, - 0xbf597fc7, - 0xc6e00bf3, - 0xd5a79147, - 0x06ca6351, - 0x14292967, - 0x27b70a85, - 0x2e1b2138, - 0x4d2c6dfc, - 0x53380d13, - 0x650a7354, - 0x766a0abb, - 0x81c2c92e, - 0x92722c85, - 0xa2bfe8a1, - 0xa81a664b, - 0xc24b8b70, - 0xc76c51a3, - 0xd192e819, - 0xd6990624, - 0xf40e3585, - 0x106aa070, - 0x19a4c116, - 0x1e376c08, - 0x2748774c, - 0x34b0bcb5, - 0x391c0cb3, - 0x4ed8aa4a, - 0x5b9cca4f, - 0x682e6ff3, - 0x748f82ee, - 0x78a5636f, - 0x84c87814, - 0x8cc70208, - 0x90befffa, - 0xa4506ceb, - 0xbef9a3f7, - 0xc67178f2 +const k: [u32; 64] = [ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, ]; #[cfg(test)] @@ -354,14 +292,14 @@ mod tests { let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"), - digest.into() + digest.into(), ); let input: ByteArray = "abc"; let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"), - digest.into() + digest.into(), ); // Following tests have been inspired by the following test suite: @@ -370,7 +308,7 @@ mod tests { let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"), - digest.into() + digest.into(), ); let input: ByteArray = @@ -378,21 +316,21 @@ mod tests { let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1"), - digest.into() + digest.into(), ); let input: ByteArray = "This is exactly 64 bytes long, not counting the terminating byte"; let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8"), - digest.into() + digest.into(), ); let input: ByteArray = "For this sample, this 63-byte string will be used as input data"; let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342"), - digest.into() + digest.into(), ); let input: ByteArray = @@ -400,7 +338,7 @@ mod tests { let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("0ab803344830f92089494fb635ad00d76164ad6e57012b237722df0d7ad26896"), - digest.into() + digest.into(), ); let input: ByteArray = @@ -408,14 +346,14 @@ mod tests { let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("e4326d0459653d7d3514674d713e74dc3df11ed4d30b4013fd327fdb9e394c26"), - digest.into() + digest.into(), ); let input: ByteArray = "The quick brown fox jumps over the lazy dog"; let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"), - digest.into() + digest.into(), ); let input: ByteArray = @@ -423,7 +361,7 @@ mod tests { let digest = DigestTrait::new(compute_sha256_byte_array(@input)); assert_eq!( from_hex("2ce675bd3b70e104d696d1b25bf3d42b2b45cd776d4f590f210f12c44bf473d5"), - digest.into() + digest.into(), ); } } diff --git a/packages/utils/src/sort.cairo b/packages/utils/src/sort.cairo index 1f0a2f06..3f89199c 100644 --- a/packages/utils/src/sort.cairo +++ b/packages/utils/src/sort.cairo @@ -37,7 +37,7 @@ fn merge_recursive, +Drop, +PartialOrd>( mut right_arr: Array, ref result_arr: Array, left_arr_ix: usize, - right_arr_ix: usize + right_arr_ix: usize, ) { if result_arr.len() == left_arr.len() + right_arr.len() { return; diff --git a/packages/utils/src/word_array.cairo b/packages/utils/src/word_array.cairo index 1112879a..033a3191 100644 --- a/packages/utils/src/word_array.cairo +++ b/packages/utils/src/word_array.cairo @@ -79,7 +79,7 @@ pub impl WordArrayImpl of WordArrayTrait { fn append_word(ref self: WordArray, word: u32, num_bytes: u32) { assert!(num_bytes <= 4, "Out of bounds `num_bytes`: {}", num_bytes); let (num_full_words, last_input_num_bytes) = DivRem::div_rem( - self.last_input_num_bytes + num_bytes, 4 + self.last_input_num_bytes + num_bytes, 4, ); if num_full_words == 1 { @@ -190,7 +190,7 @@ pub impl WordArrayImpl of WordArrayTrait { WordSpan { input: self.input.span(), last_input_word: *self.last_input_word, - last_input_num_bytes: *self.last_input_num_bytes + last_input_num_bytes: *self.last_input_num_bytes, } } @@ -240,21 +240,20 @@ pub mod hex { let mut result: ByteArray = Default::default(); while let Option::Some((word, num_bytes)) = words.pop_front() { - for i in 0 - ..num_bytes { - let div: NonZero = match (num_bytes - 1 - i) { - 0 => 1, - 1 => 0x100, - 2 => 0x10000, - 3 => 0x1000000, - _ => panic!("num_bytes out of bounds"), - }; - let (value, _) = DivRem::div_rem(word, div); - let (_, value) = DivRem::div_rem(value, 0x100); - let (l, r) = DivRem::div_rem(value, 16); - result.append_byte(alphabet.at(l).expect('l')); - result.append_byte(alphabet.at(r).expect('r')); - } + for i in 0..num_bytes { + let div: NonZero = match (num_bytes - 1 - i) { + 0 => 1, + 1 => 0x100, + 2 => 0x10000, + 3 => 0x1000000, + _ => panic!("num_bytes out of bounds"), + }; + let (value, _) = DivRem::div_rem(word, div); + let (_, value) = DivRem::div_rem(value, 0x100); + let (l, r) = DivRem::div_rem(value, 16); + result.append_byte(alphabet.at(l).expect('l')); + result.append_byte(alphabet.at(r).expect('r')); + } }; result diff --git a/packages/utreexo/src/stump/accumulator.cairo b/packages/utreexo/src/stump/accumulator.cairo index 46cd219f..0b75f038 100644 --- a/packages/utreexo/src/stump/accumulator.cairo +++ b/packages/utreexo/src/stump/accumulator.cairo @@ -42,12 +42,12 @@ pub impl StumpUtreexoAccumulatorImpl of StumpUtreexoAccumulator { leaves += 1; }; - UtreexoStumpState { roots: new_roots.span(), num_leaves: leaves, } + UtreexoStumpState { roots: new_roots.span(), num_leaves: leaves } } /// Verifies that specified leaves are part of the utreexo forest given a proof. fn verify( - self: @UtreexoStumpState, proof: @UtreexoBatchProof, leaves: Span + self: @UtreexoStumpState, proof: @UtreexoBatchProof, leaves: Span, ) -> Result<(), ByteArray> { let computed_roots = proof.compute_roots(leaves, *self.num_leaves)?; let num_computed = computed_roots.len(); @@ -74,7 +74,7 @@ pub impl StumpUtreexoAccumulatorImpl of StumpUtreexoAccumulator { num_matched, computed_roots, self.roots, - ) + ), ); } @@ -84,7 +84,7 @@ pub impl StumpUtreexoAccumulatorImpl of StumpUtreexoAccumulator { /// Verifies that the specified leaves are part of the utreexo forest given the proof, /// deletes them and returns an updated state. fn verify_and_delete( - self: @UtreexoStumpState, proof: @UtreexoBatchProof, leaves: Span + self: @UtreexoStumpState, proof: @UtreexoBatchProof, leaves: Span, ) -> Result { let mut computed_roots = proof .compute_roots_with_deletion(leaves, *self.num_leaves)? @@ -92,22 +92,21 @@ pub impl StumpUtreexoAccumulatorImpl of StumpUtreexoAccumulator { let mut new_roots = array![]; // Note that roots are sorted top down - for maybe_root in *self - .roots { - if let Option::Some(our_root) = maybe_root { - let computed_len = computed_roots.len(); - if computed_len != 0 { - // Computed roots are in reversed order (sorted bottom up) - let (their_root, new_root) = computed_roots[computed_len - 1]; - if our_root == their_root { - computed_roots.pop_back().unwrap(); - new_roots.append(*new_root); - continue; - } + for maybe_root in *self.roots { + if let Option::Some(our_root) = maybe_root { + let computed_len = computed_roots.len(); + if computed_len != 0 { + // Computed roots are in reversed order (sorted bottom up) + let (their_root, new_root) = computed_roots[computed_len - 1]; + if our_root == their_root { + computed_roots.pop_back().unwrap(); + new_roots.append(*new_root); + continue; } } - new_roots.append(*maybe_root); - }; + } + new_roots.append(*maybe_root); + }; if !computed_roots.is_empty() { return Result::Err("Proof verification / leaf deletion failed"); @@ -118,27 +117,24 @@ pub impl StumpUtreexoAccumulatorImpl of StumpUtreexoAccumulator { /// Legacy implementation of proof verification. fn verify_legacy( - self: @UtreexoStumpState, proof: @UtreexoBatchProof, del_hashes: Span + self: @UtreexoStumpState, proof: @UtreexoBatchProof, del_hashes: Span, ) -> Result<(), ByteArray> { let computed_roots: Span = proof .compute_roots_legacy(del_hashes, *self.num_leaves)?; let mut number_matched_roots: u32 = 0; - for i in 0 - ..computed_roots - .len() { - for root in *self - .roots { - match root { - Option::Some(root) => { - if (computed_roots[i] == root) { - number_matched_roots += 1; - }; - }, - Option::None => {}, - }; + for i in 0..computed_roots.len() { + for root in *self.roots { + match root { + Option::Some(root) => { + if (computed_roots[i] == root) { + number_matched_roots += 1; }; + }, + Option::None => {}, }; + }; + }; let computed_roots_len = computed_roots.len(); diff --git a/packages/utreexo/src/stump/accumulator_tests.cairo b/packages/utreexo/src/stump/accumulator_tests.cairo index 9d9393ef..4940a87e 100644 --- a/packages/utreexo/src/stump/accumulator_tests.cairo +++ b/packages/utreexo/src/stump/accumulator_tests.cairo @@ -6,15 +6,15 @@ use super::state::UtreexoStumpState; fn test_verification_1_legacy() { let state = UtreexoStumpState { roots: array![ - Option::Some(0x371cb6995ea5e7effcd2e174de264b5b407027a75a231a70c2c8d196107f0e7) + Option::Some(0x371cb6995ea5e7effcd2e174de264b5b407027a75a231a70c2c8d196107f0e7), ] .span(), - num_leaves: 2 + num_leaves: 2, }; let proof = UtreexoBatchProof { targets: array![0].span(), proof: array![2].span() }; let del_hashes = array![1]; - let result = state.verify_legacy(@proof, del_hashes.span(),); + let result = state.verify_legacy(@proof, del_hashes.span()); assert_eq!(result, Result::Ok(())); } @@ -28,7 +28,7 @@ fn test_verification_2_legacy() { Option::Some(0xf), ] .span(), - num_leaves: 15 + num_leaves: 15, }; let proof = UtreexoBatchProof { targets: array![1, 3, 10, 13].span(), @@ -38,13 +38,13 @@ fn test_verification_2_legacy() { 0xC, 0xD, 0x436e91732c0a83fa238d71460463f4b1fe0dc0b1ebcbc10967a84cec9d13154, - 0xdc9cc50aff0bdadd82a05bbab54015a07fccf2a4e30fa528fdca5a35d5423f + 0xdc9cc50aff0bdadd82a05bbab54015a07fccf2a4e30fa528fdca5a35d5423f, ] - .span() + .span(), }; let del_hashes = array![2, 4, 11, 14]; - let result = state.verify_legacy(@proof, del_hashes.span(),); + let result = state.verify_legacy(@proof, del_hashes.span()); assert_eq!(result, Result::Ok(())); } @@ -58,7 +58,7 @@ fn test_verification_3_legacy() { Option::Some(0x74f794e653e00357d8a8ed45fcb74659841190c0821aa4e20bc4e30b2f3dd20), ] .span(), - num_leaves: 30 + num_leaves: 30, }; let proof = UtreexoBatchProof { targets: array![4, 8, 12, 16, 20, 24, 28].span(), @@ -76,14 +76,14 @@ fn test_verification_3_legacy() { 0x41a4ec75a27497daa51261588a60f0956d3fd61e521634bbf36bba6343c3a1b, 0x3ba731d3734536d7cd5382cb4004ca4c24f1325b6fbeae27bcd6b4f9c0ed714, 0x117ed04a65093683f13c16cf73d2855f1f099a96581d1dad74eaf34c9a343c8, - 0x79b32f615bbd57783700ae5f8e7b1ef79677c3545c4c69dc31b3aecce1d8fa6 + 0x79b32f615bbd57783700ae5f8e7b1ef79677c3545c4c69dc31b3aecce1d8fa6, ] - .span() + .span(), }; let del_hashes = array![5, 9, 13, 17, 21, 25, 29]; - let result = state.verify_legacy(@proof, del_hashes.span(),); + let result = state.verify_legacy(@proof, del_hashes.span()); assert_eq!(result, Result::Ok(())); } @@ -91,15 +91,15 @@ fn test_verification_3_legacy() { fn test_verification_1() { let state = UtreexoStumpState { roots: array![ - Option::Some(0x371cb6995ea5e7effcd2e174de264b5b407027a75a231a70c2c8d196107f0e7) + Option::Some(0x371cb6995ea5e7effcd2e174de264b5b407027a75a231a70c2c8d196107f0e7), ] .span(), - num_leaves: 2 + num_leaves: 2, }; let proof = UtreexoBatchProof { targets: array![0].span(), proof: array![2].span() }; let del_hashes = array![1]; - let result = state.verify(@proof, del_hashes.span(),); + let result = state.verify(@proof, del_hashes.span()); assert_eq!(result, Result::Ok(())); } @@ -113,7 +113,7 @@ fn test_verification_2() { Option::Some(0xf), ] .span(), - num_leaves: 15 + num_leaves: 15, }; let proof = UtreexoBatchProof { targets: array![1, 3, 10, 13].span(), @@ -123,13 +123,13 @@ fn test_verification_2() { 0xC, 0xD, 0x436e91732c0a83fa238d71460463f4b1fe0dc0b1ebcbc10967a84cec9d13154, - 0xdc9cc50aff0bdadd82a05bbab54015a07fccf2a4e30fa528fdca5a35d5423f + 0xdc9cc50aff0bdadd82a05bbab54015a07fccf2a4e30fa528fdca5a35d5423f, ] - .span() + .span(), }; let del_hashes = array![2, 4, 11, 14]; - let result = state.verify(@proof, del_hashes.span(),); + let result = state.verify(@proof, del_hashes.span()); assert_eq!(result, Result::Ok(())); } @@ -143,7 +143,7 @@ fn test_verification_3() { Option::Some(0x74f794e653e00357d8a8ed45fcb74659841190c0821aa4e20bc4e30b2f3dd20), ] .span(), - num_leaves: 30 + num_leaves: 30, }; let proof = UtreexoBatchProof { targets: array![4, 8, 12, 16, 20, 24, 28].span(), @@ -161,14 +161,14 @@ fn test_verification_3() { 0x41a4ec75a27497daa51261588a60f0956d3fd61e521634bbf36bba6343c3a1b, 0x3ba731d3734536d7cd5382cb4004ca4c24f1325b6fbeae27bcd6b4f9c0ed714, 0x117ed04a65093683f13c16cf73d2855f1f099a96581d1dad74eaf34c9a343c8, - 0x79b32f615bbd57783700ae5f8e7b1ef79677c3545c4c69dc31b3aecce1d8fa6 + 0x79b32f615bbd57783700ae5f8e7b1ef79677c3545c4c69dc31b3aecce1d8fa6, ] - .span() + .span(), }; let del_hashes = array![5, 9, 13, 17, 21, 25, 29]; - let result = state.verify(@proof, del_hashes.span(),); + let result = state.verify(@proof, del_hashes.span()); assert_eq!(result, Result::Ok(())); } @@ -177,7 +177,7 @@ fn test_verification_4() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2778277074578782368986165095004756321440748237082580104984033528445453379385 + 2778277074578782368986165095004756321440748237082580104984033528445453379385, ), Option::None, Option::None, @@ -185,7 +185,7 @@ fn test_verification_4() { Option::None, ] .span(), - num_leaves: 16 + num_leaves: 16, }; assert_eq!( @@ -199,11 +199,11 @@ fn test_verification_4() { 2920447154653459698578961030005574439730780339384884329678783637696763668074, 361638375607381126502342109490869021742109399020176111227133094637834041180, ] - .span() + .span(), }, - array![0].span() + array![0].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -217,11 +217,11 @@ fn test_verification_4() { 2224391216833402212724735773212940252356536072547264452695587483243907176367, 1010147253610699894986241683624609428739638206544914327400350896031110287324, ] - .span() + .span(), }, - array![15].span() + array![15].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -236,11 +236,11 @@ fn test_verification_4() { 2476911194812244264213538976037850550079366744233323933541290896048104351430, 361638375607381126502342109490869021742109399020176111227133094637834041180, ] - .span() + .span(), }, - array![0, 2, 5].span() + array![0, 2, 5].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -248,11 +248,11 @@ fn test_verification_4() { .verify( @UtreexoBatchProof { targets: array![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].span(), - proof: array![].span() + proof: array![].span(), }, - array![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].span() + array![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -266,16 +266,16 @@ fn test_verification_4() { 2476911194812244264213538976037850550079366744233323933541290896048104351430, 361638375607381126502342109490869021742109399020176111227133094637834041180, ] - .span() + .span(), }, array![ 2808234728617536643410270558566096818021668177546200472079927509023409591575, 2, - 5 + 5, ] - .span() + .span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -290,7 +290,7 @@ fn test_verification_4() { 3115762988631556491925147498418117978906005591291390166955707455104569660364, 3009277733733429566191908933097273596911357184294896938062356457901603258437, ] - .span() + .span(), }, array![ 1229371501456391789924831928153470943555736434402105893904574254763197682709, @@ -298,9 +298,9 @@ fn test_verification_4() { 10, 15, ] - .span() + .span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -311,15 +311,15 @@ fn test_verification_4() { proof: array![ 2920447154653459698578961030005574439730780339384884329678783637696763668074, ] - .span() + .span(), }, array![ 1229371501456391789924831928153470943555736434402105893904574254763197682709, 361638375607381126502342109490869021742109399020176111227133094637834041180, ] - .span() + .span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -330,21 +330,19 @@ fn test_verification_4() { 1010147253610699894986241683624609428739638206544914327400350896031110287324, 361638375607381126502342109490869021742109399020176111227133094637834041180, ] - .span() + .span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( state .verify( @UtreexoBatchProof { targets: array![30].span(), proof: array![].span() }, - array![ - 2778277074578782368986165095004756321440748237082580104984033528445453379385, - ] - .span() + array![2778277074578782368986165095004756321440748237082580104984033528445453379385] + .span(), ), - Result::Ok(()) + Result::Ok(()), ); } @@ -353,18 +351,18 @@ fn test_verification_5() { let state = UtreexoStumpState { roots: array![ Option::Some( - 1010147253610699894986241683624609428739638206544914327400350896031110287324 + 1010147253610699894986241683624609428739638206544914327400350896031110287324, ), Option::Some( - 2224391216833402212724735773212940252356536072547264452695587483243907176367 + 2224391216833402212724735773212940252356536072547264452695587483243907176367, ), Option::Some( - 3009277733733429566191908933097273596911357184294896938062356457901603258437 + 3009277733733429566191908933097273596911357184294896938062356457901603258437, ), Option::Some(14), ] .span(), - num_leaves: 15 + num_leaves: 15, }; assert_eq!( @@ -377,29 +375,29 @@ fn test_verification_5() { 359114454570462701179676018441683730149326686283278794303413350979946254235, 2920447154653459698578961030005574439730780339384884329678783637696763668074, ] - .span() + .span(), }, - array![0].span() + array![0].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( state .verify( @UtreexoBatchProof { targets: array![14].span(), proof: array![].span() }, - array![14].span() + array![14].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( state .verify( @UtreexoBatchProof { targets: array![13].span(), proof: array![12].span() }, - array![13].span() + array![13].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -413,11 +411,11 @@ fn test_verification_5() { 4, 2476911194812244264213538976037850550079366744233323933541290896048104351430, ] - .span() + .span(), }, - array![0, 2, 5, 14].span() + array![0, 2, 5, 14].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -425,11 +423,11 @@ fn test_verification_5() { .verify( @UtreexoBatchProof { targets: array![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].span(), - proof: array![].span() + proof: array![].span(), }, - array![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].span() + array![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -442,17 +440,17 @@ fn test_verification_5() { 4, 2476911194812244264213538976037850550079366744233323933541290896048104351430, ] - .span() + .span(), }, array![ 2808234728617536643410270558566096818021668177546200472079927509023409591575, 2, 5, - 14 + 14, ] - .span() + .span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -463,9 +461,9 @@ fn test_verification_5() { 1229371501456391789924831928153470943555736434402105893904574254763197682709, 2920447154653459698578961030005574439730780339384884329678783637696763668074, ] - .span() + .span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( @@ -474,29 +472,27 @@ fn test_verification_5() { @UtreexoBatchProof { targets: array![24, 26].span(), proof: array![ - 2920447154653459698578961030005574439730780339384884329678783637696763668074 + 2920447154653459698578961030005574439730780339384884329678783637696763668074, ] - .span() + .span(), }, array![ 1229371501456391789924831928153470943555736434402105893904574254763197682709, 2224391216833402212724735773212940252356536072547264452695587483243907176367, ] - .span() + .span(), ), - Result::Ok(()) + Result::Ok(()), ); assert_eq!( state .verify( @UtreexoBatchProof { targets: array![28].span(), proof: array![].span() }, - array![ - 1010147253610699894986241683624609428739638206544914327400350896031110287324, - ] - .span() + array![1010147253610699894986241683624609428739638206544914327400350896031110287324] + .span(), ), - Result::Ok(()) + Result::Ok(()), ); } @@ -533,14 +529,14 @@ fn test_deletion_8_1() { let state = UtreexoStumpState { roots: array![ Option::Some( - 555370024363052154426534073187628105642230667669796211052131558433241164031 + 555370024363052154426534073187628105642230667669796211052131558433241164031, ), Option::None, Option::None, Option::None, ] .span(), - num_leaves: 8 + num_leaves: 8, }; let proof = UtreexoBatchProof { @@ -548,9 +544,9 @@ fn test_deletion_8_1() { proof: array![ 'b', 1702961261074558847535372708423978610134065667337563473891781271138689292959, - 1970675917964935639615849678644334216784892342767290630432190461589093258001 + 1970675917964935639615849678644334216784892342767290630432190461589093258001, ] - .span() + .span(), }; let leaves = array!['a']; @@ -562,13 +558,13 @@ fn test_deletion_8_1() { new_state.roots, array![ Option::Some( - 3345421944025286217980549018138297349958141750618054570424649972274280624201 + 3345421944025286217980549018138297349958141750618054570424649972274280624201, ), Option::None, Option::None, Option::None, ] - .span() + .span(), ); } @@ -577,23 +573,23 @@ fn test_deletion_8_2() { let state = UtreexoStumpState { roots: array![ Option::Some( - 555370024363052154426534073187628105642230667669796211052131558433241164031 + 555370024363052154426534073187628105642230667669796211052131558433241164031, ), Option::None, Option::None, Option::None, ] .span(), - num_leaves: 8 + num_leaves: 8, }; let proof = UtreexoBatchProof { targets: array![0, 1].span(), proof: array![ 1702961261074558847535372708423978610134065667337563473891781271138689292959, - 1970675917964935639615849678644334216784892342767290630432190461589093258001 + 1970675917964935639615849678644334216784892342767290630432190461589093258001, ] - .span() + .span(), }; let leaves = array!['a', 'b']; @@ -605,13 +601,13 @@ fn test_deletion_8_2() { new_state.roots, array![ Option::Some( - 2850064462912342803614938379907776937447719434508740518644801944855647065404 + 2850064462912342803614938379907776937447719434508740518644801944855647065404, ), Option::None, Option::None, Option::None, ] - .span() + .span(), ); } @@ -620,22 +616,22 @@ fn test_deletion_8_3() { let state = UtreexoStumpState { roots: array![ Option::Some( - 555370024363052154426534073187628105642230667669796211052131558433241164031 + 555370024363052154426534073187628105642230667669796211052131558433241164031, ), Option::None, Option::None, Option::None, ] .span(), - num_leaves: 8 + num_leaves: 8, }; let proof = UtreexoBatchProof { targets: array![0, 1, 2].span(), proof: array![ - 'd', 1970675917964935639615849678644334216784892342767290630432190461589093258001 + 'd', 1970675917964935639615849678644334216784892342767290630432190461589093258001, ] - .span() + .span(), }; let leaves = array!['a', 'b', 'c']; @@ -647,13 +643,13 @@ fn test_deletion_8_3() { new_state.roots, array![ Option::Some( - 3021045430882547327596950725247172779074256595054900316875788021760349090257 + 3021045430882547327596950725247172779074256595054900316875788021760349090257, ), Option::None, Option::None, Option::None, ] - .span() + .span(), ); } @@ -662,18 +658,18 @@ fn test_deletion_8_4() { let state = UtreexoStumpState { roots: array![ Option::Some( - 555370024363052154426534073187628105642230667669796211052131558433241164031 + 555370024363052154426534073187628105642230667669796211052131558433241164031, ), Option::None, Option::None, Option::None, ] .span(), - num_leaves: 8 + num_leaves: 8, }; let proof = UtreexoBatchProof { - targets: array![0, 1, 2, 3, 4, 5, 6].span(), proof: array!['h'].span() + targets: array![0, 1, 2, 3, 4, 5, 6].span(), proof: array!['h'].span(), }; let leaves = array!['a', 'b', 'c', 'd', 'e', 'f', 'g']; @@ -682,7 +678,7 @@ fn test_deletion_8_4() { assert_eq!(new_state.num_leaves, 8); assert_eq!( - new_state.roots, array![Option::Some('h'), Option::None, Option::None, Option::None].span() + new_state.roots, array![Option::Some('h'), Option::None, Option::None, Option::None].span(), ); } @@ -691,18 +687,18 @@ fn test_deletion_8_5() { let state = UtreexoStumpState { roots: array![ Option::Some( - 555370024363052154426534073187628105642230667669796211052131558433241164031 + 555370024363052154426534073187628105642230667669796211052131558433241164031, ), Option::None, Option::None, Option::None, ] .span(), - num_leaves: 8 + num_leaves: 8, }; let proof = UtreexoBatchProof { - targets: array![0, 1, 2, 3, 4, 5, 6, 7].span(), proof: array![].span() + targets: array![0, 1, 2, 3, 4, 5, 6, 7].span(), proof: array![].span(), }; let leaves = array!['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; @@ -711,7 +707,7 @@ fn test_deletion_8_5() { assert_eq!(new_state.num_leaves, 8); assert_eq!( - new_state.roots, array![Option::None, Option::None, Option::None, Option::None].span() + new_state.roots, array![Option::None, Option::None, Option::None, Option::None].span(), ); } @@ -720,23 +716,23 @@ fn test_deletion_7_1() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some(103), ] .span(), - num_leaves: 7 + num_leaves: 7, }; let proof = UtreexoBatchProof { targets: array![0].span(), proof: array![ - 'b', 1702961261074558847535372708423978610134065667337563473891781271138689292959 + 'b', 1702961261074558847535372708423978610134065667337563473891781271138689292959, ] - .span() + .span(), }; let leaves = array!['a']; @@ -748,14 +744,14 @@ fn test_deletion_7_1() { new_state.roots, array![ Option::Some( - 1229642933490472299984329107953625663040621781839429280809499005981139964854 + 1229642933490472299984329107953625663040621781839429280809499005981139964854, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some('g'), ] - .span() + .span(), ); } @@ -764,19 +760,19 @@ fn test_deletion_7_2() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some(103), ] .span(), - num_leaves: 7 + num_leaves: 7, }; let proof = UtreexoBatchProof { - targets: array![0, 2, 4, 6].span(), proof: array!['b', 'd', 'f'].span() + targets: array![0, 2, 4, 6].span(), proof: array!['b', 'd', 'f'].span(), }; let leaves = array!['a', 'c', 'e', 'g']; @@ -788,12 +784,12 @@ fn test_deletion_7_2() { new_state.roots, array![ Option::Some( - 1012329657042087226062405582801477394059887655150284803644932492275110107160 + 1012329657042087226062405582801477394059887655150284803644932492275110107160, ), Option::Some('f'), Option::None, ] - .span() + .span(), ); } @@ -802,19 +798,19 @@ fn test_deletion_7_3() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some(103), ] .span(), - num_leaves: 7 + num_leaves: 7, }; let proof = UtreexoBatchProof { - targets: array![1, 3, 5].span(), proof: array!['a', 'c', 'e'].span() + targets: array![1, 3, 5].span(), proof: array!['a', 'c', 'e'].span(), }; let leaves = array!['b', 'd', 'f']; @@ -826,12 +822,12 @@ fn test_deletion_7_3() { new_state.roots, array![ Option::Some( - 1442415957443312626722273931205158047965396421097404482753913691074484308909 + 1442415957443312626722273931205158047965396421097404482753913691074484308909, ), Option::Some('e'), Option::Some('g'), ] - .span() + .span(), ); } @@ -840,23 +836,23 @@ fn test_deletion_7_4() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some(103), ] .span(), - num_leaves: 7 + num_leaves: 7, }; let proof = UtreexoBatchProof { targets: array![0, 6].span(), proof: array![ - 'b', 1702961261074558847535372708423978610134065667337563473891781271138689292959 + 'b', 1702961261074558847535372708423978610134065667337563473891781271138689292959, ] - .span() + .span(), }; let leaves = array!['a', 'g']; @@ -868,14 +864,14 @@ fn test_deletion_7_4() { new_state.roots, array![ Option::Some( - 1229642933490472299984329107953625663040621781839429280809499005981139964854 + 1229642933490472299984329107953625663040621781839429280809499005981139964854, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::None, ] - .span() + .span(), ); } @@ -884,15 +880,15 @@ fn test_deletion_7_5() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some(103), ] .span(), - num_leaves: 7 + num_leaves: 7, }; let proof = UtreexoBatchProof { targets: array![4, 5, 6].span(), proof: array![].span() }; @@ -906,12 +902,12 @@ fn test_deletion_7_5() { new_state.roots, array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::None, Option::None, ] - .span() + .span(), ); } @@ -920,19 +916,19 @@ fn test_deletion_7_6() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some(103), ] .span(), - num_leaves: 7 + num_leaves: 7, }; let proof = UtreexoBatchProof { - targets: array![0, 1, 2, 3, 4, 5, 6].span(), proof: array![].span() + targets: array![0, 1, 2, 3, 4, 5, 6].span(), proof: array![].span(), }; let leaves = array!['a', 'b', 'c', 'd', 'e', 'f', 'g']; @@ -948,15 +944,15 @@ fn test_deletion_7_7() { let state = UtreexoStumpState { roots: array![ Option::Some( - 2858081605429646247202638041541950020464262679066089136848920825648707910133 + 2858081605429646247202638041541950020464262679066089136848920825648707910133, ), Option::Some( - 411226027934254579827031836427260754155547814753354544773152242745331653508 + 411226027934254579827031836427260754155547814753354544773152242745331653508, ), Option::Some(103), ] .span(), - num_leaves: 7 + num_leaves: 7, }; // Remove 0 @@ -964,9 +960,9 @@ fn test_deletion_7_7() { let proof = UtreexoBatchProof { targets: array![0].span(), proof: array![ - 'b', 1702961261074558847535372708423978610134065667337563473891781271138689292959 + 'b', 1702961261074558847535372708423978610134065667337563473891781271138689292959, ] - .span() + .span(), }; let leaves = array!['a']; @@ -978,7 +974,7 @@ fn test_deletion_7_7() { let proof = UtreexoBatchProof { targets: array![8].span(), proof: array![1702961261074558847535372708423978610134065667337563473891781271138689292959] - .span() + .span(), }; let leaves = array!['b']; diff --git a/packages/utreexo/src/stump/proof.cairo b/packages/utreexo/src/stump/proof.cairo index 7ce4a63e..a5682319 100644 --- a/packages/utreexo/src/stump/proof.cairo +++ b/packages/utreexo/src/stump/proof.cairo @@ -25,7 +25,7 @@ impl UtreexoBatchProofDisplay of Display { targets.append(@format!("{},", target)); }; let str: ByteArray = format!( - "UtreexoBatchProof {{ proof: [{}], leaf_index: [{}] }}", @targets, @proofs + "UtreexoBatchProof {{ proof: [{}], leaf_index: [{}] }}", @targets, @proofs, ); f.buffer.append(@str); Result::Ok(()) @@ -213,7 +213,7 @@ pub impl UtreexoBatchProofImpl of UtreexoBatchProofTrait { // here we accumulate the result let mut roots = array![]; let mut inner_result: Result)>, ByteArray> = Result::Ok( - array![] + array![], ); // we process the whole forest row by row from the bottom leaves to the top root @@ -245,9 +245,9 @@ pub impl UtreexoBatchProofImpl of UtreexoBatchProofTrait { ( pos / 2, parent_hash_pair( - hash, (*proof_hash, Option::Some(*proof_hash)) - ) - ) + hash, (*proof_hash, Option::Some(*proof_hash)), + ), + ), ); } else { inner_result = Result::Err("Invalid proof"); @@ -264,9 +264,9 @@ pub impl UtreexoBatchProofImpl of UtreexoBatchProofTrait { ( pos / 2, parent_hash_pair( - hash, (*proof_hash, Option::Some(*proof_hash)) - ) - ) + hash, (*proof_hash, Option::Some(*proof_hash)), + ), + ), ); } else { inner_result = Result::Err("Invalid proof"); @@ -286,8 +286,10 @@ pub impl UtreexoBatchProofImpl of UtreexoBatchProofTrait { .append( ( pos / 2, - parent_hash_pair((*proof_hash, Option::Some(*proof_hash)), hash) - ) + parent_hash_pair( + (*proof_hash, Option::Some(*proof_hash)), hash, + ), + ), ); } else { inner_result = Result::Err("Invalid proof"); @@ -397,7 +399,7 @@ pub impl UtreexoBatchProofImpl of UtreexoBatchProofTrait { if row_len == 0 { inner_result = Result::Err( - format!("Position {pos} is out of the forest range {row_len_acc}.") + format!("Position {pos} is out of the forest range {row_len_acc}."), ); break; } @@ -469,7 +471,7 @@ pub impl UtreexoBatchProofImpl of UtreexoBatchProofTrait { /// Extracts all nodes with absolute positions in [row_start; row_end) /// and transforms their positions to relative. fn extract_row, +Drop>( - ref nodes: Array<(u64, T)>, row_start: u64, row_end: u64 + ref nodes: Array<(u64, T)>, row_start: u64, row_end: u64, ) -> Array<(u64, T)> { let mut row = array![]; while let Option::Some(box) = nodes.get(0) { @@ -485,7 +487,7 @@ fn extract_row, +Drop>( /// Merges two sorted arrays into a single sorted array. fn merge_sorted>( - ref arr1: Array<(u64, T)>, ref arr2: Array<(u64, T)> + ref arr1: Array<(u64, T)>, ref arr2: Array<(u64, T)>, ) -> Array<(u64, T)> { let mut res = array![]; while let Option::Some((p1, v1)) = arr1.pop_front() { @@ -507,7 +509,7 @@ fn merge_sorted>( /// Takes two nodes containing two values each: (L1, L2) and (R1, R2), and calculates /// a parent node, that also contains two values (P1 = h(L1, R1), P2 = h(L2, R2)). fn parent_hash_pair( - left: (felt252, Option), right: (felt252, Option) + left: (felt252, Option), right: (felt252, Option), ) -> (felt252, Option) { let (old_left, new_left) = left; let (old_right, new_right) = right; diff --git a/packages/utreexo/src/stump/state.cairo b/packages/utreexo/src/stump/state.cairo index 96dde38d..eee98a15 100644 --- a/packages/utreexo/src/stump/state.cairo +++ b/packages/utreexo/src/stump/state.cairo @@ -15,7 +15,7 @@ pub struct UtreexoStumpState { /// `Default` trait implementation for `UtreexoStumpState`. pub impl UtreexoStumpStateDefault of Default { fn default() -> UtreexoStumpState { - UtreexoStumpState { roots: array![Option::None].span(), num_leaves: 0, } + UtreexoStumpState { roots: array![Option::None].span(), num_leaves: 0 } } } @@ -25,7 +25,7 @@ impl UtreexoStumpStateDisplay of Display { let str: ByteArray = format!( "UtreexoStumpState {{ roots: {}, num_leaves: {} }}", (*self.roots).len(), - *self.num_leaves + *self.num_leaves, ); f.buffer.append(@str); Result::Ok(()) diff --git a/packages/utreexo/src/test.cairo b/packages/utreexo/src/test.cairo index c43fe522..6d5a5ee6 100644 --- a/packages/utreexo/src/test.cairo +++ b/packages/utreexo/src/test.cairo @@ -17,18 +17,16 @@ fn main(args: Array) -> Array { let mut gas_before = get_available_gas(); let mut arguments = args.span(); - let Args { mut state, proof, leaves_to_del, leaves_to_add, expected_state, _unused: _ } = - Serde::deserialize( - ref arguments - ) - .expect('Failed to deserialize'); + let Args { + mut state, proof, leaves_to_del, leaves_to_add, expected_state, _unused: _, + } = Serde::deserialize(ref arguments).expect('Failed to deserialize'); match state.verify(@proof, leaves_to_del.span()) { Result::Ok(_) => {}, Result::Err(err) => { println!("FAIL: gas_spent={} error='{:?}'", gas_before - get_available_gas(), err); panic!(); - } + }, } match state.verify_and_delete(@proof, leaves_to_del.span()) { @@ -36,7 +34,7 @@ fn main(args: Array) -> Array { Result::Err(err) => { println!("FAIL: gas_spent={} error='{:?}'", gas_before - get_available_gas(), err); panic!(); - } + }, } state = state.add(leaves_to_add.span()); @@ -46,7 +44,7 @@ fn main(args: Array) -> Array { "FAIL: gas_spent={} error='expected state {:?}, actual {:?}'", gas_before - get_available_gas(), expected_state, - state + state, ); panic!(); } diff --git a/packages/utreexo/src/vanilla/accumulator.cairo b/packages/utreexo/src/vanilla/accumulator.cairo index af07e9e2..6089d907 100644 --- a/packages/utreexo/src/vanilla/accumulator.cairo +++ b/packages/utreexo/src/vanilla/accumulator.cairo @@ -11,20 +11,19 @@ pub impl VanillaUtreexoAccumulatorImpl of VanillaUtreexoAccumulator { let mut first_none_found: bool = false; let mut node = hash; - for root in *self - .roots { - if !first_none_found { - if let Option::Some(root) = root { - node = parent_hash(*root, node); - new_roots.append(Option::None); - } else { - first_none_found = true; - new_roots.append(Option::Some(node)); - } + for root in *self.roots { + if !first_none_found { + if let Option::Some(root) = root { + node = parent_hash(*root, node); + new_roots.append(Option::None); } else { - new_roots.append(*root); + first_none_found = true; + new_roots.append(Option::Some(node)); } - }; + } else { + new_roots.append(*root); + } + }; // Check if terminates with `Option::None` if (new_roots[new_roots.len() - 1].is_some()) { diff --git a/packages/utreexo/src/vanilla/accumulator_tests.cairo b/packages/utreexo/src/vanilla/accumulator_tests.cairo index a6235cbb..ecf0ca86 100644 --- a/packages/utreexo/src/vanilla/accumulator_tests.cairo +++ b/packages/utreexo/src/vanilla/accumulator_tests.cairo @@ -27,7 +27,7 @@ fn test_verify_inclusion() { let mut utxo_state = UtreexoState { roots: array![Option::Some(0x111111111111111111111111)].into(), }; - let proof = UtreexoProof { leaf_index: 0, proof: array![].span(), }; + let proof = UtreexoProof { leaf_index: 0, proof: array![].span() }; let result = utxo_state.verify(leaf1, @proof); assert!(result.is_ok(), "Root at index 0 should be 0x111111111111111111111111"); @@ -38,16 +38,16 @@ fn test_verify_inclusion() { UtreexoState { roots: array![ Option::None, - Option::Some(0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a) + Option::Some(0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a), ] .into(), }; - let proof = UtreexoProof { leaf_index: 1, proof: array![0x111111111111111111111111].span(), }; + let proof = UtreexoProof { leaf_index: 1, proof: array![0x111111111111111111111111].span() }; let result = utxo_state.verify(leaf2, @proof); assert!( result.is_ok(), - "Root at index 1 should be 0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a" + "Root at index 1 should be 0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a", ); // Add the third leaf (0x333333333333333333333333) @@ -56,16 +56,16 @@ fn test_verify_inclusion() { UtreexoState { roots: array![ Option::Some(leaf3), - Option::Some(0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a) + Option::Some(0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a), ] .into(), }; - let proof = UtreexoProof { leaf_index: 1, proof: array![0x111111111111111111111111].span(), }; + let proof = UtreexoProof { leaf_index: 1, proof: array![0x111111111111111111111111].span() }; let result = utxo_state.verify(leaf2, @proof); assert!( result.is_ok(), - "Root at index 1 should be 0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a" + "Root at index 1 should be 0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a", ); // Add the fourth leaf (0x444444444444444444444444) @@ -77,7 +77,7 @@ fn test_verify_inclusion() { roots: array![ Option::None, Option::None, - Option::Some(0x018674e0c40577cb5ba4728d6ac7bedfd9548f4020161223261941b2a8ae84b2) + Option::Some(0x018674e0c40577cb5ba4728d6ac7bedfd9548f4020161223261941b2a8ae84b2), ] .into(), }; @@ -87,7 +87,7 @@ fn test_verify_inclusion() { leaf_index: 0, proof: array![ 0x222222222222222222222222, - 0x02a6b2ae998d30e1ac356c32b2750c3126cd6b3ecf02e6918a93021d17b2b026 + 0x02a6b2ae998d30e1ac356c32b2750c3126cd6b3ecf02e6918a93021d17b2b026, ] .span(), }; @@ -147,7 +147,7 @@ fn test_utreexo_add() { let expected: Span> = array![ Option::Some(0x291F8F5FC449D42C715B529E542F24A80136D18F4A85DE28829CD3DCAAC1B9C), - Option::None + Option::None, ] .span(); assert_eq!(utreexo_state.roots, expected, "cannot add first leave"); @@ -158,7 +158,7 @@ fn test_utreexo_add() { let expected: Span> = array![ Option::None, Option::Some(0x738A7C495E564574993BBCB6A62D65C3C570BB81C63801066AF8934649F66F6), - Option::None + Option::None, ] .span(); assert_eq!(utreexo_state.roots, expected, "cannot add second leave"); @@ -169,7 +169,7 @@ fn test_utreexo_add() { let expected: Span> = array![ Option::Some(0x291F8F5FC449D42C715B529E542F24A80136D18F4A85DE28829CD3DCAAC1B9C), Option::Some(0x738A7C495E564574993BBCB6A62D65C3C570BB81C63801066AF8934649F66F6), - Option::None + Option::None, ] .span(); assert_eq!(utreexo_state.roots, expected, "cannot add thirdth leave"); @@ -181,7 +181,7 @@ fn test_utreexo_add() { Option::None, Option::None, Option::Some(0x25D0DE35DD446E3D35504866FD7A04D4245E01B5908E19EAA70ABA84DD5A1F1), - Option::None + Option::None, ] .span(); assert_eq!(utreexo_state.roots, expected, "cannot add fourth leave"); @@ -193,7 +193,7 @@ fn test_utreexo_add() { Option::Some(0x291F8F5FC449D42C715B529E542F24A80136D18F4A85DE28829CD3DCAAC1B9C), Option::None, Option::Some(0x25D0DE35DD446E3D35504866FD7A04D4245E01B5908E19EAA70ABA84DD5A1F1), - Option::None + Option::None, ] .span(); assert_eq!(utreexo_state.roots, expected, "cannot add fifth leave"); @@ -208,7 +208,7 @@ fn test_utreexo_add() { Option::None, Option::None, Option::Some(0x708EB39E30B035376EC871F8F17CD3BADAE6A68406B13C3BB671009D56F5AD), - Option::None + Option::None, ] .span(); assert_eq!(utreexo_state.roots, expected, "cannot add 3 leaves"); @@ -224,8 +224,9 @@ fn test_utreexo_add() { Option::Some(0x25D0DE35DD446E3D35504866FD7A04D4245E01B5908E19EAA70ABA84DD5A1F1), Option::Some(0x708EB39E30B035376EC871F8F17CD3BADAE6A68406B13C3BB671009D56F5AD), Option::Some(0x58D6BEF6CFC28638FB4C8271355961F50922BCC1577DD2B6D04E11B7A911702), - Option::None(()) - ].span(); + Option::None(()), + ] + .span(); assert_eq!(utreexo_state.roots, expected, "cannot add 22 leaves"); } @@ -271,9 +272,9 @@ fn test_utreexo_delete() { 0x0000000000000000000000000000000000000000444444444444444444444444, 0x05fb342b44641ae6d67310cf9da5566e1a398fd6b0121d40e2c5acd16e1ddb4a, 0x01670d29719eae8deaa34a1d75752368d180a2c3e53f08d344ad784f1a034be7, - 0x04448e395061d8b58524c81978a17837c66c7f3286ea3c1773c7fafd77d29f69 + 0x04448e395061d8b58524c81978a17837c66c7f3286ea3c1773c7fafd77d29f69, ] - .span() + .span(), }; // Deletes the 3rd leaf diff --git a/packages/utreexo/src/vanilla/proof.cairo b/packages/utreexo/src/vanilla/proof.cairo index 4c439ec7..f1e25290 100644 --- a/packages/utreexo/src/vanilla/proof.cairo +++ b/packages/utreexo/src/vanilla/proof.cairo @@ -19,7 +19,7 @@ impl UtreexoProofDisplay of Display { proofs.append(@format!("{},", proof)); }; let str: ByteArray = format!( - "UtreexoProof {{ proof: {}, leaf_index: {} }}", *self.leaf_index, @proofs + "UtreexoProof {{ proof: {}, leaf_index: {} }}", *self.leaf_index, @proofs, ); f.buffer.append(@str); Result::Ok(()) @@ -36,18 +36,17 @@ pub impl UtreexoProofImpl of UtreexoProofTrait { let mut curr_node = leaf_hash; let mut node_index = *self.leaf_index; - for sibling in *self - .proof { - let (next_node_index, is_right) = DivRem::div_rem(node_index, 2); + for sibling in *self.proof { + let (next_node_index, is_right) = DivRem::div_rem(node_index, 2); - let (left, right) = if is_right == 0 { - (curr_node, *sibling) - } else { - (*sibling, curr_node) - }; - curr_node = parent_hash(left, right); - node_index = next_node_index; + let (left, right) = if is_right == 0 { + (curr_node, *sibling) + } else { + (*sibling, curr_node) }; + curr_node = parent_hash(left, right); + node_index = next_node_index; + }; // Return the computed root (or the node itself if the proof is empty). curr_node } diff --git a/packages/utreexo/src/vanilla/state.cairo b/packages/utreexo/src/vanilla/state.cairo index e8067e2e..56bd94d7 100644 --- a/packages/utreexo/src/vanilla/state.cairo +++ b/packages/utreexo/src/vanilla/state.cairo @@ -20,7 +20,7 @@ pub impl UtreexoStateDefault of Default { /// `Display` trait implement for `UtreexoState`. impl UtreexoStateDisplay of Display { fn fmt(self: @UtreexoState, ref f: Formatter) -> Result<(), Error> { - let str: ByteArray = format!("UtreexoState {{ roots: {} }}", (*self.roots).len(),); + let str: ByteArray = format!("UtreexoState {{ roots: {} }}", (*self.roots).len()); f.buffer.append(@str); Result::Ok(()) } @@ -33,7 +33,7 @@ pub impl UtreexoStateImpl of UtreexoStateTrait { self: @UtreexoState, hashes_to_add: Span, hashes_to_delete: Span, - mut proofs: Span + mut proofs: Span, ) -> Result { let mut inner_result = Result::Ok(()); let mut state = *self;