Skip to content

Commit

Permalink
No signature in legacy transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
deffrian committed Dec 10, 2024
1 parent f721a3f commit ad54d84
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Zero_r_is_not_valid()
Transaction tx = Build.A.Transaction.WithSignature(signature).TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
txValidator.IsWellFormed(tx, MuirGlacier.Instance).AsBool().Should().BeFalse();
txValidator.IsWellFormed(tx, null, MuirGlacier.Instance).AsBool().Should().BeFalse();
}

private static byte CalculateV() => (byte)EthereumEcdsaExtensions.CalculateV(TestBlockchainIds.ChainId);
Expand All @@ -72,7 +72,7 @@ public void Zero_s_is_not_valid()
Transaction tx = Build.A.Transaction.WithSignature(signature).TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
txValidator.IsWellFormed(tx, MuirGlacier.Instance).AsBool().Should().BeFalse();
txValidator.IsWellFormed(tx, null, MuirGlacier.Instance).AsBool().Should().BeFalse();
}

[Test, MaxTime(Timeout.MaxTestTime)]
Expand All @@ -86,7 +86,7 @@ public void Bad_chain_id_is_not_valid()
Transaction tx = Build.A.Transaction.WithSignature(signature).TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
txValidator.IsWellFormed(tx, MuirGlacier.Instance).AsBool().Should().BeFalse();
txValidator.IsWellFormed(tx, null, MuirGlacier.Instance).AsBool().Should().BeFalse();
}

[Test, MaxTime(Timeout.MaxTestTime)]
Expand All @@ -100,7 +100,7 @@ public void No_chain_id_legacy_tx_is_valid()
Transaction tx = Build.A.Transaction.WithSignature(signature).TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
txValidator.IsWellFormed(tx, MuirGlacier.Instance).AsBool().Should().BeTrue();
txValidator.IsWellFormed(tx, null, MuirGlacier.Instance).AsBool().Should().BeTrue();
}

[Test, MaxTime(Timeout.MaxTestTime)]
Expand All @@ -114,7 +114,7 @@ public void Is_valid_with_valid_chain_id()
Transaction tx = Build.A.Transaction.WithSignature(signature).TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
txValidator.IsWellFormed(tx, MuirGlacier.Instance).AsBool().Should().BeTrue();
txValidator.IsWellFormed(tx, null, MuirGlacier.Instance).AsBool().Should().BeTrue();
}

[MaxTime(Timeout.MaxTestTime)]
Expand All @@ -134,7 +134,7 @@ public void Before_eip_155_has_to_have_valid_chain_id_unless_overridden(bool val
releaseSpec.ValidateChainId.Returns(validateChainId);

TxValidator txValidator = new(TestBlockchainIds.ChainId);
txValidator.IsWellFormed(tx, releaseSpec).AsBool().Should().Be(!validateChainId);
txValidator.IsWellFormed(tx, null, releaseSpec).AsBool().Should().Be(!validateChainId);
}

[MaxTime(Timeout.MaxTestTime)]
Expand All @@ -161,7 +161,7 @@ public bool Before_eip_2930_has_to_be_legacy_tx(TxType txType, bool eip2930)
tx.Type = txType;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
return txValidator.IsWellFormed(tx, eip2930 ? Berlin.Instance : MuirGlacier.Instance);
return txValidator.IsWellFormed(tx, null, eip2930 ? Berlin.Instance : MuirGlacier.Instance);
}

[MaxTime(Timeout.MaxTestTime)]
Expand Down Expand Up @@ -192,7 +192,7 @@ public bool Before_eip_1559_has_to_be_legacy_or_access_list_tx(TxType txType, bo

TxValidator txValidator = new(TestBlockchainIds.ChainId);
IReleaseSpec releaseSpec = new ReleaseSpec() { IsEip2930Enabled = eip2930, IsEip1559Enabled = eip1559 };
return txValidator.IsWellFormed(tx, releaseSpec);
return txValidator.IsWellFormed(tx, null, releaseSpec);
}

[MaxTime(Timeout.MaxTestTime)]
Expand All @@ -216,7 +216,7 @@ public bool Chain_Id_required_for_non_legacy_transactions_after_Berlin(TxType tx
tx.Type = txType;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
return txValidator.IsWellFormed(tx, Berlin.Instance);
return txValidator.IsWellFormed(tx, null, Berlin.Instance);
}

[MaxTime(Timeout.MaxTestTime)]
Expand Down Expand Up @@ -247,7 +247,7 @@ public bool MaxFeePerGas_is_required_to_be_greater_than_MaxPriorityFeePerGas(TxT
tx.Type = txType;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
return txValidator.IsWellFormed(tx, London.Instance);
return txValidator.IsWellFormed(tx, null, London.Instance);
}

[MaxTime(Timeout.MaxTestTime)]
Expand All @@ -274,7 +274,7 @@ public void Transaction_with_init_code_above_max_value_is_rejected_when_eip3860E
.WithData(initCode).TestObject;

TxValidator txValidator = new(1);
txValidator.IsWellFormed(tx, releaseSpec).AsBool().Should().Be(expectedResult);
txValidator.IsWellFormed(tx, null, releaseSpec).AsBool().Should().Be(expectedResult);
}

//leading zeros in AccessList - expected to pass (real mainnet tx)
Expand Down Expand Up @@ -312,7 +312,7 @@ public bool Incorrect_transactions_are_rejected(string rlp)
{
Transaction tx = Rlp.Decode<Transaction>(Bytes.FromHexString(rlp), RlpBehaviors.SkipTypedWrapping);
TxValidator txValidator = new(BlockchainIds.Mainnet);
return txValidator.IsWellFormed(tx, London.Instance);
return txValidator.IsWellFormed(tx, null, London.Instance);
}
catch (Exception e) when (e is RlpException or ArgumentException)
{
Expand Down Expand Up @@ -345,8 +345,8 @@ public void ShardBlobTransactions_should_have_destination_set()
.WithChainId(TestBlockchainIds.ChainId)
.SignedAndResolved().TestObject;

Assert.That(txValidator.IsWellFormed(txWithoutTo, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(txWithTo, Cancun.Instance).AsBool());
Assert.That(txValidator.IsWellFormed(txWithoutTo, null, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(txWithTo, null, Cancun.Instance).AsBool());
}

[MaxTime(Timeout.MaxTestTime)]
Expand All @@ -367,7 +367,7 @@ public bool MaxFeePerBlobGas_should_be_set_for_blob_tx_only(TxType txType, bool
Transaction tx = txBuilder.TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
return txValidator.IsWellFormed(tx, Cancun.Instance);
return txValidator.IsWellFormed(tx, null, Cancun.Instance);
}

[TestCaseSource(nameof(BlobVersionedHashInvalidTestCases))]
Expand All @@ -384,14 +384,14 @@ public bool BlobVersionedHash_should_be_correct(byte[] hash)
.SignedAndResolved().TestObject;

TxValidator txValidator = new(TestBlockchainIds.ChainId);
return txValidator.IsWellFormed(tx, Cancun.Instance);
return txValidator.IsWellFormed(tx, null, Cancun.Instance);
}

[TestCaseSource(nameof(ShardBlobTxIncorrectTransactions))]
public bool ShardBlobTransaction_fields_should_be_verified(Transaction tx)
{
TxValidator txValidator = new(TestBlockchainIds.ChainId);
return txValidator.IsWellFormed(tx, Cancun.Instance);
return txValidator.IsWellFormed(tx, null, Cancun.Instance);
}

[Test]
Expand All @@ -405,7 +405,7 @@ public void IsWellFormed_NotBlobTxButMaxFeePerBlobGasIsSet_ReturnFalse()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}

[Test]
Expand All @@ -419,7 +419,7 @@ public void IsWellFormed_NotBlobTxButBlobVersionedHashesIsSet_ReturnFalse()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}

[Test]
Expand All @@ -436,7 +436,7 @@ public void IsWellFormed_BlobTxToIsNull_ReturnFalse()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}
[Test]
public void IsWellFormed_BlobTxHasMoreDataGasThanAllowed_ReturnFalse()
Expand All @@ -452,7 +452,7 @@ public void IsWellFormed_BlobTxHasMoreDataGasThanAllowed_ReturnFalse()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}

[Test]
Expand All @@ -469,7 +469,7 @@ public void IsWellFormed_BlobTxHasNoBlobs_ReturnFalse()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}

[Test]
Expand All @@ -486,7 +486,7 @@ public void IsWellFormed_BlobTxHasBlobOverTheSizeLimit_ReturnFalse()
((ShardBlobNetworkWrapper)tx.NetworkWrapper!).Blobs[0] = new byte[Ckzg.Ckzg.BytesPerBlob + 1];
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}

[Test]
Expand All @@ -503,7 +503,7 @@ public void IsWellFormed_BlobTxHasCommitmentOverTheSizeLimit_ReturnFalse()
((ShardBlobNetworkWrapper)tx.NetworkWrapper!).Commitments[0] = new byte[Ckzg.Ckzg.BytesPerCommitment + 1];
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}

[Test]
Expand All @@ -520,7 +520,7 @@ public void IsWellFormed_BlobTxHasProofOverTheSizeLimit_ReturnFalse()
((ShardBlobNetworkWrapper)tx.NetworkWrapper!).Proofs[0] = new byte[Ckzg.Ckzg.BytesPerProof + 1];
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Cancun.Instance).AsBool(), Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Cancun.Instance).AsBool(), Is.False);
}

[Test]
Expand All @@ -540,7 +540,7 @@ public void IsWellFormed_CreateTxInSetCode_ReturnsFalse()

Assert.Multiple(() =>
{
ValidationResult validationResult = txValidator.IsWellFormed(tx, Prague.Instance);
ValidationResult validationResult = txValidator.IsWellFormed(tx, null, Prague.Instance);
Assert.That(validationResult.AsBool(), Is.False);
Assert.That(validationResult.Error, Is.EqualTo(TxErrorMessages.NotAllowedCreateTransaction));
});
Expand All @@ -561,7 +561,7 @@ public void IsWellFormed_AuthorizationListTxInPragueSpec_ReturnsTrue()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Prague.Instance).AsBool, Is.True);
Assert.That(txValidator.IsWellFormed(tx, null, Prague.Instance).AsBool, Is.True);
}

[Test]
Expand All @@ -579,7 +579,7 @@ public void IsWellFormed_EmptyAuthorizationList_ReturnsFalse()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Prague.Instance).AsBool, Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Prague.Instance).AsBool, Is.False);
}
[Test]
public void IsWellFormed_NullAuthorizationList_ReturnsFalse()
Expand All @@ -596,7 +596,7 @@ public void IsWellFormed_NullAuthorizationList_ReturnsFalse()
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Prague.Instance).AsBool, Is.False);
Assert.That(txValidator.IsWellFormed(tx, null, Prague.Instance).AsBool, Is.False);
}

private static IEnumerable<TxType> NonSetCodeTypes() =>
Expand All @@ -619,7 +619,7 @@ public void IsWellFormed_NonSetCodeTxHasAuthorizationList_ReturnsFalse(TxType ty
Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Prague.Instance).Error, Is.EqualTo(TxErrorMessages.NotAllowedAuthorizationList));
Assert.That(txValidator.IsWellFormed(tx, null, Prague.Instance).Error, Is.EqualTo(TxErrorMessages.NotAllowedAuthorizationList));
}

private static byte[] MakeArray(int count, params byte[] elements) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public bool Validate(BlockHeader header, BlockHeader[] uncles)
return _result;
}

public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec)
public ValidationResult IsWellFormed(Transaction transaction, Block? block, IReleaseSpec releaseSpec)
{
return _validationResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ protected virtual bool ValidateTransactions(Block block, IReleaseSpec spec, out
{
Transaction transaction = transactions[txIndex];

ValidationResult isWellFormed = _txValidator.IsWellFormed(transaction, spec);
ValidationResult isWellFormed = _txValidator.IsWellFormed(transaction, block, spec);
if (!isWellFormed)
{
if (_logger.IsDebug) _logger.Debug($"{Invalid(block)} Invalid transaction: {isWellFormed}");
Expand Down
Loading

0 comments on commit ad54d84

Please sign in to comment.