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

rename keccak #6197

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Difficulty.Test/TestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static UInt256 ToUInt256(string hex)

protected static DifficultyTests ToTest(string fileName, string name, DifficultyTestHexJson json)
{
Keccak noUnclesHash = Keccak.OfAnEmptySequenceRlp;
Hash256 noUnclesHash = Keccak.OfAnEmptySequenceRlp;

return new DifficultyTests(
fileName,
Expand All @@ -72,7 +72,7 @@ protected static DifficultyTests ToTest(string fileName, string name, Difficulty
(ulong)ToUInt256(json.CurrentTimestamp),
(long)ToUInt256(json.CurrentBlockNumber),
ToUInt256(json.CurrentDifficulty),
!string.IsNullOrWhiteSpace(json.ParentUncles) && new Keccak(json.ParentUncles) != noUnclesHash);
!string.IsNullOrWhiteSpace(json.ParentUncles) && new Hash256(json.ParentUncles) != noUnclesHash);
}

protected void RunTest(DifficultyTests test, ISpecProvider specProvider)
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.KeyAddress.Test/KeyAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static KeyAddressTest FromJson(KeyAddressTestJson testJson)
[TestCase("0x36d85Dc3683156e63Bf880A9fAb7788CF8143a27", "Christopher Pearce", "0x34ff4b97a0ec8f735f781f250dcd3070a72ddb640072dd39553407d0320db79939e3b080ecaa2e9f248214c6f0811fb4b4ba05b7bcff254c053e47d8513e82091b")]
public void Recovered_address_as_expected(string addressHex, string message, string sigHex)
{
Keccak messageHash = Keccak.Compute(message);
Hash256 messageHash = Keccak.Compute(message);
Signature sig = new Signature(sigHex);
Address recovered = _ecdsa.RecoverAddress(sig, messageHash);
Address address = new Address(addressHex);
Expand Down
34 changes: 17 additions & 17 deletions src/Nethermind/Ethereum.PoW.Test/EthashTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ private static EthashTest Convert(string name, EthashTestJson testJson)
return new EthashTest(
name,
nonceValue,
new Keccak(testJson.MixHash),
new Hash256(testJson.MixHash),
Bytes.FromHexString(testJson.Header),
new Keccak(testJson.Seed),
new Hash256(testJson.Seed),
testJson.CacheSize,
testJson.FullSize,
new Keccak(testJson.HeaderHash),
new Keccak(testJson.CacheHash),
new Keccak(testJson.Result));
new Hash256(testJson.HeaderHash),
new Hash256(testJson.CacheHash),
new Hash256(testJson.Result));
}

[TestCaseSource(nameof(LoadTests))]
Expand All @@ -61,7 +61,7 @@ public void Test(EthashTest test)
Assert.That(blockHeader.Nonce, Is.EqualTo(test.Nonce), "header nonce vs test nonce");
Assert.That(Bytes.AreEqual(blockHeader.MixHash.Bytes, test.MixHash.Bytes), Is.True, "header mix hash vs test mix hash");

Keccak headerHash = Keccak.Compute(Rlp.Encode(blockHeader, RlpBehaviors.ForSealing).Bytes);
Hash256 headerHash = Keccak.Compute(Rlp.Encode(blockHeader, RlpBehaviors.ForSealing).Bytes);
Assert.That(headerHash, Is.EqualTo(test.HeaderHash), "header hash");

// seed is correct
Expand All @@ -84,7 +84,7 @@ public void Test(EthashTest test)
Assert.That(Bytes.AreEqual(test.Result.Bytes, resultHalfTest), Is.True, "half test");

// here we confirm that the whole mix hash calculation is fine
(byte[] mixHash, ValueKeccak result, bool success) = ethash.Hashimoto((ulong)test.FullSize, cache, headerHash, blockHeader.MixHash, test.Nonce);
(byte[] mixHash, ValueHash256 result, bool success) = ethash.Hashimoto((ulong)test.FullSize, cache, headerHash, blockHeader.MixHash, test.Nonce);
Assert.That(Bytes.AreEqual(mixHash, test.MixHash.Bytes), Is.True, "mix hash");
Assert.That(Bytes.AreEqual(result.Bytes, test.Result.Bytes), Is.True, "result");

Expand Down Expand Up @@ -123,14 +123,14 @@ public class EthashTest
public EthashTest(
string name,
ulong nonce,
Keccak mixHash,
Hash256 mixHash,
byte[] header,
Keccak seed,
Hash256 seed,
BigInteger cacheSize,
BigInteger fullSize,
Keccak headerHash,
Keccak cacheHash,
Keccak result)
Hash256 headerHash,
Hash256 cacheHash,
Hash256 result)
{
Name = name;
Nonce = nonce;
Expand All @@ -146,14 +146,14 @@ public class EthashTest

public string Name { get; }
public ulong Nonce { get; }
public Keccak MixHash { get; }
public Hash256 MixHash { get; }
public byte[] Header { get; }
public Keccak Seed { get; }
public Hash256 Seed { get; }
public BigInteger CacheSize { get; }
public BigInteger FullSize { get; }
public Keccak HeaderHash { get; }
public Keccak CacheHash { get; }
public Keccak Result { get; }
public Hash256 HeaderHash { get; }
public Hash256 CacheHash { get; }
public Hash256 Result { get; }

public override string ToString() => Name;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class BlockchainTest : IEthereumTest
public IReleaseSpec? Network { get; set; }
public IReleaseSpec? NetworkAfterTransition { get; set; }
public ForkActivation? TransitionForkActivation { get; set; }
public Keccak? LastBlockHash { get; set; }
public Hash256? LastBlockHash { get; set; }
public Rlp? GenesisRlp { get; set; }

public TestBlockJson[]? Blocks { get; set; }
public TestBlockHeaderJson? GenesisBlockHeader { get; set; }

public Dictionary<Address, AccountState>? Pre { get; set; }
public Dictionary<Address, AccountState>? PostState { get; set; }
public Keccak? PostStateRoot { get; set; }
public Hash256? PostStateRoot { get; set; }
public bool SealEngineUsed { get; set; }
public string? LoadFailure { get; set; }

Expand Down
10 changes: 5 additions & 5 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
}

Block genesisBlock = Rlp.Decode<Block>(test.GenesisRlp.Bytes);
Assert.That(genesisBlock.Header.Hash, Is.EqualTo(new Keccak(test.GenesisBlockHeader.Hash)));
Assert.That(genesisBlock.Header.Hash, Is.EqualTo(new Hash256(test.GenesisBlockHeader.Hash)));

ManualResetEvent genesisProcessed = new(false);
blockTree.NewHeadBlock += (_, args) =>
Expand Down Expand Up @@ -264,12 +264,12 @@ private List<(Block Block, string ExpectedException)> DecodeRlps(BlockchainTest

if (testBlockJson.BlockHeader is not null)
{
Assert.That(suggestedBlock.Header.Hash, Is.EqualTo(new Keccak(testBlockJson.BlockHeader.Hash)));
Assert.That(suggestedBlock.Header.Hash, Is.EqualTo(new Hash256(testBlockJson.BlockHeader.Hash)));


for (int uncleIndex = 0; uncleIndex < suggestedBlock.Uncles.Length; uncleIndex++)
{
Assert.That(suggestedBlock.Uncles[uncleIndex].Hash, Is.EqualTo(new Keccak(testBlockJson.UncleHeaders[uncleIndex].Hash)));
Assert.That(suggestedBlock.Uncles[uncleIndex].Hash, Is.EqualTo(new Hash256(testBlockJson.UncleHeaders[uncleIndex].Hash)));
}

correctRlp.Add((suggestedBlock, testBlockJson.ExpectedException));
Expand Down Expand Up @@ -301,7 +301,7 @@ private List<(Block Block, string ExpectedException)> DecodeRlps(BlockchainTest
if (correctRlp.Count == 0)
{
Assert.NotNull(test.GenesisBlockHeader);
Assert.That(test.LastBlockHash, Is.EqualTo(new Keccak(test.GenesisBlockHeader.Hash)));
Assert.That(test.LastBlockHash, Is.EqualTo(new Hash256(test.GenesisBlockHeader.Hash)));
}

return correctRlp;
Expand Down Expand Up @@ -341,7 +341,7 @@ private List<string> RunAssertions(BlockchainTest test, Block headBlock, IWorldS

TestBlockHeaderJson testHeaderJson = (test.Blocks?
.Where(b => b.BlockHeader != null)
.SingleOrDefault(b => new Keccak(b.BlockHeader.Hash) == headBlock.Hash)?.BlockHeader) ?? test.GenesisBlockHeader;
.SingleOrDefault(b => new Hash256(b.BlockHeader.Hash) == headBlock.Hash)?.BlockHeader) ?? test.GenesisBlockHeader;
BlockHeader testHeader = JsonToEthereumTest.Convert(testHeaderJson);
List<string> differences = new();

Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Ethereum.Test.Base
{
public class HalfBlockchainTestJson : BlockchainTestJson
{
public new Keccak PostState { get; set; }
public new Hash256 PostState { get; set; }
}

public class BlockchainTestJson
Expand All @@ -27,7 +27,7 @@ public class BlockchainTestJson
public Dictionary<string, AccountStateJson>? Pre { get; set; }
public Dictionary<string, AccountStateJson>? PostState { get; set; }

public Keccak? PostStateHash { get; set; }
public Hash256? PostStateHash { get; set; }

public string? SealEngine { get; set; }
public string? LoadFailure { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Test.Base/EthereumTestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public EthereumTestResult(string? name, string? loadFailure)

[JsonIgnore] public int TimeInMs { get; set; }

public Keccak StateRoot { get; set; } = Keccak.EmptyTreeHash;
public Hash256 StateRoot { get; set; } = Keccak.EmptyTreeHash;
}
}
8 changes: 4 additions & 4 deletions src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class GeneralStateTest : IEthereumTest
public long CurrentGasLimit { get; set; }
public long CurrentNumber { get; set; }
public ulong CurrentTimestamp { get; set; }
public Keccak? PreviousHash { get; set; }
public Hash256? PreviousHash { get; set; }
public Dictionary<Address, AccountState> Pre { get; set; }
public Keccak? PostHash { get; set; }
public Keccak? PostReceiptsRoot { get; set; }
public Hash256? PostHash { get; set; }
public Hash256? PostReceiptsRoot { get; set; }
public string? LoadFailure { get; set; }
public Transaction? Transaction { get; set; }
public Keccak? CurrentRandom { get; set; }
public Hash256? CurrentRandom { get; set; }

public override string ToString()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/GeneralStateTestEnvJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GeneralStateTestEnvJson
public long CurrentNumber { get; set; }
public ulong CurrentTimestamp { get; set; }
public UInt256? CurrentBaseFee { get; set; }
public Keccak PreviousHash { get; set; }
public Keccak? CurrentRandom { get; set; }
public Hash256 PreviousHash { get; set; }
public Hash256? CurrentRandom { get; set; }
}
}
16 changes: 8 additions & 8 deletions src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public static BlockHeader Convert(TestBlockHeaderJson? headerJson)
}

BlockHeader header = new(
new Keccak(headerJson.ParentHash),
new Keccak(headerJson.UncleHash),
new Hash256(headerJson.ParentHash),
new Hash256(headerJson.UncleHash),
new Address(headerJson.Coinbase),
Bytes.FromHexString(headerJson.Difficulty).ToUInt256(),
(long)Bytes.FromHexString(headerJson.Number).ToUInt256(),
Expand All @@ -101,12 +101,12 @@ public static BlockHeader Convert(TestBlockHeaderJson? headerJson)

header.Bloom = new Bloom(Bytes.FromHexString(headerJson.Bloom));
header.GasUsed = (long)Bytes.FromHexString(headerJson.GasUsed).ToUnsignedBigInteger();
header.Hash = new Keccak(headerJson.Hash);
header.MixHash = new Keccak(headerJson.MixHash);
header.Hash = new Hash256(headerJson.Hash);
header.MixHash = new Hash256(headerJson.MixHash);
header.Nonce = (ulong)Bytes.FromHexString(headerJson.Nonce).ToUnsignedBigInteger();
header.ReceiptsRoot = new Keccak(headerJson.ReceiptTrie);
header.StateRoot = new Keccak(headerJson.StateRoot);
header.TxRoot = new Keccak(headerJson.TransactionsTrie);
header.ReceiptsRoot = new Hash256(headerJson.ReceiptTrie);
header.StateRoot = new Hash256(headerJson.StateRoot);
header.TxRoot = new Hash256(headerJson.TransactionsTrie);
return header;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ public static BlockchainTest Convert(string name, BlockchainTestJson testJson)
test.Network = testJson.EthereumNetwork;
test.NetworkAfterTransition = testJson.EthereumNetworkAfterTransition;
test.TransitionForkActivation = testJson.TransitionForkActivation;
test.LastBlockHash = new Keccak(testJson.LastBlockHash);
test.LastBlockHash = new Hash256(testJson.LastBlockHash);
test.GenesisRlp = testJson.GenesisRlp == null ? null : new Rlp(Bytes.FromHexString(testJson.GenesisRlp));
test.GenesisBlockHeader = testJson.GenesisBlockHeader;
test.Blocks = testJson.Blocks;
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/PostStateJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Ethereum.Test.Base
public class PostStateJson
{
public IndexesJson Indexes { get; set; }
public Keccak Hash { get; set; }
public Keccak Logs { get; set; }
public Hash256 Hash { get; set; }
public Hash256 Logs { get; set; }
}
}
14 changes: 7 additions & 7 deletions src/Nethermind/Ethereum.Test.Base/TestBlockHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class TestBlockHeader
public byte[] ExtraData { get; set; }
public BigInteger GasLimit { get; set; }
public BigInteger GasUsed { get; set; }
public Keccak Hash { get; set; }
public Keccak MixHash { get; set; }
public Hash256 Hash { get; set; }
public Hash256 MixHash { get; set; }
public BigInteger Nonce { get; set; }
public BigInteger Number { get; set; }
public Keccak ParentHash { get; set; }
public Keccak ReceiptTrie { get; set; }
public Keccak StateRoot { get; set; }
public Hash256 ParentHash { get; set; }
public Hash256 ReceiptTrie { get; set; }
public Hash256 StateRoot { get; set; }
public BigInteger Timestamp { get; set; }
public Keccak TransactionsTrie { get; set; }
public Keccak UncleHash { get; set; }
public Hash256 TransactionsTrie { get; set; }
public Hash256 UncleHash { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Test.Base/TestBlockhashProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Ethereum.Test.Base
{
public class TestBlockhashProvider : IBlockhashProvider
{
public Keccak GetBlockhash(BlockHeader currentBlock, in long number)
public Hash256 GetBlockhash(BlockHeader currentBlock, in long number)
{
if (number != 0)
return Keccak.Zero;
Expand Down
12 changes: 6 additions & 6 deletions src/Nethermind/Ethereum.Trie.Test/StorageTrieTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@ public class StorageTrieTests
public void Storage_trie_set_reset_with_empty()
{
StorageTree tree = new StorageTree(new TrieStore(new MemDb(), LimboLogs.Instance), Keccak.EmptyTreeHash, LimboLogs.Instance);
Keccak rootBefore = tree.RootHash;
Hash256 rootBefore = tree.RootHash;
tree.Set(1, new byte[] { 1 });
tree.Set(1, new byte[] { });
tree.UpdateRootHash();
Keccak rootAfter = tree.RootHash;
Hash256 rootAfter = tree.RootHash;
Assert.That(rootAfter, Is.EqualTo(rootBefore));
}

[Test]
public void Storage_trie_set_reset_with_long_zero()
{
StorageTree tree = new StorageTree(new TrieStore(new MemDb(), LimboLogs.Instance), Keccak.EmptyTreeHash, LimboLogs.Instance);
Keccak rootBefore = tree.RootHash;
Hash256 rootBefore = tree.RootHash;
tree.Set(1, new byte[] { 1 });
tree.Set(1, new byte[] { 0, 0, 0, 0, 0 });
tree.UpdateRootHash();
Keccak rootAfter = tree.RootHash;
Hash256 rootAfter = tree.RootHash;
Assert.That(rootAfter, Is.EqualTo(rootBefore));
}

[Test]
public void Storage_trie_set_reset_with_short_zero()
{
StorageTree tree = new StorageTree(new TrieStore(new MemDb(), LimboLogs.Instance), Keccak.EmptyTreeHash, LimboLogs.Instance);
Keccak rootBefore = tree.RootHash;
Hash256 rootBefore = tree.RootHash;
tree.Set(1, new byte[] { 1 });
tree.Set(1, new byte[] { 0 });
tree.UpdateRootHash();
Keccak rootAfter = tree.RootHash;
Hash256 rootAfter = tree.RootHash;
Assert.That(rootAfter, Is.EqualTo(rootBefore));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Ethereum.Trie.Test/TrieTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public void Delete_missing_resolved_on_branch()
PatriciaTree patriciaTree = new PatriciaTree(_db, Keccak.EmptyTreeHash, false, true, NullLogManager.Instance);
patriciaTree.Set(Keccak.Compute("1123").Bytes, new byte[] { 1 });
patriciaTree.Set(Keccak.Compute("1124").Bytes, new byte[] { 2 });
Keccak rootBefore = patriciaTree.RootHash;
Hash256 rootBefore = patriciaTree.RootHash;
patriciaTree.Set(Keccak.Compute("1125").Bytes, new byte[0]);
Assert.That(patriciaTree.RootHash, Is.EqualTo(rootBefore));
}
Expand All @@ -324,7 +324,7 @@ public void Delete_missing_resolved_on_extension()
patriciaTree.Set(new Nibble[] { 1, 2, 3, 4 }.ToPackedByteArray(), new byte[] { 1 });
patriciaTree.Set(new Nibble[] { 1, 2, 3, 4, 5 }.ToPackedByteArray(), new byte[] { 2 });
patriciaTree.UpdateRootHash();
Keccak rootBefore = patriciaTree.RootHash;
Hash256 rootBefore = patriciaTree.RootHash;
patriciaTree.Set(new Nibble[] { 1, 2, 3 }.ToPackedByteArray(), new byte[] { });
patriciaTree.UpdateRootHash();
Assert.That(patriciaTree.RootHash, Is.EqualTo(rootBefore));
Expand All @@ -337,7 +337,7 @@ public void Delete_missing_resolved_on_leaf()
patriciaTree.Set(Keccak.Compute("1234567").Bytes, new byte[] { 1 });
patriciaTree.Set(Keccak.Compute("1234501").Bytes, new byte[] { 2 });
patriciaTree.UpdateRootHash();
Keccak rootBefore = patriciaTree.RootHash;
Hash256 rootBefore = patriciaTree.RootHash;
patriciaTree.Set(Keccak.Compute("1234502").Bytes, new byte[0]);
patriciaTree.UpdateRootHash();
Assert.That(patriciaTree.RootHash, Is.EqualTo(rootBefore));
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Abi.Test/AbiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void Test_single_address_no_signature(AbiEncodingStyle encodingStyle)
[TestCase(AbiEncodingStyle.None)]
public void Test_packed(AbiEncodingStyle encodingStyle)
{
Keccak assetId = Keccak.Compute("assetId");
Hash256 assetId = Keccak.Compute("assetId");
uint expiryTime = (uint)Timestamper.Default.UnixTime.Seconds + 86000;
UInt256 value = 1.Ether();
uint units = 10U;
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Abi/AbiBaseDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class AbiBaseDescription<T> : AbiBaseDescription where T : AbiPa
public AbiEncodingInfo GetCallInfo(AbiEncodingStyle encodingStyle = AbiEncodingStyle.IncludeSignature) =>
new(encodingStyle, _callSignature ??= new AbiSignature(Name, Inputs.Select(i => i.Type).ToArray()));

public Keccak GetHash() => GetCallInfo().Signature.Hash;
public Hash256 GetHash() => GetCallInfo().Signature.Hash;

}
}
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Abi/AbiBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override byte[] Encode(object? arg, bool packed)
return Encode(Encoding.ASCII.GetBytes(stringInput), packed);
}

if (arg is Keccak hash && Length == 32)
if (arg is Hash256 hash && Length == 32)
{
return Encode(hash.Bytes.ToArray(), packed);
}
Expand Down
Loading
Loading