{"record":{"id":"4c9755b74ab42509","repo":"FuelLabs/fuel-core","slug":"could-not-convert-state-root-to-bytes32","errorCode":null,"errorMessage":"Could not convert state_root to Bytes32: {}","messagePattern":"Could not convert state_root to Bytes32: (.+?)","errorType":"validation","errorClass":"Error::Serialization","httpStatus":null,"severity":"error","filePath":"crates/services/block_aggregator_api/src/blocks/old_block_source/convertor_adapter/proto_to_fuel_conversions.rs","lineNumber":117,"sourceCode":"            \"Could not convert storage slot value to Bytes32: {}\",\n            e\n        ))\n    })?;\n    Ok(StorageSlot::new(key, value))\n}\n\nfn contract_input_from_proto(\n    proto: &ProtoContractInput,\n) -> crate::result::Result<fuel_core_types::fuel_tx::input::contract::Contract> {\n    let utxo_proto = proto.utxo_id.as_ref().ok_or_else(|| {\n        Error::Serialization(anyhow!(\"Missing utxo_id on contract input\"))\n    })?;\n    let utxo_id = utxo_id_from_proto(utxo_proto)?;\n    let balance_root = Bytes32::try_from(proto.balance_root.as_slice()).map_err(|e| {\n        Error::Serialization(anyhow!(\"Could not convert balance_root to Bytes32: {}\", e))\n    })?;\n    let state_root = Bytes32::try_from(proto.state_root.as_slice()).map_err(|e| {\n        Error::Serialization(anyhow!(\"Could not convert state_root to Bytes32: {}\", e))\n    })?;\n    let tx_pointer_proto = proto.tx_pointer.as_ref().ok_or_else(|| {\n        Error::Serialization(anyhow!(\"Missing tx_pointer on contract input\"))\n    })?;\n    let tx_pointer = tx_pointer_from_proto(tx_pointer_proto)?;\n    let contract_id =\n        fuel_core_types::fuel_types::ContractId::try_from(proto.contract_id.as_slice())\n            .map_err(|e| Error::Serialization(anyhow!(e)))?;\n\n    Ok(fuel_core_types::fuel_tx::input::contract::Contract {\n        utxo_id,\n        balance_root,\n        state_root,\n        tx_pointer,\n        contract_id,\n    })\n}\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/FuelLabs/fuel-core/blob/b9d4d170da3a31c9ace5f963d633b326348e0d42/crates/services/block_aggregator_api/src/blocks/old_block_source/convertor_adapter/proto_to_fuel_conversions.rs#L99-L135","documentation":"Thrown while decoding a proto contract input: the state_root bytes field must be exactly 32 bytes to construct fuel's Bytes32; try_from fails on any other length and is wrapped as Error::Serialization. The failed input propagates the error up through tx_from_proto_tx and fuel_block_from_protobuf.","triggerScenarios":"Decoding a proto block where a ProtoContractInput.state_root has a length other than 32 - truncated or corrupted blob, or an encoder that does not enforce the fixed size.","commonSituations":"Producer/consumer version mismatch; data corruption; test fixtures with arbitrary byte vectors.","solutions":["Log the state_root length of the failing input to confirm the mismatch.","Pre-validate all 32-byte fields (balance_root, state_root) on contract inputs before conversion.","Align producer and consumer fuel-core versions.","Re-fetch the block from a known-good source."],"exampleFix":"// before\nlet state_root = Bytes32::try_from(proto.state_root.as_slice()).map_err(|e| {\n    Error::Serialization(anyhow!(\"Could not convert state_root to Bytes32: {}\", e))\n})?;\n\n// after: caller pre-check\nif input_proto.state_root.len() != 32 {\n    return Err(Error::Serialization(anyhow::anyhow!(\n        \"state_root length {} != 32\", input_proto.state_root.len()\n    )));\n}","handlingStrategy":"validation","validationCode":"fn contract_input_state_root_valid(p: &ProtoContractInput) -> bool {\n    p.state_root.len() == 32\n}","typeGuard":"fn is_bytes32(b: &[u8]) -> bool { b.len() == 32 }","tryCatchPattern":"match contract_input_from_proto(p) {\n    Ok(input) => inputs.push(input),\n    Err(Error::Serialization(ctx)) if ctx.to_string().contains(\"state_root\") => {\n        tracing::warn!(len = p.state_root.len(), \"rejecting input with bad state_root\");\n        return Err(Error::Serialization(ctx));\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Pre-check len == 32 for balance_root and state_root together; they fail the same way.","Pin compatible fuel-core versions across the wire.","Re-encode from canonical data rather than patching malformed proto."],"tags":["rust","fuel-core","protobuf","deserialization","bytes32","contract-input"],"backgroundTag":null,"analyzedSha":"b9d4d170da3a31c9ace5f963d633b326348e0d42","analyzedAt":"2026-08-16T08:56:42.692Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}