Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Asz/tasm lib refactor #42

Merged
merged 7 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 101 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ serde_json = "1"
strum = "0"
strum_macros = "0"
tarpc = { version = "0", features = ["tokio1", "serde-transport", "tcp"] }
tasm-lib = { git = "https://github.com/TritonVM/tasm-lib.git", tag = "v0.2.1" }
# tasm-lib = { git = "https://github.com/TritonVM/tasm-lib.git", tag = "v0.2.1" }
# tasm-lib = { git = "https://github.com/TritonVM/tasm-lib.git", branch = "asz/refactor-snippet-traits" }
tasm-lib = { path = "../tasm-lib/tasm-lib/" }
tokio = { version = "1", features = ["full", "tracing"] }
tokio-serde = { version = "0", features = ["bincode", "json"] }
tokio-util = { version = "0", features = ["codec"] }
Expand All @@ -53,13 +55,13 @@ tracing-subscriber = { version = "0", features = [
"fmt",
] }
tracing-test = "0"
triton-vm = "0.32.1"
triton-vm = "0.33.0"
twenty-first = "0.32.1"
tui = "0"
unicode-width = "0"

[dev-dependencies]
pin-project-lite = "0"
pin-project-lite = "0.2.12"
tokio-test = "0"

# needed because it otherwise takes too long to sign transaction with STARK proofs
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/tasm_neptune_transaction_compute_commitment.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"name": "tasm_neptune_transaction_compute_commitment",
"clock_cycle_count": 115,
"clock_cycle_count": 114,
"hash_table_height": 18,
"u32_table_height": 0,
"case": "CommonCase"
},
{
"name": "tasm_neptune_transaction_compute_commitment",
"clock_cycle_count": 115,
"clock_cycle_count": 114,
"hash_table_height": 18,
"u32_table_height": 0,
"case": "WorstCase"
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/tasm_neptune_transaction_compute_indices.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[
{
"name": "tasm_neptune_transaction_compute_indices",
"clock_cycle_count": 5080,
"clock_cycle_count": 5079,
"hash_table_height": 0,
"u32_table_height": 4471,
"u32_table_height": 4400,
"case": "CommonCase"
},
{
"name": "tasm_neptune_transaction_compute_indices",
"clock_cycle_count": 5080,
"clock_cycle_count": 5079,
"hash_table_height": 0,
"u32_table_height": 4530,
"u32_table_height": 4536,
"case": "WorstCase"
}
]
6 changes: 3 additions & 3 deletions benchmarks/tasm_neptune_transaction_hash_index_list.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[
{
"name": "tasm_neptune_transaction_hash_index_list",
"clock_cycle_count": 1574,
"clock_cycle_count": 1573,
"hash_table_height": 0,
"u32_table_height": 145,
"case": "CommonCase"
},
{
"name": "tasm_neptune_transaction_hash_index_list",
"clock_cycle_count": 1574,
"clock_cycle_count": 6409,
"hash_table_height": 0,
"u32_table_height": 145,
"u32_table_height": 787,
"case": "WorstCase"
}
]
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"name": "tasm_neptune_transaction_hash_removal_record_indices",
"clock_cycle_count": 1568,
"clock_cycle_count": 1567,
"hash_table_height": 0,
"u32_table_height": 145,
"case": "CommonCase"
},
{
"name": "tasm_neptune_transaction_hash_removal_record_indices",
"clock_cycle_count": 1568,
"clock_cycle_count": 1567,
"hash_table_height": 0,
"u32_table_height": 145,
"case": "WorstCase"
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/tasm_neptune_transaction_hash_utxo.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"name": "tasm_neptune_transaction_hash_utxo",
"clock_cycle_count": 302,
"clock_cycle_count": 301,
"hash_table_height": 0,
"u32_table_height": 11,
"case": "CommonCase"
},
{
"name": "tasm_neptune_transaction_hash_utxo",
"clock_cycle_count": 302,
"clock_cycle_count": 301,
"hash_table_height": 0,
"u32_table_height": 11,
"case": "WorstCase"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
{
"name": "tasm_neptune_transaction_removal_records_integrity",
"clock_cycle_count": 132089,
"hash_table_height": 5580,
"u32_table_height": 16248,
"clock_cycle_count": 55964,
"hash_table_height": 5532,
"u32_table_height": 16220,
"case": "CommonCase"
}
]
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[
{
"name": "tasm_neptune_transaction_transaction_kernel_mast_hash",
"clock_cycle_count": 22459,
"clock_cycle_count": 42468,
"hash_table_height": 42,
"u32_table_height": 3000,
"u32_table_height": 6348,
"case": "CommonCase"
},
{
"name": "tasm_neptune_transaction_transaction_kernel_mast_hash",
"clock_cycle_count": 44545,
"clock_cycle_count": 46866,
"hash_table_height": 42,
"u32_table_height": 6755,
"u32_table_height": 7149,
"case": "WorstCase"
}
]
12 changes: 6 additions & 6 deletions benchmarks/tasm_neptune_transaction_verify_aocl_membership.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[
{
"name": "tasm_neptune_transaction_verify_aocl_membership",
"clock_cycle_count": 937,
"hash_table_height": 42,
"u32_table_height": 135,
"clock_cycle_count": 819,
"hash_table_height": 36,
"u32_table_height": 116,
"case": "CommonCase"
},
{
"name": "tasm_neptune_transaction_verify_aocl_membership",
"clock_cycle_count": 1258,
"hash_table_height": 60,
"u32_table_height": 202,
"clock_cycle_count": 834,
"hash_table_height": 36,
"u32_table_height": 116,
"case": "WorstCase"
}
]
69 changes: 30 additions & 39 deletions profiles/tasm_neptune_transaction_removal_records_integrity.profile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
tasm_neptune_transaction_removal_records_integrity:

# call graph
tasm_io_load_struct_from_input_secin: 76122
tasm_io_load_from_input_secin: 76110
tasm_memory_dyn_malloc: 25
tasm_io_load_from_input_secin_loop: 76068
tasm_io_load_struct_from_input_secin_loop: 5
tasm_neptune_transaction_transaction_kernel_mast_hash: 21792
tasm_list_unsafe_u32_new_digest: 33
tasm_memory_dyn_malloc: 25
Expand Down Expand Up @@ -170,9 +165,9 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_list_higher_order_unsafe_u32_zip_void_pointer_with_digest: 406
tasm_list_unsafe_u32_length_long_void_pointer: 4
tasm_list_unsafe_u32_length_long_digest: 4
tasm_list_unsafe_u32_new_pair_Lvoid_pointer_and_digestR: 33
tasm_list_unsafe_u32_new_tuple_ofstart_void-pointer_digest_ofend_: 33
tasm_memory_dyn_malloc: 25
tasm_list_unsafe_u32_set_length_pair_Lvoid_pointer_and_digestR: 2
tasm_list_unsafe_u32_set_length_tuple_ofstart_void-pointer_digest_ofend_: 2
tasm_list_higher_order_unsafe_u32_zip_void_pointer_with_digest_loop: 345
tasm_memory_memcpy: 29
tasm_memory_memcpy_loop: 24
Expand All @@ -183,12 +178,12 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_memory_memcpy: 105
tasm_memory_memcpy_loop: 100
tasm_list_higher_order_unsafe_u32_map_tasm_neptune_transaction_compute_indices: 10312
tasm_list_unsafe_u32_length_long_pair_Ldigest_and_void_pointerR: 4
tasm_list_unsafe_u32_length_long_tuple_ofstart_digest_void-pointer_ofend_: 4
tasm_list_unsafe_u32_new_void_pointer: 31
tasm_memory_dyn_malloc: 25
tasm_list_unsafe_u32_set_length_pair_Ldigest_and_void_pointerR: 2
tasm_list_unsafe_u32_set_length_tuple_ofstart_digest_void-pointer_ofend_: 2
tasm_list_higher_order_unsafe_u32_map_tasm_neptune_transaction_compute_indices_loop: 10263
tasm_list_unsafe_u32_get_element_pair_Ldigest_and_void_pointerR: 29
tasm_list_unsafe_u32_get_element_tuple_ofstart_digest_void-pointer_ofend_: 29
tasm_neptune_transaction_compute_indices: 5079
tasm_memory_push_ram_to_stack_digest: 22
tasm_memory_push_ram_to_stack_digest: 22
Expand Down Expand Up @@ -245,7 +240,7 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_hashing_sample_indices_to_unsafe_list_process_top_function_body: 16
tasm_hashing_sample_indices_to_unsafe_list_process_top_function_body: 16
tasm_hashing_sample_indices_to_unsafe_list_process_top_function_body: 16
tasm_list_higher_order_unsafe_u32_map_u32_to_u128_add_another_u128: 3031
tasm_list_higher_order_unsafe_u32_map_u32_to_u128_add_another_u128: 3026
tasm_list_unsafe_u32_length_long_u32: 4
tasm_list_unsafe_u32_new_u128: 33
tasm_memory_dyn_malloc: 25
Expand Down Expand Up @@ -387,7 +382,7 @@ tasm_neptune_transaction_removal_records_integrity:
u32_to_u128_add_another_u128: 24
tasm_list_unsafe_u32_set_element_u128: 21
tasm_list_unsafe_u32_set_element_void_pointer: 7
tasm_list_unsafe_u32_get_element_pair_Ldigest_and_void_pointerR: 29
tasm_list_unsafe_u32_get_element_tuple_ofstart_digest_void-pointer_ofend_: 29
tasm_neptune_transaction_compute_indices: 5079
tasm_memory_push_ram_to_stack_digest: 22
tasm_memory_push_ram_to_stack_digest: 22
Expand Down Expand Up @@ -444,7 +439,7 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_hashing_sample_indices_to_unsafe_list_process_top_function_body: 16
tasm_hashing_sample_indices_to_unsafe_list_process_top_function_body: 16
tasm_hashing_sample_indices_to_unsafe_list_process_top_function_body: 16
tasm_list_higher_order_unsafe_u32_map_u32_to_u128_add_another_u128: 3031
tasm_list_higher_order_unsafe_u32_map_u32_to_u128_add_another_u128: 3026
tasm_list_unsafe_u32_length_long_u32: 4
tasm_list_unsafe_u32_new_u128: 33
tasm_memory_dyn_malloc: 25
Expand Down Expand Up @@ -657,27 +652,27 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_list_unsafe_u32_multiset_equality_running_product: 113
tasm_list_unsafe_u32_multiset_equality_running_product_loop: 99
tasm_list_higher_order_unsafe_u32_map_tasm_neptune_transaction_compute_commitment: 428
tasm_list_unsafe_u32_length_long_pair_Ldigest_and_void_pointerR: 4
tasm_list_unsafe_u32_new_pair_Lvoid_pointer_and_digestR: 33
tasm_list_unsafe_u32_length_long_tuple_ofstart_digest_void-pointer_ofend_: 4
tasm_list_unsafe_u32_new_tuple_ofstart_void-pointer_digest_ofend_: 33
tasm_memory_dyn_malloc: 25
tasm_list_unsafe_u32_set_length_pair_Ldigest_and_void_pointerR: 2
tasm_list_unsafe_u32_set_length_tuple_ofstart_digest_void-pointer_ofend_: 2
tasm_list_higher_order_unsafe_u32_map_tasm_neptune_transaction_compute_commitment_loop: 377
tasm_list_unsafe_u32_get_element_pair_Ldigest_and_void_pointerR: 29
tasm_list_unsafe_u32_get_element_tuple_ofstart_digest_void-pointer_ofend_: 29
tasm_neptune_transaction_compute_commitment: 114
tasm_memory_push_ram_to_stack_digest: 22
tasm_memory_push_ram_to_stack_digest: 22
tasm_neptune_mutator_set_commit: 13
tasm_list_unsafe_u32_set_element_pair_Lvoid_pointer_and_digestR: 29
tasm_list_unsafe_u32_get_element_pair_Ldigest_and_void_pointerR: 29
tasm_list_unsafe_u32_set_element_tuple_ofstart_void-pointer_digest_ofend_: 29
tasm_list_unsafe_u32_get_element_tuple_ofstart_digest_void-pointer_ofend_: 29
tasm_neptune_transaction_compute_commitment: 114
tasm_memory_push_ram_to_stack_digest: 22
tasm_memory_push_ram_to_stack_digest: 22
tasm_neptune_mutator_set_commit: 13
tasm_list_unsafe_u32_set_element_pair_Lvoid_pointer_and_digestR: 29
tasm_list_unsafe_u32_set_element_tuple_ofstart_void-pointer_digest_ofend_: 29
tasm_list_higher_order_unsafe_u32_all_tasm_neptune_transaction_verify_aocl_membership: 12455
tasm_list_unsafe_u32_length_long_pair_Lvoid_pointer_and_digestR: 4
tasm_list_unsafe_u32_length_long_tuple_ofstart_void-pointer_digest_ofend_: 4
tasm_list_higher_order_unsafe_u32_all_tasm_neptune_transaction_verify_aocl_membership_loop: 12443
tasm_list_unsafe_u32_get_element_pair_Lvoid_pointer_and_digestR: 29
tasm_list_unsafe_u32_get_element_tuple_ofstart_void-pointer_digest_ofend_: 29
tasm_neptune_transaction_verify_aocl_membership: 6160
tasm_mmr_verify_from_memory_unsafe: 6101
tasm_mmr_leaf_index_to_mt_index_and_peak_index: 128
Expand Down Expand Up @@ -1039,7 +1034,7 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_arithmetic_u64_eq: 8
tasm_list_unsafe_u32_get_element_digest: 25
tasm_hashing_eq_digest: 15
tasm_list_unsafe_u32_get_element_pair_Lvoid_pointer_and_digestR: 29
tasm_list_unsafe_u32_get_element_tuple_ofstart_void-pointer_digest_ofend_: 29
tasm_neptune_transaction_verify_aocl_membership: 6190
tasm_mmr_verify_from_memory_unsafe: 6131
tasm_mmr_leaf_index_to_mt_index_and_peak_index: 128
Expand Down Expand Up @@ -1403,16 +1398,12 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_arithmetic_u64_eq: 8
tasm_list_unsafe_u32_get_element_digest: 25
tasm_hashing_eq_digest: 15
total: 132089
total: 55964

# aggregated
tasm_io_load_struct_from_input_secin: 76122
tasm_io_load_from_input_secin: 76110
tasm_memory_dyn_malloc: 375
tasm_io_load_from_input_secin_loop: 76068
tasm_io_load_struct_from_input_secin_loop: 5
tasm_neptune_transaction_transaction_kernel_mast_hash: 21792
tasm_list_unsafe_u32_new_digest: 132
tasm_memory_dyn_malloc: 350
tasm_list_unsafe_u32_set_length_digest: 2
tasm_hashing_hash_varlen: 28050
tasm_hashing_hash_varlen_loop: 25607
Expand Down Expand Up @@ -1440,16 +1431,16 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_list_unsafe_u32_get_element_void_pointer: 42
tasm_neptune_transaction_hash_utxo: 602
tasm_list_higher_order_unsafe_u32_zip_void_pointer_with_digest: 406
tasm_list_unsafe_u32_new_pair_Lvoid_pointer_and_digestR: 66
tasm_list_unsafe_u32_set_length_pair_Lvoid_pointer_and_digestR: 2
tasm_list_unsafe_u32_new_tuple_ofstart_void-pointer_digest_ofend_: 66
tasm_list_unsafe_u32_set_length_tuple_ofstart_void-pointer_digest_ofend_: 2
tasm_list_higher_order_unsafe_u32_zip_void_pointer_with_digest_loop: 345
tasm_memory_memcpy: 268
tasm_memory_memcpy_loop: 248
tasm_list_higher_order_unsafe_u32_map_tasm_neptune_transaction_compute_indices: 10312
tasm_list_unsafe_u32_length_long_pair_Ldigest_and_void_pointerR: 8
tasm_list_unsafe_u32_set_length_pair_Ldigest_and_void_pointerR: 4
tasm_list_unsafe_u32_length_long_tuple_ofstart_digest_void-pointer_ofend_: 8
tasm_list_unsafe_u32_set_length_tuple_ofstart_digest_void-pointer_ofend_: 4
tasm_list_higher_order_unsafe_u32_map_tasm_neptune_transaction_compute_indices_loop: 10263
tasm_list_unsafe_u32_get_element_pair_Ldigest_and_void_pointerR: 116
tasm_list_unsafe_u32_get_element_tuple_ofstart_digest_void-pointer_ofend_: 116
tasm_neptune_transaction_compute_indices: 10158
tasm_neptune_mutator_get_swbf_indices_1048576_45: 9952
tasm_arithmetic_u128_shift_right_static_3: 48
Expand All @@ -1459,7 +1450,7 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_list_unsafe_u32_set_length_u32: 8
tasm_hashing_sample_indices_to_unsafe_list_loop: 3560
tasm_hashing_sample_indices_to_unsafe_list_process_top_function_body: 1440
tasm_list_higher_order_unsafe_u32_map_u32_to_u128_add_another_u128: 6062
tasm_list_higher_order_unsafe_u32_map_u32_to_u128_add_another_u128: 6052
tasm_list_unsafe_u32_length_long_u32: 8
tasm_list_unsafe_u32_new_u128: 66
tasm_list_higher_order_unsafe_u32_map_u32_to_u128_add_another_u128_loop: 5950
Expand All @@ -1480,11 +1471,11 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_list_higher_order_unsafe_u32_map_tasm_neptune_transaction_compute_commitment_loop: 377
tasm_neptune_transaction_compute_commitment: 228
tasm_neptune_mutator_set_commit: 26
tasm_list_unsafe_u32_set_element_pair_Lvoid_pointer_and_digestR: 58
tasm_list_unsafe_u32_set_element_tuple_ofstart_void-pointer_digest_ofend_: 58
tasm_list_higher_order_unsafe_u32_all_tasm_neptune_transaction_verify_aocl_membership: 12455
tasm_list_unsafe_u32_length_long_pair_Lvoid_pointer_and_digestR: 4
tasm_list_unsafe_u32_length_long_tuple_ofstart_void-pointer_digest_ofend_: 4
tasm_list_higher_order_unsafe_u32_all_tasm_neptune_transaction_verify_aocl_membership_loop: 12443
tasm_list_unsafe_u32_get_element_pair_Lvoid_pointer_and_digestR: 58
tasm_list_unsafe_u32_get_element_tuple_ofstart_void-pointer_digest_ofend_: 58
tasm_neptune_transaction_verify_aocl_membership: 12350
tasm_mmr_verify_from_memory_unsafe: 12232
tasm_mmr_leaf_index_to_mt_index_and_peak_index: 256
Expand All @@ -1505,4 +1496,4 @@ tasm_neptune_transaction_removal_records_integrity:
tasm_arithmetic_u64_div2: 1764
tasm_hashing_swap_digest: 784
tasm_hashing_eq_digest: 30
total: 132089
total: 55964
7 changes: 7 additions & 0 deletions src/models/blockchain/transaction/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::bail;
use get_size::GetSize;
use num_bigint::BigInt;
use num_traits::{CheckedSub, Signed, Zero};
use rand::{rngs::StdRng, Rng, SeedableRng};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{
fmt::Display,
Expand Down Expand Up @@ -216,6 +217,12 @@ impl From<u64> for Amount {
}
}

pub fn pseudorandom_amount(seed: [u8; 32]) -> Amount {
let mut rng: StdRng = SeedableRng::from_seed(seed);
let number: [u32; 4] = rng.gen();
Amount(U32s::new(number))
}

#[cfg(test)]
mod amount_tests {
use get_size::GetSize;
Expand Down
Loading
Loading