Skip to content

Commit

Permalink
revert nonce increments
Browse files Browse the repository at this point in the history
  • Loading branch information
ak88 committed Aug 16, 2024
1 parent df5ba74 commit 77f2423
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public static IEnumerable<object[]> SenderSignerCases()
yield return new object[] { TestItem.PrivateKeyA, TestItem.PrivateKeyA };
}
[TestCaseSource(nameof(SenderSignerCases))]
public void Execute_SenderAndSignerCombinationsWithCodeThatSavesCallerAddress_SenderAddressIsSaved(PrivateKey sender, PrivateKey signer)
public void Execute_SenderAndSignerIsTheSameOrNotWithCodeThatSavesCallerAddress_SenderAddressIsSaved(PrivateKey sender, PrivateKey signer)
{
Address codeSource = TestItem.AddressC;
Address codeSource = TestItem.AddressB;
_stateProvider.CreateAccount(sender.Address, 1.Ether());
//Save caller in storage slot 0
byte[] code = Prepare.EvmCode
Expand All @@ -136,7 +136,7 @@ public void Execute_SenderAndSignerCombinationsWithCodeThatSavesCallerAddress_Se
.WithType(TxType.SetCode)
.WithTo(signer.Address)
.WithGasLimit(60_000)
.WithAuthorizationCode(CreateAuthorizationTuple(signer, _specProvider.ChainId, codeSource, 0))
.WithAuthorizationCode(CreateAuthorizationTuple(signer, _specProvider.ChainId, codeSource, null))
.SignedAndResolved(_ethereumEcdsa, sender, true)
.TestObject;
Block block = Build.A.Block.WithNumber(long.MaxValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,24 @@ protected virtual TransactionResult Execute(Transaction tx, in BlockExecutionCon

if (!(result = ValidateSender(tx, header, spec, tracer, opts))) return result;
if (!(result = BuyGas(tx, header, spec, tracer, opts, effectiveGasPrice, out UInt256 premiumPerGas, out UInt256 senderReservedGasPayment))) return result;
if (!(result = ValidateNonce(tx))) return result;
if (!(result = IncrementNonce(tx, header, spec, tracer, opts))) return result;

if (commit) WorldState.Commit(spec, tracer.IsTracingState ? tracer : NullTxTracer.Instance, commitStorageRoots: false);

IEnumerable<Address> authorities = Array.Empty<Address>();

if (spec.IsEip7702Enabled)
{
if (tx.HasAuthorizationList)
{
_codeInfoRepository.InsertFromAuthorizations(WorldState, tx.AuthorizationList, spec);
authorities = _codeInfoRepository.InsertFromAuthorizations(WorldState, tx.AuthorizationList, spec);
}
}

IncrementNonce(tx, header, spec, tracer, opts);

if (commit) WorldState.Commit(spec, tracer.IsTracingState ? tracer : NullTxTracer.Instance, commitStorageRoots: false);

ExecutionEnvironment env = BuildExecutionEnvironment(tx, in blCtx, spec, effectiveGasPrice, _codeInfoRepository);

long gasAvailable = tx.GasLimit - intrinsicGas;
ExecuteEvmCall(tx, header, spec, tracer, opts, gasAvailable, env, out TransactionSubstate? substate, out long spentGas, out byte statusCode);
ExecuteEvmCall(tx, header, spec, tracer, opts, authorities, gasAvailable, env, out TransactionSubstate? substate, out long spentGas, out byte statusCode);
PayFees(tx, header, spec, tracer, substate, spentGas, premiumPerGas, statusCode);

// Finalize
Expand Down Expand Up @@ -395,7 +395,7 @@ protected virtual TransactionResult BuyGas(Transaction tx, BlockHeader header, I
return TransactionResult.Ok;
}

protected virtual TransactionResult ValidateNonce(Transaction tx)
protected virtual TransactionResult IncrementNonce(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts)
{
if (tx.IsSystem()) return TransactionResult.Ok;

Expand All @@ -404,12 +404,9 @@ protected virtual TransactionResult ValidateNonce(Transaction tx)
TraceLogInvalidTx(tx, $"WRONG_TRANSACTION_NONCE: {tx.Nonce} (expected {WorldState.GetNonce(tx.SenderAddress)})");
return "wrong transaction nonce";
}
return TransactionResult.Ok;
}

protected virtual void IncrementNonce(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts)
{
WorldState.IncrementNonce(tx.SenderAddress);
return TransactionResult.Ok;
}

protected ExecutionEnvironment BuildExecutionEnvironment(
Expand Down Expand Up @@ -451,6 +448,7 @@ protected void ExecuteEvmCall(
IReleaseSpec spec,
ITxTracer tracer,
ExecutionOptions opts,
IEnumerable<Address> authorities,
in long gasAvailable,
in ExecutionEnvironment env,
out TransactionSubstate? substate,
Expand Down Expand Up @@ -484,7 +482,7 @@ protected void ExecuteEvmCall(

using (EvmState state = new(unspentGas, env, executionType, true, snapshot, false))
{
WarmUp(tx, header, spec, env, state);
WarmUp(tx, header, spec, env, state, authorities);

substate = !tracer.IsTracingActions
? VirtualMachine.Run<NotTracing>(state, WorldState, tracer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ protected override TransactionResult BuyGas(Transaction tx, BlockHeader header,
return TransactionResult.Ok;
}

protected override TransactionResult ValidateNonce(Transaction tx)
protected override TransactionResult IncrementNonce(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts)
{
if (tx.IsDeposit())
return TransactionResult.Ok;
if (!tx.IsDeposit())
return base.IncrementNonce(tx, header, spec, tracer, opts);

return base.ValidateNonce(tx);
WorldState.IncrementNonce(tx.SenderAddress!);
return TransactionResult.Ok;
}

protected override TransactionResult ValidateSender(Transaction tx, BlockHeader header, IReleaseSpec spec, ITxTracer tracer, ExecutionOptions opts) =>
Expand Down

0 comments on commit 77f2423

Please sign in to comment.