Skip to content

Commit

Permalink
add publish checks
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Feb 21, 2024
1 parent 1122494 commit a8da2b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 0 additions & 1 deletion aptos-move/aptos-vm/src/verifier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0
pub(crate) mod event_validation;

pub(crate) mod module_init;
pub(crate) mod resource_groups;
pub mod transaction_arg_validation;
Expand Down
26 changes: 22 additions & 4 deletions aptos-move/framework/src/module_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,24 @@ pub struct AttributeValidationError {
pub attribute: u8,
}

pub fn is_valid_function_which_uses_randomness(
functions: &BTreeMap<Identifier, Function>,
fun: &str,
) -> Result<(), AttributeValidationError> {
if let Ok(ident_fun) = Identifier::new(fun) {
if let Some(f) = functions.get(&ident_fun) {
if f.is_entry {
return Ok(());
}
}
}

Check warning on line 358 in aptos-move/framework/src/module_metadata.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/framework/src/module_metadata.rs#L357-L358

Added lines #L357 - L358 were not covered by tests

Err(AttributeValidationError {
key: fun.to_string(),
attribute: KnownAttributeKind::UsesRandomness as u8,
})
}

pub fn is_valid_view_function(
functions: &BTreeMap<Identifier, Function>,
fun: &str,
Expand Down Expand Up @@ -429,10 +447,10 @@ pub fn verify_module_metadata(
for (fun, attrs) in &metadata.fun_attributes {
for attr in attrs {
if attr.is_view_function() {
is_valid_view_function(&functions, fun)?
};

if !attr.is_uses_randomness() && !attr.is_view_function() {
is_valid_view_function(&functions, fun)?;
} else if attr.is_uses_randomness() {
is_valid_function_which_uses_randomness(&functions, fun)?;
} else {
return Err(AttributeValidationError {
key: fun.clone(),
attribute: attr.kind,
Expand Down

0 comments on commit a8da2b5

Please sign in to comment.