Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

laudiacay/actors review F24 #1323

Merged
merged 4 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions vm/address/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ thiserror = "1.0"
serde = { version = "1.0", features = ["derive"] }
forest_json_utils = { version = "0.1", optional = true }
once_cell = "1.7.2"
lazy_static = "1.4.0"

[features]
json = ["forest_json_utils"]
Expand Down
18 changes: 18 additions & 0 deletions vm/address/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ pub const SECP_PUB_LEN: usize = 65;
/// BLS public key length used for validation of BLS addresses.
pub const BLS_PUB_LEN: usize = 48;

lazy_static::lazy_static! {
static ref BLS_ZERO_ADDR_BYTES: BLSPublicKey = {
let bz_addr = Address::from_str("f3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaby2smx7a");
if let Ok(Address {payload: Payload::BLS(pubkey), ..}) = bz_addr {
pubkey
} else {
panic!("failed to parse BLS address from provided BLS_ZERO_ADDR string")
}
};
}

/// Length of the checksum hash for string encodings.
pub const CHECKSUM_HASH_LEN: usize = 4;

Expand Down Expand Up @@ -119,6 +130,13 @@ impl Address {
})
}

pub fn is_bls_zero_address(&self) -> bool {
match self.payload {
Payload::BLS(payload_bytes) => payload_bytes == *BLS_ZERO_ADDR_BYTES,
_ => false,
}
}

/// Returns protocol for Address
pub fn protocol(&self) -> Protocol {
Protocol::from(self.payload)
Expand Down
6 changes: 6 additions & 0 deletions vm/interpreter/src/default_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ where
) -> Result<(ActorState, Address), ActorError> {
self.charge_gas(self.price_list().on_create_actor())?;

if addr.is_bls_zero_address() && self.network_version() >= NetworkVersion::V10 {
return Err(
actor_error!(ErrIllegalArgument; "cannot create the bls zero address actor"),
);
}

let addr_id = (*self.state)
.borrow_mut()
.register_new_address(addr)
Expand Down