Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add verkle trees for state change with gas cost change #28

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
731f7df
use interface for ReadOnlyTxProcessingEnv
tanishqjasoria Dec 27, 2022
89f09a6
remove codeDb
tanishqjasoria Dec 27, 2022
1f12168
allow access to state and storage through WorldState
tanishqjasoria Dec 28, 2022
c6ad3de
merge the UpdateCode and UpdateCodeHash function into InsertCode
tanishqjasoria Jan 2, 2023
82c9062
use a composite state provider
tanishqjasoria Jan 3, 2023
a51a263
define new IWorld interface - combining state and storage provider
tanishqjasoria Jan 6, 2023
ec2a030
replace init interfaces
tanishqjasoria Jan 11, 2023
ad167e0
add verkle tree eip in cancun hardfork (#4975)
tanishqjasoria Dec 7, 2022
86ad3c0
add new gas costs (#4976)
tanishqjasoria Dec 7, 2022
c9b2269
modify blockHeader and account (#4977)
tanishqjasoria Dec 7, 2022
641efbf
add verkle tree and define state and storage interfaces
tanishqjasoria Jan 10, 2023
32fa85c
add verkle tree tests
tanishqjasoria Jan 11, 2023
bad01fa
remove parallization
tanishqjasoria Jan 11, 2023
6cbec48
update EVM tests to use verkle state
tanishqjasoria Jan 11, 2023
fc33682
update state interfaces
tanishqjasoria Jan 11, 2023
53cd3de
update init steps
tanishqjasoria Jan 11, 2023
84a5b1e
fix setting state
tanishqjasoria Jan 12, 2023
9f0ec08
update init steps for verkle tree
tanishqjasoria Jan 12, 2023
cd386d6
update
tanishqjasoria Jan 12, 2023
865c5ee
refactor
tanishqjasoria Jan 12, 2023
6c30304
refactor interfaces
tanishqjasoria Jan 12, 2023
eeb77b0
add condrieu config files - to test
tanishqjasoria Jan 12, 2023
2df1f33
make client to sync using verkle tree
tanishqjasoria Jan 13, 2023
c9134f1
new trie interfaces
tanishqjasoria Jan 15, 2023
c95953c
test state store
tanishqjasoria Jan 16, 2023
4200025
update ethHash to nethDev
tanishqjasoria Jan 16, 2023
23b8054
updates
tanishqjasoria Jan 16, 2023
8ded96a
Merge pull request #27 from tanishqjasoria/verkle/structure-refactor
tanishqjasoria Jan 16, 2023
bf685bd
update tests
tanishqjasoria Jan 16, 2023
93d4fa4
refactor database and history store
tanishqjasoria Jan 17, 2023
5f0ab9e
add another layer of cache in tree
tanishqjasoria Jan 17, 2023
40c552b
fix running evm tests for verkle trees
tanishqjasoria Jan 20, 2023
5a89b6f
upgrade packages
tanishqjasoria Jan 20, 2023
e8b394d
fix errors
tanishqjasoria Jan 20, 2023
6d807cf
Revert "upgrade packages"
tanishqjasoria Jan 21, 2023
619b319
upgrade verkle package
tanishqjasoria Jan 21, 2023
8a836ca
modify VerkleWitness - fix gas cost calculation
tanishqjasoria Jan 26, 2023
13a2faa
update gas costs for verkle trees
tanishqjasoria Jan 26, 2023
098781f
modifications for testnet
tanishqjasoria Jan 29, 2023
3f930fe
update packages
tanishqjasoria Jan 29, 2023
fdbc9e0
update for testnet
tanishqjasoria Jan 30, 2023
2c47deb
dont use destroy lists for verkle trees
tanishqjasoria Jan 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions src/Nethermind/Chains/condrieu.json

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
IEthereumEcdsa ecdsa = new EthereumEcdsa(specProvider.ChainId, _logManager);

TrieStore trieStore = new(stateDb, _logManager);
IStateProvider stateProvider = new StateProvider(trieStore, codeDb, _logManager);
IWorldState stateProvider = new WorldState(trieStore, codeDb, _logManager);
MemDb blockInfoDb = new MemDb();
IBlockTree blockTree = new BlockTree(new MemDb(), new MemDb(), blockInfoDb, new ChainLevelInfoRepository(blockInfoDb), specProvider, NullBloomStorage.Instance, _logManager);
ITransactionComparerProvider transactionComparerProvider = new TransactionComparerProvider(specProvider, blockTree);
Expand All @@ -126,7 +126,6 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
IHeaderValidator headerValidator = new HeaderValidator(blockTree, Sealer, specProvider, _logManager);
IUnclesValidator unclesValidator = new UnclesValidator(blockTree, headerValidator, _logManager);
IBlockValidator blockValidator = new BlockValidator(txValidator, headerValidator, unclesValidator, specProvider, _logManager);
IStorageProvider storageProvider = new StorageProvider(trieStore, stateProvider, _logManager);
IVirtualMachine virtualMachine = new VirtualMachine(
blockhashProvider,
specProvider,
Expand All @@ -140,12 +139,10 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
new TransactionProcessor(
specProvider,
stateProvider,
storageProvider,
virtualMachine,
_logManager),
stateProvider),
stateProvider,
storageProvider,
receiptStorage,
NullWitnessCollector.Instance,
_logManager);
Expand All @@ -158,7 +155,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
_logManager,
BlockchainProcessor.Options.NoReceipts);

InitializeTestState(test, stateProvider, storageProvider, specProvider);
InitializeTestState(test, stateProvider, specProvider);

List<(Block Block, string ExpectedException)> correctRlp = new();
for (int i = 0; i < test.Blocks.Length; i++)
Expand Down Expand Up @@ -263,7 +260,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
await blockchainProcessor.StopAsync(true);
stopwatch?.Stop();

List<string> differences = RunAssertions(test, blockTree.RetrieveHeadBlock(), storageProvider, stateProvider);
List<string> differences = RunAssertions(test, blockTree.RetrieveHeadBlock(), stateProvider);
// if (differences.Any())
// {
// BlockTrace blockTrace = blockchainProcessor.TraceBlock(blockTree.BestSuggested.Hash);
Expand All @@ -280,36 +277,32 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
);
}

private void InitializeTestState(BlockchainTest test, IStateProvider stateProvider, IStorageProvider storageProvider, ISpecProvider specProvider)
private void InitializeTestState(BlockchainTest test, IWorldState stateProvider, ISpecProvider specProvider)
{
foreach (KeyValuePair<Address, AccountState> accountState in
((IEnumerable<KeyValuePair<Address, AccountState>>)test.Pre ?? Array.Empty<KeyValuePair<Address, AccountState>>()))
{
foreach (KeyValuePair<UInt256, byte[]> storageItem in accountState.Value.Storage)
{
storageProvider.Set(new StorageCell(accountState.Key, storageItem.Key), storageItem.Value);
stateProvider.Set(new StorageCell(accountState.Key, storageItem.Key), storageItem.Value);
}

stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance);
Keccak codeHash = stateProvider.UpdateCode(accountState.Value.Code);
stateProvider.UpdateCodeHash(accountState.Key, codeHash, specProvider.GenesisSpec);
stateProvider.InsertCode(accountState.Key, accountState.Value.Code, specProvider.GenesisSpec);
for (int i = 0; i < accountState.Value.Nonce; i++)
{
stateProvider.IncrementNonce(accountState.Key);
}
}

storageProvider.Commit();
stateProvider.Commit(specProvider.GenesisSpec);

storageProvider.CommitTrees(0);
stateProvider.CommitTree(0);

storageProvider.Reset();
stateProvider.Reset();
}

private List<string> RunAssertions(BlockchainTest test, Block headBlock, IStorageProvider storageProvider, IStateProvider stateProvider)
private List<string> RunAssertions(BlockchainTest test, Block headBlock, IWorldState stateProvider)
{
if (test.PostStateRoot != null)
{
Expand Down Expand Up @@ -378,7 +371,7 @@ private List<string> RunAssertions(BlockchainTest test, Block headBlock, IStorag

foreach (KeyValuePair<UInt256, byte[]> clearedStorage in clearedStorages)
{
byte[] value = !stateProvider.AccountExists(acountAddress) ? Bytes.Empty : storageProvider.Get(new StorageCell(acountAddress, clearedStorage.Key));
byte[] value = !stateProvider.AccountExists(acountAddress) ? Bytes.Empty : stateProvider.Get(new StorageCell(acountAddress, clearedStorage.Key));
if (!value.IsZero())
{
differences.Add($"{acountAddress} storage[{clearedStorage.Key}] exp: 0x00, actual: {value.ToHexString(true)}");
Expand All @@ -387,7 +380,7 @@ private List<string> RunAssertions(BlockchainTest test, Block headBlock, IStorag

foreach (KeyValuePair<UInt256, byte[]> storageItem in accountState.Storage)
{
byte[] value = !stateProvider.AccountExists(acountAddress) ? Bytes.Empty : storageProvider.Get(new StorageCell(acountAddress, storageItem.Key)) ?? new byte[0];
byte[] value = !stateProvider.AccountExists(acountAddress) ? Bytes.Empty : stateProvider.Get(new StorageCell(acountAddress, storageItem.Key)) ?? new byte[0];
if (!Bytes.AreEqual(storageItem.Value, value))
{
differences.Add($"{acountAddress} storage[{storageItem.Key}] exp: {storageItem.Value.ToHexString(true)}, actual: {value.ToHexString(true)}");
Expand Down
17 changes: 5 additions & 12 deletions src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
}

TrieStore trieStore = new(stateDb, _logManager);
StateProvider stateProvider = new(trieStore, codeDb, _logManager);
IWorldState stateProvider = new WorldState(trieStore, codeDb, _logManager);
IBlockhashProvider blockhashProvider = new TestBlockhashProvider();
IStorageProvider storageProvider = new StorageProvider(trieStore, stateProvider, _logManager);
IVirtualMachine virtualMachine = new VirtualMachine(
blockhashProvider,
specProvider,
Expand All @@ -76,11 +75,10 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
TransactionProcessor transactionProcessor = new(
specProvider,
stateProvider,
storageProvider,
virtualMachine,
_logManager);

InitializeTestState(test, stateProvider, storageProvider, specProvider);
InitializeTestState(test, stateProvider, specProvider);

BlockHeader header = new(test.PreviousHash, Keccak.OfAnEmptySequenceRlp, test.CurrentCoinbase,
test.CurrentDifficulty, test.CurrentNumber, test.CurrentGasLimit, test.CurrentTimestamp, Array.Empty<byte>());
Expand Down Expand Up @@ -121,30 +119,25 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
return testResult;
}

private static void InitializeTestState(GeneralStateTest test, StateProvider stateProvider,
IStorageProvider storageProvider, ISpecProvider specProvider)
private static void InitializeTestState(GeneralStateTest test, IWorldState stateProvider, ISpecProvider specProvider)
{
foreach (KeyValuePair<Address, AccountState> accountState in test.Pre)
{
foreach (KeyValuePair<UInt256, byte[]> storageItem in accountState.Value.Storage)
{
storageProvider.Set(new StorageCell(accountState.Key, storageItem.Key),
stateProvider.Set(new StorageCell(accountState.Key, storageItem.Key),
storageItem.Value.WithoutLeadingZeros().ToArray());
}

stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance);
Keccak codeHash = stateProvider.UpdateCode(accountState.Value.Code);
stateProvider.UpdateCodeHash(accountState.Key, codeHash, specProvider.GenesisSpec);
stateProvider.InsertCode(accountState.Key, accountState.Value.Code, specProvider.GenesisSpec);
stateProvider.SetNonce(accountState.Key, accountState.Value.Nonce);
}

storageProvider.Commit();
stateProvider.Commit(specProvider.GenesisSpec);

storageProvider.CommitTrees(0);
stateProvider.CommitTree(0);

storageProvider.Reset();
stateProvider.Reset();
}

Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Abi.Contracts/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Nethermind.Consensus.AuRa.Contracts
/// Base class for contracts that will be interacted by the node engine.
/// </summary>
/// <remarks>
/// This class is intended to be inherited and concrete contract class should provide contract specific methods to be able for the node to use the contract.
///
/// This class is intended to be inherited and concrete contract class should provide contract specific methods to be able for the node to use the contract.
///
/// There are 3 main ways a node can interact with contract:
/// 1. It can <see cref="GenerateTransaction{T}(Nethermind.Abi.AbiFunctionDescription,Nethermind.Core.Address,object[])"/> that will be added to a block.
/// 2. It can <see cref="Call(Nethermind.Core.BlockHeader,Nethermind.Abi.AbiFunctionDescription,Nethermind.Core.Address,object[])"/> contract and modify current state of execution.
Expand All @@ -27,7 +27,7 @@ namespace Nethermind.Consensus.AuRa.Contracts
public abstract partial class Contract
{
/// <summary>
/// Default gas limit of transactions generated from contract.
/// Default gas limit of transactions generated from contract.
/// </summary>
public const long DefaultContractGasLimit = 1_600_000L;

Expand Down Expand Up @@ -182,7 +182,7 @@ protected bool TryCall(BlockHeader header, AbiFunctionDescription function, Addr
/// Creates <see cref="Address.SystemUser"/> account if its not in current state.
/// </summary>
/// <param name="stateProvider">State provider.</param>
protected void EnsureSystemAccount(IStateProvider stateProvider)
protected void EnsureSystemAccount(IWorldState stateProvider)
{
if (!stateProvider.AccountExists(Address.SystemUser))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AccountAbstractionPeerManagerTests
private IBlockTree _blockTree = Substitute.For<IBlockTree>();
private ILogger _logger = Substitute.For<ILogger>();
private ILogFinder _logFinder = Substitute.For<ILogFinder>();
private IStateProvider _stateProvider = Substitute.For<IStateProvider>();
private IWorldState _stateProvider = Substitute.For<IWorldState>();
private ISpecProvider _specProvider = Substitute.For<ISpecProvider>();
private readonly ISigner _signer = Substitute.For<ISigner>();
private readonly string[] _entryPointContractAddress = { "0x8595dd9e0438640b5e1254f9df579ac12a86865f", "0x96cc609c8f5458fb8a7da4d94b678e38ebf3d04e" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ protected override BlockProcessor CreateBlockProcessor()
NoBlockRewards.Instance,
new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State),
State,
Storage,
ReceiptStorage,
NullWitnessCollector.Instance,
LogManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ public async Task Should_execute_well_formed_op_successfully_if_codehash_not_cha
chain.SendUserOperation(entryPointAddress[0], op);
if (changeCodeHash)
{
Keccak codeHash = chain.State.UpdateCode(Bytes.Concat(chain.State.GetCode(walletAddress[0]!), 0x00));
chain.State.UpdateCodeHash(walletAddress[0]!, codeHash, chain.SpecProvider.GenesisSpec);
chain.State.InsertCode(walletAddress[0]!, Bytes.Concat(chain.State.GetCode(walletAddress[0]!), 0x00), chain.SpecProvider.GenesisSpec);
chain.State.Commit(chain.SpecProvider.GenesisSpec);
chain.State.RecalculateStateRoot();
chain.State.CommitTree(chain.BlockTree.Head!.Number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class UserOperationPoolTests
private IBlockTree _blockTree = Substitute.For<IBlockTree>();
private IReceiptFinder _receiptFinder = Substitute.For<IReceiptFinder>();
private ILogFinder _logFinder = Substitute.For<ILogFinder>();
private IStateProvider _stateProvider = Substitute.For<IStateProvider>();
private IWorldState _stateProvider = Substitute.For<IWorldState>();
private ISpecProvider _specProvider = Substitute.For<ISpecProvider>();
private readonly ISigner _signer = Substitute.For<ISigner>();
private readonly Keccak _userOperationEventTopic = new("0x33fd4d1f25a5461bea901784a6571de6debc16cd0831932c22c6969cd73ba994");
Expand Down
Loading