Skip to content

Commit d0edaff

Browse files
Merge pull request #5339 from darthsiroftardis/ta-seed-check
Transaction acceptor check for seed value
2 parents 8410ef4 + 6f71f26 commit d0edaff

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

node/src/components/transaction_acceptor.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ mod tests;
66

77
use std::{collections::BTreeSet, fmt::Debug, sync::Arc};
88

9-
use casper_types::{contracts::ProtocolVersionMajor, ContractRuntimeTag};
9+
use casper_types::{
10+
contracts::ProtocolVersionMajor, ContractRuntimeTag, InvalidTransaction, InvalidTransactionV1,
11+
};
1012
use datasize::DataSize;
1113
use prometheus::Registry;
1214
use tracing::{debug, error, trace};
@@ -546,9 +548,23 @@ impl TransactionAcceptor {
546548
NextStep::CryptoValidation
547549
}
548550
},
549-
TransactionTarget::Native | TransactionTarget::Session { .. } => {
551+
TransactionTarget::Session {
552+
is_install_upgrade,
553+
runtime,
554+
..
555+
} => {
556+
if *is_install_upgrade && txn.is_v2_wasm() && runtime.seed().is_none() {
557+
return self.reject_transaction(
558+
effect_builder,
559+
*event_metadata,
560+
Error::InvalidTransaction(InvalidTransaction::V1(
561+
InvalidTransactionV1::MissingSeed,
562+
)),
563+
);
564+
}
550565
NextStep::CryptoValidation
551566
}
567+
TransactionTarget::Native => NextStep::CryptoValidation,
552568
},
553569
};
554570

node/src/components/transaction_acceptor/tests.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ enum TestScenario {
250250
ContractVersionExistance,
251251
),
252252
VmCasperV2ByPackageHash,
253+
VmCasperV2MissingSeedValue,
253254
}
254255

255256
impl TestScenario {
@@ -305,7 +306,8 @@ impl TestScenario {
305306
| TestScenario::RedelegateExceedingMaximumDelegation
306307
| TestScenario::DelegateExceedingMaximumDelegation
307308
| TestScenario::VmCasperV2ByPackageHash
308-
| TestScenario::V1ByPackage(..) => Source::Client,
309+
| TestScenario::V1ByPackage(..)
310+
| TestScenario::VmCasperV2MissingSeedValue => Source::Client,
309311
}
310312
}
311313

@@ -860,6 +862,20 @@ impl TestScenario {
860862
.unwrap();
861863
Transaction::from(txn)
862864
}
865+
TestScenario::VmCasperV2MissingSeedValue => {
866+
let transaction_runtime = TransactionRuntimeParams::VmCasperV2 {
867+
transferred_value: 3_000_000_000u64,
868+
seed: None,
869+
};
870+
let module_bytes = Bytes::from(vec![1]);
871+
let txn =
872+
TransactionV1Builder::new_session(true, module_bytes, transaction_runtime)
873+
.with_chain_name("casper-example")
874+
.with_secret_key(&secret_key)
875+
.build()
876+
.unwrap();
877+
Transaction::from(txn)
878+
}
863879
}
864880
}
865881

@@ -937,6 +953,7 @@ impl TestScenario {
937953
HashOrName::Name => true,
938954
}
939955
},
956+
TestScenario::VmCasperV2MissingSeedValue => false,
940957
}
941958
}
942959

@@ -961,7 +978,10 @@ impl TestScenario {
961978
}
962979

963980
fn is_v2_casper_vm(&self) -> bool {
964-
matches!(self, TestScenario::VmCasperV2ByPackageHash)
981+
matches!(
982+
self,
983+
TestScenario::VmCasperV2ByPackageHash | TestScenario::VmCasperV2MissingSeedValue
984+
)
965985
}
966986
}
967987

@@ -1692,6 +1712,14 @@ async fn run_transaction_acceptor_without_timeout(
16921712
..
16931713
})
16941714
),
1715+
TestScenario::VmCasperV2MissingSeedValue => {
1716+
matches!(
1717+
event,
1718+
Event::TransactionAcceptorAnnouncement(
1719+
TransactionAcceptorAnnouncement::InvalidTransaction { .. }
1720+
)
1721+
)
1722+
}
16951723
TestScenario::V1ByPackage(
16961724
hash_or_name,
16971725
entity_version,
@@ -3063,3 +3091,17 @@ async fn should_succeed_when_asking_for_active_exact_version() {
30633091
.await;
30643092
assert!(result.is_ok())
30653093
}
3094+
3095+
#[tokio::test]
3096+
async fn should_reject_vm2_installs_without_seed_value() {
3097+
let result = run_transaction_acceptor(TestScenario::VmCasperV2MissingSeedValue).await;
3098+
assert!(
3099+
matches!(
3100+
result,
3101+
Err(super::Error::InvalidTransaction(InvalidTransaction::V1(
3102+
InvalidTransactionV1::MissingSeed
3103+
)))
3104+
),
3105+
"{result:?}"
3106+
);
3107+
}

0 commit comments

Comments
 (0)