{"record":{"id":"c66da171ea0d3cae","repo":"linera-io/linera-protocol","slug":"the-operation-should-contain-the-evm-selector-and","errorCode":null,"errorMessage":"The operation should contain the evm selector and so have length 4 or more","messagePattern":"The operation should contain the evm selector and so have length 4 or more","errorType":"validation","errorClass":"EvmExecutionError","httpStatus":null,"severity":"error","filePath":"linera-execution/src/evm/inputs.rs","lineNumber":192,"sourceCode":"        vec != PROCESS_STREAMS_SELECTOR,\n        EvmExecutionError::IllegalOperationCall(\"function process_streams\".to_string(),)\n    );\n    ensure!(\n        vec != SUMMARIZE_EVENTS_SELECTOR,\n        EvmExecutionError::IllegalOperationCall(\"function summarize_events\".to_string(),)\n    );\n    ensure!(\n        vec != INSTANTIATE_SELECTOR,\n        EvmExecutionError::IllegalOperationCall(\"function instantiate\".to_string(),)\n    );\n    Ok(())\n}\n\npub(crate) fn ensure_message_length(\n    actual_length: usize,\n    min_length: usize,\n) -> Result<(), EvmExecutionError> {\n    ensure!(\n        actual_length >= min_length,\n        EvmExecutionError::OperationIsTooShort\n    );\n    Ok(())\n}\n\npub(crate) fn ensure_selector_presence(\n    module: &[u8],\n    selector: &[u8],\n    fct_name: &str,\n) -> Result<(), EvmExecutionError> {\n    ensure!(\n        has_selector(module, selector),\n        EvmExecutionError::MissingFunction(fct_name.to_string())\n    );\n    Ok(())\n}\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-execution/src/evm/inputs.rs#L174-L210","documentation":"Every call into an EVM application is addressed by a 4-byte ABI selector, so the runtime refuses operation or query payloads shorter than 4 bytes. ensure_message_length is called from execute_operation, handle_query and init_transact before any selector is parsed; a shorter payload is rejected with OperationIsTooShort because it cannot be a valid ABI-encoded call.","triggerScenarios":"Calling an EVM application's operation or query endpoint with an empty Vec<u8> or fewer than 4 bytes: passing raw bcs/json-encoded arguments without the 4-byte selector prefix, or submitting an empty payload.","commonSituations":"Client code that bcs-encodes a struct and submits it to an EVM app (correct for Wasm apps, invalid for EVM); reusing Wasm-style test payloads against an EVM application; refactoring an operation builder and accidentally dropping the selector bytes.","solutions":["Build the payload with the Solidity ABI: construct the alloy ...Call struct and call abi_encode so the bytes start with the function selector","Assert payload.len() >= 4 in the client before submitting the operation or query","If you intended a bcs or empty payload, verify the target application is a Wasm application, not an EVM one"],"exampleFix":"// before: raw encoded args, no 4-byte selector\nlet query = serde_json::to_vec(&MyQuery::Get)?;\nlet result = client.query_application(app_id, query).await?;\n\n// after: ABI-encoded call with selector\nlet query = getCall { key: key }.abi_encode();\nlet result = client.query_application(app_id, query).await?;","handlingStrategy":"validation","validationCode":"fn is_valid_evm_payload(payload: &[u8]) -> bool {\n    payload.len() >= 4 // a 4-byte ABI selector is the minimum\n}\n\nassert!(is_valid_evm_payload(&op), \"EVM payload must start with a 4-byte selector\");","typeGuard":"fn is_operation_too_short(err: &ExecutionError) -> bool {\n    matches!(\n        err,\n        ExecutionError::EvmError(EvmExecutionError::OperationIsTooShort)\n    )\n}","tryCatchPattern":"match client.query_application(app_id, query).await {\n    Ok(bytes) => bytes,\n    Err(ref e) if is_operation_too_short(e) => {\n        return Err(anyhow!(\"payload was not ABI-encoded; rebuild it with abi_encode()\"))\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Always build EVM payloads with alloy's SolCall::abi_encode, which guarantees the selector prefix","Add a client-side length assertion before every submit or query of an EVM application","Keep Wasm (bcs) and EVM (ABI) payload builders in separate, clearly named modules to avoid mix-ups"],"tags":["evm","abi","input-validation","linera"],"backgroundTag":"invalid-function-selector","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}