Skip to content

Commit

Permalink
fix, disallow create tx in SetCode tx type
Browse files Browse the repository at this point in the history
  • Loading branch information
smartprogrammer93 committed Sep 10, 2024
1 parent d11df9c commit b347664
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Numerics;
using FluentAssertions;
using Nethermind.Consensus.Messages;
using Nethermind.Consensus.Validators;
using Nethermind.Core;
using Nethermind.Core.Crypto;
Expand Down Expand Up @@ -533,20 +534,25 @@ public void IsWellFormed_BlobTxHasProofOverTheSizeLimit_ReturnFalse()
}

[Test]
public void IsWellFormed_AuthorizationListTxInCancunSpec_ReturnsFalse()
public void IsWellFormed_CreateTxInSetCodeFalse()
{
TransactionBuilder<Transaction> txBuilder = Build.A.Transaction
.WithType(TxType.SetCode)
.WithAuthorizationCode(new AuthorizationTuple(0, TestItem.AddressA, 0, 0, [], []))
.WithMaxFeePerGas(100000)
.WithGasLimit(1000000)
.WithChainId(TestBlockchainIds.ChainId)
.SignedAndResolved();
.SignedAndResolved()
.WithTo(null);

Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance, out _), Is.False);
Assert.Multiple(() =>
{
Assert.That(txValidator.IsWellFormed(tx, Prague.Instance, out string? error), Is.False);
Assert.That(error, Is.EqualTo(TxErrorMessages.NotAllowedCreateTransaction));
});
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static string InvalidTxChainId(ulong expected, ulong? actual) =>
public const string InvalidTransaction =
$"InvalidTransaction: Cannot be {nameof(ShardBlobNetworkWrapper)}.";

public const string TxMissingTo =
"TxMissingTo: Must be set.";
public const string NotAllowedCreateTransaction =
"NotAllowedCreateTransaction: To must be set.";

public const string BlobTxMissingMaxFeePerBlobGas =
"BlobTxMissingMaxFeePerBlobGas: Must be set.";
Expand Down
31 changes: 15 additions & 16 deletions src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public bool IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec, out
&& ValidateWithError(Validate1559GasFields(transaction, releaseSpec), TxErrorMessages.InvalidMaxPriorityFeePerGas, ref error)
&& ValidateWithError(Validate3860Rules(transaction, releaseSpec), TxErrorMessages.ContractSizeTooBig, ref error)
&& Validate4844Fields(transaction, ref error)
&& ValidateAuthorityList(transaction, ref error);
&& Validate7702(transaction, ref error);
}

private static bool Validate3860Rules(Transaction transaction, IReleaseSpec releaseSpec) =>
Expand Down Expand Up @@ -155,11 +155,6 @@ private bool ValidateSignature(Transaction tx, IReleaseSpec spec)

private bool ValidateAuthoritySignature(Signature signature)
{
if (signature is null)
{
return false;
}

UInt256 sValue = new(signature.SAsSpan, isBigEndian: true);

if (sValue >= Secp256K1Curve.HalfNPlusOne)
Expand Down Expand Up @@ -197,9 +192,9 @@ private static bool Validate4844Fields(Transaction transaction, ref string? erro
return true;
}

if (transaction.To is null)
if (transaction.IsContractCreation)
{
error = TxErrorMessages.TxMissingTo;
error = TxErrorMessages.NotAllowedCreateTransaction;
return false;
}

Expand Down Expand Up @@ -313,22 +308,26 @@ private static bool Validate4844Fields(Transaction transaction, ref string? erro
return true;
}

private bool ValidateAuthorityList(Transaction tx, ref string error)
private bool Validate7702(Transaction tx, ref string error)
{
if (tx.Type != TxType.SetCode)
{
if (tx.AuthorizationList is not null)
{
error = TxErrorMessages.NotAllowedAuthorizationList;
return false;
}
if (tx.AuthorizationList is null)
return true;
error = TxErrorMessages.NotAllowedAuthorizationList;
return false;
}
if (tx.IsContractCreation)
{
error = TxErrorMessages.NotAllowedCreateTransaction;
return false;
}
else if (tx.AuthorizationList is null || tx.AuthorizationList.Length == 0)
if (tx.AuthorizationList is null || tx.AuthorizationList.Length == 0)

This comment has been minimized.

Copy link
@MarekM25

MarekM25 Sep 12, 2024

Contributor

there is one more validation in TransactionProcessor and one more in BlockProductionPicker, check EIP3860 validation

{
error = TxErrorMessages.MissingAuthorizationList;
return false;
}
else if (tx.AuthorizationList.Any(a => !ValidateAuthoritySignature(a.AuthoritySignature)))
if (tx.AuthorizationList.Any(a => !ValidateAuthoritySignature(a.AuthoritySignature)))
{
error = TxErrorMessages.InvalidAuthoritySignature;
return false;
Expand Down

0 comments on commit b347664

Please sign in to comment.