Skip to content

Commit

Permalink
small reafac and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqjasoria committed Jul 23, 2024
1 parent 0b4076d commit 24f5cd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm/EvmState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ public Address From
public long Refund { get; set; }

public Address To => Env.CodeSource ?? Env.ExecutingAccount;
public Address ExecutingAccount => Env.ExecutingAccount;
internal bool IsPrecompile => Env.CodeInfo.IsPrecompile;
public readonly ExecutionEnvironment Env;

internal ExecutionType ExecutionType { get; } // TODO: move to CallEnv
public ExecutionType ExecutionType { get; } // TODO: move to CallEnv
public bool IsContractDeployment =>
ExecutionType is ExecutionType.CREATE or ExecutionType.CREATE2;
public bool IsTopLevel { get; } // TODO: move to CallEnv
Expand Down
19 changes: 12 additions & 7 deletions src/Nethermind/Nethermind.Evm/Witness/VerkleExecWitness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Linq;
using Nethermind.Core;
using Nethermind.Core.Collections;
Expand All @@ -19,11 +20,11 @@ public class VerkleExecWitness(ILogManager logManager) : IExecutionWitness
{
private readonly ILogger _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

private readonly JournalSet<Hash256> _accessedLeaves = new();
private readonly JournalSet<byte[]> _accessedSubtrees = new(Bytes.EqualityComparer);
private readonly HashSet<Hash256> _accessedLeaves = new();
private readonly HashSet<byte[]> _accessedSubtrees = new(Bytes.EqualityComparer);

private readonly JournalSet<Hash256> _modifiedLeaves = new();
private readonly JournalSet<byte[]> _modifiedSubtrees = new(Bytes.EqualityComparer);
private readonly HashSet<Hash256> _modifiedLeaves = new();
private readonly HashSet<byte[]> _modifiedSubtrees = new(Bytes.EqualityComparer);


public long AccessForContractCreationInit(Address contractAddress, bool isValueTransfer)
Expand Down Expand Up @@ -93,6 +94,7 @@ public long AccessForGasBeneficiary(Address gasBeneficiary)

public long AccessForCodeOpCodes(Address caller)
{
// _logger.Info($"AccessForCodeOpCodes: {caller}");
var gas = AccessVersion(caller);
gas += AccessCodeSize(caller);
// _logger.Info($"AccessForCodeOpCodes: {caller.Bytes.ToHexString()} {gas}");
Expand All @@ -101,6 +103,7 @@ public long AccessForCodeOpCodes(Address caller)

public long AccessForBalance(Address address, bool isWrite = false)
{
// _logger.Info($"AccessForBalance: {address} {isWrite}");
return AccessBalance(address, isWrite);
}

Expand All @@ -119,7 +122,7 @@ public long AccessForCodeHash(Address address)
/// <returns></returns>
public long AccessForStorage(Address address, UInt256 key, bool isWrite)
{
if (address.IsPrecompile(Osaka.Instance)) return 0;
// if (address.IsPrecompile(Osaka.Instance)) return 0;
var gas = AccessKey(AccountHeader.GetTreeKeyForStorageSlot(address.Bytes, key), isWrite);
// _logger.Info($"AccessStorage: {address.Bytes.ToHexString()} {key.ToBigEndian().ToHexString()} {isWrite} {gas}");
return gas;
Expand Down Expand Up @@ -157,7 +160,7 @@ public bool AccessAndChargeForCodeSlice(Address address, int startIncluded, int
/// <returns></returns>
public long AccessCodeChunk(Address address, UInt256 chunkId, bool isWrite)
{
if (address.IsPrecompile(Osaka.Instance)) return 0;
// if (address.IsPrecompile(Osaka.Instance)) return 0;
Hash256? key = AccountHeader.GetTreeKeyForCodeChunk(address.Bytes, chunkId);
// _logger.Info($"AccessCodeChunkKey: {EnumerableExtensions.ToString(key)}");
var gas = AccessKey(key, isWrite);
Expand Down Expand Up @@ -193,6 +196,8 @@ public long AccessCompleteAccount(Address address, bool isWrite = false)

public long AccessForSelfDestruct(Address contract, Address inheritor, bool balanceIsZero, bool inheritorExist)
{
if (inheritor.IsPrecompile(Osaka.Instance)) return 0;

bool contractNotSameAsBeneficiary = contract != inheritor;
long gas = 0;
gas += AccessVersion(contract);
Expand Down Expand Up @@ -265,7 +270,7 @@ private long AccessCodeHash(Address address, bool isWrite = false)

private long AccessAccountSubTree(Address address, UInt256 treeIndex, byte subIndex, bool isWrite = false)
{
if (address.IsPrecompile(Osaka.Instance)) return 0;
// if (address.IsPrecompile(Osaka.Instance)) return 0;
return AccessKey(AccountHeader.GetTreeKey(address.Bytes, treeIndex, subIndex), isWrite);
}

Expand Down

0 comments on commit 24f5cd8

Please sign in to comment.