Skip to content

Commit 036107b

Browse files
committed
Add info about ibc_v2 entrypoint to AnalysisReport (#2401)
1 parent e240f16 commit 036107b

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

packages/vm/src/cache.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use crate::instance::{Instance, InstanceOptions};
1919
use crate::modules::{CachedModule, FileSystemCache, InMemoryCache, PinnedMemoryCache};
2020
use crate::parsed_wasm::ParsedWasm;
2121
use crate::size::Size;
22-
use crate::static_analysis::{Entrypoint, ExportInfo, REQUIRED_IBC_EXPORTS};
22+
use crate::static_analysis::{
23+
Entrypoint, ExportInfo, REQUIRED_IBC_EXPORTS, REQUIRED_IBC_V2_EXPORT,
24+
};
2325
use crate::wasm_backend::{compile, make_compiling_engine};
2426

2527
const STATE_DIR: &str = "state";
@@ -100,6 +102,9 @@ pub struct AnalysisReport {
100102
/// `true` if and only if all [`REQUIRED_IBC_EXPORTS`] exist as exported functions.
101103
/// This does not guarantee they are functional or even have the correct signatures.
102104
pub has_ibc_entry_points: bool,
105+
/// `true` if and only if all [`REQUIRED_IBC_V2_EXPORT`] exist as exported functions.
106+
/// This does not guarantee they are functional or even have the correct signatures.
107+
pub has_ibc_v2_entry_points: bool,
103108
/// A set of all entrypoints that are exported by the contract.
104109
pub entrypoints: BTreeSet<Entrypoint>,
105110
/// The set of capabilities the contract requires.
@@ -337,6 +342,7 @@ where
337342
has_ibc_entry_points: REQUIRED_IBC_EXPORTS
338343
.iter()
339344
.all(|required| exports.contains(required.as_ref())),
345+
has_ibc_v2_entry_points: exports.contains(REQUIRED_IBC_V2_EXPORT.as_ref()),
340346
entrypoints,
341347
required_capabilities: required_capabilities_from_module(&module)
342348
.into_iter()
@@ -624,6 +630,7 @@ mod tests {
624630

625631
static CONTRACT: &[u8] = include_bytes!("../testdata/hackatom.wasm");
626632
static IBC_CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
633+
static IBC_V2_CONTRACT: &[u8] = include_bytes!("../testdata/ibcv2.wasm");
627634
static EMPTY_CONTRACT: &[u8] = include_bytes!("../testdata/empty.wasm");
628635
// Invalid because it doesn't contain required memory and exports
629636
static INVALID_CONTRACT_WAT: &str = r#"(module
@@ -658,6 +665,17 @@ mod tests {
658665
}
659666
}
660667

668+
fn make_ibc_v2_testing_options() -> CacheOptions {
669+
let mut capabilities = default_capabilities();
670+
capabilities.insert("ibcv2".into());
671+
CacheOptions {
672+
base_dir: TempDir::new().unwrap().into_path(),
673+
available_capabilities: capabilities,
674+
memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE,
675+
instance_memory_limit_bytes: TESTING_MEMORY_LIMIT,
676+
}
677+
}
678+
661679
/// Takes an instance and executes it
662680
fn test_hackatom_instance_execution<S, Q>(instance: &mut Instance<MockApi, S, Q>)
663681
where
@@ -1444,6 +1462,7 @@ mod tests {
14441462
report1,
14451463
AnalysisReport {
14461464
has_ibc_entry_points: false,
1465+
has_ibc_v2_entry_points: false,
14471466
entrypoints: BTreeSet::from([
14481467
E::Instantiate,
14491468
E::Migrate,
@@ -1465,6 +1484,7 @@ mod tests {
14651484
report2,
14661485
AnalysisReport {
14671486
has_ibc_entry_points: true,
1487+
has_ibc_v2_entry_points: false,
14681488
entrypoints: ibc_contract_entrypoints,
14691489
required_capabilities: BTreeSet::from_iter([
14701490
"iterator".to_string(),
@@ -1480,6 +1500,7 @@ mod tests {
14801500
report3,
14811501
AnalysisReport {
14821502
has_ibc_entry_points: false,
1503+
has_ibc_v2_entry_points: false,
14831504
entrypoints: BTreeSet::new(),
14841505
required_capabilities: BTreeSet::from(["iterator".to_string()]),
14851506
contract_migrate_version: None,
@@ -1499,11 +1520,32 @@ mod tests {
14991520
report4,
15001521
AnalysisReport {
15011522
has_ibc_entry_points: false,
1523+
has_ibc_v2_entry_points: false,
15021524
entrypoints: BTreeSet::new(),
15031525
required_capabilities: BTreeSet::from(["iterator".to_string()]),
15041526
contract_migrate_version: Some(21),
15051527
}
15061528
);
1529+
1530+
let cache: Cache<MockApi, MockStorage, MockQuerier> =
1531+
unsafe { Cache::new(make_ibc_v2_testing_options()).unwrap() };
1532+
let checksum5 = cache.store_code(IBC_V2_CONTRACT, true, true).unwrap();
1533+
let report5 = cache.analyze(&checksum5).unwrap();
1534+
let mut ibc_v2_contract_entrypoints = BTreeSet::from([E::Instantiate, E::Query]);
1535+
ibc_v2_contract_entrypoints.extend([REQUIRED_IBC_V2_EXPORT]);
1536+
assert_eq!(
1537+
report5,
1538+
AnalysisReport {
1539+
has_ibc_entry_points: false,
1540+
has_ibc_v2_entry_points: true,
1541+
entrypoints: ibc_v2_contract_entrypoints,
1542+
required_capabilities: BTreeSet::from_iter([
1543+
"iterator".to_string(),
1544+
"ibcv2".to_string()
1545+
]),
1546+
contract_migrate_version: None,
1547+
}
1548+
);
15071549
}
15081550

15091551
#[test]

packages/vm/src/static_analysis.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub const REQUIRED_IBC_EXPORTS: &[Entrypoint] = &[
5858
Entrypoint::IbcPacketTimeout,
5959
];
6060

61+
pub const REQUIRED_IBC_V2_EXPORT: &Entrypoint = &Entrypoint::IBCv2PacketReceive;
62+
6163
/// A trait that allows accessing shared functionality of `parity_wasm::elements::Module`
6264
/// and `wasmer::Module` in a shared fashion.
6365
pub trait ExportInfo {

packages/vm/testdata/ibcv2.wasm

183 KB
Binary file not shown.

0 commit comments

Comments
 (0)