Skip to content

resolc: Detect undeployable contracts at link time - #599

Open
dimartiro wants to merge 4 commits into
paritytech:mainfrom
dimartiro:feat/96-blob-size-limit
Open

resolc: Detect undeployable contracts at link time#599
dimartiro wants to merge 4 commits into
paritytech:mainfrom
dimartiro:feat/96-blob-size-limit

Conversation

@dimartiro

Copy link
Copy Markdown

Description

Closes #96

A contract whose linked blob exceeds the target runtime's limits compiles fine and is then rejected by pallet_revive on deployment. This reproduces the pallet's checks at link time so the problem surfaces where it can still be acted on.

What it checks

pallet_revive::limits::code::enforce rejects a blob on four grounds the compiler can evaluate: the blob length (BLOB_BYTES), the longest basic block (BASIC_BLOCK_SIZE), and the purgeable and baseline interpreter memory (PURGABLE_MEMORY_LIMIT, BASELINE_MEMORY_LIMIT). All four are now checked, and each reports the measured value against the limit it broke.

The memory figures are not approximated. The pallet derives them from ProgramBlob::estimate_interpreter_memory_usage, and revive already depends on polkavm-common, so crates/linker/src/limits.rs calls the same API with the same arguments and reaches the same verdict rather than a conservative guess.

Interface

  • --memory-limit <BYTES>: the target runtime's baseline interpreter memory budget, defaulting to Asset Hub's. The compiler cannot know which runtime a blob is destined for, and the same chain at a different runtime version can carry a different budget.
  • --ignore-memory-limit: report violations as warnings and emit the contract anyway.

Exceeding the budget is an error by default, on the grounds that a contract which cannot be deployed is not a useful build artifact.

Why this matters in practice

The baseline budget is where it bites, and it is easy to cross without touching a line of Solidity, because the static heap and stack buffers are part of it. Compiling Baseline.sol unchanged:

--heap-size baseline memory verdict
64 KiB 201,542 ok
256 KiB 398,150 ok
1 MiB 1,184,582 ok
2 MiB 2,233,159 over the 1,572,864 budget

Before this change the last row compiled successfully and produced a contract that could never be deployed. It now fails with the numbers and a pointer at the knob to turn:

Error: Baseline.sol:Baseline cannot be deployed to the target runtime: the contract needs 2233159 bytes of baseline interpreter memory but the runtime provides at most 1572864 bytes; the static heap and stack buffers are part of this budget, so lowering `--heap-size` or `--stack-size` frees room for code. Pass `--ignore-memory-limit` to compile anyway, or `--memory-limit` if the target runtime has a different budget.

@xermicus xermicus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR!

!debug_config.emit_debug_info,
) {
Ok((memory_buffer_linked, ObjectFormat::PVM)) => {
self.messages.extend(check_deployment_limits(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Build::write_to_standard_json considers errors, so does this doesn't work in std json mode? Would be nice to have a test for that too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — it didn't. write_to_standard_json only forwarded errors from results and dropped messages, which is where the deployment-limit diagnostics (and other link-time issues) live.

They now land in the standard JSON errors array. Added coverage for --standard-json: the error, --ignore-memory-limit as a warning, and a larger --memory-limit.

Addressed in 98e6232.

write_to_standard_json only forwarded errors from results, so link-time
diagnostics in messages never reached Hardhat and other stdjson users.
@dimartiro
dimartiro force-pushed the feat/96-blob-size-limit branch from 98e6232 to e491463 Compare August 26, 2026 14:37
@dimartiro
dimartiro requested a review from xermicus September 2, 2026 18:17

impl PalletLimits {
/// The limits of the Asset Hub runtime.
pub const ASSET_HUB: Self = Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of duplicating code here, we should re-use this from pallet-revive directly. It's already in the dependency tree.

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.

Detect problematic blob size at link time

2 participants