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

Audit/entry store packing verification #40

Merged
merged 8 commits into from
Oct 25, 2023

Conversation

JordyRo1
Copy link
Contributor

Entry and Checkpoint Store packing overflow verification. The verification is done leveraging the difference between felt252 (252 bits) and u256 ( 256 bits). We store the max felt252 in a u256 in order to make the comparison: https://cairo-by-example.com/examples/felt252/

Audit specification:
  - Add checks in pack of EntryStorePacking to avoid bit overflow
@github-actions
Copy link

Output from Compare Snapshot:

****IMPROVEMENTS****
None


****WORSENED****
pragma::tests::test_oracle::get_data_for_sources 17385350 --> 17450870 0.38 %
pragma::tests::test_oracle::get_data_median 22325050 --> 22390570 0.29 %
pragma::tests::test_oracle::get_data_median_for_sources 16184120 --> 16249640 0.40 %
pragma::tests::test_oracle::get_data_median_for_sources_should_fail_if_wrong_sources 15539160 --> 15604680 0.42 %
pragma::tests::test_oracle::test_data_entry 17381830 --> 17447350 0.38 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found 15209530 --> 15275050 0.43 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_2 15209530 --> 15275050 0.43 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_3 15209530 --> 15275050 0.43 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_no_expiration_time_associated 15611270 --> 15676790 0.42 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_data_types 15592860 --> 15658380 0.42 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_sources 15683940 --> 15749460 0.42 %
pragma::tests::test_oracle::test_get_admin_address 15102480 --> 15168000 0.43 %
pragma::tests::test_oracle::test_get_data 25731290 --> 25796810 0.25 %
pragma::tests::test_oracle::test_get_data_median_multi 20411230 --> 20476750 0.32 %
pragma::tests::test_oracle::test_get_data_with_USD_hop_should_fail_if_wrong_id 16863850 --> 16929370 0.39 %
pragma::tests::test_oracle::test_get_data_with_usd_hop 20492730 --> 20558250 0.32 %
pragma::tests::test_oracle::test_get_decimals 16084490 --> 16150010 0.41 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found 15241580 --> 15307100 0.43 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found_2 15241580 --> 15307100 0.43 %
pragma::tests::test_oracle::test_get_last_checkpoint_before 19268750 --> 19345190 0.40 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_timestamp_too_old 18784880 --> 18861320 0.41 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_wrong_data_type 18784880 --> 18861320 0.41 %
pragma::tests::test_oracle::test_max_publish_multiple_entries 44864590 --> 45099370 0.52 %
pragma::tests::test_oracle::test_publish_multiple_entries 23369300 --> 23473040 0.44 %
pragma::tests::test_oracle::test_set_checkpoint 19093370 --> 19169810 0.40 %
pragma::tests::test_oracle::test_set_checkpoint_should_fail_if_wrong_data_type 15901520 --> 15972500 0.45 %
pragma::tests::test_summary_stats::test_set_future_checkpoint 48561510 --> 48681630 0.25 %
pragma::tests::test_summary_stats::test_summary_stats_mean_mean 43362170 --> 43449530 0.20 %
pragma::tests::test_summary_stats::test_summary_stats_mean_median 43362170 --> 43449530 0.20 %
pragma::tests::test_yield_curve::test_yield_curve_computation 16117100 --> 16149860 0.20 %


Overall gas change: performance degradation, gas consumption +0.33 %

@github-actions
Copy link

Output from Compare Snapshot:

****IMPROVEMENTS****
None


****WORSENED****
pragma::tests::test_oracle::get_data_for_sources 17385350 --> 17444870 0.34 %
pragma::tests::test_oracle::get_data_median 22325050 --> 22384570 0.27 %
pragma::tests::test_oracle::get_data_median_for_sources 16184120 --> 16243640 0.37 %
pragma::tests::test_oracle::get_data_median_for_sources_should_fail_if_wrong_sources 15539160 --> 15598680 0.38 %
pragma::tests::test_oracle::test_data_entry 17381830 --> 17441350 0.34 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found 15209530 --> 15269050 0.39 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_2 15209530 --> 15269050 0.39 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_3 15209530 --> 15269050 0.39 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_no_expiration_time_associated 15611270 --> 15670790 0.38 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_data_types 15592860 --> 15652380 0.38 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_sources 15683940 --> 15743460 0.38 %
pragma::tests::test_oracle::test_get_admin_address 15102480 --> 15162000 0.39 %
pragma::tests::test_oracle::test_get_data 25731290 --> 25790810 0.23 %
pragma::tests::test_oracle::test_get_data_median_multi 20411230 --> 20470750 0.29 %
pragma::tests::test_oracle::test_get_data_with_USD_hop_should_fail_if_wrong_id 16863850 --> 16923370 0.35 %
pragma::tests::test_oracle::test_get_data_with_usd_hop 20492730 --> 20552250 0.29 %
pragma::tests::test_oracle::test_get_decimals 16084490 --> 16144010 0.37 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found 15241580 --> 15301100 0.39 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found_2 15241580 --> 15301100 0.39 %
pragma::tests::test_oracle::test_get_last_checkpoint_before 19268750 --> 19338190 0.36 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_timestamp_too_old 18784880 --> 18854320 0.37 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_wrong_data_type 18784880 --> 18854320 0.37 %
pragma::tests::test_oracle::test_max_publish_multiple_entries 44864590 --> 45077870 0.48 %
pragma::tests::test_oracle::test_publish_multiple_entries 23369300 --> 23463540 0.40 %
pragma::tests::test_oracle::test_set_checkpoint 19093370 --> 19162810 0.36 %
pragma::tests::test_oracle::test_set_checkpoint_should_fail_if_wrong_data_type 15901520 --> 15966000 0.41 %
pragma::tests::test_summary_stats::test_set_future_checkpoint 48561510 --> 48670630 0.22 %
pragma::tests::test_summary_stats::test_summary_stats_mean_mean 43362170 --> 43441530 0.18 %
pragma::tests::test_summary_stats::test_summary_stats_mean_median 43362170 --> 43441530 0.18 %
pragma::tests::test_yield_curve::test_yield_curve_computation 16117100 --> 16146860 0.18 %


Overall gas change: performance degradation, gas consumption +0.30 %

@github-actions
Copy link

Output from Compare Snapshot:

****IMPROVEMENTS****
None


****WORSENED****
pragma::tests::test_oracle::get_data_for_sources 17385350 --> 17503526 0.68 %
pragma::tests::test_oracle::get_data_median 22325050 --> 22443226 0.53 %
pragma::tests::test_oracle::get_data_median_for_sources 16184120 --> 16302296 0.73 %
pragma::tests::test_oracle::get_data_median_for_sources_should_fail_if_wrong_sources 15539160 --> 15657336 0.76 %
pragma::tests::test_oracle::test_add_currency_should_fail_if_currency_id_null 15380090 --> 15498266 0.77 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_base_currency_do_not_corresponds 15525060 --> 15643236 0.76 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_quote_currency_do_not_corresponds 15550060 --> 15668236 0.76 %
pragma::tests::test_oracle::test_data_entry 17381830 --> 17500006 0.68 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found 15209530 --> 15327706 0.78 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_2 15209530 --> 15327706 0.78 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_3 15209530 --> 15327706 0.78 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_no_expiration_time_associated 15611270 --> 15729446 0.76 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_data_types 15592860 --> 15711036 0.76 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_sources 15683940 --> 15802116 0.75 %
pragma::tests::test_oracle::test_get_admin_address 15102480 --> 15220656 0.78 %
pragma::tests::test_oracle::test_get_data 25731290 --> 25849466 0.46 %
pragma::tests::test_oracle::test_get_data_median_multi 20411230 --> 20529406 0.58 %
pragma::tests::test_oracle::test_get_data_with_USD_hop_should_fail_if_wrong_id 16863850 --> 16982026 0.70 %
pragma::tests::test_oracle::test_get_data_with_usd_hop 20492730 --> 20610906 0.58 %
pragma::tests::test_oracle::test_get_decimals 16084490 --> 16202666 0.73 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found 15241580 --> 15359756 0.78 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found_2 15241580 --> 15359756 0.78 %
pragma::tests::test_oracle::test_get_last_checkpoint_before 19268750 --> 19386926 0.61 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_timestamp_too_old 18784880 --> 18903056 0.63 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_wrong_data_type 18784880 --> 18903056 0.63 %
pragma::tests::test_oracle::test_max_publish_multiple_entries 44864590 --> 45291954 0.95 %
pragma::tests::test_oracle::test_publish_multiple_entries 23369300 --> 23557912 0.81 %
pragma::tests::test_oracle::test_set_checkpoint 19093370 --> 19211546 0.62 %
pragma::tests::test_oracle::test_set_checkpoint_should_fail_if_wrong_data_type 15901520 --> 16019696 0.74 %
pragma::tests::test_summary_stats::test_set_future_checkpoint 48561510 --> 48699382 0.28 %
pragma::tests::test_summary_stats::test_summary_stats_mean_mean 43362170 --> 43421258 0.14 %
pragma::tests::test_summary_stats::test_summary_stats_mean_median 43362170 --> 43421258 0.14 %
pragma::tests::test_yield_curve::test_yield_curve_computation 16117100 --> 16176188 0.37 %


Overall gas change: performance degradation, gas consumption +0.56 %

@github-actions
Copy link

Output from Compare Snapshot:

****IMPROVEMENTS****
None


****WORSENED****
pragma::tests::test_oracle::get_data_for_sources 17385350 --> 17503526 0.68 %
pragma::tests::test_oracle::get_data_median 22325050 --> 22443226 0.53 %
pragma::tests::test_oracle::get_data_median_for_sources 16184120 --> 16302296 0.73 %
pragma::tests::test_oracle::get_data_median_for_sources_should_fail_if_wrong_sources 15539160 --> 15657336 0.76 %
pragma::tests::test_oracle::test_add_currency_should_fail_if_currency_id_null 15380090 --> 15498266 0.77 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_base_currency_do_not_corresponds 15525060 --> 15643236 0.76 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_quote_currency_do_not_corresponds 15550060 --> 15668236 0.76 %
pragma::tests::test_oracle::test_data_entry 17381830 --> 17500006 0.68 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found 15209530 --> 15327706 0.78 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_2 15209530 --> 15327706 0.78 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_3 15209530 --> 15327706 0.78 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_no_expiration_time_associated 15611270 --> 15729446 0.76 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_data_types 15592860 --> 15711036 0.76 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_sources 15683940 --> 15802116 0.75 %
pragma::tests::test_oracle::test_get_admin_address 15102480 --> 15220656 0.78 %
pragma::tests::test_oracle::test_get_data 25731290 --> 25849466 0.46 %
pragma::tests::test_oracle::test_get_data_median_multi 20411230 --> 20529406 0.58 %
pragma::tests::test_oracle::test_get_data_with_USD_hop_should_fail_if_wrong_id 16863850 --> 16982026 0.70 %
pragma::tests::test_oracle::test_get_data_with_usd_hop 20492730 --> 20610906 0.58 %
pragma::tests::test_oracle::test_get_decimals 16084490 --> 16202666 0.73 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found 15241580 --> 15359756 0.78 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found_2 15241580 --> 15359756 0.78 %
pragma::tests::test_oracle::test_get_last_checkpoint_before 19268750 --> 19386926 0.61 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_timestamp_too_old 18784880 --> 18903056 0.63 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_wrong_data_type 18784880 --> 18903056 0.63 %
pragma::tests::test_oracle::test_max_publish_multiple_entries 44864590 --> 45291954 0.95 %
pragma::tests::test_oracle::test_publish_multiple_entries 23369300 --> 23557912 0.81 %
pragma::tests::test_oracle::test_set_checkpoint 19093370 --> 19211546 0.62 %
pragma::tests::test_oracle::test_set_checkpoint_should_fail_if_wrong_data_type 15901520 --> 16019696 0.74 %
pragma::tests::test_summary_stats::test_set_future_checkpoint 48561510 --> 48699382 0.28 %
pragma::tests::test_summary_stats::test_summary_stats_mean_mean 43362170 --> 43421258 0.14 %
pragma::tests::test_summary_stats::test_summary_stats_mean_median 43362170 --> 43421258 0.14 %
pragma::tests::test_yield_curve::test_yield_curve_computation 16117100 --> 16176188 0.37 %


Overall gas change: performance degradation, gas consumption +0.56 %

@github-actions
Copy link

Output from Compare Snapshot:

****IMPROVEMENTS****
None


****WORSENED****
pragma::tests::test_oracle::get_data_for_sources 17385350 --> 17529854 0.83 %
pragma::tests::test_oracle::get_data_median 22325050 --> 22469554 0.65 %
pragma::tests::test_oracle::get_data_median_for_sources 16184120 --> 16328624 0.89 %
pragma::tests::test_oracle::get_data_median_for_sources_should_fail_if_wrong_sources 15539160 --> 15683664 0.93 %
pragma::tests::test_oracle::test_add_currency_should_fail_if_currency_id_null 15380090 --> 15524594 0.94 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_base_currency_do_not_corresponds 15525060 --> 15669564 0.93 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_quote_currency_do_not_corresponds 15550060 --> 15694564 0.93 %
pragma::tests::test_oracle::test_data_entry 17381830 --> 17526334 0.83 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found 15209530 --> 15354034 0.95 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_2 15209530 --> 15354034 0.95 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_3 15209530 --> 15354034 0.95 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_no_expiration_time_associated 15611270 --> 15755774 0.93 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_data_types 15592860 --> 15737364 0.93 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_sources 15683940 --> 15828444 0.92 %
pragma::tests::test_oracle::test_get_admin_address 15102480 --> 15246984 0.96 %
pragma::tests::test_oracle::test_get_data 25731290 --> 25875794 0.56 %
pragma::tests::test_oracle::test_get_data_median_multi 20411230 --> 20555734 0.71 %
pragma::tests::test_oracle::test_get_data_with_USD_hop_should_fail_if_wrong_id 16863850 --> 17008354 0.86 %
pragma::tests::test_oracle::test_get_data_with_usd_hop 20492730 --> 20637234 0.71 %
pragma::tests::test_oracle::test_get_decimals 16084490 --> 16228994 0.90 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found 15241580 --> 15386084 0.95 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found_2 15241580 --> 15386084 0.95 %
pragma::tests::test_oracle::test_get_last_checkpoint_before 19268750 --> 19413254 0.75 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_timestamp_too_old 18784880 --> 18929384 0.77 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_wrong_data_type 18784880 --> 18929384 0.77 %
pragma::tests::test_oracle::test_max_publish_multiple_entries 44864590 --> 45386296 1.16 %
pragma::tests::test_oracle::test_publish_multiple_entries 23369300 --> 23599598 0.99 %
pragma::tests::test_oracle::test_set_checkpoint 19093370 --> 19237874 0.76 %
pragma::tests::test_oracle::test_set_checkpoint_should_fail_if_wrong_data_type 15901520 --> 16046024 0.91 %
pragma::tests::test_summary_stats::test_set_future_checkpoint 48561510 --> 48730098 0.35 %
pragma::tests::test_summary_stats::test_summary_stats_mean_mean 43362170 --> 43434422 0.17 %
pragma::tests::test_summary_stats::test_summary_stats_mean_median 43362170 --> 43434422 0.17 %
pragma::tests::test_yield_curve::test_yield_curve_computation 16117100 --> 16189352 0.45 %


Overall gas change: performance degradation, gas consumption +0.68 %

@JordyRo1
Copy link
Contributor Author

The objective here is to make sure that the timestamp, the volume and the value fits within the range defined in the packing system: 32 for the timestamp, 100 for the volume and 120 for the price. To do so I suggest using the bitwise AND operation before packing the elements. Let's take the example of the timestamp: if we can assert that timestamp == timestamp & 0xffffffff, we are then sure that the timestamp fits within the 32 bits range. I think it's a good operation optimisation too.

@github-actions
Copy link

Output from Compare Snapshot:

****IMPROVEMENTS****
None


****WORSENED****
pragma::tests::test_oracle::get_data_for_sources 17613830 --> 17758334 0.82 %
pragma::tests::test_oracle::get_data_median 22553530 --> 22698034 0.64 %
pragma::tests::test_oracle::get_data_median_for_sources 16412600 --> 16557104 0.88 %
pragma::tests::test_oracle::get_data_median_for_sources_should_fail_if_wrong_sources 15767640 --> 15912144 0.92 %
pragma::tests::test_oracle::test_add_currency_should_fail_if_currency_id_null 15608570 --> 15753074 0.93 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_base_currency_do_not_corresponds 15753540 --> 15898044 0.92 %
pragma::tests::test_oracle::test_add_pair_should_panic_if_quote_currency_do_not_corresponds 15778540 --> 15923044 0.92 %
pragma::tests::test_oracle::test_data_entry 17610310 --> 17754814 0.82 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found 15438010 --> 15582514 0.94 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_2 15438010 --> 15582514 0.94 %
pragma::tests::test_oracle::test_data_entry_should_fail_if_not_found_3 15438010 --> 15582514 0.94 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_no_expiration_time_associated 15839750 --> 15984254 0.91 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_data_types 15821340 --> 15965844 0.91 %
pragma::tests::test_oracle::test_data_median_multi_should_fail_if_wrong_sources 15912420 --> 16056924 0.91 %
pragma::tests::test_oracle::test_get_admin_address 15330960 --> 15475464 0.94 %
pragma::tests::test_oracle::test_get_data 25959770 --> 26104274 0.56 %
pragma::tests::test_oracle::test_get_data_median_multi 20639710 --> 20784214 0.70 %
pragma::tests::test_oracle::test_get_data_with_USD_hop_should_fail_if_wrong_id 17092330 --> 17236834 0.85 %
pragma::tests::test_oracle::test_get_data_with_usd_hop 20721210 --> 20865714 0.70 %
pragma::tests::test_oracle::test_get_decimals 16312970 --> 16457474 0.89 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found 15470060 --> 15614564 0.93 %
pragma::tests::test_oracle::test_get_decimals_should_fail_if_not_found_2 15470060 --> 15614564 0.93 %
pragma::tests::test_oracle::test_get_last_checkpoint_before 19497230 --> 19641734 0.74 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_timestamp_too_old 19013360 --> 19157864 0.76 %
pragma::tests::test_oracle::test_get_last_checkpoint_before_should_fail_if_wrong_data_type 19013360 --> 19157864 0.76 %
pragma::tests::test_oracle::test_max_publish_multiple_entries 45713310 --> 46235016 1.14 %
pragma::tests::test_oracle::test_publish_multiple_entries 23735060 --> 23965358 0.97 %
pragma::tests::test_oracle::test_set_checkpoint 19321850 --> 19466354 0.75 %
pragma::tests::test_oracle::test_set_checkpoint_should_fail_if_wrong_data_type 16130000 --> 16274504 0.90 %
pragma::tests::test_summary_stats::test_set_future_checkpoint 48837070 --> 49005658 0.35 %
pragma::tests::test_summary_stats::test_summary_stats_mean_mean 43480410 --> 43552662 0.17 %
pragma::tests::test_summary_stats::test_summary_stats_mean_median 43480410 --> 43552662 0.17 %
pragma::tests::test_yield_curve::test_yield_curve_computation 16231340 --> 16303592 0.45 %


Overall gas change: performance degradation, gas consumption +0.67 %

@EvolveArt EvolveArt merged commit 9e721f4 into main Oct 25, 2023
6 checks passed
@EvolveArt EvolveArt deleted the audit/entry-store-packing-verification branch October 25, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants