feat: ensure epoch matches type

When in epoch < 2.1, we should not see `CallableType` and in epoch
>= 2.1, we should not see `TraitReferenceType`.
This commit is contained in:
Brice Dobry
2022-12-19 17:00:25 -05:00
parent 3a5d8ef834
commit 2c2635f80d
2 changed files with 17 additions and 3 deletions

View File

@@ -183,12 +183,23 @@ impl DefinedFunction {
(
TypeSignature::TraitReferenceType(trait_identifier),
Value::Principal(PrincipalData::Contract(callee_contract_id)),
)
) if *env.epoch() < StacksEpochId::Epoch21 => {
// Argument is a trait reference, probably leading to a dynamic contract call
// We keep a reference of the mapping (var-name: (callee_contract_id, trait_id)) in the context.
// The code fetching and checking the trait is implemented in the contract_call eval function.
context.callable_contracts.insert(
name.clone(),
CallableData {
contract_identifier: callee_contract_id.clone(),
trait_identifier: Some(trait_identifier.clone()),
},
);
}
// Epoch >= 2.1 uses CallableType
| (
(
TypeSignature::CallableType(CallableSubtype::Trait(trait_identifier)),
Value::Principal(PrincipalData::Contract(callee_contract_id)),
) => {
) if *env.epoch() >= StacksEpochId::Epoch21 => {
// Argument is a trait reference, probably leading to a dynamic contract call
// We keep a reference of the mapping (var-name: (callee_contract_id, trait_id)) in the context.
// The code fetching and checking the trait is implemented in the contract_call eval function.

View File

@@ -641,6 +641,9 @@ impl TypeSignature {
}
}
NoType => Err(CheckErrors::CouldNotDetermineType),
TraitReferenceType(_) => {
unreachable!("TraitReferenceType should not be used in epoch v2.1")
}
_ => Ok(&other == self),
}
}