Skip to content

Commit

Permalink
EIP-3651 Warm COINBASE (#4594)
Browse files Browse the repository at this point in the history
* Implementation (tests need writing)

* Tests

* spacing fixes
  • Loading branch information
smartprogrammer93 committed Sep 28, 2022
1 parent 54dd027 commit f13b0e7
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ public interface IReleaseSpec
/// </summary>
bool IsEip3675Enabled { get; }

/// <summary>
/// Warm COINBASE
/// </summary>
bool IsEip3651Enabled { get; }

/// <summary>
/// Transient storage
/// </summary>
Expand Down Expand Up @@ -284,6 +289,8 @@ public interface IReleaseSpec

public bool UseTxAccessLists => IsEip2930Enabled;

public bool AddCoinbaseToTxAccessList => IsEip3651Enabled;

public bool ModExpEnabled => IsEip198Enabled;

public bool Bn128Enabled => IsEip196Enabled && IsEip197Enabled;
Expand Down
69 changes: 69 additions & 0 deletions src/Nethermind/Nethermind.Evm.Test/Eip3651Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.

using FluentAssertions;
using Nethermind.Core.Extensions;
using Nethermind.Core.Specs;
using Nethermind.Specs;
using Nethermind.Core.Test.Builders;
using NUnit.Framework;
using Nethermind.Core;

namespace Nethermind.Evm.Test
{
/// <summary>
/// https://gist.github.com/holiman/174548cad102096858583c6fbbb0649a
/// </summary>
public class Eip3651Tests : VirtualMachineTestsBase
{
protected override long BlockNumber => MainnetSpecProvider.ShanghaiBlockNumber;

[Test]
public void Access_beneficiary_address_after_eip_3651()
{
byte[] code = Prepare.EvmCode
.PushData(MinerKey.Address)
.Op(Instruction.BALANCE)
.Op(Instruction.POP)
.Done;
TestAllTracerWithOutput result = Execute(code);
result.StatusCode.Should().Be(1);
AssertGas(result, GasCostOf.Transaction + 105);
}

[Test]
public void Access_beneficiary_address_before_eip_3651()
{
TestState.CreateAccount(TestItem.AddressF, 100.Ether());
byte[] code = Prepare.EvmCode
.PushData(MinerKey.Address)
.Op(Instruction.BALANCE)
.Op(Instruction.POP)
.Done;
TestAllTracerWithOutput result = Execute(BlockNumber - 1, 100000, code);
result.StatusCode.Should().Be(1);
AssertGas(result, GasCostOf.Transaction + 2605);
}

protected override TestAllTracerWithOutput CreateTracer()
{
TestAllTracerWithOutput tracer = base.CreateTracer();
tracer.IsTracingAccess = false;
return tracer;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra
state.WarmUp(recipient); // eip-2929
}

if (spec.AddCoinbaseToTxAccessList)
{
state.WarmUp(block.GasBeneficiary);
}

substate = _virtualMachine.Run(state, _worldState, txTracer);
unspentGas = state.GasAvailable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,6 @@ public long Eip1559TransitionBlock
public Address? Eip1559FeeCollector => _spec.Eip1559FeeCollector;
public bool IsEip1153Enabled => _spec.IsEip1153Enabled;
public bool IsEip3675Enabled => _spec.IsEip3675Enabled;
public bool IsEip3651Enabled => _spec.IsEip3651Enabled;
}
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Specs/Forks/15_Shanghai.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected Shanghai()
Name = "Shanghai";
IsEip1153Enabled = true;
IsEip3675Enabled = true;
IsEip3651Enabled = true;
}

public new static IReleaseSpec Instance => LazyInitializer.EnsureInitialized(ref _instance, () => new Shanghai());
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Specs/ReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ public class ReleaseSpec : IReleaseSpec
public UInt256? Eip1559BaseFeeMinValue { get; set; }
public bool IsEip1153Enabled { get; set; }
public bool IsEip3675Enabled { get; set; }
public bool IsEip3651Enabled { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@ public bool IsEip158IgnoredAccount(Address address)
public Address Eip1559FeeCollector => _spec.Eip1559FeeCollector;
public bool IsEip1153Enabled => _spec.IsEip1153Enabled;
public bool IsEip3675Enabled => _spec.IsEip3675Enabled;
public bool IsEip3651Enabled => _spec.IsEip3651Enabled;
}
}

0 comments on commit f13b0e7

Please sign in to comment.