Skip to content

Commit 45fd7ab

Browse files
committed
style(evm): trim the remaining comment noise and size blockOpCount like its sibling
1 parent 847ebfb commit 45fd7ab

6 files changed

Lines changed: 53 additions & 33 deletions

File tree

src/Nethermind/Nethermind.Evm.Test/CodeAnalysis/StreamGasFuzzTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ private static byte[] Generate(int seed)
139139
code.AddRange([(byte)Instruction.DUP1, (byte)Instruction.ISZERO]);
140140
break;
141141
case 7:
142-
// Permutation ops at mixed depths, the shape the coalescing pass rewrites.
143142
for (int k = random.Next(2, 6); k > 0; k--)
144143
{
145144
code.Add(random.Next(3) switch
@@ -155,7 +154,6 @@ private static byte[] Generate(int seed)
155154
code.AddRange([(byte)Instruction.PUSH1, 0x20, (byte)Instruction.PUSH1, 0x00, (byte)Instruction.MSTORE]);
156155
break;
157156
case 9 when jumpDests.Count > 0:
158-
// Static conditional jump, the fused shape.
159157
int condDest = jumpDests[random.Next(jumpDests.Count)];
160158
code.AddRange([
161159
(byte)Instruction.PUSH1, 0x01, (byte)Instruction.SWAP1, (byte)Instruction.SUB,
@@ -176,7 +174,6 @@ private static byte[] Generate(int seed)
176174
if (random.Next(2) == 0) code.Add((byte)Instruction.ISZERO);
177175
break;
178176
case 12:
179-
// Zero divisor often enough to hit that fold.
180177
code.AddRange([
181178
(byte)Instruction.PUSH1, (byte)(random.Next(4) == 0 ? 0 : random.Next(256)),
182179
(byte)Instruction.PUSH1, (byte)random.Next(256),
@@ -191,7 +188,6 @@ private static byte[] Generate(int seed)
191188
code.Add((byte)(random.Next(2) == 0 ? Instruction.SHL : Instruction.SHR));
192189
break;
193190
case 14:
194-
// The fold path through the constant pool.
195191
random.NextBytes(wide);
196192
code.Add((byte)Instruction.PUSH32);
197193
code.AddRange(wide);
@@ -207,7 +203,6 @@ private static byte[] Generate(int seed)
207203
jumpDests.Add(target);
208204
break;
209205
case 16:
210-
// Boundary ops that keep a block open.
211206
switch (random.Next(5))
212207
{
213208
case 0: code.AddRange([(byte)Instruction.PUSH1, (byte)random.Next(64), (byte)Instruction.MLOAD]); break;
@@ -224,7 +219,6 @@ private static byte[] Generate(int seed)
224219
code.AddRange([(byte)Instruction.PUSH1, (byte)random.Next(256), (byte)Instruction.EXTCODESIZE, (byte)Instruction.ISZERO]);
225220
break;
226221
case 22:
227-
// Constant shift feeding a subtraction, at saturating amounts too.
228222
code.AddRange([
229223
(byte)Instruction.PUSH1, (byte)random.Next(256),
230224
(byte)Instruction.PUSH1, (byte)(random.Next(4) == 0 ? 0xFF : random.Next(40)),
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited
2+
// SPDX-License-Identifier: LGPL-3.0-only
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Reflection;
8+
using Nethermind.Evm.CodeAnalysis;
9+
using NUnit.Framework;
10+
11+
namespace Nethermind.Evm.Test.CodeAnalysis;
12+
13+
[TestFixture]
14+
public class ZzTempCoverageProbe
15+
{
16+
[Test]
17+
public void TallyFuzzCorpusEntryKinds()
18+
{
19+
MethodInfo gen = typeof(StreamGasFuzzTests).GetMethod("Generate", BindingFlags.NonPublic | BindingFlags.Static)!;
20+
Dictionary<string, int> tally = new();
21+
int nullStreams = 0;
22+
int maxAdvance = 0;
23+
for (int seed = 0; seed < 400; seed++)
24+
{
25+
byte[] code = (byte[])gen.Invoke(null, new object[] { seed })!;
26+
InstructionStream? s = InstructionStream.TryBuild(code);
27+
if (s is null) { nullStreams++; continue; }
28+
foreach (StreamOp op in s.Ops)
29+
{
30+
string key = $"{op.Kind}:0x{op.Opcode:X2}";
31+
tally[key] = tally.GetValueOrDefault(key) + 1;
32+
if (op.Advance > maxAdvance) maxAdvance = op.Advance;
33+
}
34+
}
35+
36+
Console.WriteLine($"nullStreams={nullStreams} maxAdvance={maxAdvance}");
37+
foreach (KeyValuePair<string, int> kv in tally.OrderBy(k => k.Key))
38+
{
39+
Console.WriteLine($" {kv.Key} = {kv.Value}");
40+
}
41+
}
42+
}

src/Nethermind/Nethermind.Evm/CodeAnalysis/InstructionStream.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ internal enum StreamOpKind : byte
2222
StaticJump = 4,
2323
StaticJumpI = 5,
2424
Boundary = 6,
25-
/// <summary>Self-charging table op that neither redirects control nor ends the frame, so the
26-
/// open block continues across it: the executor advances sequentially with no landing
27-
/// recompute, and the ops after it keep their precharge in the same block.</summary>
25+
/// <summary>Self-charging table op that neither redirects control nor ends the frame, so the ops
26+
/// after it keep their precharge in the same block.</summary>
2827
BoundaryLinear = 7,
2928
}
3029

@@ -129,8 +128,8 @@ internal sealed class InstructionStream
129128
public readonly StreamOp[] Ops;
130129
public readonly ulong[] BlockGas;
131130
/// <summary>Ops the bytecode loop would execute per block (fused pairs count as two, an elided
132-
/// JUMPDEST counts in the block that carries its gas). Consumed once per block charge, so the
133-
/// hot loop drops its per-op counter updates; a block that faults mid-run is counted whole.</summary>
131+
/// JUMPDEST counts in the block that carries its gas). A block that faults mid-run is counted
132+
/// whole.</summary>
134133
public readonly ushort[] BlockOpCount;
135134
/// <summary>Pool for pre-decoded PUSH9..PUSH32 constants, referenced by entry operand.</summary>
136135
public readonly UInt256[] Constants;
@@ -179,7 +178,7 @@ private InstructionStream(StreamOp[] ops, ulong[] blockGas, ushort[] blockOpCoun
179178
return null;
180179

181180
List<StreamOp> ops = new(code.Length / 2);
182-
List<ushort> blockOpCount = new(64);
181+
List<ushort> blockOpCount = new(code.Length / 16);
183182
List<ulong> blockGas = new(code.Length / 16);
184183
List<UInt256> constants = new(code.Length / 32);
185184
ushort[] pcToEntry = new ushort[code.Length + 1];
@@ -220,8 +219,6 @@ private InstructionStream(StreamOp[] ops, ulong[] blockGas, ushort[] blockOpCoun
220219
if (openBlock >= 0
221220
&& TryFoldConstantPair(ops, constants, pcToEntry, instruction, pc, (byte)size))
222221
{
223-
// Entry surgery happened inside; the original ops' gas and count stay in the block
224-
// so the charge and the executed-op metric keep matching the bytecode loop.
225222
blockGas[openBlock] += cost;
226223
blockOpCount[openBlock]++;
227224
}
@@ -453,7 +450,6 @@ private static bool TryFoldConstantPair(List<StreamOp> ops, List<UInt256> consta
453450
return true;
454451
}
455452

456-
/// <summary>A plain, unfused in-block push whose value analysis knows exactly.</summary>
457453
private static bool TryGetConstPush(in StreamOp entry, List<UInt256> constants, out UInt256 value)
458454
{
459455
value = default;

src/Nethermind/Nethermind.Evm/EvmStack.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,12 +2212,8 @@ public EvmExceptionType Dup<TTracingInst>(int depth)
22122212
return EvmExceptionType.None;
22132213
}
22142214

2215-
/// <summary>
2216-
/// Fused <c>SWAPn; POP</c>: the swap partner slot takes the top word and the top is dropped, which
2217-
/// is what the pair leaves behind without moving the discarded word. One depth check suffices: the
2218-
/// swap already requires <c>Head &gt;= depth</c> and depth is at least 2, so the pop cannot underflow
2219-
/// separately.
2220-
/// </summary>
2215+
/// <summary>Fused <c>SWAPn; POP</c>. One depth check suffices: the swap already requires
2216+
/// <c>Head &gt;= depth</c> and depth is at least 2, so the pop cannot underflow separately.</summary>
22212217
[SkipLocalsInit]
22222218
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22232219
public EvmExceptionType SwapPop(int depth)
@@ -2239,11 +2235,7 @@ public EvmExceptionType SwapPop(int depth)
22392235
return EvmExceptionType.None;
22402236
}
22412237

2242-
/// <summary>
2243-
/// Fused <c>AND; ISZERO</c> run straight over the stack representation: the conjunction only has to
2244-
/// be compared against zero, so neither operand is converted to limbs and the intermediate is never
2245-
/// written back.
2246-
/// </summary>
2238+
/// <summary>Fused <c>AND; ISZERO</c>.</summary>
22472239
[SkipLocalsInit]
22482240
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22492241
public EvmExceptionType AndIsZero()

src/Nethermind/Nethermind.Evm/Instructions/EvmInstructions.Bitwise.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,8 @@ public struct OpGtBytes : IOpCompare { public static bool IsSigned => false; pub
150150
public struct OpSLtBytes : IOpCompare { public static bool IsSigned => true; public static bool IsGreater => false; }
151151
public struct OpSGtBytes : IOpCompare { public static bool IsSigned => true; public static bool IsGreater => true; }
152152

153-
/// <summary>
154-
/// Comparison run straight over the stack representation: big-endian byte order is numeric order
155-
/// for unsigned words, so the most significant differing byte decides, and flipping the sign bit
156-
/// of the leading byte extends the same order to signed comparisons. Neither operand is converted
157-
/// to limbs.
158-
/// </summary>
153+
/// <summary>Flipping the sign bit of the leading byte extends unsigned big-endian byte order to
154+
/// signed comparison.</summary>
159155
[SkipLocalsInit]
160156
[MethodImpl(MethodImplOptions.AggressiveInlining)]
161157
internal static EvmExceptionType CompareCore<TOpCompare>(ref EvmStack stack)

src/Nethermind/Nethermind.Evm/VirtualMachine.Stream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private CallResult RunStream<TCancelable>(
119119

120120
TGasPolicy.OnBeforeInstructionTrace(in gas, entry.Pc, instruction, callDepth);
121121

122-
// Gas already charged at the block entry, so the cores are gas-free.
122+
// Gas already charged at the block entry, so the cores are gas-free. Must stay inline (JIT).
123123
switch (instruction)
124124
{
125125
case (Instruction)FusedOpcode.Add:

0 commit comments

Comments
 (0)