Skip to content

Commit 91ff9fa

Browse files
geoff-vballarajasekZenGround0
authored
fix: Add runtime caller validation for change_beneficiary (#761)
* Add runtime caller validation for change_beneficiary * Miner tests: expect_validate_caller_any for calls to change_beneficiary * Test VM fix: Fail if caller isn't validated Co-authored-by: Aayush <arajasek94@gmail.com> Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>
1 parent 2f10a80 commit 91ff9fa

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

actors/miner/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,6 +3297,7 @@ impl Actor {
32973297
BS: Blockstore,
32983298
RT: Runtime<BS>,
32993299
{
3300+
rt.validate_immediate_caller_accept_any()?;
33003301
let caller = rt.message().caller();
33013302
let new_beneficiary =
33023303
Address::new_id(rt.resolve_address(&params.new_beneficiary).ok_or_else(|| {

actors/miner/tests/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,10 +2266,12 @@ impl ActorHarness {
22662266
new_expiration: beneficiary_term.expiration,
22672267
};
22682268
let raw_bytes = &RawBytes::serialize(param).unwrap();
2269+
rt.expect_validate_caller_any();
22692270
rt.call::<Actor>(Method::ChangeBeneficiary as u64, raw_bytes)?;
22702271
rt.verify();
22712272

22722273
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, beneficiary_id_addr);
2274+
rt.expect_validate_caller_any();
22732275
rt.call::<Actor>(Method::ChangeBeneficiary as u64, raw_bytes)?;
22742276
rt.verify();
22752277

@@ -2284,6 +2286,7 @@ impl ActorHarness {
22842286
beneficiary_change: &BeneficiaryChange,
22852287
expect_beneficiary_addr: Option<Address>,
22862288
) -> Result<RawBytes, ActorError> {
2289+
rt.expect_validate_caller_any();
22872290
rt.set_address_actor_type(
22882291
beneficiary_change.beneficiary_addr.clone(),
22892292
*ACCOUNT_ACTOR_CODE_ID,

test_vm/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use fil_actor_power::{Actor as PowerActor, Method as MethodPower, State as Power
1414
use fil_actor_reward::{Actor as RewardActor, State as RewardState};
1515
use fil_actor_system::{Actor as SystemActor, State as SystemState};
1616
use fil_actor_verifreg::{Actor as VerifregActor, State as VerifRegState};
17+
use fil_actors_runtime::actor_error;
1718
use fil_actors_runtime::cbor::serialize;
1819
use fil_actors_runtime::runtime::builtins::Type;
1920
use fil_actors_runtime::runtime::{
@@ -671,7 +672,8 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
671672
// call target actor
672673
let to_actor = self.v.get_actor(to_addr).unwrap();
673674
let params = self.msg.params.clone();
674-
let res = match ACTOR_TYPES.get(&to_actor.code).expect("Target actor is not a builtin") {
675+
let mut res = match ACTOR_TYPES.get(&to_actor.code).expect("Target actor is not a builtin")
676+
{
675677
Type::Account => AccountActor::invoke_method(self, self.msg.method, &params),
676678
Type::Cron => CronActor::invoke_method(self, self.msg.method, &params),
677679
Type::Init => InitActor::invoke_method(self, self.msg.method, &params),
@@ -686,9 +688,13 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
686688
// Type::EVM => panic!("no EVM"),
687689
Type::DataCap => DataCapActor::invoke_method(self, self.msg.method, &params),
688690
};
691+
if res.is_ok() && !self.caller_validated {
692+
res = Err(actor_error!(assertion_failed, "failed to validate caller"));
693+
}
689694
if res.is_err() {
690695
self.v.rollback(prior_root)
691696
};
697+
692698
res
693699
}
694700
}
@@ -754,6 +760,7 @@ impl<'invocation, 'bs> Runtime<&'bs MemoryBlockstore> for InvocationCtx<'invocat
754760
"caller double validated".to_string(),
755761
));
756762
}
763+
self.caller_validated = true;
757764
for addr in addresses {
758765
if *addr == self.msg.from {
759766
return Ok(());
@@ -775,6 +782,7 @@ impl<'invocation, 'bs> Runtime<&'bs MemoryBlockstore> for InvocationCtx<'invocat
775782
"caller double validated".to_string(),
776783
));
777784
}
785+
self.caller_validated = true;
778786
let to_match = ACTOR_TYPES.get(&self.v.get_actor(self.msg.from).unwrap().code).unwrap();
779787
if types.into_iter().any(|t| *t == *to_match) {
780788
return Ok(());

0 commit comments

Comments
 (0)