Skip to content

Commit

Permalink
Charge for authority account creation
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Aug 2, 2024
1 parent 54a8831 commit 90c05f4
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ int64_t compute_tx_intrinsic_cost(evmc_revision rev, const Transaction& tx) noex
{
static constexpr auto call_tx_cost = 21000;
static constexpr auto create_tx_cost = 53000;
static constexpr auto per_auth_base_cost = 2500;
static constexpr auto per_empty_account_cost = 25000;
static constexpr auto initcode_word_cost = 2;
const auto is_create = !tx.to.has_value(); // Covers also EOF creation txs.
const auto auth_list_cost =
static_cast<int64_t>(per_auth_base_cost * tx.authorization_list.size());
static_cast<int64_t>(per_empty_account_cost * tx.authorization_list.size());
const auto initcode_cost =
is_create && rev >= EVMC_SHANGHAI ? initcode_word_cost * num_words(tx.data.size()) : 0;
const auto tx_cost = is_create && rev >= EVMC_HOMESTEAD ? create_tx_cost : call_tx_cost;
Expand Down Expand Up @@ -480,20 +480,39 @@ std::variant<TransactionReceipt, std::error_code> transition(State& state, const
{
// TODO check chain_id

auto& acc = state.get_or_insert(auth.signer);
if (!acc.code.empty() && !is_code_delegated(acc.code))
continue;
// Check if authority exists
auto* authority_ptr = state.find(auth.signer);
if (authority_ptr != nullptr)

Check warning on line 485 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L484-L485

Added lines #L484 - L485 were not covered by tests
{
// Skip if authority has non-delegated code
if (!authority_ptr->code.empty() && !is_code_delegated(authority_ptr->code))
continue;

Check warning on line 489 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L488-L489

Added lines #L488 - L489 were not covered by tests

// Skip if authorization nonce is incorrect
if (auth.nonce != authority_ptr->nonce)
continue;

Check warning on line 493 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L492-L493

Added lines #L492 - L493 were not covered by tests

// Refund if authority account creation is not needed
static constexpr int64_t EXISTING_AUTHORITY_REFUND = 25000 - 2500;
sender_ptr->balance += EXISTING_AUTHORITY_REFUND;

Check warning on line 497 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L497

Added line #L497 was not covered by tests
}
else
{
// Skip if authorization nonce is incorrect
if (auth.nonce != 0)
continue;

Check warning on line 503 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L502-L503

Added lines #L502 - L503 were not covered by tests

if (acc.nonce != auth.nonce)
continue;
// Create authority account
authority_ptr = &state.insert(auth.signer, {});

Check warning on line 506 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L506

Added line #L506 was not covered by tests
}

acc.code.reserve(std::size(DELEGATION_MAGIC) + std::size(auth.addr.bytes));
acc.code = DELEGATION_MAGIC;
acc.code += auth.addr;
authority_ptr->code.reserve(std::size(DELEGATION_MAGIC) + std::size(auth.addr.bytes));
authority_ptr->code = DELEGATION_MAGIC;
authority_ptr->code += auth.addr;

Check warning on line 511 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L509-L511

Added lines #L509 - L511 were not covered by tests

++acc.nonce;
++authority_ptr->nonce;

Check warning on line 513 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L513

Added line #L513 was not covered by tests

acc.access_status = EVMC_ACCESS_WARM;
authority_ptr->access_status = EVMC_ACCESS_WARM;

Check warning on line 515 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L515

Added line #L515 was not covered by tests
}

// Once the transaction is valid, create new sender account.
Expand Down

0 comments on commit 90c05f4

Please sign in to comment.