Skip to content

Commit

Permalink
Add fields and spec
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Nov 24, 2022
1 parent c8c6868 commit 8a8c6f8
Show file tree
Hide file tree
Showing 34 changed files with 402 additions and 13 deletions.
70 changes: 70 additions & 0 deletions src/Nethermind/Chains/eip4844_local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "Eip4844Local",
"dataDir": "eip4844_local",
"engine": {
"clique": {
"params": {
"period": 5,
"epoch": 30000
}
}
},
"params": {
"terminalTotalDifficulty": "2",
"terminalPowBlockNumber": 1,
"chainID": "1",
"networkID": "69",
"maximumExtraDataSize": "1000000",
"eip140Transition": "0x0",
"eip145Transition": "0x0",
"eip150Transition": "0x0",
"eip155Transition": "0x0",
"eip160Transition": "0x0",
"eip161abcTransition": "0x0",
"eip161dTransition": "0x0",
"eip211Transition": "0x0",
"eip214Transition": "0x0",
"eip658Transition": "0x0",
"eip1014Transition": "0x0",
"eip1052Transition": "0x0",
"eip1283Transition": "0x0",
"eip1283DisableTransition": "0x0",
"eip152Transition": "0x0",
"eip1108Transition": "0x0",
"eip1344Transition": "0x0",
"eip1884Transition": "0x0",
"eip2028Transition": "0x0",
"eip2200Transition": "0x0",
"eip2565Transition": "0x0",
"eip2929Transition": "0x0",
"eip2930Transition": "0x0",
"maxCodeSizeTransition": "0x0",
"eip1559Transition": "0x0",
"eip4895TransitionTimestamp": "0x0",
"eip4844TransitionTimestamp": "0x0"
},
"genesis": {
"author": "0x0000000000000000000000000000000000000000",
"difficulty": "0x0",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x1C9C380",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"seal": {
"ethereum": {
"nonce": "0x42",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
},
"timestamp": 0,
"baseFeePerGas": "0x7"
},
"accounts": {
"0x8A04d14125D0FDCDc742F4A05C051De07232EDa4": {
"code": "0x60806040526004361061003f5760003560e01c806301ffc9a714610044578063228951181461008c578063621fd130146101a2578063c5f2892f1461022c575b600080fd5b34801561005057600080fd5b506100786004803603602081101561006757600080fd5b50356001600160e01b031916610253565b604080519115158252519081900360200190f35b6101a0600480360360808110156100a257600080fd5b8101906020810181356401000000008111156100bd57600080fd5b8201836020820111156100cf57600080fd5b803590602001918460018302840111640100000000831117156100f157600080fd5b91939092909160208101903564010000000081111561010f57600080fd5b82018360208201111561012157600080fd5b8035906020019184600183028401116401000000008311171561014357600080fd5b91939092909160208101903564010000000081111561016157600080fd5b82018360208201111561017357600080fd5b8035906020019184600183028401116401000000008311171561019557600080fd5b91935091503561028a565b005b3480156101ae57600080fd5b506101b7610ce6565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101f15781810151838201526020016101d9565b50505050905090810190601f16801561021e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561023857600080fd5b50610241610cf8565b60408051918252519081900360200190f35b60006001600160e01b031982166301ffc9a760e01b148061028457506001600160e01b03198216638564090760e01b145b92915050565b603086146102c95760405162461bcd60e51b81526004018080602001828103825260268152602001806112516026913960400191505060405180910390fd5b602084146103085760405162461bcd60e51b81526004018080602001828103825260368152602001806111e86036913960400191505060405180910390fd5b606082146103475760405162461bcd60e51b81526004018080602001828103825260298152602001806112c46029913960400191505060405180910390fd5b670de0b6b3a764000034101561038e5760405162461bcd60e51b815260040180806020018281038252602681526020018061129e6026913960400191505060405180910390fd5b633b9aca003406156103d15760405162461bcd60e51b815260040180806020018281038252603381526020018061121e6033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff81111561041f5760405162461bcd60e51b81526004018080602001828103825260278152602001806112776027913960400191505060405180910390fd5b606061042a82610fc6565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a61045f602054610fc6565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f01601f191690910187810386528c815260200190508c8c808284376000838201819052601f909101601f191690920188810386528c5181528c51602091820193918e019250908190849084905b838110156104f65781810151838201526020016104de565b50505050905090810190601f1680156105235780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f909101601f19169092018881038452895181528951602091820193918b019250908190849084905b8381101561057f578181015183820152602001610567565b50505050905090810190601f1680156105ac5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284376fffffffffffffffffffffffffffffffff199094169190930190815260408051600f19818403018152601090920190819052815191955093508392506020850191508083835b602083106106415780518252601f199092019160209182019101610622565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610680573d6000803e3d6000fd5b5050506040513d602081101561069557600080fd5b5051905060006002806106ab6040848a8c61114a565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106107015780518252601f1990920191602091820191016106e2565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610740573d6000803e3d6000fd5b5050506040513d602081101561075557600080fd5b50516002610766896040818d61114a565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106107c15780518252601f1990920191602091820191016107a2565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610800573d6000803e3d6000fd5b5050506040513d602081101561081557600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b6020831061086b5780518252601f19909201916020918201910161084c565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156108aa573d6000803e3d6000fd5b5050506040513d60208110156108bf57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b6020831061092e5780518252601f19909201916020918201910161090f565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa15801561096d573d6000803e3d6000fd5b5050506040513d602081101561098257600080fd5b50516040518651600291889160009188916020918201918291908601908083835b602083106109c25780518252601f1990920191602091820191016109a3565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610a495780518252601f199092019160209182019101610a2a565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610a88573d6000803e3d6000fd5b5050506040513d6020811015610a9d57600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610af35780518252601f199092019160209182019101610ad4565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610b32573d6000803e3d6000fd5b5050506040513d6020811015610b4757600080fd5b50519050858114610b895760405162461bcd60e51b81526004018080602001828103825260548152602001806111946054913960600191505060405180910390fd5b60205463ffffffff11610bcd5760405162461bcd60e51b81526004018080602001828103825260218152602001806111736021913960400191505060405180910390fd5b602080546001019081905560005b6020811015610cda578160011660011415610c0d578260008260208110610bfe57fe5b015550610cdd95505050505050565b600260008260208110610c1c57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610c745780518252601f199092019160209182019101610c55565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610cb3573d6000803e3d6000fd5b5050506040513d6020811015610cc857600080fd5b50519250600282049150600101610bdb565b50fe5b50505050505050565b6060610cf3602054610fc6565b905090565b6020546000908190815b6020811015610ea9578160011660011415610ddb57600260008260208110610d2657fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610d7e5780518252601f199092019160209182019101610d5f565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610dbd573d6000803e3d6000fd5b5050506040513d6020811015610dd257600080fd5b50519250610e9b565b60028360218360208110610deb57fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b60208310610e425780518252601f199092019160209182019101610e23565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610e81573d6000803e3d6000fd5b5050506040513d6020811015610e9657600080fd5b505192505b600282049150600101610d02565b50600282610eb8602054610fc6565b600060401b6040516020018084815260200183805190602001908083835b60208310610ef55780518252601f199092019160209182019101610ed6565b51815160209384036101000a600019018019909216911617905267ffffffffffffffff199590951692019182525060408051808303600719018152601890920190819052815191955093508392850191508083835b60208310610f695780518252601f199092019160209182019101610f4a565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610fa8573d6000803e3d6000fd5b5050506040513d6020811015610fbd57600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b8260008151811061100057fe5b60200101906001600160f81b031916908160001a9053508060061a60f81b8260018151811061102b57fe5b60200101906001600160f81b031916908160001a9053508060051a60f81b8260028151811061105657fe5b60200101906001600160f81b031916908160001a9053508060041a60f81b8260038151811061108157fe5b60200101906001600160f81b031916908160001a9053508060031a60f81b826004815181106110ac57fe5b60200101906001600160f81b031916908160001a9053508060021a60f81b826005815181106110d757fe5b60200101906001600160f81b031916908160001a9053508060011a60f81b8260068151811061110257fe5b60200101906001600160f81b031916908160001a9053508060001a60f81b8260078151811061112d57fe5b60200101906001600160f81b031916908160001a90535050919050565b60008085851115611159578182fd5b83861115611165578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a164736f6c634300060b000a",
"balance": "0x0"
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x6d6172697573766477000000"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,27 @@ public bool MaxFeePerGas_is_required_to_be_greater_than_MaxPriorityFeePerGas(TxT
TxValidator txValidator = new(TestChainIds.ChainId);
return txValidator.IsWellFormed(tx, London.Instance);
}

[TestCase(TxType.EIP1559, false, ExpectedResult = false)]
[TestCase(TxType.Blob, false, ExpectedResult = false)]
[TestCase(TxType.EIP1559, true, ExpectedResult = false)]
[TestCase(TxType.Blob, true, ExpectedResult = true)]
public bool MaxFeePerDataGas_should_be_set_for_blob_tx_only(TxType txType, bool isMaxFeePerDataGasSet)
{
byte[] sigData = new byte[65];
sigData[31] = 1; // correct r
sigData[63] = 1; // correct s
sigData[64] = 1 + TestChainIds.ChainId * 2 + 35;
Signature signature = new(sigData);
Transaction tx = Build.A.Transaction
.WithType(txType)
.WithTimestamp(ulong.MaxValue)
.WithMaxFeePerDataGas(isMaxFeePerDataGasSet ? 1 : null)
.WithChainId(TestChainIds.ChainId)
.WithSignature(signature).TestObject;

TxValidator txValidator = new(TestChainIds.ChainId);
return txValidator.IsWellFormed(tx, ShardingFork.Instance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ private Block PrepareBlockForProcessing(Block suggestedBlock)
AuRaSignature = bh.AuRaSignature,
ReceiptsRoot = bh.ReceiptsRoot,
BaseFeePerGas = bh.BaseFeePerGas,
IsPostMerge = bh.IsPostMerge
ExcessDataGas = bh.ExcessDataGas,
IsPostMerge = bh.IsPostMerge,
};

return suggestedBlock.CreateCopy(headerForProcessing);
Expand Down
12 changes: 11 additions & 1 deletion src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public bool IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec)
while for an init it will be empty */
ValidateSignature(transaction.Signature, releaseSpec) &&
ValidateChainId(transaction) &&
Validate1559GasFields(transaction, releaseSpec);
Validate1559GasFields(transaction, releaseSpec) &&
Validate4844Fields(transaction);
}

private bool ValidateTxType(Transaction transaction, IReleaseSpec releaseSpec)
Expand All @@ -51,6 +52,8 @@ private bool ValidateTxType(Transaction transaction, IReleaseSpec releaseSpec)
return releaseSpec.UseTxAccessLists;
case TxType.EIP1559:
return releaseSpec.IsEip1559Enabled;
case TxType.Blob:
return releaseSpec.IsEip4844Enabled;
default:
return false;
}
Expand All @@ -72,6 +75,7 @@ private bool ValidateChainId(Transaction transaction)
return true;
case TxType.AccessList:
case TxType.EIP1559:
case TxType.Blob:
return transaction.ChainId == _chainIdValue;
default:
return false;
Expand Down Expand Up @@ -105,5 +109,11 @@ private bool ValidateSignature(Signature? signature, IReleaseSpec spec)

return !spec.ValidateChainId || (signature.V == 27 || signature.V == 28);
}

private bool Validate4844Fields(Transaction transaction)
{
// TODO: Add blobs validation
return transaction.Type != TxType.Blob ^ transaction.MaxFeePerDataGas is not null;
}
}
}
15 changes: 15 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/BlockHeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ public void Hash_as_expected_2()
Assert.AreEqual(new Keccak(Bytes.FromHexString("0x1423c2875714c31049cacfea8450f66a73ecbd61d7a6ab13089406a491aa9fc2")), header.Hash);
}

[TestCase(0ul, null, "0x9890f002d41c83cc1f07bcfc59357181439b15665bda52541ec05662250222d5")]
[TestCase(0ul, 1ul, "0x9890f002d41c83cc1f07bcfc59357181439b15665bda52541ec05662250222d5")]
[TestCase(ulong.MaxValue, null, "0x32cfdac3b6fd3452c5bbebbc638d5666fa0ce8a2f855dea82758ae0917d65ad3")]
[TestCase(ulong.MaxValue, 0ul, "0x32cfdac3b6fd3452c5bbebbc638d5666fa0ce8a2f855dea82758ae0917d65ad3")]
[TestCase(ulong.MaxValue, 1ul, "0xd45ce0ae69381efc25172c4e81d6e7d283d98f0b236692968e8bfa1c26b2c0ab")]
public void Hash_changes_with_fork_and_excessDataGas_value(ulong timestampForForkActivation, ulong? excessDataGas, string expectedHash)
{
BlockHeader header = Build.A.BlockHeader
.WithTimestamp(timestampForForkActivation)
.WithExcessDataGas(excessDataGas)
.TestObject;
header.Hash = header.CalculateHash();
Assert.AreEqual(new Keccak(Bytes.FromHexString(expectedHash)), header.Hash);
}

[Test]
public void Author()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ public BlockHeaderBuilder WithNonce(ulong nonce)
return this;
}

public BlockHeaderBuilder WithExcessDataGas(UInt256? excessDataGas)
{
TestObjectInternal.ExcessDataGas = excessDataGas;
return this;
}

public BlockHeaderBuilder WithAura(long step, byte[]? signature = null)
{
TestObjectInternal.AuRaStep = step;
Expand Down
12 changes: 12 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ public TransactionBuilder<T> WithSenderAddress(Address? address)
return this;
}

public TransactionBuilder<T> WithMaxFeePerDataGas(UInt256? maxFeePerDataGas)
{
TestObjectInternal.MaxFeePerDataGas = maxFeePerDataGas;
return this;
}

public TransactionBuilder<T> WithBlobHashes(byte[][] blobVersionedHashes)
{
TestObjectInternal.BlobVersionedHashes = blobVersionedHashes;
return this;
}

public TransactionBuilder<T> WithSignature(Signature signature)
{
TestObjectInternal.Signature = signature;
Expand Down
23 changes: 23 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/Encoding/HeaderDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using FluentAssertions;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Core.Test.Builders;
using Nethermind.Crypto;
using Nethermind.Db;
using Nethermind.Int256;
using Nethermind.Serialization.Rlp;
using NUnit.Framework;
Expand Down Expand Up @@ -140,5 +142,26 @@ public void Can_encode_decode_with_negative_long_when_using_span(long negativeLo
blockHeader.Number.Should().Be(negativeLong);
blockHeader.GasLimit.Should().Be(negativeLong);
}

[TestCaseSource(nameof(ExcessDataGasCaseSource))]
public void Can_encode_decode_with_excessDataGas(UInt256? excessDataGas, UInt256? decodedExcessDataGas)
{
BlockHeader header = Build.A.BlockHeader
.WithTimestamp(ulong.MaxValue)
.WithExcessDataGas(excessDataGas).TestObject;

Rlp rlp = Rlp.Encode(header);
BlockHeader blockHeader = Rlp.Decode<BlockHeader>(rlp.Bytes.AsSpan());

blockHeader.ExcessDataGas.Should().Be(decodedExcessDataGas);
}
public static IEnumerable<(UInt256?, UInt256?)> ExcessDataGasCaseSource()
{
yield return (null, 0);
yield return (0, 0);
yield return (1, 1);
yield return (UInt256.UInt128MaxValue, UInt256.UInt128MaxValue);
yield return (UInt256.MaxValue, UInt256.MaxValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TxTypeConverterTests : ConverterTestBase<TxType>
[TestCase((TxType)255)]
[TestCase(TxType.Legacy)]
[TestCase(TxType.AccessList)]
[TestCase(TxType.Blob)]
public void Test_roundtrip(TxType arg)
{
TestConverter(arg, (before, after) => before.Equals(after), new TxTypeConverter());
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Core/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public Block(BlockHeader blockHeader)

public UInt256 BaseFeePerGas => Header.BaseFeePerGas; // do not add setter here

public UInt256? ExcessDataGas => Header.ExcessDataGas; // do not add setter here

public bool IsPostMerge => Header.IsPostMerge; // do not add setter here

public bool IsBodyMissing => Header.HasBody && Body.IsEmpty;
Expand Down
Loading

0 comments on commit 8a8c6f8

Please sign in to comment.