-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
600 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
namespace Evm.t8n.Errors; | ||
|
||
public class T8NErrorCodes | ||
{ | ||
public const int ErrorEVM = 2; // Other EVM error | ||
public const int ErrorConfig = 3; // Failed configuration: when a non-supported or invalid fork was specified. | ||
|
||
public const int ErrorMissingBlockhash = 4; // Block history is not supplied, but needed for a BLOCKHASH operation. If BLOCKHASH is invoked targeting a block which history has not been provided for, the program will exit with code 4. | ||
|
||
public const int ErrorJson = 10; // Invalid input json: the supplied data could not be marshalled | ||
public const int ErrorIO = 11; // IO problems: failure to load or save files | ||
public const int ErrorRlp = 12; // Invalid Rlp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Exceptions; | ||
|
||
namespace Evm.t8n.Errors; | ||
|
||
public class T8NException : Exception, IExceptionWithExitCode | ||
{ | ||
public T8NException(Exception e, int exitCode) : base(e.Message, e) | ||
{ | ||
ExitCode = exitCode; | ||
} | ||
|
||
public T8NException(Exception e, string message, int exitCode) : base(message, e) | ||
{ | ||
ExitCode = exitCode; | ||
} | ||
|
||
public T8NException(string message, int exitCode) : base(message) | ||
{ | ||
ExitCode = exitCode; | ||
} | ||
|
||
public int ExitCode { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Int256; | ||
|
||
namespace Evm.t8n.JsonTypes; | ||
|
||
public class EnvJson | ||
{ | ||
public Address? CurrentCoinbase { get; set; } | ||
public long CurrentGasLimit { get; set; } | ||
public long CurrentNumber { get; set; } | ||
public ulong CurrentTimestamp { get; set; } | ||
public Withdrawal[]? Withdrawals { get; set; } | ||
|
||
public UInt256? CurrentRandom { get; set; } | ||
public ulong ParentTimestamp { get; set; } | ||
public UInt256? ParentDifficulty { get; set; } | ||
public UInt256? CurrentBaseFee { get; set; } | ||
public UInt256? CurrentDifficulty { get; set; } | ||
public Hash256? ParentUncleHash { get; set; } | ||
public Hash256? ParentBeaconBlockRoot { get; set; } | ||
public UInt256? ParentBaseFee { get; set; } | ||
public long ParentGasUsed { get; set; } | ||
public long ParentGasLimit { get; set; } | ||
public ulong? ParentExcessBlobGas { get; set; } | ||
public ulong? CurrentExcessBlobGas { get; set; } | ||
public ulong? ParentBlobGasUsed { get; set; } | ||
|
||
public Dictionary<string, Hash256> BlockHashes { get; set; } = []; | ||
public Ommer[] Ommers { get; set; } = []; | ||
|
||
public Hash256? GetCurrentRandomHash256() | ||
{ | ||
if (CurrentRandom is null) return null; | ||
|
||
Span<byte> bytes = stackalloc byte[32]; | ||
CurrentRandom?.ToBigEndian(bytes); | ||
return new Hash256(bytes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Ethereum.Test.Base; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Crypto; | ||
using Nethermind.Facade.Eth.RpcTransaction; | ||
using Nethermind.Serialization.Rlp; | ||
|
||
namespace Evm.t8n.JsonTypes; | ||
|
||
public class InputData | ||
{ | ||
public Dictionary<Address, AccountState>? Alloc { get; set; } | ||
public EnvJson? Env { get; set; } | ||
public TransactionForRpc[]? Txs { get; set; } | ||
public TransactionMetaData[]? TransactionMetaDataList { get; set; } | ||
public string? TxRlp { get; set; } | ||
|
||
public Transaction[] GetTransactions(TxDecoder decoder) | ||
{ | ||
List<Transaction> transactions = []; | ||
if (TxRlp is not null) | ||
{ | ||
RlpStream rlp = new(Bytes.FromHexString(TxRlp)); | ||
transactions = decoder.DecodeArray(rlp).ToList(); | ||
} | ||
else if (Txs is not null && TransactionMetaDataList is not null) | ||
{ | ||
for (int i = 0; i < Txs.Length; i++) | ||
{ | ||
var transaction = Txs[i].ToTransaction(); | ||
transaction.SenderAddress = null; // t8n does not accept SenderAddress from input, so need to reset senderAddress | ||
|
||
SignTransaction(transaction, TransactionMetaDataList[i], (LegacyTransactionForRpc) Txs[i]); | ||
|
||
transaction.Hash = transaction.CalculateHash(); | ||
transactions.Add(transaction); | ||
} | ||
} | ||
|
||
return transactions.ToArray(); | ||
} | ||
|
||
private static void SignTransaction(Transaction transaction, TransactionMetaData transactionMetaData, LegacyTransactionForRpc txLegacy) | ||
{ | ||
if (transactionMetaData.SecretKey is not null) | ||
{ | ||
var privateKey = new PrivateKey(transactionMetaData.SecretKey); | ||
transaction.SenderAddress = privateKey.Address; | ||
|
||
EthereumEcdsa ecdsa = new(transaction.ChainId ?? TestBlockchainIds.ChainId); | ||
|
||
ecdsa.Sign(privateKey, transaction, transactionMetaData.Protected ?? true); | ||
} | ||
else if (txLegacy.R.HasValue && txLegacy.S.HasValue && txLegacy.V.HasValue) | ||
{ | ||
transaction.Signature = new Signature(txLegacy.R.Value, txLegacy.S.Value, txLegacy.V.Value.ToUInt64(null)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core; | ||
|
||
namespace Evm.t8n.JsonTypes; | ||
|
||
public class Ommer(int delta, Address address) | ||
{ | ||
public int Delta { get; set; } = delta; | ||
public Address Address { get; set; } = address; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Ethereum.Test.Base; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Evm.Tracing.GethStyle; | ||
using Nethermind.Int256; | ||
using Nethermind.Specs; | ||
|
||
namespace Evm.t8n.JsonTypes; | ||
|
||
public class T8NTest(IReleaseSpec spec, ISpecProvider specProvider) | ||
{ | ||
public IReleaseSpec Spec { get; set; } = spec; | ||
public ISpecProvider SpecProvider { get; set; } = specProvider; | ||
public Address? CurrentCoinbase { get; set; } | ||
public UInt256? CurrentDifficulty { get; set; } | ||
|
||
public UInt256? CurrentBaseFee { get; set; } | ||
public long CurrentGasLimit { get; set; } | ||
public long CurrentNumber { get; set; } | ||
public ulong CurrentTimestamp { get; set; } | ||
public Hash256? PreviousHash { get; set; } | ||
public Dictionary<Address, AccountState> Alloc { get; set; } = []; | ||
public Hash256? PostHash { get; set; } | ||
public Transaction[] Transactions { get; set; } = []; | ||
public Hash256? CurrentRandom { get; set; } | ||
public Hash256? CurrentBeaconRoot { get; set; } | ||
public Hash256? CurrentWithdrawalsRoot { get; set; } | ||
public ulong? CurrentExcessBlobGas { get; set; } | ||
public UInt256? ParentBlobGasUsed { get; set; } | ||
public UInt256? ParentExcessBlobGas { get; set; } | ||
|
||
public Withdrawal[]? Withdrawals { get; set; } | ||
public ulong ParentTimestamp { get; set; } | ||
public UInt256? ParentDifficulty { get; set; } | ||
public Hash256? ParentUncleHash { get; set; } | ||
public Hash256? ParentBeaconBlockRoot { get; set; } | ||
public UInt256? ParentBaseFee { get; set; } | ||
public long ParentGasUsed { get; set; } | ||
public long ParentGasLimit { get; set; } | ||
public Dictionary<string, Hash256> BlockHashes { get; set; } = []; | ||
public Ommer[] Ommers { get; set; } = []; | ||
public ulong StateChainId { get; set; } = MainnetSpecProvider.Instance.ChainId; | ||
public GethTraceOptions GethTraceOptions { get; set; } = GethTraceOptions.Default; | ||
public bool IsTraceEnabled { get; set; } = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
namespace Evm.t8n.JsonTypes; | ||
|
||
public class TransactionMetaData | ||
{ | ||
public bool? Protected { get; set; } | ||
public byte[]? SecretKey { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.