Skip to content

Commit 63556f1

Browse files
committed
Restrict internal APIs of all actors (#809)
1 parent 05dad67 commit 63556f1

File tree

9 files changed

+21
-7
lines changed

9 files changed

+21
-7
lines changed

actors/cron/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

44
use fil_actors_runtime::runtime::{ActorCode, Runtime};
5-
use fil_actors_runtime::{actor_error, cbor, ActorError, SYSTEM_ACTOR_ADDR};
5+
use fil_actors_runtime::{actor_error, cbor, restrict_internal_api, ActorError, SYSTEM_ACTOR_ADDR};
66

77
use fvm_ipld_encoding::tuple::*;
88
use fvm_ipld_encoding::RawBytes;
@@ -83,6 +83,7 @@ impl ActorCode for Actor {
8383
where
8484
RT: Runtime,
8585
{
86+
restrict_internal_api(rt, method)?;
8687
match FromPrimitive::from_u64(method) {
8788
Some(Method::Constructor) => {
8889
Self::constructor(rt, cbor::deserialize_params(params)?)?;

actors/cron/tests/cron_actor_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ fn epoch_tick_with_entries() {
114114
}
115115

116116
fn construct_and_verify(rt: &mut MockRuntime, params: &ConstructorParams) {
117+
rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR);
117118
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
118119
let ret = rt.call::<CronActor>(1, &RawBytes::serialize(&params).unwrap()).unwrap();
119120
assert_eq!(RawBytes::default(), ret);

actors/paych/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use fil_actors_runtime::runtime::builtins::Type;
55
use fil_actors_runtime::runtime::{ActorCode, Runtime};
66
use fil_actors_runtime::{
7-
actor_error, cbor, resolve_to_actor_id, ActorDowncast, ActorError, Array,
7+
actor_error, cbor, resolve_to_actor_id, restrict_internal_api, ActorDowncast, ActorError, Array,
88
};
99
use fvm_ipld_blockstore::Blockstore;
1010
use fvm_ipld_encoding::RawBytes;
@@ -324,6 +324,7 @@ impl ActorCode for Actor {
324324
where
325325
RT: Runtime,
326326
{
327+
restrict_internal_api(rt, method)?;
327328
match FromPrimitive::from_u64(method) {
328329
Some(Method::Constructor) => {
329330
Self::constructor(rt, cbor::deserialize_params(params)?)?;

actors/paych/tests/paych_actor_test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ mod paych_constructor {
108108
#[test]
109109
fn actor_doesnt_exist_test() {
110110
let mut rt = construct_runtime();
111+
rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR);
111112
rt.expect_validate_caller_type(vec![Type::Init]);
112113
let params = ConstructorParams {
113114
to: Address::new_id(TEST_PAYCH_ADDR),
@@ -226,6 +227,7 @@ mod paych_constructor {
226227
ExitCode::OK,
227228
);
228229

230+
rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR);
229231
rt.expect_validate_caller_type(vec![Type::Init]);
230232
let params = ConstructorParams { from: non_id_addr, to: to_addr };
231233
expect_abort(
@@ -263,6 +265,7 @@ mod paych_constructor {
263265
ExitCode::OK,
264266
);
265267

268+
rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR);
266269
rt.expect_validate_caller_type(vec![Type::Init]);
267270
let params = ConstructorParams { from: from_addr, to: non_id_addr };
268271
expect_abort(
@@ -1201,6 +1204,7 @@ fn require_add_new_lane(rt: &mut MockRuntime, param: LaneParams) -> SignedVouche
12011204

12021205
fn construct_and_verify(rt: &mut MockRuntime, sender: Address, receiver: Address) {
12031206
let params = ConstructorParams { from: sender, to: receiver };
1207+
rt.set_caller(*INIT_ACTOR_CODE_ID, INIT_ACTOR_ADDR);
12041208
rt.expect_validate_caller_type(vec![Type::Init]);
12051209
call(rt, METHOD_CONSTRUCTOR, &RawBytes::serialize(&params).unwrap());
12061210
rt.verify();

actors/power/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use ext::init;
99
use fil_actors_runtime::runtime::builtins::Type;
1010
use fil_actors_runtime::runtime::{ActorCode, Runtime};
1111
use fil_actors_runtime::{
12-
actor_error, cbor, make_map_with_root_and_bitwidth, ActorDowncast, ActorError, Multimap,
13-
CRON_ACTOR_ADDR, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
12+
actor_error, cbor, make_map_with_root_and_bitwidth, restrict_internal_api, ActorDowncast,
13+
ActorError, Multimap, CRON_ACTOR_ADDR, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
1414
};
1515
use fvm_ipld_encoding::RawBytes;
1616
use fvm_shared::address::Address;
@@ -625,6 +625,7 @@ impl ActorCode for Actor {
625625
where
626626
RT: Runtime,
627627
{
628+
restrict_internal_api(rt, method)?;
628629
match FromPrimitive::from_u64(method) {
629630
Some(Method::Constructor) => {
630631
Self::constructor(rt)?;

actors/power/tests/harness/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub struct Harness {
101101

102102
impl Harness {
103103
pub fn construct(&self, rt: &mut MockRuntime) {
104+
rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR);
104105
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
105106
rt.call::<PowerActor>(Method::Constructor as MethodNum, &RawBytes::default()).unwrap();
106107
rt.verify()

actors/reward/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use fil_actors_runtime::runtime::{ActorCode, Runtime};
55
use fil_actors_runtime::{
6-
actor_error, cbor, ActorError, BURNT_FUNDS_ACTOR_ADDR, EXPECTED_LEADERS_PER_EPOCH,
7-
STORAGE_POWER_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
6+
actor_error, cbor, restrict_internal_api, ActorError, BURNT_FUNDS_ACTOR_ADDR,
7+
EXPECTED_LEADERS_PER_EPOCH, STORAGE_POWER_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
88
};
99

1010
use fvm_ipld_encoding::RawBytes;
@@ -223,6 +223,7 @@ impl ActorCode for Actor {
223223
where
224224
RT: Runtime,
225225
{
226+
restrict_internal_api(rt, method)?;
226227
match FromPrimitive::from_u64(method) {
227228
Some(Method::Constructor) => {
228229
let param: Option<BigIntDe> = cbor::deserialize_params(params)?;

actors/reward/tests/reward_actor_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ fn construct_and_verify(curr_power: &StoragePower) -> MockRuntime {
340340
caller_type: *SYSTEM_ACTOR_CODE_ID,
341341
..Default::default()
342342
};
343+
rt.set_caller(*SYSTEM_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR);
343344
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
344345
let ret = rt
345346
.call::<RewardActor>(

actors/system/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use num_derive::FromPrimitive;
1111
use num_traits::FromPrimitive;
1212

1313
use fil_actors_runtime::runtime::{ActorCode, Runtime};
14-
use fil_actors_runtime::{actor_error, ActorContext, ActorError, AsActorError, SYSTEM_ACTOR_ADDR};
14+
use fil_actors_runtime::{
15+
actor_error, restrict_internal_api, ActorContext, ActorError, AsActorError, SYSTEM_ACTOR_ADDR,
16+
};
1517

1618
#[cfg(feature = "fil-actor")]
1719
fil_actors_runtime::wasm_trampoline!(Actor);
@@ -73,6 +75,7 @@ impl ActorCode for Actor {
7375
where
7476
RT: Runtime,
7577
{
78+
restrict_internal_api(rt, method)?;
7679
match FromPrimitive::from_u64(method) {
7780
Some(Method::Constructor) => {
7881
Self::constructor(rt)?;

0 commit comments

Comments
 (0)