File tree 3 files changed +23
-6
lines changed
3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,12 @@ impl<'a> ExtendedChecker<'a> {
93
93
) ;
94
94
}
95
95
}
96
+ if fun. get_parameters ( ) . len ( ) > 1 {
97
+ self . env . error (
98
+ & fun. get_loc ( ) ,
99
+ "`init_module` function can only take at most one parameter" ,
100
+ ) ;
101
+ }
96
102
if fun. get_return_count ( ) > 0 {
97
103
self . env . error (
98
104
& fun. get_loc ( ) ,
Original file line number Diff line number Diff line change @@ -581,10 +581,14 @@ impl MoveVM {
581
581
// with the general verify_module above.
582
582
if init_function. is_ok ( ) {
583
583
if verify_module_init_function ( module) . is_ok ( ) {
584
- let args: Vec < Vec < u8 > > = senders
585
- . iter ( )
586
- . map ( |s| MoveValue :: Signer ( * s) . simple_serialize ( ) . unwrap ( ) )
587
- . collect ( ) ;
584
+ let args: Vec < Vec < u8 > > = if init_function. unwrap ( ) . parameters . is_empty ( ) {
585
+ vec ! [ ]
586
+ } else {
587
+ senders
588
+ . iter ( )
589
+ . map ( |s| MoveValue :: Signer ( * s) . simple_serialize ( ) . unwrap ( ) )
590
+ . collect ( )
591
+ } ;
588
592
589
593
// first execution does not execute `charge_call`, so need to record call here
590
594
gas_meter. record_call ( & module. self_id ( ) ) ;
Original file line number Diff line number Diff line change @@ -31,15 +31,22 @@ pub(crate) fn verify_module_init_function(module: &CompiledModule) -> PartialVMR
31
31
}
32
32
33
33
let fhandle = module. function_handle_at ( fdef. function ) ;
34
- let parameters = module. signature_at ( fhandle. parameters ) ;
35
34
35
+ // check init_module has no return
36
36
let return_ = module. signature_at ( fhandle. return_ ) ;
37
-
38
37
if !return_. 0 . is_empty ( ) {
39
38
return Err ( PartialVMError :: new ( StatusCode :: VERIFICATION_ERROR )
40
39
. with_message ( "module_init_function should not return" . to_string ( ) ) ) ;
41
40
}
42
41
42
+ // check init_module has exactly one argument
43
+ let parameters = module. signature_at ( fhandle. parameters ) ;
44
+ if parameters. 0 . len ( ) > 1 {
45
+ return Err ( PartialVMError :: new ( StatusCode :: VERIFICATION_ERROR )
46
+ . with_message ( "module_init_function can only take at most one parameter" . to_string ( ) ) ) ;
47
+ }
48
+
49
+ // check init_module has only signer arguments
43
50
let non_signer_tokens = parameters
44
51
. 0
45
52
. iter ( )
You can’t perform that action at this time.
0 commit comments