{"record":{"id":"a3d380524868826c","repo":"linera-io/linera-protocol","slug":"bytecodetoolarge","errorCode":"BytecodeTooLarge","errorMessage":"ExecutionError::BytecodeTooLarge","messagePattern":"ExecutionError::BytecodeTooLarge","errorType":"exception","errorClass":"ExecutionError","httpStatus":null,"severity":"error","filePath":"linera-execution/src/policy.rs","lineNumber":453,"sourceCode":"    }\n\n    /// Returns how much fuel can be paid with the given balance.\n    pub(crate) fn remaining_fuel(&self, balance: Amount, vm_runtime: VmRuntime) -> u64 {\n        let fuel_unit = self.fuel_unit_price(vm_runtime);\n        u64::try_from(balance.saturating_ratio(fuel_unit)).unwrap_or(u64::MAX)\n    }\n\n    /// Checks that the blob's size does not exceed the maximum allowed by this policy.\n    pub fn check_blob_size(&self, content: &BlobContent) -> Result<(), ExecutionError> {\n        ensure!(\n            u64::try_from(content.bytes().len())\n                .ok()\n                .is_some_and(|size| size <= self.maximum_blob_size),\n            ExecutionError::BlobTooLarge\n        );\n        match content.blob_type() {\n            BlobType::ContractBytecode | BlobType::ServiceBytecode | BlobType::EvmBytecode => {\n                ensure!(\n                    CompressedBytecode::decompressed_size_at_most(\n                        content.bytes(),\n                        self.maximum_bytecode_size\n                    )?,\n                    ExecutionError::BytecodeTooLarge\n                );\n            }\n            BlobType::Data\n            | BlobType::ApplicationDescription\n            | BlobType::ApplicationFormats\n            | BlobType::Committee\n            | BlobType::ChainDescription\n            | BlobType::CheckpointExecutionState => {}\n        }\n        Ok(())\n    }\n}\n","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-execution/src/policy.rs#L435-L471","documentation":"For bytecode blob types (ContractBytecode, ServiceBytecode, EvmBytecode), policy additionally checks the decompressed size: CompressedBytecode::decompressed_size_at_most fails with BytecodeTooLarge when the decompressed module would exceed maximum_bytecode_size (policy.rs:453), even if the compressed blob itself fits maximum_blob_size.","triggerScenarios":"Publishing contract, service, or EVM bytecode whose decompressed module size exceeds the policy's maximum_bytecode_size, e.g. shipping an uncompressed or unoptimized Wasm module that is bigger than the limit once loaded.","commonSituations":"Unoptimized Wasm builds (debug symbols, no wasm-opt); a contract that grew past the limit after adding dependencies; networks that lowered maximum_bytecode_size; publishing raw bytes instead of a compressed bytecode container.","solutions":["Optimize the build to shrink the decompressed module: run wasm-opt, raise opt-level, strip debug and custom sections","Split functionality into multiple smaller applications","Ensure the blob is actually compressed (publish CompressedBytecode, not raw module bytes)","If you operate the network, raise maximum_bytecode_size in the resource policy"],"exampleFix":"# before: publish raw module (decompressed size > maximum_bytecode_size)\ncargo build --target wasm32-unknown-unknown\npublish target/debug/myapp.wasm\n\n# after: optimize then compress before publishing\nwasm-opt -O3 target/debug/myapp.wasm -o myapp.opt.wasm\npublish compress myapp.opt.wasm","handlingStrategy":"validation","validationCode":"// Validate the decompressed size against policy before publishing bytecode\nlet fits = CompressedBytecode::decompressed_size_at_most(\n    bytecode.bytes(),\n    policy.maximum_bytecode_size,\n)?;\nif !fits {\n    return Err(anyhow!(\"decompressed bytecode exceeds maximum_bytecode_size\"));\n}\npublish(bytecode)?;","typeGuard":"fn is_bytecode_too_large(err: &ExecutionError) -> bool {\n    matches!(err, ExecutionError::BytecodeTooLarge)\n}","tryCatchPattern":"match publisher.publish_blob(bytecode_content).await {\n    Ok(id) => id,\n    Err(ref e) if is_bytecode_too_large(e) => {\n        // deterministic: optimize or compress the module and republish\n        return Err(anyhow!(\"bytecode too large after decompression; run wasm-opt and compress\"));\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Run wasm-opt and strip debug sections in the release pipeline for contract and service modules","Fail the CI build when the decompressed module size exceeds the network policy","Keep applications small; split growth into additional applications instead"],"tags":["bytecode","wasm","size-limit","resource-policy","linera"],"backgroundTag":"bytecode-size-limit-exceeded","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}