From 07a894e537db6b2db925bdaf3fcfbc6fe3bf2b93 Mon Sep 17 00:00:00 2001 From: George Mitenkov Date: Wed, 21 Feb 2024 17:03:55 +0000 Subject: [PATCH] add publish checks --- aptos-move/framework/src/module_metadata.rs | 26 +++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/aptos-move/framework/src/module_metadata.rs b/aptos-move/framework/src/module_metadata.rs index 79d0ee8e4eb06..664218b8a81e3 100644 --- a/aptos-move/framework/src/module_metadata.rs +++ b/aptos-move/framework/src/module_metadata.rs @@ -345,6 +345,24 @@ pub struct AttributeValidationError { pub attribute: u8, } +pub fn is_valid_function_which_uses_randomness( + functions: &BTreeMap, + 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(()); + } + } + } + + Err(AttributeValidationError { + key: fun.to_string(), + attribute: KnownAttributeKind::UsesRandomness as u8, + }) +} + pub fn is_valid_view_function( functions: &BTreeMap, fun: &str, @@ -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,