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

Fix op-mainnet snapshot #7881

Merged
merged 9 commits into from
Dec 10, 2024
Merged

Fix op-mainnet snapshot #7881

merged 9 commits into from
Dec 10, 2024

Conversation

deffrian
Copy link
Contributor

Fixes Closes Resolves #
Pre-bedrock legacy transactions might not have signature

Changes

  • Adds op legacy tx decoder and signature verifier

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes
  • No

@@ -20,7 +20,7 @@

namespace Nethermind.Init.Steps
{
[RunnerStepDependencies(typeof(InitTxTypesAndRlp), typeof(InitDatabase), typeof(MigrateConfigs), typeof(SetupKeyStore))]
[RunnerStepDependencies(typeof(InitTxTypesAndRlp), typeof(InitDatabase), typeof(MigrateConfigs), typeof(SetupKeyStore), typeof(InitTxTypesAndRlp))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InitTxTypesAndRlp is twice there

@@ -8,6 +8,6 @@ namespace Nethermind.TxPool
{
public interface ITxValidator
{
public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec);
public ValidationResult IsWellFormed(Transaction transaction, Block? block, IReleaseSpec releaseSpec);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? Would reduce those unnecessary nulls all over the place

Suggested change
public ValidationResult IsWellFormed(Transaction transaction, Block? block, IReleaseSpec releaseSpec);
public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec, Block? block = null);

{
public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec, BlockHeader? header = null)
{
if (header is null || specHelper.IsBedrock(header))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could IsBedrock be in IReleaseSpec, then we don't have to pass header?

IReleaseSpec was created to have all fork information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check if eip1559 is enabled. Not sure it's good idea. But as I know ReleaseSpec is not aware of optimism forks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to make IReleaseSpec extendable by plugins then

@deffrian deffrian marked this pull request as ready for review December 10, 2024 12:00
@deffrian deffrian merged commit d00410f into master Dec 10, 2024
79 checks passed
@deffrian deffrian deleted the fix/optimism-snapshot branch December 10, 2024 12:26
// In op bedrock eip1559 activated with bedrock
if (releaseSpec.IsEip1559Enabled)
{
return transaction.Signature is null ? new ValidationResult("Empty signature") : ValidationResult.Success;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we were not performing any validations on Deposit transactions, but now we require that post-Bedrock transactions contain a non-null signature. Is this correct? If so, shouldn't we also validate the signature (using SignatureTxValidator)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if signature is null here it means that while decoding signature in DecodeSignature we got inside if (v == 0 && rBytes.IsEmpty && sBytes.IsEmpty). Without this pr we would crash inside DecodeSignature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, what I'm missing is why we don't validate the signature of a Legacy transaction post bedrock. More so, why are we not performing the standard Legacy validations:

RegisterValidator(TxType.Legacy, new CompositeTxValidator([
IntrinsicGasTxValidator.Instance,
new LegacySignatureTxValidator(chainId),
ContractSizeTxValidator.Instance,
NonBlobFieldsTxValidator.Instance,
NonSetCodeFieldsTxValidator.Instance
]));

With these changes, Legacy transactions that are processed in Optimism are not validated at all, when previously they went through several checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that means I made a mistake. But why we don't check DepositTransaction?
api.RegisterTxType<OptimismTransactionForRpc>(new OptimismTxDecoder<Transaction>(), Always.Valid);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It dates back to the original Optimism plugin PR where the OptimismTxValidator performed no checks on Deposit transactions

public bool IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec) =>
IsWellFormed(transaction, releaseSpec, out _);
public bool IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec, [NotNullWhen(false)] out string? error)
{
error = null;
return transaction.Type == TxType.DepositTx || _txValidator.IsWellFormed(transaction, releaseSpec, out error);
}

We didn't change the logic in the Transaction refactoring, so the current validator for Deposit transactions always succeeds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #7887.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants