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

Macro for testing host function dispatch with bad inputs #1213

Merged
merged 6 commits into from
Nov 16, 2023

Conversation

jayz22
Copy link
Contributor

@jayz22 jayz22 commented Nov 15, 2023

What

Resolves #1155

Add a macro that

  • Generates synth-wasm for each host function
  • For each type which appears in any host function, pass in an invalid type and call the synth-wasm in a new test
  • For every object type argument of a host function, pass in an invalid object handle and call the synth-wasm in a new test

Catches and fixes three issues where invalid object handle isn't caught early enough: contract_event, require_auth, require_auth_for_args.

@jayz22 jayz22 requested review from graydon, sisuresh, dmkozh and a team as code owners November 15, 2023 03:12
@jayz22
Copy link
Contributor Author

jayz22 commented Nov 15, 2023

New tests generated:

cargo test --package soroban-env-host --lib -- test::dispatch --nocapture
   Compiling soroban-env-macros v20.0.0-rc2 (/Users/jay/Projects/rs-soroban-env/soroban-env-macros)
   Compiling soroban-env-common v20.0.0-rc2 (/Users/jay/Projects/rs-soroban-env/soroban-env-common)
   Compiling soroban-bench-utils v20.0.0-rc2 (/Users/jay/Projects/rs-soroban-env/soroban-bench-utils)
   Compiling soroban-synth-wasm v20.0.0-rc2 (/Users/jay/Projects/rs-soroban-env/soroban-synth-wasm)
   Compiling soroban-env-host v20.0.0-rc2 (/Users/jay/Projects/rs-soroban-env/soroban-env-host)
    Finished test [unoptimized + debuginfo] target(s) in 5.96s
     Running unittests src/lib.rs (target/debug/deps/soroban_env_host-2edb876499acf109)

running 112 tests
test test::dispatch::dispatch_with_wrong_arg_type_obj_cmp ... ok
test test::dispatch::dispatch_with_wrong_arg_type_contract_event ... ok
test test::dispatch::dispatch_with_wrong_arg_type_obj_to_i128_lo64 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_call ... ok
test test::dispatch::dispatch_with_wrong_arg_type_log_from_linear_memory ... ok
test test::dispatch::dispatch_with_wrong_arg_type_create_contract ... ok
test test::dispatch::dispatch_with_wrong_arg_type_obj_to_i256_hi_hi ... ok
test test::dispatch::dispatch_with_wrong_arg_type_fail_with_error ... ok
test test::dispatch::dispatch_with_wrong_arg_type_map_put ... ok
test test::dispatch::dispatch_with_wrong_arg_type_i256_val_to_be_bytes ... ok
test test::dispatch::dispatch_with_wrong_arg_type_duration_obj_to_u64 ... ok
test test::dispatch::invalid_object_handle_address_to_strkey_arg_0 ... ok
test test::dispatch::invalid_object_handle_authorize_as_curr_contract_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_append_arg_0 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_obj_to_u128_lo64 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_obj_to_u64 ... ok
test test::dispatch::invalid_object_handle_bytes_append_arg_1 ... ok
test test::dispatch::invalid_object_handle_bytes_copy_to_linear_memory_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_back_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_copy_from_linear_memory_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_front_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_del_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_insert_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_get_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_len_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_put_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_pop_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_push_arg_0 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_timepoint_obj_to_u64 ... ok
test test::dispatch::invalid_object_handle_call_arg_0 ... ok
test test::dispatch::invalid_object_handle_bytes_slice_arg_0 ... ok
test test::dispatch::invalid_object_handle_call_arg_2 ... ok
test test::dispatch::invalid_object_handle_compute_hash_keccak256_arg_0 ... ok
test test::dispatch::invalid_object_handle_compute_hash_sha256_arg_0 ... ok
test test::dispatch::invalid_object_handle_contract_event_arg_0 ... ok
test test::dispatch::invalid_object_handle_create_asset_contract_arg_0 ... ok
test test::dispatch::invalid_object_handle_create_contract_arg_1 ... ok
test test::dispatch::invalid_object_handle_create_contract_arg_2 ... ok
test test::dispatch::invalid_object_handle_create_contract_arg_0 ... ok
test test::dispatch::invalid_object_handle_deserialize_from_bytes_arg_0 ... ok
test test::dispatch::invalid_object_handle_extend_contract_instance_and_code_arg_0 ... ok
test test::dispatch::invalid_object_handle_get_asset_contract_id_arg_0 ... ok
test test::dispatch::invalid_object_handle_duration_obj_to_u64_arg_0 ... ok
test test::dispatch::invalid_object_handle_get_contract_id_arg_1 ... ok
test test::dispatch::invalid_object_handle_i256_val_from_be_bytes_arg_0 ... ok
test test::dispatch::invalid_object_handle_get_contract_id_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_del_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_has_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_get_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_keys_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_key_by_pos_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_len_arg_0 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_u256_val_to_be_bytes ... ok
test test::dispatch::invalid_object_handle_map_put_arg_0 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_symbol_copy_to_linear_memory ... ok
test test::dispatch::invalid_object_handle_map_unpack_to_linear_memory_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_val_by_pos_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_i128_lo64_arg_0 ... ok
test test::dispatch::invalid_object_handle_map_values_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_i256_hi_hi_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_i128_hi64_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_i256_hi_lo_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_i256_lo_lo_arg_0 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_u256_val_from_be_bytes ... ok
test test::dispatch::invalid_object_handle_obj_to_u128_hi64_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_u128_lo64_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_i64_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_i256_lo_hi_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_u256_hi_hi_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_u256_lo_hi_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_u256_hi_lo_arg_0 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_string_copy_to_linear_memory ... ok
test test::dispatch::invalid_object_handle_obj_to_u64_arg_0 ... ok
test test::dispatch::invalid_object_handle_obj_to_u256_lo_lo_arg_0 ... ok
test test::dispatch::invalid_object_handle_prng_reseed_arg_0 ... ok
test test::dispatch::invalid_object_handle_require_auth_for_args_arg_0 ... ok
test test::dispatch::invalid_object_handle_require_auth_for_args_arg_1 ... ok
test test::dispatch::invalid_object_handle_string_len_arg_0 ... ok
test test::dispatch::invalid_object_handle_prng_vec_shuffle_arg_0 ... ok
test test::dispatch::invalid_object_handle_require_auth_arg_0 ... ok
test test::dispatch::invalid_object_handle_symbol_copy_to_linear_memory_arg_0 ... ok
test test::dispatch::invalid_object_handle_string_copy_to_linear_memory_arg_0 ... ok
test test::dispatch::invalid_object_handle_symbol_len_arg_0 ... ok
test test::dispatch::invalid_object_handle_timepoint_obj_to_u64_arg_0 ... ok
test test::dispatch::invalid_object_handle_try_call_arg_0 ... ok
test test::dispatch::invalid_object_handle_try_call_arg_2 ... ok
test test::dispatch::invalid_object_handle_update_current_contract_wasm_arg_0 ... ok
test test::dispatch::invalid_object_handle_u256_val_from_be_bytes_arg_0 ... ok
test test::dispatch::invalid_object_handle_upload_wasm_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_append_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_back_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_binary_search_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_append_arg_1 ... ok
test test::dispatch::invalid_object_handle_vec_front_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_del_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_first_index_of_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_last_index_of_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_insert_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_get_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_len_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_pop_front_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_put_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_push_back_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_pop_back_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_push_front_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_slice_arg_0 ... ok
test test::dispatch::invalid_object_handle_vec_unpack_to_linear_memory_arg_0 ... ok
test test::dispatch::invalid_object_handle_verify_sig_ed25519_arg_0 ... ok
test test::dispatch::invalid_object_handle_verify_sig_ed25519_arg_2 ... ok
test test::dispatch::invalid_object_handle_verify_sig_ed25519_arg_1 ... ok
test test::dispatch::dispatch_with_wrong_arg_type_obj_to_u256_hi_hi ... ok
test test::dispatch::dispatch_with_wrong_arg_type_obj_to_i64 ... ok

test result: ok. 112 passed; 0 failed; 0 ignored; 0 measured; 230 filtered out; finished in 0.12s

Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I'm going to work on some followups to improve the integrity checking but I'm really happy to see improved input coverage like this, thanks!

@graydon graydon added this pull request to the merge queue Nov 16, 2023
Merged via the queue into stellar:main with commit b42eaf7 Nov 16, 2023
10 checks passed
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.

[test] type and argument checking on host function dispatch
2 participants