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/evm: Fix incorrect return value trimming in queries #1509

Merged
merged 1 commit into from Sep 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime-sdk/modules/evm/src/lib.rs
Expand Up @@ -485,7 +485,7 @@ impl<Cfg: Config> Module<Cfg> {
) -> (evm::ExitReason, Vec<u8>),
C: TxContext,
{
let is_query = ctx.is_check_only();
let is_query = ctx.is_check_only() || ctx.is_simulation();
let cfg = Cfg::evm_config(estimate_gas);
let gas_limit: u64 = <C::Runtime as Runtime>::Core::remaining_tx_gas(ctx);
let gas_price: primitive_types::U256 = ctx.tx_auth_info().fee.gas_price().into();
Expand Down
21 changes: 20 additions & 1 deletion runtime-sdk/modules/evm/src/test.rs
Expand Up @@ -28,7 +28,6 @@ use oasis_runtime_sdk::{
use crate::{
derive_caller,
mock::{decode_reverted, decode_reverted_raw, load_contract_bytecode, EvmSigner, QueryOptions},
state,
types::{self, H160},
Config, Genesis, Module as EVMModule,
};
Expand Down Expand Up @@ -1074,4 +1073,24 @@ fn test_return_value_limits() {
} else {
panic!("call should revert");
}

// Make sure that in query context, the return value is not trimmed.
let mut ctx =
mock.create_ctx_for_runtime::<EVMRuntime<EVMConfig>>(context::Mode::CheckTx, true);

let result = signer
.query_evm_opts(
&mut ctx,
contract_address,
"testSuccess",
&[],
&[],
Default::default(),
)
.expect("query should succeed");

assert_eq!(result.len(), 1120, "result should not be trimmed");
// Actual payload is ABI-encoded so the raw result starts at offset 64.
assert_eq!(result[64], 0xFF, "result should be correct");
assert_eq!(result[1023], 0x42, "result should be correct");
}