Skip to content

Commit

Permalink
Use uint256 for sig values
Browse files Browse the repository at this point in the history
  • Loading branch information
ak88 committed Sep 4, 2024
1 parent 419d727 commit 19f3ad5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/Nethermind/Nethermind.Core/AuthorizationTuple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Nethermind.Int256;
using Nethermind.Logging;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Nethermind.Core;
public class AuthorizationTuple(
Expand All @@ -21,8 +20,8 @@ public AuthorizationTuple(
Address codeAddress,
ulong nonce,
ulong yParity,
byte[] r,
byte[] s,
UInt256 r,
UInt256 s,
Address? authority = null) : this(chainId, codeAddress, nonce, new Signature(r, s, yParity + Signature.VOffset), authority)
{ }

Expand Down
28 changes: 14 additions & 14 deletions src/Nethermind/Nethermind.Evm.Test/IntrinsicGasCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ [new AuthorizationTuple(
new Address(TestContext.CurrentContext.Random.NextBytes(20)),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextBytes(10),
TestContext.CurrentContext.Random.NextBytes(10))
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)))
],
GasCostOf.PerAuthBaseCost);
yield return (
Expand All @@ -137,15 +137,15 @@ [new AuthorizationTuple(
new Address(TestContext.CurrentContext.Random.NextBytes(20)),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextBytes(10),
TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10))),
new AuthorizationTuple(
TestContext.CurrentContext.Random.NextULong(),
new Address(TestContext.CurrentContext.Random.NextBytes(20)),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextBytes(10),
TestContext.CurrentContext.Random.NextBytes(10))
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)))
],
GasCostOf.PerAuthBaseCost * 2);
yield return (
Expand All @@ -154,22 +154,22 @@ [new AuthorizationTuple(
new Address(TestContext.CurrentContext.Random.NextBytes(20)),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextBytes(10),
TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10))),
new AuthorizationTuple(
TestContext.CurrentContext.Random.NextULong(),
new Address(TestContext.CurrentContext.Random.NextBytes(20)),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextBytes(10),
TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10))),
new AuthorizationTuple(
TestContext.CurrentContext.Random.NextULong(),
new Address(TestContext.CurrentContext.Random.NextBytes(20)),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextBytes(10),
TestContext.CurrentContext.Random.NextBytes(10))
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)))
],
GasCostOf.PerAuthBaseCost * 3);
}
Expand All @@ -194,8 +194,8 @@ public void Calculate_TxHasAuthorizationListBeforePrague_ThrowsInvalidDataExcept
TestItem.AddressF,
0,
TestContext.CurrentContext.Random.NextULong(),
TestContext.CurrentContext.Random.NextBytes(10),
TestContext.CurrentContext.Random.NextBytes(10))
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)),
new UInt256(TestContext.CurrentContext.Random.NextBytes(10)))
)
.TestObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,9 @@ protected virtual TransactionResult Execute(Transaction tx, in BlockExecutionCon

HashSet<Address> accessedAddresses = new();
int delegationRefunds = 0;
if (spec.IsEip7702Enabled)
if (spec.IsEip7702Enabled && tx.HasAuthorizationList)
{
if (tx.HasAuthorizationList)
{
delegationRefunds = _codeInfoRepository.InsertFromAuthorizations(WorldState, tx.AuthorizationList, accessedAddresses, spec);
}
delegationRefunds = _codeInfoRepository.InsertFromAuthorizations(WorldState, tx.AuthorizationList, accessedAddresses, spec);
}

ExecutionEnvironment env = BuildExecutionEnvironment(tx, in blCtx, spec, effectiveGasPrice, _codeInfoRepository, accessedAddresses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public AuthorizationTuple Decode(RlpStream stream, RlpBehaviors rlpBehaviors = R
ulong nonce = stream.DecodeULong();

ulong yParity = stream.DecodeULong();
byte[] r = stream.DecodeByteArray();
byte[] s = stream.DecodeByteArray();
UInt256 r = stream.DecodeUInt256();
UInt256 s = stream.DecodeUInt256();
if (!rlpBehaviors.HasFlag(RlpBehaviors.AllowExtraBytes))
stream.Check(check);
return new AuthorizationTuple(
Expand All @@ -48,8 +48,8 @@ public AuthorizationTuple Decode(ref Rlp.ValueDecoderContext decoderContext, Rlp
ulong nonce = decoderContext.DecodeULong();

ulong yParity = decoderContext.DecodeULong();
byte[] r = decoderContext.DecodeByteArray();
byte[] s = decoderContext.DecodeByteArray();
UInt256 r = decoderContext.DecodeUInt256();
UInt256 s = decoderContext.DecodeUInt256();
if (!rlpBehaviors.HasFlag(RlpBehaviors.AllowExtraBytes))
decoderContext.Check(check);
return new AuthorizationTuple(
Expand Down

0 comments on commit 19f3ad5

Please sign in to comment.