@@ -77,6 +77,12 @@ const TABLE_SIZE_LIMIT: u32 = 2500; // entries
77
77
/// when a user accidentally includes wasm-bindgen, they get a bunch of unsupported imports.
78
78
const MAX_IMPORTS : usize = 100 ;
79
79
80
+ const MAX_FUNCTIONS : usize = 10000 ;
81
+
82
+ const MAX_FUNCTION_PARAMS : usize = 50 ;
83
+
84
+ const MAX_FUNCTION_RESULTS : usize = 1 ;
85
+
80
86
/// Checks if the data is valid wasm and compatibility with the CosmWasm API (imports and exports)
81
87
pub fn check_wasm ( wasm_code : & [ u8 ] , available_capabilities : & HashSet < String > ) -> VmResult < ( ) > {
82
88
let module = ParsedWasm :: parse ( wasm_code) ?;
@@ -87,6 +93,7 @@ pub fn check_wasm(wasm_code: &[u8], available_capabilities: &HashSet<String>) ->
87
93
check_wasm_exports ( & module) ?;
88
94
check_wasm_imports ( & module, SUPPORTED_IMPORTS ) ?;
89
95
check_wasm_capabilities ( & module, available_capabilities) ?;
96
+ check_wasm_functions ( & module) ?;
90
97
91
98
Ok ( ( ) )
92
99
}
@@ -234,6 +241,25 @@ fn check_wasm_capabilities(
234
241
Ok ( ( ) )
235
242
}
236
243
244
+ fn check_wasm_functions ( module : & ParsedWasm ) -> VmResult < ( ) > {
245
+ if module. function_count > MAX_FUNCTIONS {
246
+ return Err ( VmError :: static_validation_err ( format ! (
247
+ "Wasm contract contains more than {MAX_FUNCTIONS} functions"
248
+ ) ) ) ;
249
+ }
250
+ if module. max_func_params > MAX_FUNCTION_PARAMS {
251
+ return Err ( VmError :: static_validation_err ( format ! (
252
+ "Wasm contract contains function with more than {MAX_FUNCTION_PARAMS} parameters"
253
+ ) ) ) ;
254
+ }
255
+ if module. max_func_results > MAX_FUNCTION_RESULTS {
256
+ return Err ( VmError :: static_validation_err ( format ! (
257
+ "Wasm contract contains function with more than {MAX_FUNCTION_RESULTS} results"
258
+ ) ) ) ;
259
+ }
260
+ Ok ( ( ) )
261
+ }
262
+
237
263
#[ cfg( test) ]
238
264
mod tests {
239
265
use super :: * ;
0 commit comments