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

runtime-sdk/modules/contracts: Fix subcall dispatch #1066

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

kostko
Copy link
Member

@kostko kostko commented Aug 3, 2022

Previously various gas and fee checks were performed even for internal
subcalls (e.g. when smart contracts called into other modules) which
was wrong and also caused failures due to minimum gas price not being
met (the fee is always set to zero for subcalls).

@kostko kostko added bug Something isn't working m:contracts Module: contracts labels Aug 3, 2022
@kostko kostko linked an issue Aug 3, 2022 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Aug 3, 2022

Codecov Report

Merging #1066 (6bde461) into main (35b1adb) will decrease coverage by 1.37%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1066      +/-   ##
==========================================
- Coverage   68.17%   66.80%   -1.38%     
==========================================
  Files         128      127       -1     
  Lines       11101    11000     -101     
==========================================
- Hits         7568     7348     -220     
- Misses       3501     3620     +119     
  Partials       32       32              
Impacted Files Coverage Δ
runtime-sdk/modules/contracts/src/results.rs 71.90% <100.00%> (+8.56%) ⬆️
runtime-sdk/modules/contracts/src/test.rs 97.93% <100.00%> (+0.13%) ⬆️
runtime-sdk/src/context.rs 79.27% <100.00%> (+0.79%) ⬆️
runtime-sdk/src/modules/core/mod.rs 72.87% <100.00%> (-0.15%) ⬇️
contract-sdk/specs/token/oas20/src/lib.rs 0.00% <0.00%> (-98.24%) ⬇️
contract-sdk/specs/token/oas20/src/helpers.rs 0.00% <0.00%> (-84.57%) ⬇️
runtime-sdk/src/dispatcher.rs 26.47% <0.00%> (-0.29%) ⬇️
contract-sdk/specs/token/oas20/src/types.rs
runtime-sdk/src/modules/accounts/mod.rs 81.72% <0.00%> (+0.26%) ⬆️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@kostko kostko force-pushed the kostko/fix/subcall-dispatch-feechecks branch 3 times, most recently from 0b59482 to 1d42a37 Compare August 8, 2022 10:12
Copy link
Contributor

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

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

need to ask about simulation

@@ -513,7 +513,9 @@ impl Runtime for ContractRuntime {
}

#[test]
fn test_hello_contract_subcalls() {
fn test_hello_contract_subcalls_overflow() {
Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ apparently this was always a stack overflow test. this renames it to something more descriptive. in the same change, we're adding a new non-stack-overflow test with the old name

};
ctx.with_tx(0, 0, tx, |mut tx_ctx, call| {
let result = Contracts::tx_call(&mut tx_ctx, cbor::from_value(call.body).unwrap())
.expect("call should succeed");
Copy link
Contributor

Choose a reason for hiding this comment

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

ℹ️ same test as above except once: true and it succeeds

runtime-sdk/src/modules/core/mod.rs Outdated Show resolved Hide resolved

// Skip additional checks/gas payment for internally generated transactions.
if ctx.is_internal() && !ctx.is_simulation() {
return Ok(());
Copy link
Contributor

Choose a reason for hiding this comment

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

if things later get more complex, we should move subsets of the checking logic, e.g. the gas price checking and signature verification gas use, to helper functions and call them inside if blocks instead of early returning

Previously various gas and fee checks were performed even for internal
subcalls (e.g. when smart contracts called into other modules) which
was wrong and also caused failures due to minimum gas price not being
met (the fee is always set to zero for subcalls).
@kostko kostko force-pushed the kostko/fix/subcall-dispatch-feechecks branch from 1d42a37 to 6bde461 Compare August 8, 2022 18:41
Copy link
Contributor

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

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

explicit internal flag

@kostko kostko merged commit 98c3fba into main Aug 9, 2022
@kostko kostko deleted the kostko/fix/subcall-dispatch-feechecks branch August 9, 2022 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working m:contracts Module: contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime-sdk: Unable to transfer tokens from a contract to an address
2 participants