Skip to content

Commit

Permalink
fixup! rework block reward application
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 30, 2023
1 parent 21e91f1 commit b8a6573
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,19 @@ void finalize(State& state, evmc_revision rev, const address& coinbase,
// TODO: The block reward can be represented as a withdrawal.
if (block_reward.has_value())
{
state.touch(coinbase).balance += *block_reward;
const auto r = *block_reward;
assert(r % 32 == 0); // Assume block reward is divisible by 32.
const auto r_32 = r / 32;
const auto r_8 = r / 8;

state.touch(coinbase).balance += r + r_32 * ommers.size();
if (!ommers.empty())
{
state.touch(coinbase).balance += *block_reward * ommers.size() / 32;

for (const auto& ommer : ommers)
{
uint256 block_reward_256 = *block_reward;
block_reward_256 = block_reward_256 * (8 - ommer.delta) / 8;
assert(block_reward_256 <= std::numeric_limits<uint64_t>::max());
state.touch(ommer.beneficiary).balance += block_reward_256[0];
assert(ommer.delta > 0);
assert(ommer.delta <= 8);
state.get_or_insert(ommer.beneficiary).balance += r_8 * (8 - ommer.delta);
}
}
}
Expand Down

0 comments on commit b8a6573

Please sign in to comment.