Skip to content

Commit

Permalink
Merge branch 'ray/vp-verify-masp-failure' (#942) into maint-0.12
Browse files Browse the repository at this point in the history
* ray/vp-verify-masp-failure:
  changelog: add #942
  vp_verify_masp: avoid panicking unwrap()s
  • Loading branch information
juped committed Dec 21, 2022
2 parents f6262aa + 97934a7 commit ddf4bf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/942-vp-verify-masp-failure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Avoid panicking unwrap()s in vp_verify_masp, to prevent crashing the node on
malformed transactions. ([#942](https://github.com/anoma/namada/pull/942))
20 changes: 12 additions & 8 deletions shared/src/vm/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,22 +1822,26 @@ where
EVAL: VpEvaluator,
CA: WasmCacheAccess,
{
use masp_primitives::transaction::Transaction;

use crate::types::token::Transfer;

let gas_meter = unsafe { env.ctx.gas_meter.get() };
let (tx_bytes, gas) = env
.memory
.read_bytes(tx_ptr, tx_len as _)
.map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?;
vp_host_fns::add_gas(gas_meter, gas)?;

let full_tx: Transfer =
BorshDeserialize::try_from_slice(tx_bytes.as_slice()).unwrap();
let shielded_tx: Transaction = full_tx.shielded.unwrap();
Ok(HostEnvResult::from(crate::ledger::masp::verify_shielded_tx(
&shielded_tx,
))
.to_i64())
BorshDeserialize::try_from_slice(tx_bytes.as_slice())
.map_err(vp_host_fns::RuntimeError::EncodingError)?;

match full_tx.shielded {
Some(shielded_tx) => Ok(HostEnvResult::from(
crate::ledger::masp::verify_shielded_tx(&shielded_tx),
)
.to_i64()),
None => Ok(HostEnvResult::Fail.to_i64()),
}
}

/// Log a string from exposed to the wasm VM Tx environment. The message will be
Expand Down

0 comments on commit ddf4bf1

Please sign in to comment.