Skip to content

chore: Accumulated backports to v4#21783

Merged
AztecBot merged 2 commits intov4from
backport-to-v4-staging
Mar 19, 2026
Merged

chore: Accumulated backports to v4#21783
AztecBot merged 2 commits intov4from
backport-to-v4-staging

Conversation

@AztecBot
Copy link
Copy Markdown
Collaborator

@AztecBot AztecBot commented Mar 19, 2026

BEGIN_COMMIT_OVERRIDE
feat(p2p): add tx validator for contract instance deployment addresses (#21771)
END_COMMIT_OVERRIDE

#21771)

## Motivation

When a contract instance is deployed, a `ContractInstancePublishedEvent`
is emitted as a private log containing the contract address and all
fields needed to recompute it. Currently the archiver blindly trusts
these addresses. A malicious or buggy client could submit a tx with an
incorrect address, poisoning the archiver's contract data.

## Approach

Added a new stateless tx validator that extracts
`ContractInstancePublishedEvent` logs from a tx's private logs,
recomputes the contract address via
`computeContractAddressFromInstance`, and rejects the tx if the claimed
address doesn't match. The validator is wired into all tx entry points
(gossip, JSON-RPC, req/resp, and block proposals).

## Changes

- **stdlib**: Added `TX_ERROR_INCORRECT_CONTRACT_ADDRESS` and
`TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG` error constants
- **p2p**: New `ContractInstanceTxValidator` that validates contract
instance deployment addresses in private logs
- **p2p**: Wired the validator into all three entry-point factory
functions (gossip stage 1, req/resp + block proposals, JSON-RPC)
- **p2p (tests)**: Unit tests for the new validator (correct address,
wrong address, malformed log, no instance logs) and updated factory
tests
…21787)

## Motivation

The archiver blindly stores contract instance data extracted from
private logs without verifying that the claimed address matches the
instance fields. While the p2p tx validator (#21771) catches this at the
network layer, blocks received via req/resp or proposals skip that
check. This adds a second line of defense at the storage layer.

## Approach

Before storing contract instances, the archiver now recomputes the
address from the instance fields via
`computeContractAddressFromInstance` and filters out any with mismatched
addresses. The check is skipped during delete operations since we need
to remove instances regardless.

## Changes

- **archiver**: Validate contract instance addresses in
`updateDeployedContractInstances` before storing, filtering out
mismatches with a warning log
- **stdlib (tests)**: Add elapsed timing to
`computeContractAddressFromInstance` test (~1.3ms per call)
Copy link
Copy Markdown
Collaborator

@ludamad ludamad left a comment

Choose a reason for hiding this comment

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

🤖 Auto-approved

@AztecBot AztecBot merged commit 7d03c44 into v4 Mar 19, 2026
9 checks passed
@AztecBot
Copy link
Copy Markdown
Collaborator Author

🤖 Auto-merge enabled after 8 hours of inactivity. This PR will be merged automatically once all checks pass.

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