Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Papierski committed Aug 17, 2023
1 parent e009bed commit 0ddcf85
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 44 deletions.
1 change: 1 addition & 0 deletions execution_engine/src/engine_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,7 @@ fn should_charge_for_errors_in_wasm(execution_result: &ExecutionResult) -> bool
| ExecError::NoActiveContractVersions(_)
| ExecError::InvalidContractVersion(_)
| ExecError::NoSuchMethod(_)
| ExecError::AbstractMethod(_)
| ExecError::KeyIsNotAURef(_)
| ExecError::UnexpectedStoredValueVariant
| ExecError::LockedContract(_)
Expand Down
3 changes: 3 additions & 0 deletions execution_engine/src/execution/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ pub enum Error {
/// Contract does not have specified entry point.
#[error("No such method: {}", _0)]
NoSuchMethod(String),
/// Contract does
#[error("Error calling an abstract entry point: {}", _0)]
AbstractMethod(String),
/// Error processing WASM bytes.
#[error("Wasm preprocessing error: {}", _0)]
WasmPreprocessing(PreprocessingError),
Expand Down
23 changes: 10 additions & 13 deletions execution_engine/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,16 @@ where
// Session code can't be called from Contract code for security reasons.
Err(Error::InvalidContext)
}
(EntryPointType::Install, EntryPointType::Session) => {
// Session code can't be called from Installer code for security reasons.
Err(Error::InvalidContext)
}
(EntryPointType::Session, EntryPointType::Session) => {
// Session code called from session reuses current base key
Ok(self.context.get_entity_address())
}
(EntryPointType::Session, EntryPointType::Contract)
| (EntryPointType::Contract, EntryPointType::Contract) => Ok(contract_hash.into()),

_ => {
// Any other combination (installer, normal, etc.) is a contract context.
Ok(contract_hash.into())
Expand Down Expand Up @@ -1228,11 +1231,7 @@ where
self.context.entity().named_keys().clone(),
self.context.entity().extract_access_rights(contract_hash),
),
EntryPointType::Contract => (
contract.named_keys().clone(),
contract.extract_access_rights(contract_hash),
),
EntryPointType::Install | EntryPointType::Normal => (
EntryPointType::Contract | EntryPointType::Install => (
contract.named_keys().clone(),
contract.extract_access_rights(contract_hash),
),
Expand All @@ -1255,12 +1254,10 @@ where
contract.contract_package_hash(),
contract_hash,
),
EntryPointType::Install | EntryPointType::Normal => {
CallStackElement::stored_contract(
contract.contract_package_hash(),
contract_hash,
)
}
EntryPointType::Install => CallStackElement::stored_contract(
contract.contract_package_hash(),
contract_hash,
),
};
stack.push(call_stack_element)?;

Expand Down Expand Up @@ -2668,7 +2665,7 @@ where

Ok(())
}
EntryPointAccess::Abstract => Err(Error::NoSuchMethod(name.to_string())),
EntryPointAccess::Abstract => Err(Error::AbstractMethod(name.to_string())),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn assert_each_context_has_correct_call_stack_info(
let stored_call_stack_key = format!("call_stack-{}", i);
// we need to know where to look for the call stack information
let call_stack = match call.entry_point_type {
EntryPointType::Contract | EntryPointType::Install | EntryPointType::Normal => builder
EntryPointType::Contract | EntryPointType::Install => builder
.get_call_stack_from_contract_context(
&stored_call_stack_key,
current_contract_package_hash,
Expand Down Expand Up @@ -262,14 +262,14 @@ fn assert_each_context_has_correct_call_stack_info_module_bytes(
let stored_call_stack_key = format!("call_stack-{}", i);
// we need to know where to look for the call stack information
let call_stack = match call.entry_point_type {
EntryPointType::Contract => builder.get_call_stack_from_contract_context(
&stored_call_stack_key,
current_contract_package_hash,
),
EntryPointType::Contract | EntryPointType::Install => builder
.get_call_stack_from_contract_context(
&stored_call_stack_key,
current_contract_package_hash,
),
EntryPointType::Session => {
builder.get_call_stack_from_session_context(&stored_call_stack_key)
}
_ => unreachable!(),
};
let (head, rest) = call_stack.split_at(usize::one());
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions execution_engine_testing/tests/src/test/counter_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn should_not_call_undefined_entrypoints_on_factory() {
let no_such_method_2 = builder.get_error().expect("should have error");

assert!(
matches!(&no_such_method_2, Error::Exec(execution::Error::NoSuchMethod(function_name)) if function_name == INCREASE_ENTRY_POINT),
matches!(&no_such_method_2, Error::Exec(execution::Error::AbstractMethod(function_name)) if function_name == INCREASE_ENTRY_POINT),
"{:?}",
&no_such_method_2
);
Expand All @@ -76,7 +76,7 @@ fn should_not_call_undefined_entrypoints_on_factory() {
let no_such_method_3 = builder.get_error().expect("should have error");

assert!(
matches!(&no_such_method_3, Error::Exec(execution::Error::NoSuchMethod(function_name)) if function_name == DECREASE_ENTRY_POINT),
matches!(&no_such_method_3, Error::Exec(execution::Error::AbstractMethod(function_name)) if function_name == DECREASE_ENTRY_POINT),
"{:?}",
&no_such_method_3
);
Expand Down
8 changes: 4 additions & 4 deletions smart_contracts/contracts/test/counter-factory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ fn installer(name: String, initial_value: U512) {
Parameters::new(),
CLType::Unit,
EntryPointAccess::Public,
EntryPointType::Normal,
EntryPointType::Contract,
);
entry_points.add_entry_point(entry_point);
let entry_point: EntryPoint = EntryPoint::new(
DECREASE_ENTRY_POINT.to_string(),
Parameters::new(),
CLType::Unit,
EntryPointAccess::Public,
EntryPointType::Normal,
EntryPointType::Contract,
);
entry_points.add_entry_point(entry_point);

Expand Down Expand Up @@ -137,15 +137,15 @@ pub extern "C" fn call() {
Parameters::new(),
CLType::Unit,
EntryPointAccess::Abstract,
EntryPointType::Normal,
EntryPointType::Contract,
);
entry_points.add_entry_point(entry_point);
let entry_point: EntryPoint = EntryPoint::new(
DECREASE_ENTRY_POINT.to_string(),
Parameters::new(),
CLType::Unit,
EntryPointAccess::Abstract,
EntryPointType::Normal,
EntryPointType::Contract,
);
entry_points.add_entry_point(entry_point);

Expand Down
15 changes: 2 additions & 13 deletions types/src/access_rights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub const ACCESS_RIGHTS_SERIALIZED_LENGTH: usize = 1;
bitflags! {
/// A struct which behaves like a set of bitflags to define access rights associated with a
/// [`URef`](crate::URef).
// #[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
pub struct AccessRights: u8 {
#[cfg_attr(feature = "datasize", derive(DataSize))]
pub struct AccessRights: u8 {
/// No permissions
const NONE = 0;
/// Permission to read the value under the associated `URef`.
Expand All @@ -42,17 +42,6 @@ bitflags! {
}
}

#[cfg(feature = "datasize")]
impl DataSize for AccessRights {
const IS_DYNAMIC: bool = u8::IS_DYNAMIC;

const STATIC_HEAP_SIZE: usize = u8::STATIC_HEAP_SIZE;

fn estimate_heap_size(&self) -> usize {
self.bits().estimate_heap_size()
}
}

impl Default for AccessRights {
fn default() -> Self {
AccessRights::NONE
Expand Down
9 changes: 4 additions & 5 deletions types/src/addressable_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,17 +1024,16 @@ pub enum EntryPointType {
Session = 0b00000000,
/// Runs within contract's context
Contract = 0b00000001,
/// Pattern of entry point types introduced in 2.0.
///
/// If this bit is missing, that means given entry point type was defined in pre-2.0 world.
/// Installer entry point.
Install = 0b10000000,
/// Normal entry point.
Normal = 0b10000001,
}

impl EntryPointType {
/// Checks if entry point type is introduced before 2.0.
///
/// This method checks if there is a bit pattern for entry point types introduced in 2.0.
///
/// If this bit is missing, that means given entry point type was defined in pre-2.0 world.
pub fn is_legacy_pattern(&self) -> bool {
(*self as u8) & 0b10000000 == 0
}
Expand Down
1 change: 0 additions & 1 deletion types/src/gens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ pub fn entry_point_type_arb() -> impl Strategy<Value = EntryPointType> {
Just(EntryPointType::Session),
Just(EntryPointType::Contract),
Just(EntryPointType::Install),
Just(EntryPointType::Normal),
]
}

Expand Down

0 comments on commit 0ddcf85

Please sign in to comment.