Skip to content

Incorrect docs for Handler::validate_against_state_and_deduct_caller #3255

@preston-evans98

Description

@preston-evans98

The validate_against_state_and_deduct_caller docs state that the method is responsible for deducting the transfer value from the caller's balance.

/// Deducts maximum possible fee and transfer value from caller's balance.

In fact, the default implementation only deducts the fee and the deduction of the transfer value is performed during execution. Overrides which follow the documented behavior can result in loss of funds, since the deduction is also made during EVM execution.

let gas_balance_spending = effective_balance_spending - tx.value();
// new balance
let mut new_balance = balance.saturating_sub(gas_balance_spending);
if is_balance_check_disabled {
// Make sure the caller's balance is at least the value of the transaction.
new_balance = new_balance.max(tx.value());
}
Ok(new_balance)

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