refactor(core): centralize EIP-7702 SetCode shape checks#11641
Conversation
|
@claude review |
|
Claude finished @LukaszRozmej's task in 3m 43s —— View job PR Review: refactor(core): centralize EIP-7702 SetCode shape checks
SummaryClean, well-scoped refactoring. Behavior is fully preserved — I verified the before/after logic in both sites:
Architecture, test coverage, XML docs, and the class-level 3 Low findings — none block merge. Low1. // current
.WithAuthorizationCode(new[] { AuthorizationTuple() })
// preferred (C# 14, per project "Prefer the latest C# syntax and conventions")
.WithAuthorizationCode([AuthorizationTuple()])2. private static AuthorizationTuple AuthorizationTuple() => ...The method is named identically to the 3.
Notes
Verdict: Mergeable. The Low findings are advisory; none affect correctness or behavior. |
| { | ||
| Transaction tx = Build.A.Transaction | ||
| .To(TestItem.AddressA) | ||
| .WithAuthorizationCode(new[] { AuthorizationTuple() }) |
There was a problem hiding this comment.
Prefer C# 14 collection expression over new[]:
| .WithAuthorizationCode(new[] { AuthorizationTuple() }) | |
| .WithAuthorizationCode([AuthorizationTuple()]) |
| [Parallelizable(ParallelScope.All)] | ||
| public class SetCodeTxValidationTests | ||
| { | ||
| private static AuthorizationTuple AuthorizationTuple() => |
There was a problem hiding this comment.
The method name AuthorizationTuple() exactly shadows the AuthorizationTuple type it returns. Consider SampleAuthorizationTuple() or CreateAuthorizationTuple() to avoid ambiguity for future readers.
| public void ValidateAuthorizationList_returns_error_when_list_is_null() | ||
| { | ||
| Transaction tx = Build.A.Transaction.To(TestItem.AddressA).TestObject; | ||
|
|
||
| ValidationResult result = SetCodeTxValidation.ValidateAuthorizationList(tx); | ||
|
|
||
| result.AsBool().Should().BeFalse(); | ||
| result.Error.Should().Be(TxErrorMessages.MissingAuthorizationList); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ValidateAuthorizationList_returns_error_when_list_is_empty() | ||
| { | ||
| Transaction tx = Build.A.Transaction | ||
| .To(TestItem.AddressA) | ||
| .WithAuthorizationCode(Array.Empty<AuthorizationTuple>()) | ||
| .TestObject; | ||
|
|
||
| ValidationResult result = SetCodeTxValidation.ValidateAuthorizationList(tx); | ||
|
|
||
| result.AsBool().Should().BeFalse(); | ||
| result.Error.Should().Be(TxErrorMessages.MissingAuthorizationList); | ||
| } |
There was a problem hiding this comment.
These two tests differ only by the auth-list value supplied (null vs empty array). Per AGENTS.md, consider collapsing them into a single [TestCaseSource]-backed test. For just two cases the two-method form is tolerable, but flagging per project guidelines.
Address review feedback on NethermindEth#11641: - Rename `AuthorizationTuple()` helper to `CreateAuthorizationTuple()` so it no longer shadows the `AuthorizationTuple` type it returns. - Replace `new[] { ... }` array literal with C# 14 collection expression `[...]`. - Collapse the two `_returns_error_when_list_is_null` and `_returns_error_when_list_is_empty` tests into one `[TestCaseSource]`-driven method (`ValidateAuthorizationList_returns_error_when_list_is_missing`), per AGENTS.md test-parameterization guideline.
| if (tx.SupportsAuthorizationList) | ||
| { | ||
| if (tx.IsContractCreation) | ||
| // SetCode-specific shape checks live in Nethermind.Core.Validation.SetCodeTxValidation |
Per @flcl42 review on NethermindEth#11641 — the comment block above the SetCodeTxValidation calls in TransactionProcessor.ValidateStatic restated context that lives in the helper class XML docs.
`TransactionProcessor.ValidateStatic` (Evm) and the `NoContractCreationTxValidator` / `AuthorizationListTxValidator` classes (Consensus) each carried their own copy of the EIP-7702 no-contract-creation and non-empty-authorization-list checks. The two sites cannot be collapsed into one — the consensus validators run for block validation / mempool admission, while the transaction-processor checks gate the RPC paths (eth_call, eth_estimateGas) that bypass `TxValidator` entirely — but they must not drift. Extract the underlying predicates into a new `Nethermind.Core.Validation.SetCodeTxValidation` static helper (`ValidateNoContractCreation`, `ValidateAuthorizationList`) and have both sites delegate to it: - `NoContractCreationTxValidator.IsWellFormed` and `AuthorizationListTxValidator.IsWellFormed` are now one-liners that call into the helper. - `TransactionProcessor.ValidateStatic` calls the same helpers, preserving its existing trace tags (`SETCODE_TX_CREATE`, `EMPTY_AUTHORIZATION_LIST`) and the `MalformedTransaction.WithDetail(... (sender ...))` error shape. No behavior change: error strings, trace tags, and consensus-side dispatch via `TxValidator` register table are unchanged. `Nethermind.Core.Test.Validation.SetCodeTxValidationTests` covers the helper directly. Existing `TxValidatorTests`, `TransactionProcessorEip7702Tests`, and the EthRpcModule `eth_call` / `eth_estimateGas` tests still pass and continue to exercise both call paths end-to-end. Closes NethermindEth#11619
Address review feedback on NethermindEth#11641: - Rename `AuthorizationTuple()` helper to `CreateAuthorizationTuple()` so it no longer shadows the `AuthorizationTuple` type it returns. - Replace `new[] { ... }` array literal with C# 14 collection expression `[...]`. - Collapse the two `_returns_error_when_list_is_null` and `_returns_error_when_list_is_empty` tests into one `[TestCaseSource]`-driven method (`ValidateAuthorizationList_returns_error_when_list_is_missing`), per AGENTS.md test-parameterization guideline.
Per @flcl42 review on NethermindEth#11641 — the comment block above the SetCodeTxValidation calls in TransactionProcessor.ValidateStatic restated context that lives in the helper class XML docs.
02ef34e to
d3c0175
Compare
|
@claude re-review |
|
Claude finished @LukaszRozmej's task in 1m 28s —— View job Re-review: refactor(core): centralize EIP-7702 SetCode shape checks
SummaryAll three Low findings from the first review have been resolved, and flcl42's comment was addressed:
Remaining nit (non-blocking)
Verdict: Mergeable. The PR is a clean, well-scoped deduplication with no behavior change. Code, tests, and documentation are all in good shape. |
Closes #11619
Changes
TransactionProcessor.ValidateStatic(Nethermind.Evm) and theNoContractCreationTxValidator/AuthorizationListTxValidatorclasses (Nethermind.Consensus) each carried their own copy of the EIP-7702 no-contract-creation and non-empty-authorization-list checks. The two sites cannot be collapsed into one — the consensus validators run for block validation / mempool admission, while the transaction-processor checks gate the RPC paths (eth_call,eth_estimateGas) that bypassTxValidatorentirely — but they must not drift.Nethermind.Core.Validation.SetCodeTxValidation(ValidateNoContractCreation,ValidateAuthorizationList).NoContractCreationTxValidator.IsWellFormedandAuthorizationListTxValidator.IsWellFormedare now one-liners delegating to the helper.TransactionProcessor.ValidateStaticcalls the same helpers, preserving its existing trace tags (SETCODE_TX_CREATE,EMPTY_AUTHORIZATION_LIST) and theMalformedTransaction.WithDetail(... (sender ...))error shape.Nethermind.Core.Test.Validation.SetCodeTxValidationTestscovers the helper directly.No behavior change: error strings, trace tags, and consensus-side dispatch via the
TxValidatorregister table are unchanged. The PR is a pure deduplication so that future EIP-7702 rule edits land in one place rather than two.Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Notes on testing
SetCodeTxValidationTests— 5/5 inNethermind.Core.Test.TxValidatorTests+TransactionProcessorEip7702Tests— 164/164 inNethermind.Blockchain.Test.EthRpcModuleTests(coverseth_callandeth_estimateGasSetCode rejection paths viaTransactionProcessor) — 381/383 inNethermind.JsonRpc.Test(2 unrelated skipped).dotnet format whitespace --folderclean.Documentation
Requires documentation update
Requires explanation in Release Notes