Skip to content

Commit

Permalink
evil: fixes gas functions and error conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Nov 7, 2023
1 parent 6688ba1 commit e2c4f27
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
3 changes: 0 additions & 3 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ where
msg
)
}
self.wl_storage
.write_tx_hash(tx.header_hash())
.expect("Error while writing tx hash to storage");
}
}

Expand Down
5 changes: 1 addition & 4 deletions shared/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,9 @@ where
)?;

// Account for gas
shell_params.tx_gas_meter.add_wrapper_gas(tx_bytes)?;

// If wrapper was succesful, write inner tx hash to storage
shell_params
.tx_gas_meter
.add_tx_size_gas(tx_bytes)
.add_wrapper_gas(tx_bytes)
.map_err(|err| Error::GasError(err.to_string()))?;

Ok(changed_keys)
Expand Down
8 changes: 7 additions & 1 deletion shared/src/ledger/vp_host_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ pub fn get_tx_code_hash(
tx: &Tx,
sentinel: &mut VpSentinel,
) -> EnvResult<Option<Hash>> {
add_gas(gas_meter, HASH_LENGTH as u64 * MEMORY_ACCESS_GAS_PER_BYTE)?;
add_gas(
gas_meter,
HASH_LENGTH as u64 * MEMORY_ACCESS_GAS_PER_BYTE,
sentinel,
)?;
let hash = tx
.get_section(tx.code_sechash())
.and_then(|x| Section::code_sec(x.as_ref()))
Expand Down Expand Up @@ -337,6 +341,7 @@ pub fn get_tx_index(
add_gas(
gas_meter,
TX_INDEX_LENGTH as u64 * MEMORY_ACCESS_GAS_PER_BYTE,
sentinel,
)?;
Ok(*tx_index)
}
Expand All @@ -354,6 +359,7 @@ where
add_gas(
gas_meter,
ESTABLISHED_ADDRESS_BYTES_LEN as u64 * MEMORY_ACCESS_GAS_PER_BYTE,
sentinel,
)?;
Ok(storage.native_token.clone())
}
Expand Down
4 changes: 3 additions & 1 deletion shared/src/vm/wasm/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ where
.map_err(|e| Error::GasError(e.to_string()))?;
validate_untrusted_wasm(code).map_err(Error::ValidationError)?;

gas_meter.add_compiling_gas(tx_len)?;
gas_meter
.add_compiling_gas(tx_len)
.map_err(|e| Error::GasError(e.to_string()))?;
match wasm_cache.compile_or_fetch(code)? {
Some((module, store)) => Ok((module, store)),
None => Err(Error::NoCompiledWasmCode),
Expand Down

0 comments on commit e2c4f27

Please sign in to comment.