casper-network/casper-wasm-utils

Wrong documentation for `instruction_cost()`

Opened this issue · 0 comments

Note: This is upstream bug, but I stumbled upon it while investigating forbidden opcodes in Casper.

Looking at the documentation of Rules::instruction_cost():

/// Returning `None` makes the gas instrumention end with an error. This is meant
/// as a way to have a partial rule set where any instruction that is not specifed
/// is considered as forbidden.

the part "where any instruction that is not specifed is considered as forbidden" does not seem to be fully correct.

None - which is used as indication of error - is returned only when instruction type is marked as forbidden. In case instruction type does not have metering type assigned, regular cost will be used for opcode:

impl Rules for Set {
fn instruction_cost(&self, instruction: &Instruction) -> Option<u32> {
match self.entries.get(&InstructionType::op(instruction)) {
None | Some(Metering::Regular) => Some(self.regular),
Some(Metering::Fixed(val)) => Some(*val),
Some(Metering::Forbidden) => None,