Skip to content

core/vm: Better handling of static mode violation (ErrWriteProtection) #23968

Closed
@chfast

Description

@chfast

Detection of static mode violation (ErrWriteProtection) should be handled by the affected instructions (operation.writes), not in the interpreter loop:

// If the operation is valid, enforce write restrictions
if in.readOnly && in.evm.chainRules.IsByzantium {
// If the interpreter is operating in readonly mode, make sure no
// state-modifying operation is performed. The 3rd stack item
// for a call operation is the value. Transferring value from one
// account to the others means the state is modified and should also
// return with an error.
if operation.writes || (op == CALL && stack.Back(2).Sign() != 0) {
return nil, ErrWriteProtection
}
}

  1. Please confirm that in.readOnly can be true only when in.evm.chainRules.IsByzantium, so the condition in.readOnly && in.evm.chainRules.IsByzantium can be simplified.
  2. Move this check to implementations of the affected instructions (e.g. opCall(), opSstore()).
  3. Remove the check from the interpreter loop.
  4. Remove operation.writes field.

This should land after #23952.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions