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

[1.0] Update payloadless contract to avoid UB in shift operator. #684

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

greg7mdp
Copy link
Contributor

@greg7mdp greg7mdp commented Sep 3, 2024

Hopefully resolves #425.

Issue #425 reports a rare test failure with performance_test_basic_read_only_trxs where we see a wasm exception when running one of the 50 identical transactions:

,"except":{"code":3070002,"name":"wasm_execution_error","message":"Runtime Error Processing WASM","stack":[{"context":{"level":"error","file":"eos-vm.cpp","line":165,"method":"apply","hostname":"","thread_name":"read-0","timestamp":"2024-07-27T01:22:38.694"},"format":"access violation","data":{}}

The contract used in the test (payloadless) calls operator<<() with a rhs value greater than the number of bits in lhs, which is UB.

This PR corrects this UB whith the hope that it might resolves the issue.

Is the contract code optimized out?

Looking at the log when running the test, I see:

info  2024-09-03T12:18:47.649 trx_gener trx_generator.cpp:272         setup                ] Initial action packed data ${index}: 
info  2024-09-03T12:18:47.649 trx_gener trx_generator.cpp:275         setup                ] Populate initial transaction.
info  2024-09-03T12:18:47.649 trx_gener trx_generator.cpp:279         setup                ] Setup p2p transaction provider
info  2024-09-03T12:18:47.649 trx_gener trx_generator.cpp:282         setup                ] Update each trx to qualify as unique and fresh timestamps and update each action with unique generated account name if necessary, re-sign trx, and send each updated transactions via p2p transaction provider
info  2024-09-03T12:18:52.549 trx_gener trx_provider.cpp:119          disconnect           ] disconnect waiting on ack - sent 50 | acked 49 | waited 0
info  2024-09-03T12:18:52.549 trx_gener trx_provider.cpp:119          disconnect           ] disconnect waiting on ack - sent 50 | acked 49 | waited 0
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:292         tear_down            ] Sent transactions: 50
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:293         tear_down            ] Tear down p2p transaction provider
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:296         tear_down            ] Stop Generation.
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:342         stop_generation      ] Stopping transaction generation
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:345         stop_generation      ] 50 transactions executed, 0.00000000000000000us / transaction
info  2024-09-03T12:18:53.550 trx_gener main.cpp:226                  main                 ] Exiting main SUCCESS
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:292         tear_down            ] Sent transactions: 50
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:293         tear_down            ] Tear down p2p transaction provider
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:296         tear_down            ] Stop Generation.
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:342         stop_generation      ] Stopping transaction generation
info  2024-09-03T12:18:53.550 trx_gener trx_generator.cpp:345         stop_generation      ] 50 transactions executed, 0.00000000000000000us / transaction
info  2024-09-03T12:18:53.550 trx_gener main.cpp:226                  main                 ] Exiting main SUCCESS

The times of 0.00000000000000000us / transaction seem suspicious to me. Possibly the code is optimized out?

void payloadless::doitslow() {
   print("Im a payloadless slow action");

   for (size_t p = 2; p <= cpu_prime_max; p += 1) {
      if (is_prime(p) && is_mersenne_prime(p)) {
         // We need to keep an eye on this to make sure it doesn't get optimized out. So far so good.
         //eosio::print_f(" %u", p);
      }
   }
}

I uncommented out the eosio::print_f(" %u", p); in the contract, but didn't see any significant difference in the log output.

@greg7mdp greg7mdp requested review from heifner and linh2931 September 3, 2024 12:34
@heifner
Copy link
Member

heifner commented Sep 3, 2024

The times of 0.00000000000000000us / transaction seem suspicious to me. Possibly the code is optimized out?

Bug in trx_generator. _total_us is never updated.

ilog("${d} transactions executed, ${t}us / transaction", ("d", _txcount)("t", _total_us / (double) _txcount));

@heifner heifner changed the title Update payloadless contract to avoid UB in shift operator. [1.0] Update payloadless contract to avoid UB in shift operator. Sep 3, 2024
@heifner heifner linked an issue Sep 3, 2024 that may be closed by this pull request
@greg7mdp greg7mdp merged commit 21cec1f into release/1.0 Sep 3, 2024
36 checks passed
@greg7mdp greg7mdp deleted the gh_425 branch September 3, 2024 14:17
@ericpassmore
Copy link
Contributor

Note:start
group: STABILITY
category: TEST
summary: Updates variable in test contract to unsigned integer to prevent overflow.
Note:end

@arhag arhag added this to the Spring v1.0.0 milestone Sep 4, 2024
@ericpassmore ericpassmore added the test-instability tag issues for flaky tests, high priority to address label Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test-instability tag issues for flaky tests, high priority to address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failure: performance_test_basic_read_only_trxs
5 participants