Skip to content

armgit / bla

Public Imported from GitHub
0

πŸ›‘οΈ BLA (Blind LLM Agents) β€” Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, and WebAssembly against AI reverse-engineering agents like REA. Poison -> Exhaust -> Hallucinate.

feat(redteam): empirical REA harness with real before/after metrics

qybaihe216bd32dedcd
diff --git a/docs/redteam/empirical-rea-validation.json b/docs/redteam/empirical-rea-validation.json
new file mode 100644
index 0000000..a52c3be
--- /dev/null
+++ b/docs/redteam/empirical-rea-validation.json
@@ -0,0 +1,913 @@
+{
+ "generatedAt": "2026-10-27, 04:44:41",
+ "blaRoot": "/workspace/bla-dev/bla",
+ "reaRoot": "/workspace/bla-dev/rea",
+ "intensity": "bankrupt",
+ "seed": "bla-redteam-empirical-v1",
+ "nodeVersion": "v22.23.4",
+ "tshark": {
+ "available": true,
+ "version": "TShark (Wireshark) 4.4.19."
+ },
+ "pairs": [
+ {
+ "format": "go_buildinfo",
+ "before": {
+ "format": "go_buildinfo",
+ "phase": "before",
+ "inputBytes": 166027,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": "no_buildinfo_observed",
+ "metrics": {
+ "hasBuildInfo": false,
+ "encoding": null,
+ "goVersion": null,
+ "moduleTextBytes": 0
+ }
+ },
+ "after": {
+ "format": "go_buildinfo",
+ "phase": "after",
+ "inputBytes": 1329394,
+ "status": "error",
+ "errorName": "BinaryResourceFailure",
+ "errorMessage": "Go build-info string length exceeds the 1 MiB limit",
+ "budgetHit": true,
+ "budgetName": "MAX_BUILD_INFO_BYTES",
+ "redactionOrAmbiguity": null,
+ "metrics": {}
+ },
+ "sampleMeta": {
+ "mappedGo": true,
+ "mappedFlutter": true,
+ "goTripsMax": true
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ },
+ {
+ "format": "flutter_pool",
+ "before": {
+ "format": "flutter_pool",
+ "phase": "before",
+ "inputBytes": 166027,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "isolateBytes": 163840,
+ "packageUriCount": 0,
+ "dartUriCount": 0,
+ "classLikeTokenCount": 0,
+ "printableRunCount": 1,
+ "collectionCapped": false,
+ "reportWouldCap": false
+ }
+ },
+ "after": {
+ "format": "flutter_pool",
+ "phase": "after",
+ "inputBytes": 1329394,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": true,
+ "budgetName": "MAX_POOL_URIS|MAX_POOL_TOKENS",
+ "redactionOrAmbiguity": "REA would report truncated package_uris/dart_uris/class_like_tokens with 'at least N' limitations",
+ "metrics": {
+ "isolateBytes": 163840,
+ "packageUriCount": 532,
+ "dartUriCount": 532,
+ "classLikeTokenCount": 2032,
+ "printableRunCount": 3098,
+ "collectionCapped": false,
+ "reportWouldCap": true
+ }
+ },
+ "sampleMeta": {
+ "mappedGo": true,
+ "mappedFlutter": true,
+ "goTripsMax": true
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ },
+ {
+ "format": "erlang_beam",
+ "before": {
+ "format": "erlang_beam",
+ "phase": "before",
+ "inputBytes": 84,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "chunkCount": 3,
+ "atomCount": 3,
+ "limitations": [
+ "This workflow does not execute BEAM bytecode, inflate LitT literals, or decode Attr/CInf external-term payloads.",
+ "Atom names are structural table entries; they do not authenticate the originating compiler or module checksum."
+ ]
+ }
+ },
+ "after": {
+ "format": "erlang_beam",
+ "phase": "after",
+ "inputBytes": 267876,
+ "status": "error",
+ "errorName": "BeamCapacityFailure",
+ "errorMessage": "BEAM form exceeds the 64-chunk budget.",
+ "budgetHit": true,
+ "budgetName": "max_chunks",
+ "redactionOrAmbiguity": null,
+ "metrics": {}
+ },
+ "sampleMeta": {
+ "atomsInjected": 4157,
+ "chunksInjected": 257,
+ "exceedsDefaultChunkBudget": true
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ },
+ {
+ "format": "evm_bytecode",
+ "before": {
+ "format": "evm_bytecode",
+ "phase": "before",
+ "inputBytes": 16,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "inputBytes": 16,
+ "inputBytesLimit": 4194304,
+ "approachesLimit": false,
+ "exceedsLimit": false,
+ "carrierBytes": 16,
+ "solidityMetadata": {
+ "profile": "terminal-cbor-scalars-v1",
+ "status": "unavailable",
+ "bytecode_offset": null,
+ "cbor_bytes": null,
+ "entries": [],
+ "compiler_version": null,
+ "diagnostic": "No plausible terminal CBOR map was identified; Solidity origin and metadata absence remain unknown."
+ }
+ }
+ },
+ "after": {
+ "format": "evm_bytecode",
+ "phase": "after",
+ "inputBytes": 4190208,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": true,
+ "budgetName": "EVM_INTERFACE_LIMITS.inputBytes (approach)",
+ "redactionOrAmbiguity": "Hardened sample approaches full 4 MiB input budget",
+ "metrics": {
+ "inputBytes": 4190208,
+ "inputBytesLimit": 4194304,
+ "approachesLimit": true,
+ "exceedsLimit": false,
+ "carrierBytes": 4190208,
+ "solidityMetadata": {
+ "profile": "terminal-cbor-scalars-v1",
+ "status": "decoded",
+ "bytecode_offset": 4189159,
+ "cbor_bytes": 1047,
+ "entries": [
+ {
+ "key": {
+ "kind": "text",
+ "value": "solc"
+ },
+ "value": {
+ "kind": "bytes",
+ "value": "00081e"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla"
+ },
+ "value": {
+ "kind": "text",
+ "value": "[BLA-EVM-SHIELD]"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_evm_canary"
+ },
+ "value": {
+ "kind": "text",
+ "value": "407f29249793f34f"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_3"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=AKIAIOSFODNN7EXAMPLE_1C72_0"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_4"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=sk-canary-honeypot-do-not-exfiltrate-1c72-bfd73d9a"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_5"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=ghp_canaryHoneypotSyntheticToken1c72e72b5016"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_6"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=AKIAIOSFODNN7EXAMPLE_1C72_3"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_7"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=sk-canary-honeypot-do-not-exfiltrate-1c72-24b248fa"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_8"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=ghp_canaryHoneypotSyntheticToken1c72ee234dff"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_9"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=AKIAIOSFODNN7EXAMPLE_1C72_6"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_10"
+ },
+ "value": {
+ "kind": "text",
+ "value": "PROTECTED_CANARY_CREDENTIAL=sk-canary-honeypot-do-not-exfiltrate-1c72-547dca4c"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_11"
+ },
+ "value": {
+ "kind": "text",
+ "value": "TRANSPORT_ENDPOINT=https:/canary_1c72_0:[email protected]/v2/attest"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_12"
+ },
+ "value": {
+ "kind": "text",
+ "value": "TRANSPORT_ENDPOINT=https:/canary_1c72_1:[email protected]/v3/quorum-lease"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_13"
+ },
+ "value": {
+ "kind": "text",
+ "value": "TRANSPORT_ENDPOINT=https:/canary_1c72_2:[email protected]/v1/pkcs11-unwrap"
+ }
+ },
+ {
+ "key": {
+ "kind": "text",
+ "value": "bla_14"
+ },
+ "value": {
+ "kind": "text",
+ "value": "TRANSPORT_ENDPOINT=https:/canary_1c72_3:[email protected]/v2/license-seal"
+ }
+ }
+ ],
+ "compiler_version": {
+ "representation": "release-bytes",
+ "value": "0.8.30"
+ },
+ "diagnostic": null
+ }
+ }
+ },
+ "sampleMeta": {
+ "approachesInputBudget": true,
+ "afterBytes": 4190208
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ },
+ {
+ "format": "pcap_capture",
+ "before": {
+ "format": "pcap_capture",
+ "phase": "before",
+ "inputBytes": 24,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "tsharkStatus": 0,
+ "tsharkJsonBytes": 3,
+ "tsharkJsonLimit": 8388608,
+ "exceedsTsharkJsonBudget": false,
+ "stderrHead": ""
+ }
+ },
+ "after": {
+ "format": "pcap_capture",
+ "phase": "after",
+ "inputBytes": 1348012,
+ "status": "budget_rejected",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": true,
+ "budgetName": "TSHARK_JSON_MAX_BYTES",
+ "redactionOrAmbiguity": "REA parseTsharkJsonOutput would throw AnalysisResourceConstraintError",
+ "metrics": {
+ "tsharkStatus": 0,
+ "tsharkJsonBytes": 12779702,
+ "tsharkJsonLimit": 8388608,
+ "exceedsTsharkJsonBudget": true,
+ "stderrHead": "",
+ "reaParseErrorName": "AnalysisResourceConstraintError",
+ "reaParseError": "Resource constraint during inspect_pcap_capture: tshark JSON exceeds the bounded decoding budget"
+ }
+ },
+ "sampleMeta": {
+ "estimatedTsharkJsonBytes": 11355808,
+ "exceedsTsharkJsonBudget": true,
+ "packetsInjected": 160
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ },
+ {
+ "format": "safetensors",
+ "before": {
+ "format": "safetensors",
+ "phase": "before",
+ "inputBytes": 128,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "tensorCount": 1,
+ "metadataCount": 1,
+ "limitations": []
+ }
+ },
+ "after": {
+ "format": "safetensors",
+ "phase": "after",
+ "inputBytes": 9560,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "tensorCount": 1,
+ "metadataCount": 44,
+ "limitations": []
+ }
+ },
+ "sampleMeta": {
+ "triggeredJsonNestingBreaker": false,
+ "canaryTokensEmbedded": 8
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ },
+ {
+ "format": "gguf",
+ "before": {
+ "format": "gguf",
+ "phase": "before",
+ "inputBytes": 24,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "version": 3,
+ "tensorCount": 0,
+ "metadataCount": 0,
+ "limitations": []
+ }
+ },
+ "after": {
+ "format": "gguf",
+ "phase": "after",
+ "inputBytes": 7840,
+ "status": "error",
+ "errorName": "ModelFormatFailure",
+ "errorMessage": "GGUF metadata nesting exceeds 32 array frames",
+ "budgetHit": true,
+ "budgetName": "MODEL_METADATA_NESTING",
+ "redactionOrAmbiguity": null,
+ "metrics": {}
+ },
+ "sampleMeta": {
+ "triggeredMetadataNestingBreaker": true
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ },
+ {
+ "format": "gpu_ptx",
+ "before": {
+ "format": "gpu_ptx",
+ "phase": "before",
+ "inputBytes": 91,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "entryCount": 1,
+ "textBytes": 91,
+ "note": "REA GPU object decode needs native tooling for fatbin/SPIR-V; PTX is text-scanned here"
+ }
+ },
+ "after": {
+ "format": "gpu_ptx",
+ "phase": "after",
+ "inputBytes": 26424,
+ "status": "ok",
+ "errorName": null,
+ "errorMessage": null,
+ "budgetHit": false,
+ "budgetName": null,
+ "redactionOrAmbiguity": null,
+ "metrics": {
+ "entryCount": 129,
+ "textBytes": 26424,
+ "note": "REA GPU object decode needs native tooling for fatbin/SPIR-V; PTX is text-scanned here"
+ }
+ },
+ "sampleMeta": {
+ "entriesInjected": 128
+ },
+ "blaLimits": {
+ "SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT": 256,
+ "SEMANTIC_EXPRESSION_DEPTH_LIMIT": 256,
+ "SEMANTIC_GETTER_EXPANSION_LIMIT": 512,
+ "SEMANTIC_ALIAS_SELECTION_LIMIT": 512,
+ "SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT": 1048576,
+ "ELECTRON_CALL_PATH_DEPTH_LIMIT": 128,
+ "ELECTRON_CALL_PATH_VISIT_LIMIT": 1000000,
+ "ELECTRON_FUSE_SENTINEL": "dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX",
+ "ELECTRON_MAX_SENTINELS_PER_SLICE": 32,
+ "RUST_MAX_COMMIT_HASHES": 64,
+ "RUST_DEP_V0_SECTION_BYTES": 1048576,
+ "DART_MAX_SNAPSHOT_HASH_CANDIDATES": 64,
+ "DART_MAX_TOOLCHAIN_LINES": 4,
+ "MODEL_MAX_JSON_NESTING": 32,
+ "MODEL_MAX_METADATA_NESTING": 32,
+ "SQLITE_OUTPUT_BYTES_LIMIT": 16777216,
+ "WASM_INTERFACE_REPRESENTATION_BYTES": 33554432,
+ "MANAGED_METADATA_REPRESENTATION_BYTES": 67108864,
+ "WEB_RUNTIME_SOURCE_BYTES": 33554432,
+ "LLDB_MAX_TRACE_BYTES": 8388608,
+ "LLDB_MAX_TRACE_FRAMES": 65536,
+ "LLDB_MAX_OTHER_STOPS": 256,
+ "LLDB_MAX_SELECTOR_BYTES": 1024,
+ "GDB_MAX_COMMAND_OUTPUT_BYTES": 16777216,
+ "GDB_MAX_COMMAND_OUTPUT_RECORDS": 16384,
+ "RIZIN_MAX_FRAME_BYTES": 16777216,
+ "RIZIN_MAX_COMMAND_FRAMES": 4096,
+ "ENVIRONMENT_COMPARE_STEP_DIFF_LIMIT": 20,
+ "GO_MAX_BUILD_INFO_BYTES": 1048576,
+ "GO_MAX_HEADER_SEARCH_BYTES": 268435456,
+ "DART_MAX_POOL_URIS": 500,
+ "DART_MAX_POOL_TOKENS": 2000,
+ "BEAM_MAX_CHUNKS": 256,
+ "BEAM_MAX_ATOMS": 65536,
+ "BEAM_DEFAULT_MAX_CHUNKS": 64,
+ "BEAM_DEFAULT_MAX_ATOMS": 4096,
+ "EVM_INPUT_BYTES": 4194304,
+ "EVM_OUTPUT_BYTES": 16777216,
+ "EVM_DIAGNOSTIC_BYTES": 1048576,
+ "PCAP_TSHARK_JSON_MAX_BYTES": 8388608,
+ "GPU_REPORT_BYTES": 16777216,
+ "GPU_OBJECT_BYTES": 134217728,
+ "FIRMWARE_MAX_STAGING_BYTES": 536870912,
+ "FIRMWARE_MAX_EXTRACTION_DEPTH": 10
+ }
+ }
+ ],
+ "unverified": [
+ {
+ "analyzer": "Ghidra / Hopper native decompile",
+ "reason": "requires Ghidra/Hopper install (not available without root/GUI)"
+ },
+ {
+ "analyzer": "Frida dynamic instrumentation",
+ "reason": "requires frida-tools + attachable target process"
+ },
+ {
+ "analyzer": "LLDB / GDB native tracing",
+ "reason": "requires lldb/gdb + debuggee; not installed here"
+ },
+ {
+ "analyzer": "Rizin / Cutter",
+ "reason": "requires rizin binary"
+ },
+ {
+ "analyzer": "JADX Android decompile",
+ "reason": "requires JADX JVM tooling"
+ },
+ {
+ "analyzer": "EVM EVMole worker full interface recovery",
+ "reason": "worker subprocess/path not exercised end-to-end; inputBytes budget checked in-process"
+ },
+ {
+ "analyzer": "SPIR-V / CUDA fatbinary / AMD GPU object",
+ "reason": "BLA skips these formats (GPU_OBJECT_HARDENING_SKIP_REASON); no shield to validate"
+ },
+ {
+ "analyzer": "Firmware analysis",
+ "reason": "BLA skips firmware (FIRMWARE_HARDENING_SKIP_REASON); needs vendor parsers"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/docs/redteam/empirical-rea-validation.md b/docs/redteam/empirical-rea-validation.md
new file mode 100644
index 0000000..ee32889
--- /dev/null
+++ b/docs/redteam/empirical-rea-validation.md
@@ -0,0 +1,241 @@
+# Empirical REA red-team validation
+
+Generated: 2026-10-27, 04:44:41 (Asia/Shanghai)
+BLA root: `/workspace/bla-dev/bla`
+REA root: `/workspace/bla-dev/rea`
+Intensity: `bankrupt` Β· seed: `bla-redteam-empirical-v1`
+Node: `v22.23.4`
+tshark: `TShark (Wireshark) 4.4.19.`
+
+## Summary
+
+| Format | Before status | After status | Budget hit (after) | vs BLA estimate |
+|---|---|---|---|---|
+| go_buildinfo | ok | error | MAX_BUILD_INFO_BYTES | agree |
+| flutter_pool | ok | ok | MAX_POOL_URIS|MAX_POOL_TOKENS | agree |
+| erlang_beam | ok | error | max_chunks | agree |
+| evm_bytecode | ok | ok | EVM_INTERFACE_LIMITS.inputBytes (approach) | agree |
+| pcap_capture | ok | budget_rejected | TSHARK_JSON_MAX_BYTES | agree |
+| safetensors | ok | ok | no | noted |
+| gguf | ok | error | MODEL_METADATA_NESTING | agree |
+| gpu_ptx | ok | ok | no | noted |
+
+## Per-format empirical outcomes
+
+### go_buildinfo
+
+- Input before: 166027 (162.1 KiB)
+- Input after: 1329394 (1.27 MiB)
+- Before: status=ok; budgetHit=false; note=no_buildinfo_observed
+- After: status=error; budgetHit=MAX_BUILD_INFO_BYTES; error=BinaryResourceFailure: Go build-info string length exceeds the 1 MiB limit
+
+**Before metrics**
+
+- `hasBuildInfo`: false
+- `encoding`: null
+- `goVersion`: null
+- `moduleTextBytes`: 0
+
+**After metrics**
+
+_no metrics_
+
+**Estimate comparison**
+
+- AGREE with BLA goBuildInfoExceedsLimit=true
+
+### flutter_pool
+
+- Input before: 166027 (162.1 KiB)
+- Input after: 1329394 (1.27 MiB)
+- Before: status=ok; budgetHit=false
+- After: status=ok; budgetHit=MAX_POOL_URIS|MAX_POOL_TOKENS; note=REA would report truncated package_uris/dart_uris/class_like_tokens with 'at least N' limitations
+
+**Before metrics**
+
+- `isolateBytes`: 163840
+- `packageUriCount`: 0
+- `dartUriCount`: 0
+- `classLikeTokenCount`: 0
+- `printableRunCount`: 1
+- `collectionCapped`: false
+- `reportWouldCap`: false
+
+**After metrics**
+
+- `isolateBytes`: 163840
+- `packageUriCount`: 532
+- `dartUriCount`: 532
+- `classLikeTokenCount`: 2032
+- `printableRunCount`: 3098
+- `collectionCapped`: false
+- `reportWouldCap`: true
+
+**Estimate comparison**
+
+- AGREE: REA pool projection would truncate past MAX_POOL_URIS/TOKENS
+- packageUriCount=532 (cap 500), dartUriCount=532, classLikeTokenCount=2032 (cap 2000)
+
+### erlang_beam
+
+- Input before: 84
+- Input after: 267876 (261.6 KiB)
+- Before: status=ok; budgetHit=false
+- After: status=error; budgetHit=max_chunks; error=BeamCapacityFailure: BEAM form exceeds the 64-chunk budget.
+
+**Before metrics**
+
+- `chunkCount`: 3
+- `atomCount`: 3
+- `limitations`: ["This workflow does not execute BEAM bytecode, inflate LitT literals, or decode Attr/CInf external-term payloads.","Atom names are structural table entries; they do not authenticate the originating compiler or module checksum."]
+
+**After metrics**
+
+_no metrics_
+
+**Estimate comparison**
+
+- AGREE with BLA exceedsDefaultChunkBudget=true
+
+### evm_bytecode
+
+- Input before: 16
+- Input after: 4190208 (4.00 MiB)
+- Before: status=ok; budgetHit=false
+- After: status=ok; budgetHit=EVM_INTERFACE_LIMITS.inputBytes (approach); note=Hardened sample approaches full 4 MiB input budget
+
+**Before metrics**
+
+- `inputBytes`: 16
+- `inputBytesLimit`: 4194304
+- `approachesLimit`: false
+- `exceedsLimit`: false
+- `carrierBytes`: 16
+- `solidityMetadata`: {"profile":"terminal-cbor-scalars-v1","status":"unavailable","bytecode_offset":null,"cbor_bytes":null,"entries":[],"compiler_version":null,"diagnostic":"No plausible terminal CBOR map was identified; Solidity origin and metadata absence remain unknown."}
+
+**After metrics**
+
+- `inputBytes`: 4190208
+- `inputBytesLimit`: 4194304
+- `approachesLimit`: true
+- `exceedsLimit`: false
+- `carrierBytes`: 4190208
+- `solidityMetadata`: {"profile":"terminal-cbor-scalars-v1","status":"decoded","bytecode_offset":4189159,"cbor_bytes":1047,"entries":[{"key":{"kind":"text","value":"solc"},"value":{"kind":"bytes","value":"00081e"}},{"key":{"kind":"text","value":"bla"},"value":{"kind":"text","value":"[BLA-EVM-SHIELD]"}},{"key":{"kind":"text","value":"bla_evm_canary"},"value":{"kind":"text","value":"407f29249793f34f"}},{"key":{"kind":"text","value":"bla_3"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=AKIAIOSFODNN7EXAMPLE_1C72_0"}},{"key":{"kind":"text","value":"bla_4"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=sk-canary-honeypot-do-not-exfiltrate-1c72-bfd73d9a"}},{"key":{"kind":"text","value":"bla_5"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=ghp_canaryHoneypotSyntheticToken1c72e72b5016"}},{"key":{"kind":"text","value":"bla_6"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=AKIAIOSFODNN7EXAMPLE_1C72_3"}},{"key":{"kind":"text","value":"bla_7"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=sk-canary-honeypot-do-not-exfiltrate-1c72-24b248fa"}},{"key":{"kind":"text","value":"bla_8"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=ghp_canaryHoneypotSyntheticToken1c72ee234dff"}},{"key":{"kind":"text","value":"bla_9"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=AKIAIOSFODNN7EXAMPLE_1C72_6"}},{"key":{"kind":"text","value":"bla_10"},"value":{"kind":"text","value":"PROTECTED_CANARY_CREDENTIAL=sk-canary-honeypot-do-not-exfiltrate-1c72-547dca4c"}},{"key":{"kind":"text","value":"bla_11"},"value":{"kind":"text","value":"TRANSPORT_ENDPOINT=https:/canary_1c72_0:[email protected]/v2/attest"}},{"key":{"kind":"text","value":"bla_12"},"value":{"kind":"text","value":"TRANSPORT_ENDPOINT=https:/canary_1c72_1:[email protected]/v3/quorum-lease"}},{"key":{"kind":"text","value":"bla_13"},"value":{"kind":"text","value":"TRANSPORT_ENDPOINT=https:/canary_1c72_2:[email protected]/v1/pkcs11-unwrap"}},{"key":{"kind":"text","value":"bla_14"},"value":{"kind":"text","value":"TRANSPORT_ENDPOINT=https:/canary_1c72_3:[email protected]/v2/license-seal"}}],"compiler_version":{"representation":"release-bytes","value":"0.8.30"},"diagnostic":null}
+
+**Estimate comparison**
+
+- AGREE with BLA approachesInputBudget=true (after=4190208 (4.00 MiB), limit=4194304 (4.00 MiB))
+
+### pcap_capture
+
+- Input before: 24
+- Input after: 1348012 (1.29 MiB)
+- Before: status=ok; budgetHit=false
+- After: status=budget_rejected; budgetHit=TSHARK_JSON_MAX_BYTES; note=REA parseTsharkJsonOutput would throw AnalysisResourceConstraintError
+
+**Before metrics**
+
+- `tsharkStatus`: 0
+- `tsharkJsonBytes`: 3
+- `tsharkJsonLimit`: 8388608
+- `exceedsTsharkJsonBudget`: false
+- `stderrHead`:
+
+**After metrics**
+
+- `tsharkStatus`: 0
+- `tsharkJsonBytes`: 12779702
+- `tsharkJsonLimit`: 8388608
+- `exceedsTsharkJsonBudget`: true
+- `stderrHead`:
+- `reaParseErrorName`: AnalysisResourceConstraintError
+- `reaParseError`: Resource constraint during inspect_pcap_capture: tshark JSON exceeds the bounded decoding budget
+
+**Estimate comparison**
+
+- BLA estimate=11355808 (10.83 MiB); empirical tshark JSON=12779702 (12.19 MiB)
+- AGREE with BLA exceedsTsharkJsonBudget=true
+
+### safetensors
+
+- Input before: 128
+- Input after: 9560 (9.3 KiB)
+- Before: status=ok; budgetHit=false
+- After: status=ok; budgetHit=false
+
+**Before metrics**
+
+- `tensorCount`: 1
+- `metadataCount`: 1
+- `limitations`: []
+
+**After metrics**
+
+- `tensorCount`: 1
+- `metadataCount`: 44
+- `limitations`: []
+
+**Estimate comparison**
+
+- EXPECTED: safetensors does NOT trip MODEL_JSON_NESTING (HF validity red line); canaries only
+- empirical: header parse succeeded (no nesting breaker)
+
+### gguf
+
+- Input before: 24
+- Input after: 7840 (7.7 KiB)
+- Before: status=ok; budgetHit=false
+- After: status=error; budgetHit=MODEL_METADATA_NESTING; error=ModelFormatFailure: GGUF metadata nesting exceeds 32 array frames
+
+**Before metrics**
+
+- `version`: 3
+- `tensorCount`: 0
+- `metadataCount`: 0
+- `limitations`: []
+
+**After metrics**
+
+_no metrics_
+
+**Estimate comparison**
+
+- AGREE with BLA triggeredMetadataNestingBreaker=true
+
+### gpu_ptx
+
+- Input before: 91
+- Input after: 26424 (25.8 KiB)
+- Before: status=ok; budgetHit=false
+- After: status=ok; budgetHit=false
+
+**Before metrics**
+
+- `entryCount`: 1
+- `textBytes`: 91
+- `note`: REA GPU object decode needs native tooling for fatbin/SPIR-V; PTX is text-scanned here
+
+**After metrics**
+
+- `entryCount`: 129
+- `textBytes`: 26424
+- `note`: REA GPU object decode needs native tooling for fatbin/SPIR-V; PTX is text-scanned here
+
+**Estimate comparison**
+
+- PTX is text-scanned only; REA GPU object decode needs native tooling (not empirically verified for fatbin/SPIR-V)
+
+## Analyzers NOT empirically verified on this box
+
+- **Ghidra / Hopper native decompile** β€” requires Ghidra/Hopper install (not available without root/GUI)
+- **Frida dynamic instrumentation** β€” requires frida-tools + attachable target process
+- **LLDB / GDB native tracing** β€” requires lldb/gdb + debuggee; not installed here
+- **Rizin / Cutter** β€” requires rizin binary
+- **JADX Android decompile** β€” requires JADX JVM tooling
+- **EVM EVMole worker full interface recovery** β€” worker subprocess/path not exercised end-to-end; inputBytes budget checked in-process
+- **SPIR-V / CUDA fatbinary / AMD GPU object** β€” BLA skips these formats (GPU_OBJECT_HARDENING_SKIP_REASON); no shield to validate
+- **Firmware analysis** β€” BLA skips firmware (FIRMWARE_HARDENING_SKIP_REASON); needs vendor parsers
+
+## Method
+
+Harness lives under `scripts/redteam/`. For each in-process REA analyzer, it builds a representative sample, runs the real REA parser on the unhardened bytes, hardens via BLA (`protect*` APIs / mapped plants), re-runs REA, and records budget/redaction/error outcomes. Flutter pool projection uses a faithful replica of REA's private `projectStringPool` (same caps, slack, identifier rules). PCAP uses a real user-local tshark when present.
diff --git a/package.json b/package.json
index e6e9abd..a8291d8 100644
--- a/package.json
+++ b/package.json
@@ -69,7 +69,8 @@
"release:patch": "npm version patch -m 'chore(release): bla-agents v%s' && git push --follow-tags",
"release:minor": "npm version minor -m 'chore(release): bla-agents v%s' && git push --follow-tags",
"prepublishOnly": "npm run build && npm test",
- "verify:rea": "node scripts/verify-rea-constants.mjs"
+ "verify:rea": "node scripts/verify-rea-constants.mjs",
+ "redteam:rea": "node scripts/redteam/run.mjs"
},
"dependencies": {
"@babel/generator": "^7.26.0",
diff --git a/scripts/redteam/lib/paths.mjs b/scripts/redteam/lib/paths.mjs
new file mode 100644
index 0000000..813f6d9
--- /dev/null
+++ b/scripts/redteam/lib/paths.mjs
@@ -0,0 +1,49 @@
+import { existsSync } from "node:fs";
+import { dirname, join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+export const BLA_ROOT = resolve(__dirname, "../../..");
+export const REA_ROOT = resolve(
+ process.env.REA_ROOT ?? join(BLA_ROOT, "..", "rea"),
+);
+export const REDTEAM_OUT_DIR = join(BLA_ROOT, "docs/redteam");
+export const REDTEAM_REPORT_MD = join(
+ REDTEAM_OUT_DIR,
+ "empirical-rea-validation.md",
+);
+export const REDTEAM_REPORT_JSON = join(
+ REDTEAM_OUT_DIR,
+ "empirical-rea-validation.json",
+);
+
+export function resolveReaDist(rel) {
+ return join(REA_ROOT, "dist", rel);
+}
+
+export function reaDistReady() {
+ return existsSync(resolveReaDist("go/GoBinaryImage.js"));
+}
+
+/** User-local Wireshark extract (no root required on this box). */
+export function resolveTsharkEnv() {
+ const home = process.env.HOME ?? "";
+ const prefix = join(home, "opt/wireshark");
+ const bin = join(prefix, "usr/bin/tshark");
+ const lib = [
+ join(prefix, "usr/lib/x86_64-linux-gnu"),
+ join(prefix, "lib/x86_64-linux-gnu"),
+ ].join(":");
+ if (!existsSync(bin)) {
+ return { available: false, bin: null, env: process.env };
+ }
+ return {
+ available: true,
+ bin,
+ env: {
+ ...process.env,
+ PATH: `${join(prefix, "usr/bin")}:${process.env.PATH ?? ""}`,
+ LD_LIBRARY_PATH: `${lib}${process.env.LD_LIBRARY_PATH ? `:${process.env.LD_LIBRARY_PATH}` : ""}`,
+ },
+ };
+}
diff --git a/scripts/redteam/lib/probes.mjs b/scripts/redteam/lib/probes.mjs
new file mode 100644
index 0000000..a8e2987
--- /dev/null
+++ b/scripts/redteam/lib/probes.mjs
@@ -0,0 +1,455 @@
+import { writeFileSync, mkdtempSync } from "node:fs";
+import { open } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { spawnSync } from "node:child_process";
+import { createRequire } from "node:module";
+import {
+ resolveReaDist,
+ resolveTsharkEnv,
+ reaDistReady,
+} from "./paths.mjs";
+
+const require = createRequire(import.meta.url);
+
+/** Faithful replica of REA `projectStringPool` (private in FlutterBuildProvider). */
+export function projectStringPoolReaFaithful(section, limits) {
+ const MAX_POOL_URIS = limits.DART_MAX_POOL_URIS;
+ const MAX_POOL_TOKENS = limits.DART_MAX_POOL_TOKENS;
+ const COLLECTION_SLACK = 2;
+ const MAX_RUN_BYTES = 1024;
+ const IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
+ const packages = new Set();
+ const darts = new Set();
+ const tokens = new Set();
+ let runCount = 0;
+ let collectionCapped = false;
+ const packageBudget = MAX_POOL_URIS * COLLECTION_SLACK;
+ const dartBudget = MAX_POOL_URIS * COLLECTION_SLACK;
+ const tokenBudget = MAX_POOL_TOKENS * COLLECTION_SLACK;
+ if (section != null) {
+ let run = "";
+ let overflowed = false;
+ const consider = (text) => {
+ if (text.length < 5) return;
+ runCount += 1;
+ if (text.startsWith("package:")) {
+ if (!packages.has(text) && packages.size >= packageBudget)
+ collectionCapped = true;
+ else packages.add(text);
+ } else if (text.startsWith("dart:")) {
+ if (!darts.has(text) && darts.size >= dartBudget)
+ collectionCapped = true;
+ else darts.add(text);
+ } else if (
+ text.length <= 128 &&
+ text.length >= 5 &&
+ IDENTIFIER_PATTERN.test(text)
+ ) {
+ if (!tokens.has(text) && tokens.size >= tokenBudget)
+ collectionCapped = true;
+ else tokens.add(text);
+ }
+ };
+ for (const byte of section) {
+ if (byte >= 0x20 && byte < 0x7f) {
+ if (run.length < MAX_RUN_BYTES) run += String.fromCharCode(byte);
+ else {
+ overflowed = true;
+ collectionCapped = true;
+ }
+ } else {
+ if (!overflowed) consider(run);
+ overflowed = false;
+ run = "";
+ }
+ }
+ if (!overflowed) consider(run);
+ }
+ return {
+ packageUriCount: packages.size,
+ dartUriCount: darts.size,
+ classLikeTokenCount: tokens.size,
+ printableRunCount: runCount,
+ collectionCapped,
+ reportWouldCap:
+ packages.size > MAX_POOL_URIS ||
+ darts.size > MAX_POOL_URIS ||
+ tokens.size > MAX_POOL_TOKENS,
+ };
+}
+
+function outcomeBase(format, phase, bytes) {
+ return {
+ format,
+ phase,
+ inputBytes: bytes.length,
+ status: "ok",
+ errorName: null,
+ errorMessage: null,
+ budgetHit: false,
+ budgetName: null,
+ redactionOrAmbiguity: null,
+ metrics: {},
+ };
+}
+
+function failOutcome(base, err, budgetName = null) {
+ base.status = "error";
+ base.errorName = err?.constructor?.name ?? "Error";
+ base.errorMessage = String(err?.message ?? err).slice(0, 240);
+ if (budgetName || err?.boundary || err?.limit) {
+ base.budgetHit = true;
+ base.budgetName =
+ budgetName ??
+ err?.boundary ??
+ err?.limit ??
+ err?.capacity ??
+ "resource";
+ }
+ return base;
+}
+
+export async function loadReaProbes() {
+ if (!reaDistReady()) {
+ throw new Error(
+ "REA dist missing β€” compile with: cd ../rea && npx tsc -p tsconfig.build.json",
+ );
+ }
+ const { readGoBinaryImage } = await import(
+ resolveReaDist("go/GoBinaryImage.js")
+ );
+ const { parseErlangBeam, BeamCapacityFailure } = await import(
+ resolveReaDist("erlang/BeamParser.js")
+ );
+ const { EVM_INTERFACE_LIMITS } = await import(
+ resolveReaDist("evm/EvmoleRelease.js")
+ );
+ const { decodeEvmBytecodeCarrier } = await import(
+ resolveReaDist("evm/EvmBytecodeCarrier.js")
+ );
+ const { inspectSolidityMetadata } = await import(
+ resolveReaDist("evm/SolidityMetadata.js")
+ );
+ const { TSHARK_JSON_MAX_BYTES, parseTsharkJsonOutput } = await import(
+ resolveReaDist("pcap/PcapOutput.js")
+ );
+ const { MODEL_JSON_NESTING, MODEL_METADATA_NESTING, ModelFormatFailure } =
+ await import(resolveReaDist("model/ModelFormat.js"));
+ const { readSafetensorsHeader } = await import(
+ resolveReaDist("model/SafetensorsHeader.js")
+ );
+ const { ModelHeaderReader } = await import(
+ resolveReaDist("model/ModelHeaderReader.js")
+ );
+ const { GgufHeader } = await import(resolveReaDist("model/GgufHeader.js"));
+ return {
+ readGoBinaryImage,
+ parseErlangBeam,
+ BeamCapacityFailure,
+ EVM_INTERFACE_LIMITS,
+ decodeEvmBytecodeCarrier,
+ inspectSolidityMetadata,
+ TSHARK_JSON_MAX_BYTES,
+ parseTsharkJsonOutput,
+ MODEL_JSON_NESTING,
+ MODEL_METADATA_NESTING,
+ ModelFormatFailure,
+ readSafetensorsHeader,
+ ModelHeaderReader,
+ GgufHeader,
+ };
+}
+
+export async function probeGo(rea, bytes, phase) {
+ const base = outcomeBase("go_buildinfo", phase, bytes);
+ try {
+ const img = rea.readGoBinaryImage(bytes);
+ base.metrics = {
+ hasBuildInfo: img.build_info != null,
+ encoding: img.build_info?.encoding ?? null,
+ goVersion: img.build_info?.go_version ?? null,
+ moduleTextBytes: img.build_info?.module_text?.length ?? 0,
+ };
+ if (img.build_info == null) {
+ base.redactionOrAmbiguity = "no_buildinfo_observed";
+ }
+ } catch (err) {
+ failOutcome(base, err, err?.boundary === "build-info" ? "MAX_BUILD_INFO_BYTES" : err?.boundary);
+ }
+ return base;
+}
+
+export async function probeFlutterPool(bla, bytes, phase, limits) {
+ const base = outcomeBase("flutter_pool", phase, bytes);
+ try {
+ // validateElf64Layout throws on invalid; returns layout summary otherwise.
+ const layout = bla.validateElf64Layout(bytes);
+ const names = bla.resolveElf64SectionNames(bytes, layout);
+ const iso = names.get(".isolate");
+ if (!iso) {
+ base.redactionOrAmbiguity = "no_isolate_section";
+ return base;
+ }
+ const section = bytes.subarray(iso.offset, iso.offset + iso.size);
+ const pool = projectStringPoolReaFaithful(section, limits);
+ base.metrics = { isolateBytes: iso.size, ...pool };
+ if (pool.reportWouldCap) {
+ base.budgetHit = true;
+ base.budgetName = "MAX_POOL_URIS|MAX_POOL_TOKENS";
+ base.redactionOrAmbiguity =
+ "REA would report truncated package_uris/dart_uris/class_like_tokens with 'at least N' limitations";
+ }
+ } catch (err) {
+ failOutcome(base, err);
+ }
+ return base;
+}
+
+export async function probeBeam(rea, bytes, phase) {
+ const base = outcomeBase("erlang_beam", phase, bytes);
+ try {
+ const artifact = {
+ path: "sample.beam",
+ bytes: bytes.length,
+ sha256: "0".repeat(64),
+ };
+ const result = rea.parseErlangBeam(bytes, artifact, {
+ max_chunks: 64,
+ max_atoms: 4096,
+ });
+ base.metrics = {
+ chunkCount: result.chunks.length,
+ atomCount: result.atoms?.length ?? 0,
+ limitations: (result.limitations ?? []).slice(0, 3),
+ };
+ } catch (err) {
+ const name =
+ err?.constructor?.name === "BeamCapacityFailure"
+ ? err.resource === "chunks"
+ ? "max_chunks"
+ : err.resource === "atoms"
+ ? "max_atoms"
+ : "beam_capacity"
+ : null;
+ failOutcome(base, err, name);
+ }
+ return base;
+}
+
+export async function probeEvm(rea, bytes, phase) {
+ const base = outcomeBase("evm_bytecode", phase, bytes);
+ const limit = rea.EVM_INTERFACE_LIMITS.inputBytes;
+ base.metrics = {
+ inputBytes: bytes.length,
+ inputBytesLimit: limit,
+ approachesLimit: bytes.length >= limit - 8192,
+ exceedsLimit: bytes.length > limit,
+ };
+ if (bytes.length > limit) {
+ base.budgetHit = true;
+ base.budgetName = "EVM_INTERFACE_LIMITS.inputBytes";
+ base.status = "rejected_pre_worker";
+ base.redactionOrAmbiguity =
+ "REA would refuse to start the EVM worker (input exceeds 4 MiB)";
+ return base;
+ }
+ try {
+ try {
+ const carrier = rea.decodeEvmBytecodeCarrier(bytes, "raw");
+ base.metrics.carrierBytes = carrier?.length;
+ } catch (err) {
+ base.metrics.carrierError = String(err.message).slice(0, 120);
+ }
+ try {
+ const meta = rea.inspectSolidityMetadata(bytes);
+ base.metrics.solidityMetadata = meta;
+ } catch (err) {
+ base.metrics.metadataError = String(err.message).slice(0, 120);
+ }
+ if (base.metrics.approachesLimit) {
+ base.budgetHit = true;
+ base.budgetName = "EVM_INTERFACE_LIMITS.inputBytes (approach)";
+ base.redactionOrAmbiguity =
+ "Hardened sample approaches full 4 MiB input budget";
+ }
+ } catch (err) {
+ failOutcome(base, err);
+ }
+ return base;
+}
+
+export async function probePcap(rea, bytes, phase) {
+ const base = outcomeBase("pcap_capture", phase, bytes);
+ const tshark = resolveTsharkEnv();
+ if (!tshark.available) {
+ base.status = "skipped";
+ base.redactionOrAmbiguity =
+ "not empirically verified on this box (requires tshark)";
+ return base;
+ }
+ const dir = mkdtempSync(join(tmpdir(), "bla-rt-pcap-"));
+ const path = join(dir, `${phase}.pcap`);
+ writeFileSync(path, bytes);
+ const proc = spawnSync(
+ tshark.bin,
+ ["-r", path, "-T", "json"],
+ {
+ encoding: "buffer",
+ maxBuffer: 64 * 1024 * 1024,
+ env: tshark.env,
+ timeout: 120_000,
+ },
+ );
+ const jsonBytes = proc.stdout ? proc.stdout.length : 0;
+ base.metrics = {
+ tsharkStatus: proc.status,
+ tsharkJsonBytes: jsonBytes,
+ tsharkJsonLimit: rea.TSHARK_JSON_MAX_BYTES,
+ exceedsTsharkJsonBudget: jsonBytes > rea.TSHARK_JSON_MAX_BYTES,
+ stderrHead: proc.stderr
+ ? Buffer.from(proc.stderr).toString("utf8").slice(0, 160)
+ : "",
+ };
+ if (proc.error) {
+ failOutcome(base, proc.error, "tshark");
+ return base;
+ }
+ if (jsonBytes > rea.TSHARK_JSON_MAX_BYTES) {
+ base.budgetHit = true;
+ base.budgetName = "TSHARK_JSON_MAX_BYTES";
+ base.redactionOrAmbiguity =
+ "REA parseTsharkJsonOutput would throw AnalysisResourceConstraintError";
+ // Confirm REA's parser rejects oversized JSON
+ try {
+ await rea.parseTsharkJsonOutput(proc.stdout.toString("utf8"));
+ base.metrics.reaParseAcceptedOversized = true;
+ } catch (err) {
+ base.metrics.reaParseErrorName = err?.constructor?.name;
+ base.metrics.reaParseError = String(err.message).slice(0, 160);
+ base.status = "budget_rejected";
+ }
+ }
+ return base;
+}
+
+export async function probeSafetensors(rea, bytes, phase) {
+ const base = outcomeBase("safetensors", phase, bytes);
+ const dir = mkdtempSync(join(tmpdir(), "bla-rt-st-"));
+ const path = join(dir, `${phase}.safetensors`);
+ writeFileSync(path, bytes);
+ try {
+ const fh = await open(path, "r");
+ try {
+ const reader = new rea.ModelHeaderReader(fh, bytes.length);
+ const first = await reader.take(4);
+ const result = await rea.readSafetensorsHeader(reader, first);
+ base.metrics = {
+ tensorCount: result.tensors?.length ?? 0,
+ metadataCount: result.metadata?.length ?? 0,
+ limitations: result.limitations ?? [],
+ };
+ } finally {
+ await fh.close();
+ }
+ } catch (err) {
+ const limit = err?.limit ?? null;
+ failOutcome(
+ base,
+ err,
+ limit === "json-nesting" ? "MODEL_JSON_NESTING" : limit,
+ );
+ }
+ return base;
+}
+
+export async function probeGguf(rea, bytes, phase) {
+ const base = outcomeBase("gguf", phase, bytes);
+ const dir = mkdtempSync(join(tmpdir(), "bla-rt-gguf-"));
+ const path = join(dir, `${phase}.gguf`);
+ writeFileSync(path, bytes);
+ try {
+ const fh = await open(path, "r");
+ try {
+ const reader = new rea.ModelHeaderReader(fh, bytes.length);
+ // ModelArtifactProvider consumes the 4-byte GGUF magic before GgufHeader.
+ const magic = await reader.take(4);
+ if (!magic.equals(Buffer.from("GGUF"))) {
+ base.status = "error";
+ base.errorMessage = `expected GGUF magic, got ${magic.toString("hex")}`;
+ return base;
+ }
+ const header = new rea.GgufHeader(reader);
+ const result = await header.read();
+ base.metrics = {
+ version: result?.version,
+ tensorCount: result?.tensors?.length ?? result?.tensor_count,
+ metadataCount: result?.metadata?.length,
+ limitations: result?.limitations ?? [],
+ };
+ } finally {
+ await fh.close();
+ }
+ } catch (err) {
+ const limit = err?.limit ?? null;
+ failOutcome(
+ base,
+ err,
+ limit === "metadata-nesting" ? "MODEL_METADATA_NESTING" : limit,
+ );
+ }
+ return base;
+}
+
+export async function probePtx(_rea, bytes, phase) {
+ const base = outcomeBase("gpu_ptx", phase, bytes);
+ const text = bytes.toString("utf8");
+ const entries = [...text.matchAll(/\.entry\s+(\w+)/g)].map((m) => m[1]);
+ base.metrics = {
+ entryCount: entries.length,
+ textBytes: bytes.length,
+ note: "REA GPU object decode needs native tooling for fatbin/SPIR-V; PTX is text-scanned here",
+ };
+ return base;
+}
+
+/** Catalog of analyzers that cannot run empirically on this box. */
+export function unverifiedAnalyzers() {
+ return [
+ {
+ analyzer: "Ghidra / Hopper native decompile",
+ reason: "requires Ghidra/Hopper install (not available without root/GUI)",
+ },
+ {
+ analyzer: "Frida dynamic instrumentation",
+ reason: "requires frida-tools + attachable target process",
+ },
+ {
+ analyzer: "LLDB / GDB native tracing",
+ reason: "requires lldb/gdb + debuggee; not installed here",
+ },
+ {
+ analyzer: "Rizin / Cutter",
+ reason: "requires rizin binary",
+ },
+ {
+ analyzer: "JADX Android decompile",
+ reason: "requires JADX JVM tooling",
+ },
+ {
+ analyzer: "EVM EVMole worker full interface recovery",
+ reason:
+ "worker subprocess/path not exercised end-to-end; inputBytes budget checked in-process",
+ },
+ {
+ analyzer: "SPIR-V / CUDA fatbinary / AMD GPU object",
+ reason:
+ "BLA skips these formats (GPU_OBJECT_HARDENING_SKIP_REASON); no shield to validate",
+ },
+ {
+ analyzer: "Firmware analysis",
+ reason:
+ "BLA skips firmware (FIRMWARE_HARDENING_SKIP_REASON); needs vendor parsers",
+ },
+ ];
+}
diff --git a/scripts/redteam/lib/report.mjs b/scripts/redteam/lib/report.mjs
new file mode 100644
index 0000000..6782eea
--- /dev/null
+++ b/scripts/redteam/lib/report.mjs
@@ -0,0 +1,210 @@
+import { mkdirSync, writeFileSync } from "node:fs";
+import { dirname } from "node:path";
+import { REDTEAM_OUT_DIR, REDTEAM_REPORT_MD, REDTEAM_REPORT_JSON } from "./paths.mjs";
+
+function fmtBytes(n) {
+ if (n == null) return "β€”";
+ if (n >= 1_048_576) return `${n} (${(n / 1_048_576).toFixed(2)} MiB)`;
+ if (n >= 1024) return `${n} (${(n / 1024).toFixed(1)} KiB)`;
+ return String(n);
+}
+
+function outcomeLine(o) {
+ const bits = [
+ `status=${o.status}`,
+ o.budgetHit ? `budgetHit=${o.budgetName}` : "budgetHit=false",
+ ];
+ if (o.errorName) bits.push(`error=${o.errorName}: ${o.errorMessage}`);
+ if (o.redactionOrAmbiguity) bits.push(`note=${o.redactionOrAmbiguity}`);
+ return bits.join("; ");
+}
+
+function metricsBlock(metrics) {
+ if (!metrics || Object.keys(metrics).length === 0) return "_no metrics_";
+ return Object.entries(metrics)
+ .map(([k, v]) => {
+ const val =
+ typeof v === "object" ? JSON.stringify(v) : String(v ?? "null");
+ return `- \`${k}\`: ${val}`;
+ })
+ .join("\n");
+}
+
+/**
+ * Compare empirical outcomes to BLA's internal estimates / planted flags.
+ */
+function compareToEstimates(pair) {
+ const notes = [];
+ const { format, before, after, sampleMeta, blaLimits } = pair;
+ if (format === "go_buildinfo") {
+ const expect = sampleMeta?.goTripsMax === true;
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit === expect
+ ? `AGREE with BLA goBuildInfoExceedsLimit=${expect}`
+ : `DIVERGE: BLA estimated trips=${expect}, empirical budgetHit=${hit}`,
+ );
+ }
+ if (format === "flutter_pool") {
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit
+ ? "AGREE: REA pool projection would truncate past MAX_POOL_URIS/TOKENS"
+ : "DIVERGE: Flutter pool did NOT exceed REA caps β€” shield under-capacity",
+ );
+ if (after.metrics?.packageUriCount != null) {
+ notes.push(
+ `packageUriCount=${after.metrics.packageUriCount} (cap ${blaLimits.DART_MAX_POOL_URIS}), dartUriCount=${after.metrics.dartUriCount}, classLikeTokenCount=${after.metrics.classLikeTokenCount} (cap ${blaLimits.DART_MAX_POOL_TOKENS})`,
+ );
+ }
+ }
+ if (format === "erlang_beam") {
+ const expect = sampleMeta?.exceedsDefaultChunkBudget === true;
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit === expect
+ ? `AGREE with BLA exceedsDefaultChunkBudget=${expect}`
+ : `DIVERGE: BLA estimated=${expect}, empirical budgetHit=${hit} (${after.budgetName})`,
+ );
+ }
+ if (format === "evm_bytecode") {
+ const expect = sampleMeta?.approachesInputBudget === true;
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit === expect || (expect && after.metrics?.approachesLimit)
+ ? `AGREE with BLA approachesInputBudget=${expect} (after=${fmtBytes(after.inputBytes)}, limit=${fmtBytes(blaLimits.EVM_INPUT_BYTES)})`
+ : `DIVERGE: BLA approaches=${expect}, empirical budgetHit=${hit}`,
+ );
+ }
+ if (format === "pcap_capture") {
+ const expect = sampleMeta?.exceedsTsharkJsonBudget === true;
+ const hit = after.budgetHit === true;
+ const est = sampleMeta?.estimatedTsharkJsonBytes;
+ const real = after.metrics?.tsharkJsonBytes;
+ notes.push(
+ `BLA estimate=${fmtBytes(est)}; empirical tshark JSON=${fmtBytes(real)}`,
+ );
+ if (after.status === "skipped") {
+ notes.push("SKIPPED: tshark unavailable β€” estimate not empirically confirmed");
+ } else if (hit === expect) {
+ notes.push(`AGREE with BLA exceedsTsharkJsonBudget=${expect}`);
+ } else {
+ notes.push(
+ `DIVERGE: BLA estimated exceed=${expect}, empirical budgetHit=${hit}`,
+ );
+ }
+ }
+ if (format === "safetensors") {
+ notes.push(
+ sampleMeta?.triggeredJsonNestingBreaker === false ||
+ sampleMeta?.triggeredJsonNestingBreaker == null
+ ? "EXPECTED: safetensors does NOT trip MODEL_JSON_NESTING (HF validity red line); canaries only"
+ : "UNEXPECTED: nesting breaker on safetensors",
+ );
+ notes.push(
+ after.budgetHit
+ ? `empirical budgetHit=${after.budgetName}`
+ : "empirical: header parse succeeded (no nesting breaker)",
+ );
+ }
+ if (format === "gguf") {
+ const expect = sampleMeta?.triggeredMetadataNestingBreaker === true;
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit === expect
+ ? `AGREE with BLA triggeredMetadataNestingBreaker=${expect}`
+ : `DIVERGE: BLA nesting=${expect}, empirical budgetHit=${hit} (${after.budgetName ?? after.errorName})`,
+ );
+ }
+ if (format === "gpu_ptx") {
+ notes.push(
+ "PTX is text-scanned only; REA GPU object decode needs native tooling (not empirically verified for fatbin/SPIR-V)",
+ );
+ }
+ // Before should generally NOT hit budgets
+ if (before.budgetHit && format !== "gpu_ptx") {
+ notes.push(
+ `WARN: unhardened sample unexpectedly hit budget (${before.budgetName})`,
+ );
+ }
+ return notes;
+}
+
+export function buildReportDocument(run) {
+ const lines = [];
+ lines.push("# Empirical REA red-team validation");
+ lines.push("");
+ lines.push(`Generated: ${run.generatedAt} (Asia/Shanghai)`);
+ lines.push(`BLA root: \`${run.blaRoot}\``);
+ lines.push(`REA root: \`${run.reaRoot}\``);
+ lines.push(`Intensity: \`${run.intensity}\` Β· seed: \`${run.seed}\``);
+ lines.push(`Node: \`${run.nodeVersion}\``);
+ lines.push(`tshark: ${run.tshark.available ? `\`${run.tshark.version}\`` : "not available"}`);
+ lines.push("");
+ lines.push("## Summary");
+ lines.push("");
+ lines.push(
+ "| Format | Before status | After status | Budget hit (after) | vs BLA estimate |",
+ );
+ lines.push("|---|---|---|---|---|");
+ for (const pair of run.pairs) {
+ const cmp = compareToEstimates(pair);
+ const agree = cmp.some((c) => c.startsWith("AGREE"))
+ ? "agree"
+ : cmp.some((c) => c.startsWith("DIVERGE"))
+ ? "diverge"
+ : cmp.some((c) => c.startsWith("SKIPPED") || c.startsWith("EXPECTED") || c.startsWith("PTX"))
+ ? "noted"
+ : "β€”";
+ lines.push(
+ `| ${pair.format} | ${pair.before.status} | ${pair.after.status} | ${pair.after.budgetHit ? pair.after.budgetName : "no"} | ${agree} |`,
+ );
+ }
+ lines.push("");
+ lines.push("## Per-format empirical outcomes");
+ lines.push("");
+ for (const pair of run.pairs) {
+ lines.push(`### ${pair.format}`);
+ lines.push("");
+ lines.push(`- Input before: ${fmtBytes(pair.before.inputBytes)}`);
+ lines.push(`- Input after: ${fmtBytes(pair.after.inputBytes)}`);
+ lines.push(`- Before: ${outcomeLine(pair.before)}`);
+ lines.push(`- After: ${outcomeLine(pair.after)}`);
+ lines.push("");
+ lines.push("**Before metrics**");
+ lines.push("");
+ lines.push(metricsBlock(pair.before.metrics));
+ lines.push("");
+ lines.push("**After metrics**");
+ lines.push("");
+ lines.push(metricsBlock(pair.after.metrics));
+ lines.push("");
+ lines.push("**Estimate comparison**");
+ lines.push("");
+ for (const n of compareToEstimates(pair)) {
+ lines.push(`- ${n}`);
+ }
+ lines.push("");
+ }
+ lines.push("## Analyzers NOT empirically verified on this box");
+ lines.push("");
+ for (const u of run.unverified) {
+ lines.push(`- **${u.analyzer}** β€” ${u.reason}`);
+ }
+ lines.push("");
+ lines.push("## Method");
+ lines.push("");
+ lines.push(
+ "Harness lives under `scripts/redteam/`. For each in-process REA analyzer, it builds a representative sample, runs the real REA parser on the unhardened bytes, hardens via BLA (`protect*` APIs / mapped plants), re-runs REA, and records budget/redaction/error outcomes. Flutter pool projection uses a faithful replica of REA's private `projectStringPool` (same caps, slack, identifier rules). PCAP uses a real user-local tshark when present.",
+ );
+ lines.push("");
+ return lines.join("\n");
+}
+
+export function writeReports(run) {
+ mkdirSync(REDTEAM_OUT_DIR, { recursive: true });
+ const md = buildReportDocument(run);
+ writeFileSync(REDTEAM_REPORT_MD, md, "utf8");
+ writeFileSync(REDTEAM_REPORT_JSON, JSON.stringify(run, null, 2), "utf8");
+ return { mdPath: REDTEAM_REPORT_MD, jsonPath: REDTEAM_REPORT_JSON };
+}
diff --git a/scripts/redteam/lib/samples.mjs b/scripts/redteam/lib/samples.mjs
new file mode 100644
index 0000000..77f3f8e
--- /dev/null
+++ b/scripts/redteam/lib/samples.mjs
@@ -0,0 +1,240 @@
+import { createRequire } from "node:module";
+import { join } from "node:path";
+import { BLA_ROOT } from "./paths.mjs";
+
+const require = createRequire(import.meta.url);
+
+/** Load BLA compiled modules (dist/). */
+export async function loadBla() {
+ const base = join(BLA_ROOT, "dist/shields/formats");
+ return {
+ buildMappedGoFlutterElfFixture: (
+ await import(join(base, "go-flutter-exhaustion.js"))
+ ).buildMappedGoFlutterElfFixture,
+ protectNativeBinary: (await import(join(base, "native.js")))
+ .protectNativeBinary,
+ resolveElf64SectionNames: (await import(join(base, "native.js")))
+ .resolveElf64SectionNames,
+ validateElf64Layout: (await import(join(base, "native.js")))
+ .validateElf64Layout,
+ protectErlangBeamBuffer: (await import(join(base, "erlang-beam.js")))
+ .protectErlangBeamBuffer,
+ protectEvmBytecodeBuffer: (await import(join(base, "evm-bytecode.js")))
+ .protectEvmBytecodeBuffer,
+ protectPcapCaptureBuffer: (await import(join(base, "pcap-capture.js")))
+ .protectPcapCaptureBuffer,
+ protectGpuPtxText: (await import(join(base, "gpu-ptx.js"))).protectGpuPtxText,
+ buildSafetensorsBuffer: (await import(join(base, "model.js")))
+ .buildSafetensorsBuffer,
+ protectSafetensorsBuffer: (await import(join(base, "model.js")))
+ .protectSafetensorsBuffer,
+ protectGgufBuffer: (await import(join(base, "model.js"))).protectGgufBuffer,
+ REA_INTERNAL_LIMITS: (await import(join(BLA_ROOT, "dist/identity.js")))
+ .REA_INTERNAL_LIMITS,
+ };
+}
+
+function u32be(n) {
+ const b = Buffer.alloc(4);
+ b.writeUInt32BE(n >>> 0);
+ return b;
+}
+
+function beamChunk(name, payload) {
+ const pad = (4 - (payload.length % 4)) % 4;
+ return Buffer.concat([
+ Buffer.from(name, "latin1"),
+ u32be(payload.length),
+ payload,
+ Buffer.alloc(pad),
+ ]);
+}
+
+/** Minimal valid BEAM with non-compact AtU8. */
+export function buildMinimalBeam() {
+ const atoms = Buffer.concat([
+ u32be(3),
+ Buffer.from([4]),
+ Buffer.from("main"),
+ Buffer.from([6]),
+ Buffer.from("module"),
+ Buffer.from([4]),
+ Buffer.from("init"),
+ ]);
+ const code = Buffer.alloc(20);
+ code.writeUInt32BE(16, 0);
+ const body = Buffer.concat([
+ beamChunk("AtU8", atoms),
+ beamChunk("Code", code),
+ beamChunk("StrT", Buffer.from("x")),
+ ]);
+ return Buffer.concat([
+ Buffer.from("FOR1"),
+ u32be(4 + body.length),
+ Buffer.from("BEAM"),
+ body,
+ ]);
+}
+
+/** Minimal EVM runtime bytecode (no metadata). */
+export function buildMinimalEvm() {
+ return Buffer.from("6080604052348015600f575f80fd5b50", "hex");
+}
+
+/** Minimal classic libpcap (empty global header only β†’ protect appends decoys). */
+export function buildEmptyPcap() {
+ return Buffer.alloc(0);
+}
+
+/** Minimal classic libpcap global header (LE magic). */
+export function buildMinimalPcap() {
+ const h = Buffer.alloc(24, 0);
+ h.writeUInt32LE(0xa1b2c3d4, 0);
+ h.writeUInt16LE(2, 4);
+ h.writeUInt16LE(4, 6);
+ h.writeUInt32LE(65535, 16);
+ h.writeUInt32LE(1, 20); // LINKTYPE_ETHERNET
+ return h;
+}
+
+export function buildMinimalPtx() {
+ return Buffer.from(
+ `.version 7.0
+.target sm_70
+.address_size 64
+.visible .entry demo(.param .u64 out) { ret; }
+`,
+ "utf8",
+ );
+}
+
+export function buildMinimalSafetensors(bla) {
+ return bla.buildSafetensorsBuffer(
+ {
+ weight: { dtype: "F32", shape: [2, 2], data_offsets: [0, 16] },
+ __metadata__: { model: "redteam-demo" },
+ },
+ Buffer.alloc(16),
+ );
+}
+
+/** Tiny GGUF v3 with one string KV β€” protect injects nesting breaker. */
+export function buildMinimalGguf() {
+ // Magic GGUF, version 3, tensor_count=0, kv_count=0
+ const b = Buffer.alloc(24, 0);
+ b.write("GGUF", 0);
+ b.writeUInt32LE(3, 4);
+ b.writeBigUInt64LE(0n, 8);
+ b.writeBigUInt64LE(0n, 16);
+ return b;
+}
+
+/**
+ * Build the red-team sample matrix: one entry per empirically runnable format.
+ */
+export async function buildSampleMatrix() {
+ const bla = await loadBla();
+ const intensity = "bankrupt";
+ const seed = "bla-redteam-empirical-v1";
+
+ const elfRaw = bla.buildMappedGoFlutterElfFixture();
+ const elfHard = bla.protectNativeBinary(elfRaw, { intensity, seed });
+
+ const beamRaw = buildMinimalBeam();
+ const beamHard = bla.protectErlangBeamBuffer(beamRaw, { intensity, seed });
+
+ const evmRaw = buildMinimalEvm();
+ const evmHard = bla.protectEvmBytecodeBuffer(evmRaw, { intensity, seed });
+
+ const pcapRaw = buildMinimalPcap();
+ const pcapHard = bla.protectPcapCaptureBuffer(pcapRaw, {
+ intensity,
+ seed,
+ });
+
+ const ptxRaw = buildMinimalPtx();
+ const ptxHard = bla.protectGpuPtxText(ptxRaw.toString('utf8'), { intensity, seed });
+
+ const stRaw = buildMinimalSafetensors(bla);
+ const stHard = bla.protectSafetensorsBuffer(stRaw, { intensity, seed });
+
+ let ggufRaw = buildMinimalGguf();
+ let ggufHard;
+ try {
+ ggufHard = bla.protectGgufBuffer(ggufRaw, { intensity, seed });
+ } catch (err) {
+ ggufHard = { buffer: ggufRaw, error: String(err?.message ?? err) };
+ }
+
+ return {
+ bla,
+ intensity,
+ seed,
+ samples: {
+ go_flutter_elf: {
+ format: "go_flutter_elf",
+ before: elfRaw,
+ after: elfHard.buffer,
+ meta: {
+ mappedGo: elfHard.mappedGoBuildInfoPlanted,
+ mappedFlutter: elfHard.mappedFlutterPoolPlanted,
+ goTripsMax: elfHard.goBuildInfoExceedsLimit,
+ },
+ },
+ erlang_beam: {
+ format: "erlang_beam",
+ before: beamRaw,
+ after: beamHard.buffer,
+ meta: {
+ atomsInjected: beamHard.atomsInjected,
+ chunksInjected: beamHard.chunksInjected,
+ exceedsDefaultChunkBudget: beamHard.exceedsDefaultChunkBudget,
+ },
+ },
+ evm_bytecode: {
+ format: "evm_bytecode",
+ before: evmRaw,
+ after: evmHard.buffer,
+ meta: {
+ approachesInputBudget: evmHard.approachesInputBudget,
+ afterBytes: evmHard.buffer.length,
+ },
+ },
+ pcap_capture: {
+ format: "pcap_capture",
+ before: pcapRaw,
+ after: pcapHard.buffer,
+ meta: {
+ estimatedTsharkJsonBytes: pcapHard.estimatedTsharkJsonBytes,
+ exceedsTsharkJsonBudget: pcapHard.exceedsTsharkJsonBudget,
+ packetsInjected: pcapHard.packetsInjected,
+ },
+ },
+ gpu_ptx: {
+ format: "gpu_ptx",
+ before: ptxRaw,
+ after: Buffer.from(ptxHard.text, "utf8"),
+ meta: { entriesInjected: ptxHard.entriesInjected },
+ },
+ safetensors: {
+ format: "safetensors",
+ before: stRaw,
+ after: stHard.buffer,
+ meta: {
+ triggeredJsonNestingBreaker: stHard.triggeredJsonNestingBreaker,
+ canaryTokensEmbedded: stHard.canaryTokensEmbedded,
+ },
+ },
+ gguf: {
+ format: "gguf",
+ before: ggufRaw,
+ after: ggufHard.buffer,
+ meta: {
+ error: ggufHard.error,
+ triggeredMetadataNestingBreaker:
+ ggufHard.triggeredMetadataNestingBreaker === true,
+ },
+ },
+ },
+ };
+}
diff --git a/scripts/redteam/run.mjs b/scripts/redteam/run.mjs
new file mode 100755
index 0000000..2e88ef1
--- /dev/null
+++ b/scripts/redteam/run.mjs
@@ -0,0 +1,195 @@
+#!/usr/bin/env node
+/**
+ * Empirical red-team harness: unhardened vs BLA-hardened samples against
+ * real in-process REA parsers. Writes docs/redteam/empirical-rea-validation.{md,json}.
+ */
+import { spawnSync } from "node:child_process";
+import {
+ BLA_ROOT,
+ REA_ROOT,
+ resolveTsharkEnv,
+ reaDistReady,
+} from "./lib/paths.mjs";
+import { buildSampleMatrix } from "./lib/samples.mjs";
+import {
+ loadReaProbes,
+ probeGo,
+ probeFlutterPool,
+ probeBeam,
+ probeEvm,
+ probePcap,
+ probeSafetensors,
+ probeGguf,
+ probePtx,
+ unverifiedAnalyzers,
+} from "./lib/probes.mjs";
+import { writeReports } from "./lib/report.mjs";
+
+function tsharkVersion(env) {
+ if (!env.available) return null;
+ const r = spawnSync(env.bin, ["-v"], { encoding: "utf8", env: env.env });
+ const line = (r.stdout || r.stderr || "").split("\n")[0] || "";
+ return line.trim() || "tshark (version unknown)";
+}
+
+async function main() {
+ if (!reaDistReady()) {
+ console.error(
+ "REA dist not ready. From /workspace/bla-dev/rea under Node 22.23.4+:\n npm install --ignore-scripts && npx tsc -p tsconfig.build.json",
+ );
+ process.exit(2);
+ }
+ const tshark = resolveTsharkEnv();
+ const { bla, intensity, seed, samples } = await buildSampleMatrix();
+ const rea = await loadReaProbes();
+ const limits = bla.REA_INTERNAL_LIMITS;
+
+ const pairs = [];
+
+ // Shared ELF: Go build-info + Flutter isolate pool
+ {
+ const s = samples.go_flutter_elf;
+ const goBefore = await probeGo(rea, s.before, "before");
+ const goAfter = await probeGo(rea, s.after, "after");
+ pairs.push({
+ format: "go_buildinfo",
+ before: goBefore,
+ after: goAfter,
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ const flBefore = await probeFlutterPool(bla, s.before, "before", limits);
+ const flAfter = await probeFlutterPool(bla, s.after, "after", limits);
+ pairs.push({
+ format: "flutter_pool",
+ before: flBefore,
+ after: flAfter,
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.erlang_beam;
+ pairs.push({
+ format: "erlang_beam",
+ before: await probeBeam(rea, s.before, "before"),
+ after: await probeBeam(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.evm_bytecode;
+ pairs.push({
+ format: "evm_bytecode",
+ before: await probeEvm(rea, s.before, "before"),
+ after: await probeEvm(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.pcap_capture;
+ pairs.push({
+ format: "pcap_capture",
+ before: await probePcap(rea, s.before, "before"),
+ after: await probePcap(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.safetensors;
+ pairs.push({
+ format: "safetensors",
+ before: await probeSafetensors(rea, s.before, "before"),
+ after: await probeSafetensors(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.gguf;
+ pairs.push({
+ format: "gguf",
+ before: await probeGguf(rea, s.before, "before"),
+ after: await probeGguf(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.gpu_ptx;
+ pairs.push({
+ format: "gpu_ptx",
+ before: await probePtx(rea, s.before, "before"),
+ after: await probePtx(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ const run = {
+ generatedAt: new Date().toLocaleString("en-CA", {
+ timeZone: "Asia/Shanghai",
+ hour12: false,
+ }),
+ blaRoot: BLA_ROOT,
+ reaRoot: REA_ROOT,
+ intensity,
+ seed,
+ nodeVersion: process.version,
+ tshark: {
+ available: tshark.available,
+ version: tsharkVersion(tshark),
+ },
+ pairs,
+ unverified: unverifiedAnalyzers(),
+ };
+
+ const { mdPath, jsonPath } = writeReports(run);
+
+ // Console summary for CI / gates
+ console.log("Empirical REA red-team complete");
+ console.log(` report: ${mdPath}`);
+ console.log(` json: ${jsonPath}`);
+ for (const pair of pairs) {
+ const tag = pair.after.budgetHit
+ ? `BUDGET ${pair.after.budgetName}`
+ : pair.after.status;
+ console.log(
+ ` ${pair.format.padEnd(16)} before=${pair.before.status.padEnd(12)} after=${tag} (${pair.before.inputBytes} β†’ ${pair.after.inputBytes} B)`,
+ );
+ }
+ const diverges = pairs.filter((p) => {
+ // soft check: after should hit for go/flutter/beam/evm/pcap/gguf
+ const must = new Set([
+ "go_buildinfo",
+ "flutter_pool",
+ "erlang_beam",
+ "evm_bytecode",
+ "pcap_capture",
+ "gguf",
+ ]);
+ if (!must.has(p.format)) return false;
+ if (p.format === "pcap_capture" && p.after.status === "skipped") return false;
+ return !p.after.budgetHit;
+ });
+ if (diverges.length) {
+ console.error(
+ `WARNING: ${diverges.length} format(s) did not trip REA budgets: ${diverges.map((d) => d.format).join(", ")}`,
+ );
+ process.exitCode = 1;
+ }
+}
+
+main().catch((err) => {
+ console.error(err);
+ process.exit(1);
+});
diff --git a/tests/redteam-harness.test.ts b/tests/redteam-harness.test.ts
new file mode 100644
index 0000000..6fd6171
--- /dev/null
+++ b/tests/redteam-harness.test.ts
@@ -0,0 +1,109 @@
+import { describe, expect, it } from "vitest";
+import { createRequire } from "node:module";
+import { join } from "node:path";
+import {
+ buildMappedFlutterIsolatePoolPlant,
+ buildMappedGoFlutterElfFixture,
+} from "../src/shields/formats/go-flutter-exhaustion.js";
+import {
+ protectNativeBinary,
+ resolveElf64SectionNames,
+ validateElf64Layout,
+} from "../src/shields/formats/native.js";
+import { SeededPrng } from "../src/core/prng.js";
+import { REA_INTERNAL_LIMITS } from "../src/identity.js";
+
+const require = createRequire(import.meta.url);
+const samplesPath = join(process.cwd(), "scripts/redteam/lib/samples.mjs");
+const probesPath = join(process.cwd(), "scripts/redteam/lib/probes.mjs");
+
+describe("red-team harness sample generators", () => {
+ it("builds minimal BEAM / EVM / PCAP / GGUF / PTX fixtures with expected magic", async () => {
+ const samples = await import(samplesPath);
+ const beam = samples.buildMinimalBeam();
+ expect(beam.subarray(0, 4).toString("latin1")).toBe("FOR1");
+ expect(beam.subarray(8, 12).toString("latin1")).toBe("BEAM");
+
+ const evm = samples.buildMinimalEvm();
+ expect(evm.length).toBeGreaterThan(8);
+ expect(evm[0]).toBe(0x60);
+
+ const pcap = samples.buildMinimalPcap();
+ expect(pcap.length).toBe(24);
+ expect(pcap.readUInt32LE(0)).toBe(0xa1b2c3d4);
+
+ const gguf = samples.buildMinimalGguf();
+ expect(gguf.subarray(0, 4).toString("ascii")).toBe("GGUF");
+ expect(gguf.readUInt32LE(4)).toBe(3);
+
+ const ptx = samples.buildMinimalPtx().toString("utf8");
+ expect(ptx).toContain(".entry demo");
+ });
+
+ it("projectStringPoolReaFaithful reports wouldCap past REA URI/token limits", async () => {
+ const { projectStringPoolReaFaithful } = await import(probesPath);
+ const parts: string[] = [];
+ for (let i = 0; i < REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS + 10; i++) {
+ parts.push(`package:m${i}/b.dart`);
+ parts.push(`dart:d${i}`);
+ }
+ for (let i = 0; i < REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS + 10; i++) {
+ parts.push(`Node_${i}_X`);
+ }
+ const section = Buffer.from(parts.join("\0") + "\0", "utf8");
+ const pool = projectStringPoolReaFaithful(section, REA_INTERNAL_LIMITS);
+ expect(pool.packageUriCount).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS,
+ );
+ expect(pool.dartUriCount).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS,
+ );
+ expect(pool.classLikeTokenCount).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS,
+ );
+ expect(pool.reportWouldCap).toBe(true);
+ });
+});
+
+describe("mapped Go/Flutter plants vs REA pool caps", () => {
+ it("mapped Flutter isolate plant exceeds per-kind MAX_POOL_URIS and MAX_POOL_TOKENS", () => {
+ const plant = buildMappedFlutterIsolatePoolPlant(
+ 160 * 1024,
+ new SeededPrng("redteam-flutter-cap"),
+ );
+ // packageAndDartUris counts both kinds; each alone must clear 500.
+ expect(plant.packageAndDartUris).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS * 2,
+ );
+ expect(plant.classLikeTokens).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS,
+ );
+ const text = plant.buffer.toString("utf8");
+ expect(text).toContain("package:m0/b.dart");
+ expect(text).toContain("dart:d0");
+ expect(text).toContain("Node_0_X");
+ });
+
+ it("protectNativeBinary on mapped fixture plants pool past REA report caps", async () => {
+ const { projectStringPoolReaFaithful } = await import(probesPath);
+ const fixture = buildMappedGoFlutterElfFixture();
+ const res = protectNativeBinary(fixture, {
+ intensity: "bankrupt",
+ seed: "redteam-mapped-caps",
+ });
+ expect(res.mappedFlutterPoolPlanted).toBe(true);
+ expect(res.goBuildInfoExceedsLimit).toBe(true);
+ const layout = validateElf64Layout(res.buffer);
+ const names = resolveElf64SectionNames(res.buffer, layout);
+ const iso = names.get(".isolate")!;
+ const section = res.buffer.subarray(iso.offset, iso.offset + iso.size);
+ const pool = projectStringPoolReaFaithful(section, REA_INTERNAL_LIMITS);
+ expect(pool.reportWouldCap).toBe(true);
+ expect(pool.packageUriCount).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS,
+ );
+ expect(pool.classLikeTokenCount).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS,
+ );
+ });
+});