Skip to content

Commit

Permalink
shielded_token: env agnostic VP
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Sep 12, 2024
1 parent a75ad66 commit 4b472ba
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 169 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ fn masp(c: &mut Criterion) {
let gas_meter = RefCell::new(VpGasMeter::new_from_tx_meter(
&TxGasMeter::new(u64::MAX),
));
let masp = MaspVp::new(Ctx::new(
let ctx = Ctx::new(
&Address::Internal(InternalAddress::Masp),
&shell_read.state,
&signed_tx.tx,
Expand All @@ -644,14 +644,15 @@ fn masp(c: &mut Criterion) {
&keys_changed,
&verifiers,
shell_read.vp_wasm_cache.clone(),
));
);

b.iter(|| {
assert!(
masp.validate_tx(
MaspVp::validate_tx(
&ctx,
&signed_tx.to_ref(),
masp.ctx.keys_changed,
masp.ctx.verifiers,
ctx.keys_changed,
ctx.verifiers,
)
.is_ok()
);
Expand Down
33 changes: 20 additions & 13 deletions crates/node/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use namada_vm::wasm::{TxCache, VpCache};
use namada_vm::{self, wasm, WasmCacheAccess};
use namada_vote_ext::EthereumTxData;
use namada_vp::native_vp::NativeVp;
use namada_vp::state::ReadConversionState;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use smooth_operator::checked;
use thiserror::Error;
Expand Down Expand Up @@ -340,7 +341,11 @@ pub(crate) fn dispatch_inner_txs<'a, S, D, H, CA>(
tx_wasm_cache: &'a mut TxCache<CA>,
) -> std::result::Result<ExtendedTxResult<Error>, DispatchError>
where
S: 'static + State<D = D, H = H> + Read<Err = state::Error> + Sync,
S: 'static
+ State<D = D, H = H>
+ Read<Err = state::Error>
+ ReadConversionState
+ Sync,
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
CA: 'static + WasmCacheAccess + Sync,
Expand Down Expand Up @@ -457,6 +462,7 @@ where
+ State<D = D, H = H>
+ Read<Err = state::Error>
+ TxWrites
+ ReadConversionState
+ Sync,
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
Expand Down Expand Up @@ -531,6 +537,7 @@ where
+ StorageRead
+ TxWrites
+ Read<Err = state::Error>
+ ReadConversionState
+ Sync,
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
Expand Down Expand Up @@ -693,6 +700,7 @@ where
+ State<D = D, H = H>
+ StorageRead
+ Read<Err = state::Error>
+ ReadConversionState
+ Sync,
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
Expand Down Expand Up @@ -870,6 +878,7 @@ where
+ State<D = D, H = H>
+ StorageRead
+ Read<Err = state::Error>
+ ReadConversionState
+ Sync,
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
Expand Down Expand Up @@ -940,7 +949,7 @@ fn apply_wasm_tx<S, D, H, CA>(
shell_params: ShellParams<'_, S, D, H, CA>,
) -> Result<BatchedTxResult>
where
S: 'static + State<D = D, H = H> + Sync,
S: 'static + State<D = D, H = H> + ReadConversionState + Sync,
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
CA: 'static + WasmCacheAccess + Sync,
Expand Down Expand Up @@ -1124,7 +1133,7 @@ fn check_vps<S, CA>(
}: CheckVps<'_, S, CA>,
) -> Result<VpsResult>
where
S: 'static + State + Sync,
S: 'static + ReadConversionState + State + Sync,
CA: 'static + WasmCacheAccess + Sync,
{
let (verifiers, keys_changed) = state
Expand Down Expand Up @@ -1161,7 +1170,7 @@ fn execute_vps<S, CA>(
vp_wasm_cache: &mut VpCache<CA>,
) -> Result<(VpsResult, namada_sdk::gas::Gas)>
where
S: 'static + State + Sync,
S: 'static + ReadConversionState + State + Sync,
CA: 'static + WasmCacheAccess + Sync,
{
let vps_result = verifiers
Expand Down Expand Up @@ -1274,15 +1283,13 @@ where
)
.map_err(Error::NativeVpError)
}
InternalAddress::Masp => {
let masp = MaspVp::new(ctx);
masp.validate_tx(
batched_tx,
&keys_changed,
&verifiers,
)
.map_err(Error::NativeVpError)
}
InternalAddress::Masp => MaspVp::validate_tx(
&ctx,
batched_tx,
&keys_changed,
&verifiers,
)
.map_err(Error::NativeVpError),
InternalAddress::EthBridge => {
EthBridgeVp::validate_tx(
&ctx,
Expand Down
16 changes: 7 additions & 9 deletions crates/sdk/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ pub type MultitokenVp<'ctx, CTX> = token::vp::MultitokenVp<
>;

/// Native MASP VP
pub type MaspVp<'a, S, CA> = token::vp::MaspVp<
'a,
S,
VpCache<CA>,
Eval<S, CA>,
ParamsPreStore<'a, S, CA>,
GovPreStore<'a, S, CA>,
IbcPostStore<'a, S, CA>,
TokenPreStore<'a, S, CA>,
pub type MaspVp<'ctx, CTX> = token::vp::MaspVp<
'ctx,
CTX,
parameters::Store<<CTX as VpEnv<'ctx>>::Pre>,
governance::Store<<CTX as VpEnv<'ctx>>::Pre>,
ibc::Store<<CTX as VpEnv<'ctx>>::Post>,
token::Store<<CTX as VpEnv<'ctx>>::Pre>,
token::Transfer,
>;

Expand Down
2 changes: 1 addition & 1 deletion crates/shielded_token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namada_migrations = { path = "../migrations", optional = true }
namada_state = { path = "../state" }
namada_systems = { path = "../systems" }
namada_tx = { path = "../tx" }
namada_vp = { path = "../vp" }
namada_vp_env = { path = "../vp_env" }
namada_wallet = { path = "../wallet", optional = true }

async-trait.workspace = true
Expand Down
Loading

0 comments on commit 4b472ba

Please sign in to comment.