Skip to content

Commit

Permalink
fix: balance opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
IaroslavMazur committed Aug 26, 2024
1 parent 98977c3 commit 60afbd2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,27 @@ use std::vec::Vec;

pub fn balance<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_address!(interpreter, address);
push_b256!(interpreter, address.into_word());
push!(interpreter, BASE_TOKEN_ID);

balance_of::<H, SPEC>(interpreter, host);
let Some((balance, is_cold)) = host.balance(BASE_TOKEN_ID, address) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};

gas!(
interpreter,
if SPEC::enabled(BERLIN) {
warm_cold_cost(is_cold)
} else if SPEC::enabled(ISTANBUL) {
// EIP-1884: Repricing for trie-size-dependent opcodes
700
} else if SPEC::enabled(TANGERINE) {
400
} else {
20
}
);

push!(interpreter, balance);
}

/// EIP-1884: Repricing for trie-size-dependent opcodes
Expand Down

0 comments on commit 60afbd2

Please sign in to comment.