@@ -16,7 +16,7 @@ use crate::instance::{Instance, InstanceOptions};
16
16
use crate :: modules:: { CachedModule , FileSystemCache , InMemoryCache , PinnedMemoryCache } ;
17
17
use crate :: parsed_wasm:: ParsedWasm ;
18
18
use crate :: size:: Size ;
19
- use crate :: static_analysis:: has_ibc_entry_points ;
19
+ use crate :: static_analysis:: { ExportInfo , REQUIRED_IBC_EXPORTS } ;
20
20
use crate :: wasm_backend:: { compile, make_compiling_engine, make_runtime_engine} ;
21
21
22
22
const STATE_DIR : & str = "state" ;
@@ -117,7 +117,16 @@ pub struct Cache<A: BackendApi, S: Storage, Q: Querier> {
117
117
118
118
#[ derive( PartialEq , Eq , Debug ) ]
119
119
pub struct AnalysisReport {
120
+ /// `true` if and only if all [`REQUIRED_IBC_EXPORTS`] exist as exported functions.
121
+ /// This does not guarantee they are functional or even have the correct signatures.
120
122
pub has_ibc_entry_points : bool ,
123
+ /// `true` if the module has an `instantiate` export.
124
+ /// This does not guarantee it is functional or even has the correct signature.
125
+ pub has_instantiate_entry_point : bool ,
126
+ /// `true` if the module has a `migrate` export.
127
+ /// This does not guarantee it is functional or even has the correct signature.
128
+ pub has_migrate_entry_point : bool ,
129
+ /// The set of capabilities the contract requires.
121
130
pub required_capabilities : HashSet < String > ,
122
131
}
123
132
@@ -274,8 +283,14 @@ where
274
283
// Here we could use a streaming deserializer to slightly improve performance. However, this way it is DRYer.
275
284
let wasm = self . load_wasm ( checksum) ?;
276
285
let module = ParsedWasm :: parse ( & wasm) ?;
286
+ let exports = module. exported_function_names ( None ) ;
287
+
277
288
Ok ( AnalysisReport {
278
- has_ibc_entry_points : has_ibc_entry_points ( & module) ,
289
+ has_ibc_entry_points : REQUIRED_IBC_EXPORTS
290
+ . iter ( )
291
+ . all ( |required| exports. contains ( * required) ) ,
292
+ has_instantiate_entry_point : exports. contains ( "instantiate" ) ,
293
+ has_migrate_entry_point : exports. contains ( "migrate" ) ,
279
294
required_capabilities : required_capabilities_from_module ( & module) ,
280
295
} )
281
296
}
@@ -538,6 +553,7 @@ mod tests {
538
553
539
554
static CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/hackatom.wasm" ) ;
540
555
static IBC_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/ibc_reflect.wasm" ) ;
556
+ static EMPTY_CONTRACT : & [ u8 ] = include_bytes ! ( "../testdata/empty.wasm" ) ;
541
557
// Invalid because it doesn't contain required memory and exports
542
558
static INVALID_CONTRACT_WAT : & str = r#"(module
543
559
(type $t0 (func (param i32) (result i32)))
@@ -1289,6 +1305,8 @@ mod tests {
1289
1305
report1,
1290
1306
AnalysisReport {
1291
1307
has_ibc_entry_points: false ,
1308
+ has_instantiate_entry_point: true ,
1309
+ has_migrate_entry_point: true ,
1292
1310
required_capabilities: HashSet :: new( ) ,
1293
1311
}
1294
1312
) ;
@@ -1299,12 +1317,26 @@ mod tests {
1299
1317
report2,
1300
1318
AnalysisReport {
1301
1319
has_ibc_entry_points: true ,
1320
+ has_instantiate_entry_point: true ,
1321
+ has_migrate_entry_point: true ,
1302
1322
required_capabilities: HashSet :: from_iter( [
1303
1323
"iterator" . to_string( ) ,
1304
1324
"stargate" . to_string( )
1305
1325
] ) ,
1306
1326
}
1307
1327
) ;
1328
+
1329
+ let checksum3 = cache. save_wasm ( EMPTY_CONTRACT ) . unwrap ( ) ;
1330
+ let report3 = cache. analyze ( & checksum3) . unwrap ( ) ;
1331
+ assert_eq ! (
1332
+ report3,
1333
+ AnalysisReport {
1334
+ has_ibc_entry_points: false ,
1335
+ has_instantiate_entry_point: false ,
1336
+ has_migrate_entry_point: false ,
1337
+ required_capabilities: HashSet :: from( [ "iterator" . to_string( ) ] ) ,
1338
+ }
1339
+ ) ;
1308
1340
}
1309
1341
1310
1342
#[ test]
0 commit comments