{"record":{"id":"0be608faf9fbb6bf","repo":"FuelLabs/fuel-core","slug":"contract-code-should-not-exist","errorCode":null,"errorMessage":"Contract code should not exist","messagePattern":"Contract code should not exist","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/fuel-core/src/service/genesis/importer/on_chain.rs","lineNumber":305,"sourceCode":"    }\n\n    Ok(())\n}\n\nfn init_contract_raw_code(\n    transaction: &mut StorageTransaction<&mut GenesisDatabase>,\n    entry: &TableEntry<ContractsRawCode>,\n) -> anyhow::Result<()> {\n    let contract = entry.value.as_ref();\n    let contract_id = entry.key;\n\n    // insert contract code\n    if transaction\n        .storage::<ContractsRawCode>()\n        .replace(&contract_id, contract)?\n        .is_some()\n    {\n        return Err(anyhow!(\"Contract code should not exist\"));\n    }\n\n    Ok(())\n}\n\nfn init_da_message(\n    transaction: &mut StorageTransaction<&mut GenesisDatabase>,\n    msg: TableEntry<Messages>,\n    da_height: DaBlockHeight,\n) -> anyhow::Result<()> {\n    let message: Message = msg.value;\n\n    if message.da_height() > da_height {\n        return Err(anyhow!(\n            \"message da_height cannot be greater than genesis da block height\"\n        ));\n    }\n","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/FuelLabs/fuel-core/blob/b9d4d170da3a31c9ace5f963d633b326348e0d42/crates/fuel-core/src/service/genesis/importer/on_chain.rs#L287-L323","documentation":"Duplicate guard for ContractsRawCode during on-chain genesis import: replace(&contract_id, contract) returned Some, meaning bytecode for this contract id was already inserted in the same genesis batch or already exists in the database.","triggerScenarios":"The genesis state lists the same contract id twice under contracts_raw_code, or the importer targets storage that already holds that contract code.","commonSituations":"Snapshot merging or generation bugs producing repeated contract entries; dirty db from a previous import run; test fixtures that add the same contract twice.","solutions":["Dedupe contracts_raw_code entries by contract id in the genesis state and re-import.","Wipe the on-chain db directory and retry.","Regenerate the snapshot with tooling that emits each contract exactly once."],"exampleFix":"// before: duplicate contract entries\n\"contracts\": [\n  { \"key\": \"0xcafe...\", \"value\": \"0x60016000\" },\n  { \"key\": \"0xcafe...\", \"value\": \"0x60016000\" }\n]\n\n// after: one entry per contract id\n\"contracts\": [ { \"key\": \"0xcafe...\", \"value\": \"0x60016000\" } ]","handlingStrategy":"validation","validationCode":"fn validate_contract_code_uniqueness(\n    entries: &[TableEntry<ContractsRawCode>],\n) -> Result<(), String> {\n    let mut seen = std::collections::HashSet::new();\n    for e in entries {\n        if !seen.insert(e.key) {\n            return Err(format!(\"duplicate ContractsRawCode entry for contract {}\", e.key));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match importer.run().await {\n    Err(e) if e.to_string().contains(\"Contract code should not exist\") => {\n        // dedupe contracts_raw_code by contract id and re-import\n    }\n    rest => rest,\n}","preventionTips":["Treat contract id as the primary key in snapshot tooling and dedupe on it.","Do not concatenate contract lists from multiple snapshots.","Run import into a clean db directory."],"tags":["genesis","storage","duplicate-data","contracts","fuel-core","rust"],"backgroundTag":null,"analyzedSha":"b9d4d170da3a31c9ace5f963d633b326348e0d42","analyzedAt":"2026-08-16T08:56:42.692Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}