{"record":{"id":"75ff9613b1f74cde","repo":"FuelLabs/sway","slug":"incomplete-bytecode","errorCode":null,"errorMessage":"Incomplete bytecode","messagePattern":"Incomplete bytecode","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-util/src/bytecode.rs","lineNumber":74,"sourceCode":"\n    Ok(InstructionWithBytesIterator::new(buf_reader))\n}\n\n/// Gets the bytecode ID from a bytecode file. The bytecode ID is the hash of the bytecode after removing the\n/// condigurables section, if any.\npub fn get_bytecode_id<P>(path: P) -> anyhow::Result<String>\nwhere\n    P: AsRef<Path> + Clone,\n{\n    let mut instructions = parse_bytecode_to_instructions(path.clone())?;\n\n    // Collect the first six instructions into a temporary vector\n    let mut first_six_instructions = Vec::with_capacity(CONFIGURABLES_OFFSET_PREAMBLE);\n    for _ in 0..CONFIGURABLES_OFFSET_PREAMBLE {\n        if let Some(instruction) = instructions.next() {\n            first_six_instructions.push(instruction);\n        } else {\n            return Err(anyhow!(\"Incomplete bytecode\"));\n        }\n    }\n\n    let (lo_instr, low_raw) = &first_six_instructions[CONFIGURABLES_OFFSET_INSTR_LO];\n    let (hi_instr, hi_raw) = &first_six_instructions[CONFIGURABLES_OFFSET_INSTR_HI];\n\n    if let Err(fuel_asm::InvalidOpcode) = lo_instr {\n        if let Err(fuel_asm::InvalidOpcode) = hi_instr {\n            // Now assemble the configurables offset.\n            let configurables_offset = usize::from_be_bytes([\n                low_raw[0], low_raw[1], low_raw[2], low_raw[3], hi_raw[0], hi_raw[1], hi_raw[2],\n                hi_raw[3],\n            ]);\n\n            // Hash the first six instructions\n            let mut hasher = Sha256::new();\n            for (_, raw) in first_six_instructions {\n                hasher.update(raw);","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-util/src/bytecode.rs#L56-L92","documentation":"get_bytecode_id requires at least CONFIGURABLES_OFFSET_PREAMBLE = 6 instructions (48 bytes; indices 0..5, with the offset sentinel at indices 4 and 5) in the bytecode file because the Fuel VM preamble embeds the configurables section offset there. If the instruction iterator runs dry before six entries are collected, the file is truncated/empty/not real bytecode and this error returns.","triggerScenarios":"Passing an empty or truncated .bin, a non-bytecode file (e.g. a .json ABI file) to get_bytecode_id / `forc contract-id --bytecode-file`, or a build artifact cut short by a full disk or interrupted `forc build`.","commonSituations":"Confusing the ABI json artifact with the binary artifact in out/debug, partial artifacts left after a cancelled build, or a script globbing *.bin in a directory that contains placeholder files.","solutions":["Rebuild with `forc build` and use the newly produced .bin","Confirm the file is the raw bytecode binary (out/debug/<pkg>.bin), not the ABI json, and is at least 48 bytes","If it persists, delete the out/ directory entirely and rebuild from scratch"],"exampleFix":"# before\nforc contract-id --bytecode-file out/debug/my_pkg-abi.json\n\n# after\nforc contract-id --bytecode-file out/debug/my_pkg.bin","handlingStrategy":"validation","validationCode":"const MIN_INSTR_BYTES: u64 = 6 * 4; // CONFIGURABLES_OFFSET_PREAMBLE instructions, 4 bytes each\nlet meta = std::fs::metadata(&bin_path)?;\nif meta.len() < MIN_INSTR_BYTES {\n    anyhow::bail!(\"bytecode too small ({} bytes); rebuild with `forc build`\", meta.len());\n}","typeGuard":null,"tryCatchPattern":"let id = match get_bytecode_id(&path) {\n    Ok(id) => id,\n    Err(e) if e.to_string() == \"Incomplete bytecode\" => {\n        anyhow::bail!(\"artifact at {} is empty/truncated — rerun `forc build`\", path.display())\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Never feed ABI json or placeholder files into --bytecode-file; verify the artifact is the raw .bin","Treat interrupted builds as producing no artifacts: check exit status before using out/ files"],"tags":["forc-util","bytecode","truncated-file","contract-id"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}