Skip to content

fix(withdrawal): support legacy + nullifier finalize selectors#350

Closed
cryptocake wants to merge 1 commit intovianetwork:mainfrom
cryptocake:fix/issue-347-withdrawal-selector-compat
Closed

fix(withdrawal): support legacy + nullifier finalize selectors#350
cryptocake wants to merge 1 commit intovianetwork:mainfrom
cryptocake:fix/issue-347-withdrawal-selector-compat

Conversation

@cryptocake
Copy link
Copy Markdown

Summary

Add withdrawal selector compatibility for the deprecation migration by accepting both legacy and nullifier finalize selectors when parsing L2->L1 withdrawal messages.

Changes

  • via_verifier/lib/via_da_client/src/types.rs

    • split legacy selector into WITHDRAW_FUNC_SIG_LEGACY
    • added nullifier selector WITHDRAW_FUNC_SIG_NULLIFIER
    • added WITHDRAW_FUNC_SIGS allowlist
  • via_verifier/lib/via_withdrawal_client/src/withdraw.rs

    • switched selector validation from single-selector check to allowlist check
    • replaced single-selector helper with _get_supported_withdraw_function_selectors()
    • added test test_parse_l2_withdrawal_message_accepts_nullifier_selector

Why

Issue #347 tracks zkSync Mailbox deprecations. This change keeps withdrawal message parsing compatible during migration windows where both legacy and replacement finalize selectors may appear.

Validation

  • cargo check -q in via_verifier/lib/via_da_client
  • cargo test -q in via_verifier/lib/via_withdrawal_client is blocked in this environment by missing protoc (dependency build for celestia-proto) ❌ environment/tooling issue
  • Existing tests plus new nullifier-selector test compile in the modified module context.

Linked issues

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for multiple L2 withdrawal message function signatures to facilitate the Bridgehub/L1Nullifier migration. It replaces the single WITHDRAW_FUNC_SIG constant with a list of supported signatures and updates the parsing logic to validate against any of these selectors. Feedback focuses on maintaining backward compatibility for the removed constant and optimizing the selector retrieval process to avoid redundant hashing and memory allocations.

Comment on lines +8 to +9
pub const WITHDRAW_FUNC_SIG_LEGACY: &str =
"finalizeEthWithdrawal(uint256,uint256,uint16,bytes,bytes32[])";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The constant WITHDRAW_FUNC_SIG has been removed and replaced by WITHDRAW_FUNC_SIG_LEGACY. If this constant is used by other crates in the workspace or by external consumers, this change will break their compilation. Consider keeping WITHDRAW_FUNC_SIG as an alias (possibly marked with #[deprecated]) to maintain backward compatibility during the migration period.

Comment on lines +119 to 127
fn _get_supported_withdraw_function_selectors() -> Vec<Vec<u8>> {
WITHDRAW_FUNC_SIGS
.iter()
.map(|sig| {
let hash = keccak256(sig.as_bytes());
hash[0..4].to_vec()
})
.collect()
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The function _get_supported_withdraw_function_selectors is called on every invocation of parse_l2_withdrawal_message. It performs multiple keccak256 hashes and several Vec allocations each time. Since the function signatures are static constants, these 4-byte selectors should be computed once or defined as constants to improve performance, especially when processing large batches of withdrawals. Consider using std::sync::OnceLock (available in Rust 1.70+) or a similar lazy initialization pattern to cache the results.

@cryptocake
Copy link
Copy Markdown
Author

Closing per author request.

@cryptocake cryptocake closed this Apr 1, 2026
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.

1 participant