@wowok/agent-mcp 3.2.3 → 3.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chain-semantics/field-capability.js +1 -1
- package/dist/chain-semantics/freeze-map.js +1 -1
- package/dist/chain-semantics/fund-flow.js +1 -1
- package/dist/chain-semantics/guard-verbs.js +1 -1
- package/dist/communication/proof-reuse.d.ts +9 -0
- package/dist/communication/proof-reuse.js +1 -0
- package/dist/composition/blueprint-view.d.ts +64 -0
- package/dist/composition/blueprint-view.js +1 -0
- package/dist/evaluation/builtins/graph-service.spec.js +1 -1
- package/dist/evaluation/engine.js +1 -1
- package/dist/experience/realtime-feedback.js +1 -1
- package/dist/extensions/industry-pack.d.ts +1 -0
- package/dist/extensions/industry-pack.js +1 -1
- package/dist/extensions/modes.js +1 -1
- package/dist/extensions/registry.d.ts +1 -2
- package/dist/extensions/registry.js +1 -1
- package/dist/graph/onchain/expand.js +1 -1
- package/dist/graph/onchain/exposure.js +1 -1
- package/dist/graph/onchain/facts.js +1 -1
- package/dist/harness/recover.js +1 -1
- package/dist/knowledge/allocation-ledger.js +1 -1
- package/dist/knowledge/audit-rules.d.ts +2 -0
- package/dist/knowledge/audit-rules.js +1 -1
- package/dist/knowledge/baselines/rules/allocation.json +5 -5
- package/dist/knowledge/baselines/rules/arb.json +1 -1
- package/dist/knowledge/baselines/rules/guard.json +9 -9
- package/dist/knowledge/baselines/rules/machine.json +5 -5
- package/dist/knowledge/baselines/rules/order.json +1 -1
- package/dist/knowledge/builtin-templates.d.ts +2 -1
- package/dist/knowledge/builtin-templates.js +1 -1
- package/dist/knowledge/entity-recipient-guard.js +1 -1
- package/dist/knowledge/getting-started.js +1 -1
- package/dist/knowledge/guard-bindings.js +1 -1
- package/dist/knowledge/guard-design-patterns.d.ts +1 -1
- package/dist/knowledge/guard-design-patterns.js +1 -1
- package/dist/knowledge/guard-ledger.js +1 -1
- package/dist/knowledge/guard-risk.js +1 -1
- package/dist/knowledge/guard-templates.d.ts +1 -1
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-generalizer.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/jsonrpc-enum.js +1 -1
- package/dist/knowledge/machine-ledger.js +1 -1
- package/dist/knowledge/machine-templates.js +1 -1
- package/dist/knowledge/order-ledger.js +1 -1
- package/dist/knowledge/progress-ledger.js +1 -1
- package/dist/knowledge/scenario-modes.d.ts +3 -4
- package/dist/knowledge/scenario-modes.js +1 -1
- package/dist/knowledge/service-ledger.js +1 -1
- package/dist/knowledge/service-templates.js +1 -1
- package/dist/knowledge/template-loader.d.ts +8 -2
- package/dist/knowledge/template-loader.js +1 -1
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/template-scanner.js +1 -1
- package/dist/knowledge/template-validation.d.ts +2 -0
- package/dist/knowledge/template-validation.js +1 -0
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/participation/radar-core.js +1 -1
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/game-theory.d.ts +2 -2
- package/dist/playbooks/service-build/game-theory.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/merchant-guide.d.ts +54 -11
- package/dist/playbooks/service-build/merchant-guide.js +1 -1
- package/dist/playbooks/service-build/mode-actions.js +1 -1
- package/dist/playbooks/service-build/object-panorama.js +1 -1
- package/dist/playbooks/service-build/participation-radar.js +1 -1
- package/dist/playbooks/service-build/relationship-profile.js +1 -1
- package/dist/playbooks/service-build/reverse-mapping-nk4.spec.d.ts +1 -0
- package/dist/playbooks/service-build/reverse-mapping-nk4.spec.js +1 -0
- package/dist/playbooks/service-build/reverse-mapping.d.ts +24 -0
- package/dist/playbooks/service-build/reverse-mapping.js +1 -1
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/playbooks/service-build/service-quote.js +1 -1
- package/dist/playbooks/service-build/service-quote.spec.d.ts +1 -0
- package/dist/playbooks/service-build/service-quote.spec.js +1 -0
- package/dist/playbooks/service-build/workflow-design-assessment.d.ts +2 -2
- package/dist/playbooks/service-build/workflow-design-assessment.js +1 -1
- package/dist/review/index.js +1 -1
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/schema/call/arbitration.js +1 -1
- package/dist/schema/call/base.d.ts +4 -0
- package/dist/schema/call/base.js +1 -1
- package/dist/schema/call/bridge.d.ts +1 -0
- package/dist/schema/call/error-codes.d.ts +1 -1
- package/dist/schema/call/error-codes.js +1 -1
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.js +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +14 -0
- package/dist/schema/call/service.js +1 -1
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/goal/planning.js +1 -1
- package/dist/schema/interaction/index.d.ts +1 -1
- package/dist/schema/local/index.d.ts +10 -0
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/operations.d.ts +7 -0
- package/dist/schema/query/bi.d.ts +26 -0
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/account_operation.output.json +1 -0
- package/dist/schemas/bridge_operation.output.json +1 -0
- package/dist/schemas/goal_operation.schema.json +1 -1
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/local_cache_operation.output.json +1 -0
- package/dist/schemas/local_history_operation.output.json +1 -0
- package/dist/schemas/local_info_operation.output.json +1 -0
- package/dist/schemas/local_mark_operation.output.json +1 -0
- package/dist/schemas/onchain_operations.output.json +1 -0
- package/dist/schemas/onchain_operations.schema.json +40 -5
- package/dist/schemas/onchain_operations_arbitration.schema.json +1 -1
- package/dist/schemas/onchain_operations_machine.schema.json +1 -1
- package/dist/schemas/onchain_operations_service.schema.json +38 -3
- package/dist/schemas/query_toolkit.output.json +91 -7
- package/dist/tools/handlers/benchmark-migration.d.ts +2 -13
- package/dist/tools/handlers/benchmark-migration.js +1 -1
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/industry-pack.js +1 -1
- package/dist/tools/handlers/messenger.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/handlers/query.js +1 -1
- package/dist/tools/move-fn-index.gen.js +1 -1
- package/dist/tools/registry/agent.js +1 -1
- package/dist/tools/wip-deploy-assist.js +1 -1
- package/dist/tools/wrap.js +1 -1
- package/package.json +2 -2
- package/dist/playbooks/service-build/semantic-graph.d.ts +0 -99
- package/dist/playbooks/service-build/semantic-graph.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export const GUARD_SCENES=[{'id':'service_buy_guard','name':'Service\x20purchase\x20validation\x20(buy_guard)','host_object':'Service','binding_field':'buy_guard','validation_scene':'When\x20a\x20customer\x20places\x20an\x20order\x20to\x20purchase\x20a\x20service,\x20the\x20Guard\x20validates\x20whether\x20the\x20customer\x20is\x20eligible\x20to\x20purchase\x20(identity/permission/condition)','pass_result':'Create\x20the\x20Order\x20object;\x20the\x20customer\x20enters\x20the\x20payment\x20flow','fail_result':'Transaction\x20rejected;\x20Order\x20is\x20not\x20created;\x20the\x20customer\x20cannot\x20purchase','submission_source':'Customer\x20(signer\x20address,\x20credentials,\x20Passport,\x20etc.)','special_constraints':['The\x20Guard\x20table\x20must\x20declare\x20all\x20data\x20the\x20customer\x20needs\x20to\x20submit','The\x20name\x20of\x20b_submission=true\x20entries\x20must\x20be\x20a\x20natural-language\x20description\x20(the\x20contract\x20the\x20customer\x20sees)','If\x20the\x20Guard\x20references\x20the\x20Service\x20itself,\x20use\x20the\x20circular\x20reference\x20pattern\x20(CREATE\x20Service\x20→\x20CREATE\x20Guard\x20→\x20MODIFY\x20Service)','buy_guard\x20can\x20still\x20be\x20modified\x20after\x20Service\x20is\x20published\x20(via\x20MODIFY\x20Service)','Reentrancy:\x20LOW\x20—\x20Each\x20purchase\x20creates\x20a\x20fresh\x20Order;\x20no\x20existing\x20Order\x20state\x20is\x20modified.\x20Default:\x20no\x20reentrancy\x20risk.\x20IF\x20business\x20intent\x20is\x20\x27limit\x20one\x20purchase\x20per\x20user\x27\x20(limited-edition\x20goods,\x20whitelist\x20single-buy),\x20an\x20anti-reentrancy\x20check\x20is\x20REQUIRED\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20for\x20per-user\x20purchase\x20history\x20—\x20use\x20a\x20Repository\x20to\x20record\x20prior\x20purchases\x20and\x20add\x20`repository.data\x20has`\x20(query\x201166)\x20+\x20`logic_not`\x20to\x20root,\x20or\x20revoke\x20EntityRegistrar\x20membership\x20after\x20first\x20buy'],'common_patterns':['Identity\x20check:\x20context(Signer)\x20+\x20logic_equal\x20(single\x20address)\x20/\x20vec_contains_address\x20(whitelist)','Membership\x20validation:\x20query\x20EntityRegistrar(0xaab)\x20+\x20logic_and\x20combination','Time\x20limit:\x20context(Clock)\x20+\x20logic_as_u256_greater_or_equal','Multi-condition:\x20logic_and\x20combining\x20multiple\x20checks'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R7','R9']},{'id':'service_order_allocators_guard','name':'Allocation\x20strategy\x20selection\x20validation\x20(order_allocators[].guard)','host_object':'Service','binding_field':'order_allocators','validation_scene':'When\x20an\x20order\x20is\x20completed\x20or\x20allocation\x20conditions\x20are\x20met,\x20the\x20caller\x20submits\x20ONE\x20guard.\x20Every\x20allocator\x20bound\x20to\x20that\x20guard\x20fires,\x20in\x20vector\x20order,\x20each\x20against\x20the\x20balance\x20left\x20by\x20the\x20previous\x20(allocation.move:366-368).','pass_result':'Execute\x20the\x20allocation\x20strategy\x20for\x20every\x20allocator\x20bound\x20to\x20the\x20submitted\x20guard','fail_result':'If\x20the\x20submitted\x20guard\x20does\x20not\x20match\x20any\x20allocator\x27s\x20guard,\x20or\x20if\x20the\x20guard\x27s\x20conditions\x20fail,\x20no\x20funds\x20are\x20distributed','submission_source':'System\x20auto-derives\x20from\x20Progress\x20state\x20(no\x20explicit\x20customer\x20submission\x20needed)','special_constraints':['A\x20distribution\x20call\x20submits\x20ONE\x20guard;\x20every\x20allocator\x20bound\x20to\x20that\x20guard\x20fires\x20in\x20vector\x20order\x20against\x20the\x20shrinking\x20pool\x20(allocation.move:366-368).\x20Allocator\x20list\x20order\x20determines\x20the\x20firing\x20sequence\x20when\x20multiple\x20allocators\x20share\x20the\x20same\x20guard,\x20NOT\x20which\x20path\x20is\x20selected','order_allocators\x20cannot\x20be\x20modified\x20after\x20Service\x20is\x20published\x20(immutable)','Guard\x20usually\x20queries\x20Order/Progress\x20state\x20to\x20determine\x20allocation\x20conditions','Common\x20queries:\x20order.amount,\x20progress.current_node,\x20order.completed,\x20etc.','GuardIdentifier\x20can\x20be\x20used\x20for\x20dynamic\x20amounts\x20(extract\x20u64\x20value\x20from\x20table\x20as\x20allocation\x20ratio)','Guard+sharing\x20coupling:\x20Guard\x20determines\x20IF\x20allocation\x20happens;\x20sharing.who\x20determines\x20WHERE\x20funds\x20go.\x20If\x20sharing.who=Signer,\x20the\x20caller\x20receives\x20funds\x20—\x20the\x20Guard\x20MUST\x20bind\x20Signer\x20(context(Signer)==authorized)\x20to\x20prevent\x20theft.\x20PREFERRED:\x20use\x20sharing.who=Entity\x20(Treasury\x20or\x20fixed\x20address)\x20so\x20funds\x20always\x20go\x20to\x20the\x20legitimate\x20recipient\x20regardless\x20of\x20caller.','allocators\x20require\x20unique\x20guard\x20addresses\x20when\x20they\x20represent\x20alternative\x20paths:\x20bind\x20each\x20path\x20to\x20its\x20OWN\x20Guard\x20object\x20(they\x20may\x20share\x20root/table\x20but\x20must\x20differ\x20in\x20description).\x20Same-guard\x20allocators\x20fire\x20sequentially\x20on\x20the\x20same\x20call,\x20which\x20is\x20only\x20correct\x20for\x20intended\x20waterfalls\x20(fee\x20first,\x20then\x20split\x20remainder)','Every\x20allocator\x20bound\x20to\x20the\x20submitted\x20guard\x20fires\x20in\x20vector\x20order.\x20Alternative\x20business\x20paths\x20(settle\x20vs\x20refund\x20vs\x20damage)\x20must\x20use\x20DIFFERENT\x20guards\x20—\x20the\x20caller\x27s\x20guard\x20choice\x20selects\x20the\x20path,\x20not\x20the\x20allocator\x20list\x20position','If\x20sharing.who=Entity\x20references\x20a\x20Treasury\x20object,\x20verify\x20the\x20Treasury\x27s\x20permission\x20is\x20consistent\x20with\x20the\x20Service\x27s\x20permission\x20(different\x20permissions\x20=\x20different\x20permission\x20organizations\x20=\x20minor\x20risk).','Reentrancy:\x20LOW\x20—\x20Protocol-level\x20protection:\x20the\x20Order\x20layer\x20asserts\x20the\x20`allocation`\x20field\x20is\x20None\x20(E_ALLOCATION_ALREADY_SPECIFIED),\x20enforcing\x20ONE\x20Allocation\x20object\x20per\x20Order,\x20ever.\x20After\x20alloc()\x20executes,\x20typical\x20Rate-mode\x20allocators\x20(sum=10000)\x20and\x20any\x20Surplus-mode\x20allocator\x20drain\x20balance\x20to\x200\x20via\x20balance::withdraw_all,\x20making\x20a\x20second\x20alloc()\x20fail\x20at\x20`assert!(balance\x20>=\x20threshold)`.\x20EDGE\x20CASE:\x20Amount-mode-only\x20allocators\x20(no\x20Surplus,\x20total\x20<\x20full\x20balance)\x20leave\x20remainder;\x20a\x20second\x20alloc()\x20could\x20extract\x20more\x20—\x20mitigated\x20by\x20preferring\x20Rate/Surplus\x20modes.\x20External\x20deposit\x20via\x20receive()\x20is\x20possible\x20but\x20irrational\x20(attacker\x20funds\x20the\x20Allocation\x20they\x20attack).\x20Optional\x20anti-reentrancy\x20primitive:\x20`order.allocation\x20some`\x20(query\x201568)\x20+\x20logic_not'],'common_patterns':['Node\x20state\x20check:\x20query(Progress.current_node)\x20+\x20logic_equal(\x27Completed\x27)','Amount\x20threshold:\x20query(Order.amount)\x20+\x20logic_as_u256_greater_or_equal(threshold)','Multi-condition\x20combination:\x20logic_and\x20(node\x20state\x20+\x20amount\x20+\x20time)','GuardIdentifier\x20dynamic\x20ratio:\x20table[u64]\x20extracts\x20allocation\x20ratio','Treasury+personal\x202-allocator\x20pattern:\x202\x20Guard\x20objects\x20(identical\x20root/table,\x20different\x20descriptions)\x20+\x202\x20allocators\x20(sharing.who=Entity\x20Treasury\x20/\x20Entity\x20personal)\x20—\x202\x20alternative\x20merchant\x20collection\x20approaches\x20bound\x20to\x20DIFFERENT\x20guards;\x20the\x20caller\x27s\x20guard\x20choice\x20selects\x20which\x20allocator\x20fires'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7']},{'id':'machine_forward_guard','name':'Workflow\x20node\x20advancement\x20validation\x20(Forward.guard)','host_object':'Machine','binding_field':'Forward.guard','validation_scene':'When\x20a\x20customer\x20or\x20provider\x20executes\x20a\x20Forward\x20operation\x20to\x20advance\x20the\x20workflow,\x20the\x20Guard\x20validates\x20whether\x20advancement\x20to\x20the\x20next\x20node\x20is\x20allowed','pass_result':'Progress\x20advances\x20to\x20next_node;\x20session\x20accumulates\x20weight','fail_result':'Forward\x20is\x20blocked;\x20Progress\x20stays\x20at\x20the\x20current\x20node.\x20Optional\x20retained_submission\x20retains\x20audit\x20data','submission_source':'The\x20party\x20executing\x20Forward\x20(Customer\x20or\x20Provider,\x20depending\x20on\x20Forward\x20configuration)','special_constraints':['Forward.guard\x20cannot\x20be\x20modified\x20after\x20Machine\x20is\x20published\x20(a\x20new\x20Machine\x20must\x20be\x20created)','Optional\x20retained_submission:\x20stores\x20submission\x20data\x20in\x20Progress\x20for\x20later\x20audit','retained_submission\x20indices\x20must\x20correspond\x20to\x20the\x20Guard\x20table','Common\x20queries:\x20progress.current_node,\x20progress.session_forward,\x20order.service,\x20etc.','Time\x20lock:\x20context(Clock)\x20+\x20calc_number_add(progress.current_time,\x20duration)\x20tested\x20with\x201000ms','Reentrancy:\x20ALLOWED\x20—\x20By\x20design,\x20Forward\x20moves\x20progress.current_node\x20to\x20next_node,\x20naturally\x20invalidating\x20the\x20Guard\x20at\x20the\x20old\x20node.\x20Re-submission\x20at\x20the\x20SAME\x20node\x20(before\x20forward\x20completes)\x20is\x20intentional:\x20users\x20may\x20fix\x20prior\x20submission\x20data\x20or\x20accumulate\x20session\x20weight\x20toward\x20threshold.\x20No\x20anti-reentrancy\x20primitive\x20needed.\x20Optional\x20observability\x20queries:\x20`progress.session_forward`\x20(1262),\x20`progress.history`\x20(1273),\x20`query_progress_history_find`\x20(1274)'],'common_patterns':['Identity\x20check:\x20context(Signer)\x20+\x20logic_equal\x20(only\x20specific\x20parties\x20can\x20advance)','Time\x20lock:\x20context(Clock)\x20+\x20calc_number_add\x20+\x20logic_as_u256_greater_or_equal','Prior\x20Forward\x20completion:\x20query_progress_history_find\x20+\x20logic_equal(accomplished=true)','Submission\x20data\x20validation:\x20identifier(submission)\x20+\x20logic_equal(expected_value)','Cross-object\x20query:\x20convert_witness=TypeOrderProgress(100)\x20queries\x20Progress\x20from\x20Order'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7','R8','R9']},{'id':'progress_submission_guard','name':'Progress\x20submission\x20data\x20validation\x20(submission\x20guard)','host_object':'Progress','binding_field':'submission','validation_scene':'Whether\x20the\x20data\x20(e.g.\x20signature,\x20credential,\x20confirmation)\x20submitted\x20during\x20Forward\x20execution\x20satisfies\x20the\x20Guard\x20condition','pass_result':'Forward\x20completes;\x20node\x20advances\x20after\x20session\x20accumulates\x20weight\x20to\x20threshold','fail_result':'Forward\x20does\x20not\x20complete;\x20waits\x20for\x20resubmission\x20or\x20condition\x20satisfaction','submission_source':'The\x20party\x20submitting\x20data\x20(Customer\x20or\x20Provider)','special_constraints':['Works\x20in\x20concert\x20with\x20Forward.guard:\x20Forward.guard\x20validates\x20eligibility,\x20submission\x20guard\x20validates\x20data','retained_submission\x20stores\x20submission\x20data\x20in\x20Progress\x20session\x20for\x20audit','Common\x20queries:\x20progress.session_forward,\x20progress.session_weight,\x20etc.','Reentrancy:\x20ALLOWED\x20—\x20Multiple\x20submissions\x20accumulate\x20session\x20weight\x20toward\x20threshold\x20by\x20design.\x20Re-submission\x20is\x20the\x20intended\x20mechanism\x20for\x20reaching\x20threshold;\x20no\x20anti-reentrancy\x20primitive\x20needed'],'common_patterns':['Signature\x20validation:\x20identifier(signature_submission)\x20+\x20logic_equal(expected)','Credential\x20validation:\x20query(Repository.data)\x20+\x20logic_equal(submission_proof)','Confirmation\x20validation:\x20identifier(confirm_submission)\x20+\x20logic_equal(true)'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R8']},{'id':'reward_claim','name':'Reward\x20claim\x20validation\x20(Reward.guard)','host_object':'Reward','binding_field':'guard','validation_scene':'When\x20a\x20user\x20claims\x20from\x20a\x20reward\x20pool,\x20the\x20Guard\x20validates\x20eligibility\x20to\x20claim','pass_result':'Reward\x20is\x20distributed\x20to\x20the\x20Claimant\x20and\x20recorded\x20in\x20reward_record','fail_result':'Claim\x20rejected;\x20reward\x20is\x20not\x20distributed','submission_source':'Claimant\x20(address,\x20credentials,\x20Passport)','special_constraints':['Common\x20query_reward_record_count\x20prevents\x20duplicate\x20claims\x20(one-time\x20claim)','Guard\x20usually\x20queries\x20history\x20records\x20+\x20time\x20conditions\x20+\x20identity\x20validation','If\x20the\x20Reward\x20references\x20a\x20Service,\x20use\x20the\x20circular\x20reference\x20pattern','Reentrancy:\x20CRITICAL\x20—\x20Guard\x20pass\x20distributes\x20reward\x20funds\x20to\x20the\x20Claimant\x20AND\x20creates\x20a\x20reward_record,\x20but\x20the\x20Guard\x20conditions\x20(identity,\x20time,\x20node\x20state)\x20do\x20NOT\x20naturally\x20invalidate\x20after\x20a\x20claim.\x20Without\x20an\x20explicit\x20anti-reentrancy\x20primitive,\x20the\x20same\x20Claimant\x20can\x20repeatedly\x20pass\x20the\x20Guard\x20and\x20DRAIN\x20THE\x20ENTIRE\x20POOL.\x20This\x20is\x20the\x20most\x20severe\x20reentrancy\x20scene.\x20REQUIRED\x20anti-reentrancy\x20primitive\x20(any\x20one):\x20`reward.record\x20has`\x20(query\x201613,\x20Bool)\x20+\x20`logic_not`;\x20OR\x20`reward.record\x20count`\x20(query\x201612,\x20U64)\x20+\x20`logic_equal(0)`;\x20OR\x20`reward.record.find_first`\x20(query\x201626,\x20U64)\x20+\x20`logic_not`/`logic_equal(0)`.\x20Reference\x20template:\x20MyShop_Advanced\x20Guard\x207\x20condition\x204\x20—\x20`logic_not(query_reward_record_exists(where.storeFromId=order_id))`'],'common_patterns':['One-time\x20claim:\x20query_reward_record_count(recipient)\x20+\x20logic_equal(0)','Time\x20window:\x20context(Clock)\x20+\x20logic_as_u256_greater_or_equal(start_time)','Identity\x20validation:\x20context(Signer)\x20+\x20vec_contains_address(allowlist)','Multi-condition:\x20logic_and\x20(identity\x20+\x20time\x20+\x20not\x20claimed\x20before)'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R7','R8','R9']},{'id':'repository_write_guard','name':'Repository\x20write\x20validation\x20(write_guard)','host_object':'Repository','binding_field':'write_guard','validation_scene':'When\x20writing\x20to\x20on-chain\x20storage,\x20the\x20Guard\x20validates\x20write\x20eligibility\x20and\x20optionally\x20extracts\x20data','pass_result':'Write\x20succeeds;\x20optional\x20id_from_submission\x20extracts\x20the\x20entity\x20ID,\x20data_from_submission\x20extracts\x20the\x20data\x20value','fail_result':'Write\x20rejected','submission_source':'Writer/Reader','special_constraints':['The\x20table\x20entry\x20referenced\x20by\x20id_from_submission\x20must\x20be\x20of\x20Address\x20type','The\x20table\x20entry\x20referenced\x20by\x20data_from_submission\x20must\x20match\x20the\x20Repository\x27s\x20value_type','Type\x20mismatch\x20leads\x20to\x20write\x20failure\x20or\x20data\x20corruption','Commonly\x20used\x20for\x20oracle\x20data\x20writes,\x20third-party\x20credential\x20attestation,\x20etc.','Reentrancy:\x20LOW\x20—\x20Default\x20writes\x20are\x20idempotent\x20(same\x20ID\x20overwrites,\x20different\x20ID\x20appends);\x20no\x20fund\x20flow.\x20IF\x20business\x20intent\x20is\x20\x27one\x20write\x20per\x20ID\x27\x20(e.g.\x20voting,\x20immutable\x20credential,\x20single-attestation),\x20an\x20anti-reentrancy\x20check\x20is\x20needed.\x20Optional\x20primitive:\x20`repository.data\x20has`\x20(query\x201166,\x20Bool)\x20+\x20`logic_not`','CONTENT\x20BLIND\x20SPOT\x20(testnet\x20test-14\x20HIGH-04):\x20under\x20id_from=None\x20the\x20chain\x20asserts\x20only\x20that\x20the\x20write_guard\x20LIST\x20is\x20non-empty\x20(the\x20Repository\x20policy-creation\x20entry,\x20repository.move\x20L511-536,\x20E_POLICY_WRITE_GUARD_REQUIRED=22)\x20—\x20never\x20what\x20a\x20listed\x20Guard\x20proves.\x20A\x20guard\x20that\x20returns\x20true\x20for\x20every\x20caller\x20(constant-true\x20leaf,\x20self-comparison,\x20unsigned\x20>=\x200)\x20therefore\x20publishes\x20as\x20\x27guarded\x27\x20while\x20being\x20an\x20OPEN\x20write:\x20any\x20address\x20can\x20add\x20or\x20overwrite\x20any\x20row,\x20and\x20rows\x20carry\x20no\x20author\x20field.\x20Rule\x20R-X1-17\x20folds\x20the\x20tree\x20and\x20reports\x20it;\x20generate\x20the\x20guard\x20from\x20pattern.repository_write_authorization\x20(an\x20identity\x20leaf\x20—\x20context(Signer)\x20/\x20allowlist\x20/\x20Permission\x20staff\x20/\x20Order\x20holder\x20—\x20is\x20mandatory).\x20Under\x20id_from=Signer|Clock\x20the\x20list\x20MAY\x20stay\x20non-empty,\x20but\x20every\x20PolicyGuard\x27s\x20id_from_submission\x20must\x20be\x20None\x20(E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN=23)'],'common_patterns':['Authorized\x20writer:\x20context(Signer)\x20+\x20vec_contains_address(authorized_writers)','Data\x20format\x20validation:\x20identifier(data_submission)\x20+\x20logic_string_contains(expected_prefix)','ID\x20extraction:\x20id_from_submission\x20+\x20data_from_submission\x20combination'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7']},{'id':'arbitration_usage_guard','name':'Dispute\x20initiation\x20validation\x20(usage_guard)','host_object':'Arbitration','binding_field':'usage_guard','validation_scene':'When\x20a\x20customer\x20initiates\x20a\x20dispute\x20against\x20an\x20order,\x20the\x20Guard\x20validates\x20whether\x20the\x20customer\x20is\x20eligible\x20to\x20initiate\x20the\x20dispute','pass_result':'Create\x20an\x20Arb\x20case\x20and\x20enter\x20the\x20arbitration\x20flow','fail_result':'Dispute\x20rejected;\x20Arb\x20is\x20not\x20created','submission_source':'Customer\x20(Passport\x20credential)','special_constraints':['When\x20Arbitration\x20bPaused=true,\x20it\x20blocks\x20first\x20(before\x20the\x20Guard\x20check)','The\x20customer\x20must\x20first\x20generate\x20a\x20Passport\x20(gen_passport\x20passes\x20usage_guard)','Common\x20queries:\x20order.completed,\x20order.service,\x20entity.has,\x20etc.','Guard\x20validates\x20customer\x20identity\x20+\x20order\x20status\x20+\x20dispute\x20eligibility','Reentrancy:\x20HIGH\x20—\x20Guard\x20pass\x20creates\x20a\x20new\x20Arb\x20case.\x20Without\x20anti-reentrancy,\x20a\x20customer\x20can\x20create\x20multiple\x20Arb\x20cases\x20for\x20the\x20SAME\x20Order\x20(up\x20to\x20MAX_DISPUTE_COUNT=10),\x20harassing\x20the\x20counterparty\x20and\x20inflating\x20arbitration\x20system\x20load.\x20Not\x20direct\x20fund\x20loss,\x20but\x20severe\x20system\x20abuse.\x20Note:\x20the\x20dispute\x20entry\x20point\x20deduplicates\x20by\x20Arb\x20address\x20but\x20does\x20NOT\x20prevent\x20multiple\x20distinct\x20Arbs\x20for\x20the\x20same\x20Order.\x20REQUIRED\x20anti-reentrancy\x20primitive\x20(any\x20one):\x20`order.dispute\x20has`\x20(query\x201565,\x20Bool,\x20per-Arb\x20check)\x20+\x20`logic_not`;\x20OR\x20`order.dispute\x20count`\x20(query\x201564,\x20U64)\x20+\x20`logic_equal(0)`\x20(strict:\x20block\x20any\x20prior\x20dispute)\x20or\x20`logic_as_u256_less_or_equal(N)`\x20(lenient:\x20allow\x20up\x20to\x20N\x20disputes)'],'common_patterns':['Order\x20status\x20validation:\x20query(Order.status)\x20+\x20logic_equal(\x27completed\x27)','Membership\x20validation:\x20query(EntityRegistrar)\x20+\x20logic_and','Time\x20window:\x20query(Order.time)\x20+\x20calc_number_add\x20+\x20context(Clock)','Passport\x20credential:\x20identifier(passport_submission)\x20+\x20context(Signer)'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R7','R8','R9']},{'id':'arbitration_voting_guard','name':'Arbitration\x20voting\x20weight\x20validation\x20(voting_guard[])','host_object':'Arbitration','binding_field':'voting_guard','validation_scene':'When\x20an\x20arbitrator\x20votes,\x20the\x20Guard\x20validates\x20voting\x20eligibility\x20and\x20extracts\x20the\x20voting\x20weight\x20(u32)\x20from\x20GuardIdentifier','pass_result':'Vote\x20is\x20counted;\x20weight\x20is\x20the\x20value\x20extracted\x20by\x20GuardIdentifier','fail_result':'Vote\x20rejected','submission_source':'Voter\x20(Passport\x20credential\x20with\x20weight\x20data)','special_constraints':['The\x20table\x20entry\x20referenced\x20by\x20GuardIdentifier\x20must\x20be\x20of\x20a\x20numeric\x20type\x20(U8-U256),\x20cast\x20to\x20u32','Non-numeric\x20types\x20cause\x20E_GUARD_IDENTIFIER_NOT_NUMBER\x20error','b_submission\x20must\x20be\x20true\x20(weight\x20is\x20submitted\x20at\x20runtime\x20by\x20the\x20voter)','Multiple\x20voting_guards\x20can\x20be\x20configured,\x20each\x20corresponding\x20to\x20a\x20different\x20voter\x20group','When\x20Arbitration\x20bPaused=true,\x20voting\x20is\x20blocked','Reentrancy:\x20CRITICAL\x20—\x20Guard\x20pass\x20counts\x20the\x20vote\x20with\x20the\x20extracted\x20weight.\x20Without\x20anti-reentrancy,\x20the\x20same\x20voter\x20can\x20vote\x20MULTIPLE\x20times,\x20multiplying\x20their\x20weight\x20and\x20skewing\x20the\x20arbitration\x20result\x20(which\x20directly\x20determines\x20fund\x20ownership\x20via\x20compensation).\x20The\x20voter\x27s\x20eligibility\x20(identity,\x20reputation)\x20does\x20NOT\x20naturally\x20invalidate\x20after\x20voting.\x20REQUIRED\x20anti-reentrancy\x20primitive\x20(any\x20one):\x20`arb.voted\x20has`\x20(query\x201404,\x20Bool,\x20per-voter)\x20+\x20`logic_not`;\x20OR\x20`arb.voted.agree\x20has`\x20(query\x201406,\x20Bool,\x20per-voter-per-proposition)\x20+\x20`logic_not`;\x20OR\x20`arb.voted.agree\x20count`\x20(query\x201405,\x20U64,\x20per-voter)\x20+\x20`logic_equal(0)`.\x20Note:\x20`arb.voted_count`\x20(1403)\x20is\x20total\x20voter\x20count\x20(NOT\x20per-voter)\x20and\x20does\x20NOT\x20serve\x20as\x20an\x20anti-reentrancy\x20primitive\x20for\x20individual\x20voters'],'common_patterns':['Reputation\x20score\x20weight:\x20query(EntityRegistrar.records[reputation])\x20+\x20GuardIdentifier(u64)','Fixed\x20weight:\x20identifier(constant_weight)\x20+\x20GuardIdentifier','Multi-tier\x20voting:\x20different\x20voting_guards\x20correspond\x20to\x20different\x20weight\x20tiers','Eligibility\x20+\x20weight:\x20logic_and\x20(eligibility\x20check\x20+\x20GuardIdentifier\x20extracts\x20weight)'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7','R8','R9']},{'id':'gen_passport_guard','name':'Passport\x20credential\x20generation\x20validation\x20(gen_passport)','host_object':'Standalone','binding_field':'none','validation_scene':'When\x20a\x20user\x20calls\x20gen_passport,\x20the\x20Guard\x20validates\x20user\x20eligibility\x20and\x20generates\x20a\x20Passport\x20with\x20credentials','pass_result':'Passport\x20is\x20generated,\x20containing\x20credentials\x20validated\x20by\x20the\x20Guard','fail_result':'Passport\x20generation\x20fails;\x20the\x20user\x20did\x20not\x20pass\x20validation','submission_source':'Passport\x20applicant\x20(signer\x20+\x20credentials)','special_constraints':['quote_guard\x20is\x20a\x20RIGID\x20verification\x20requirement\x20when\x20querying\x20Repository\x20data\x20(query\x201167)','Two-phase:\x20passport\x20generation\x20scans\x20guard\x20+\x20prepares\x20quote_guard,\x20passport\x20verification\x20re-checks\x20+\x20verifies','If\x20quote_guard==None:\x20Repository\x20data\x20is\x20freely\x20queryable\x20(no\x20access\x20control)','Guard\x20can\x20be\x20created\x20standalone\x20(not\x20bound\x20to\x20a\x20specific\x20Host\x20Object)','Guard\x20can\x20be\x20depended\x20on\x20by\x20other\x20Guards\x20via\x20rely\x20(requires\x20rep=true)','The\x20Passport\x20generated\x20by\x20gen_passport\x20can\x20be\x20used\x20as\x20submission\x20data\x20for\x20subsequent\x20operations','Reentrancy:\x20LOW\x20—\x20Each\x20gen_passport\x20call\x20generates\x20an\x20independent\x20Passport\x20(one\x20Passport\x20per\x20operation).\x20Multiple\x20Passports\x20for\x20the\x20same\x20user\x20are\x20usually\x20valid\x20(each\x20serves\x20a\x20different\x20subsequent\x20operation).\x20IF\x20business\x20intent\x20is\x20\x27one\x20active\x20Passport\x20per\x20user\x27,\x20an\x20anti-reentrancy\x20check\x20is\x20needed\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20—\x20use\x20off-chain\x20tracking\x20or\x20a\x20Repository\x20to\x20record\x20issued\x20Passport\x20IDs'],'common_patterns':['Identity\x20validation:\x20context(Signer)\x20+\x20logic_equal\x20(single\x20address/whitelist)','Membership\x20eligibility:\x20query(EntityRegistrar)\x20+\x20logic_equal','Reputation\x20threshold:\x20query(EntityRegistrar.records[reputation])\x20+\x20logic_as_u256_greater_or_equal','Multi-condition\x20combination:\x20logic_and\x20(identity\x20+\x20eligibility\x20+\x20reputation)'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7']}];export function findScene(a,b){return GUARD_SCENES['find'](c=>c['host_object']===a&&c['binding_field']===b);}export function inferSceneFromAction(a){const b={'buy':'service_buy_guard','forward':'machine_forward_guard','allocate':'service_order_allocators_guard','claim_reward':'reward_claim','vote':'arbitration_voting_guard','dispute':'arbitration_usage_guard','write_repository':'repository_write_guard','submit_progress':'progress_submission_guard','gen_passport':'gen_passport_guard'},c=b[a];return GUARD_SCENES['find'](d=>d['id']===c);}export function getImmutableScenes(){return GUARD_SCENES['filter'](a=>!a['mutable_after_publish']);}export function getNumericIdentifierScenes(){return GUARD_SCENES['filter'](a=>a['special_constraints']['some'](b=>b['includes']('numeric')||b['includes']('GuardIdentifier')));}
|
|
1
|
+
export const GUARD_SCENES=[{'id':'service_buy_guard','name':'Service\x20purchase\x20validation\x20(buy_guard)','host_object':'Service','binding_field':'buy_guard','validation_scene':'When\x20a\x20customer\x20places\x20an\x20order\x20to\x20purchase\x20a\x20service,\x20the\x20Guard\x20validates\x20whether\x20the\x20customer\x20is\x20eligible\x20to\x20purchase\x20(identity/permission/condition)','pass_result':'Create\x20the\x20Order\x20object;\x20the\x20customer\x20enters\x20the\x20payment\x20flow','fail_result':'Transaction\x20rejected;\x20Order\x20is\x20not\x20created;\x20the\x20customer\x20cannot\x20purchase','submission_source':'Customer\x20(signer\x20address,\x20credentials,\x20Passport,\x20etc.)','special_constraints':['The\x20Guard\x20table\x20must\x20declare\x20all\x20data\x20the\x20customer\x20needs\x20to\x20submit','The\x20name\x20of\x20b_submission=true\x20entries\x20must\x20be\x20a\x20natural-language\x20description\x20(the\x20contract\x20the\x20customer\x20sees)','If\x20the\x20Guard\x20references\x20the\x20Service\x20itself,\x20use\x20the\x20circular\x20reference\x20pattern\x20(CREATE\x20Service\x20→\x20CREATE\x20Guard\x20→\x20MODIFY\x20Service)','buy_guard\x20can\x20still\x20be\x20modified\x20after\x20Service\x20is\x20published\x20(via\x20MODIFY\x20Service)','Reentrancy:\x20LOW\x20—\x20Each\x20purchase\x20creates\x20a\x20fresh\x20Order;\x20no\x20existing\x20Order\x20state\x20is\x20modified.\x20Default:\x20no\x20reentrancy\x20risk.\x20IF\x20business\x20intent\x20is\x20\x27limit\x20one\x20purchase\x20per\x20user\x27\x20(limited-edition\x20goods,\x20whitelist\x20single-buy),\x20an\x20anti-reentrancy\x20check\x20is\x20REQUIRED\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20for\x20per-user\x20purchase\x20history\x20—\x20use\x20a\x20Repository\x20to\x20record\x20prior\x20purchases\x20and\x20add\x20`repository.data\x20has`\x20(query\x201166)\x20+\x20`logic_not`\x20to\x20root,\x20or\x20revoke\x20EntityRegistrar\x20membership\x20after\x20first\x20buy'],'common_patterns':['Identity\x20check:\x20context(Signer)\x20+\x20logic_equal\x20(single\x20address)\x20/\x20vec_contains_address\x20(whitelist)','Membership\x20validation:\x20query\x20EntityRegistrar(0xaab)\x20+\x20logic_and\x20combination','Time\x20limit:\x20context(Clock)\x20+\x20logic_as_u256_greater_or_equal(open_time)\x20for\x20an\x20OPENING\x20window\x20(valid\x20from\x20open\x20onwards);\x20for\x20a\x20DEADLINE\x20window\x20use\x20logic_as_u256_lesser_or_equal(calc_number_add(anchor,\x20duration))\x20—\x20Clock\x20<=\x20anchor+N.\x20NEVER\x20greater_or_equal(end_time):\x20inverts\x20the\x20window\x20(rejects\x20everything\x20inside\x20it,\x20admits\x20everything\x20after\x20it).\x20See\x20pattern.deadline_window','Multi-condition:\x20logic_and\x20combining\x20multiple\x20checks'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R7','R9']},{'id':'service_order_allocators_guard','name':'Allocation\x20strategy\x20selection\x20validation\x20(order_allocators[].guard)','host_object':'Service','binding_field':'order_allocators','validation_scene':'When\x20an\x20order\x20is\x20completed\x20or\x20allocation\x20conditions\x20are\x20met,\x20the\x20caller\x20submits\x20ONE\x20guard.\x20Every\x20allocator\x20bound\x20to\x20that\x20guard\x20fires,\x20in\x20vector\x20order,\x20each\x20against\x20the\x20balance\x20left\x20by\x20the\x20previous\x20(allocation.move:366-368).','pass_result':'Execute\x20the\x20allocation\x20strategy\x20for\x20every\x20allocator\x20bound\x20to\x20the\x20submitted\x20guard','fail_result':'If\x20the\x20submitted\x20guard\x20does\x20not\x20match\x20any\x20allocator\x27s\x20guard,\x20or\x20if\x20the\x20guard\x27s\x20conditions\x20fail,\x20no\x20funds\x20are\x20distributed','submission_source':'System\x20auto-derives\x20from\x20Progress\x20state\x20(no\x20explicit\x20customer\x20submission\x20needed)','special_constraints':['A\x20distribution\x20call\x20submits\x20ONE\x20guard;\x20every\x20allocator\x20bound\x20to\x20that\x20guard\x20fires\x20in\x20vector\x20order\x20against\x20the\x20shrinking\x20pool\x20(allocation.move:366-368).\x20Allocator\x20list\x20order\x20determines\x20the\x20firing\x20sequence\x20when\x20multiple\x20allocators\x20share\x20the\x20same\x20guard,\x20NOT\x20which\x20path\x20is\x20selected','order_allocators\x20cannot\x20be\x20modified\x20after\x20Service\x20is\x20published\x20(immutable)','Guard\x20usually\x20queries\x20Order/Progress\x20state\x20to\x20determine\x20allocation\x20conditions','Common\x20queries:\x20order.amount,\x20progress.current_node,\x20order.completed,\x20etc.','GuardIdentifier\x20can\x20be\x20used\x20for\x20dynamic\x20amounts\x20(extract\x20u64\x20value\x20from\x20table\x20as\x20allocation\x20ratio)','Guard+sharing\x20coupling:\x20Guard\x20determines\x20IF\x20allocation\x20happens;\x20sharing.who\x20determines\x20WHERE\x20funds\x20go.\x20If\x20sharing.who=Signer,\x20the\x20caller\x20receives\x20funds\x20—\x20the\x20Guard\x20MUST\x20bind\x20Signer\x20(context(Signer)==authorized)\x20to\x20prevent\x20theft.\x20PREFERRED:\x20use\x20sharing.who=Entity\x20(Treasury\x20or\x20fixed\x20address)\x20so\x20funds\x20always\x20go\x20to\x20the\x20legitimate\x20recipient\x20regardless\x20of\x20caller.','allocators\x20require\x20unique\x20guard\x20addresses\x20when\x20they\x20represent\x20alternative\x20paths:\x20bind\x20each\x20path\x20to\x20its\x20OWN\x20Guard\x20object\x20(they\x20may\x20share\x20root/table\x20but\x20must\x20differ\x20in\x20description).\x20Same-guard\x20allocators\x20fire\x20sequentially\x20on\x20the\x20same\x20call,\x20which\x20is\x20only\x20correct\x20for\x20intended\x20waterfalls\x20(fee\x20first,\x20then\x20split\x20remainder)','Every\x20allocator\x20bound\x20to\x20the\x20submitted\x20guard\x20fires\x20in\x20vector\x20order.\x20Alternative\x20business\x20paths\x20(settle\x20vs\x20refund\x20vs\x20damage)\x20must\x20use\x20DIFFERENT\x20guards\x20—\x20the\x20caller\x27s\x20guard\x20choice\x20selects\x20the\x20path,\x20not\x20the\x20allocator\x20list\x20position','If\x20sharing.who=Entity\x20references\x20a\x20Treasury\x20object,\x20verify\x20the\x20Treasury\x27s\x20permission\x20is\x20consistent\x20with\x20the\x20Service\x27s\x20permission\x20(different\x20permissions\x20=\x20different\x20permission\x20organizations\x20=\x20minor\x20risk).','Reentrancy:\x20LOW\x20—\x20Protocol-level\x20protection:\x20the\x20Order\x20layer\x20asserts\x20the\x20`allocation`\x20field\x20is\x20None\x20(E_ALLOCATION_ALREADY_SPECIFIED),\x20enforcing\x20ONE\x20Allocation\x20object\x20per\x20Order,\x20ever.\x20After\x20alloc()\x20executes,\x20typical\x20Rate-mode\x20allocators\x20(sum=10000)\x20and\x20any\x20Surplus-mode\x20allocator\x20drain\x20balance\x20to\x200\x20via\x20balance::withdraw_all,\x20making\x20a\x20second\x20alloc()\x20fail\x20at\x20`assert!(balance\x20>=\x20threshold)`.\x20EDGE\x20CASE:\x20Amount-mode-only\x20allocators\x20(no\x20Surplus,\x20total\x20<\x20full\x20balance)\x20leave\x20remainder;\x20a\x20second\x20alloc()\x20could\x20extract\x20more\x20—\x20mitigated\x20by\x20preferring\x20Rate/Surplus\x20modes.\x20External\x20deposit\x20via\x20receive()\x20is\x20possible\x20but\x20irrational\x20(attacker\x20funds\x20the\x20Allocation\x20they\x20attack).\x20Optional\x20anti-reentrancy\x20primitive:\x20`order.allocation\x20some`\x20(query\x201568)\x20+\x20logic_not'],'common_patterns':['Node\x20state\x20check:\x20query(Progress.current_node)\x20+\x20logic_equal(\x27Completed\x27)','Amount\x20threshold:\x20query(Order.amount)\x20+\x20logic_as_u256_greater_or_equal(threshold)','Multi-condition\x20combination:\x20logic_and\x20(node\x20state\x20+\x20amount\x20+\x20time)','GuardIdentifier\x20dynamic\x20ratio:\x20table[u64]\x20extracts\x20allocation\x20ratio','Treasury+personal\x202-allocator\x20pattern:\x202\x20Guard\x20objects\x20(identical\x20root/table,\x20different\x20descriptions)\x20+\x202\x20allocators\x20(sharing.who=Entity\x20Treasury\x20/\x20Entity\x20personal)\x20—\x202\x20alternative\x20merchant\x20collection\x20approaches\x20bound\x20to\x20DIFFERENT\x20guards;\x20the\x20caller\x27s\x20guard\x20choice\x20selects\x20which\x20allocator\x20fires'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7']},{'id':'machine_forward_guard','name':'Workflow\x20node\x20advancement\x20validation\x20(Forward.guard)','host_object':'Machine','binding_field':'Forward.guard','validation_scene':'When\x20a\x20customer\x20or\x20provider\x20executes\x20a\x20Forward\x20operation\x20to\x20advance\x20the\x20workflow,\x20the\x20Guard\x20validates\x20whether\x20advancement\x20to\x20the\x20next\x20node\x20is\x20allowed','pass_result':'Progress\x20advances\x20to\x20next_node;\x20session\x20accumulates\x20weight','fail_result':'Forward\x20is\x20blocked;\x20Progress\x20stays\x20at\x20the\x20current\x20node.\x20Optional\x20retained_submission\x20retains\x20audit\x20data','submission_source':'The\x20party\x20executing\x20Forward\x20(Customer\x20or\x20Provider,\x20depending\x20on\x20Forward\x20configuration)','special_constraints':['Forward.guard\x20cannot\x20be\x20modified\x20after\x20Machine\x20is\x20published\x20(a\x20new\x20Machine\x20must\x20be\x20created)','Optional\x20retained_submission:\x20stores\x20submission\x20data\x20in\x20Progress\x20for\x20later\x20audit','retained_submission\x20indices\x20must\x20correspond\x20to\x20the\x20Guard\x20table','Common\x20queries:\x20progress.current_node,\x20progress.session_forward,\x20order.service,\x20etc.','Time\x20lock:\x20context(Clock)\x20+\x20calc_number_add(progress.current_time,\x20duration)\x20tested\x20with\x201000ms','Reentrancy:\x20ALLOWED\x20—\x20By\x20design,\x20Forward\x20moves\x20progress.current_node\x20to\x20next_node,\x20naturally\x20invalidating\x20the\x20Guard\x20at\x20the\x20old\x20node.\x20Re-submission\x20at\x20the\x20SAME\x20node\x20(before\x20forward\x20completes)\x20is\x20intentional:\x20users\x20may\x20fix\x20prior\x20submission\x20data\x20or\x20accumulate\x20session\x20weight\x20toward\x20threshold.\x20No\x20anti-reentrancy\x20primitive\x20needed.\x20Optional\x20observability\x20queries:\x20`progress.session_forward`\x20(1262),\x20`progress.history`\x20(1273),\x20`query_progress_history_find`\x20(1274)'],'common_patterns':['Identity\x20check:\x20context(Signer)\x20+\x20logic_equal\x20(only\x20specific\x20parties\x20can\x20advance)','Time\x20lock:\x20context(Clock)\x20+\x20calc_number_add\x20+\x20logic_as_u256_greater_or_equal','Prior\x20Forward\x20completion:\x20query_progress_history_find\x20+\x20logic_equal(accomplished=true)','Submission\x20data\x20validation:\x20identifier(submission)\x20+\x20logic_equal(expected_value)','Cross-object\x20query:\x20convert_witness=TypeOrderProgress(100)\x20queries\x20Progress\x20from\x20Order'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7','R8','R9']},{'id':'progress_submission_guard','name':'Progress\x20submission\x20data\x20validation\x20(submission\x20guard)','host_object':'Progress','binding_field':'submission','validation_scene':'Whether\x20the\x20data\x20(e.g.\x20signature,\x20credential,\x20confirmation)\x20submitted\x20during\x20Forward\x20execution\x20satisfies\x20the\x20Guard\x20condition','pass_result':'Forward\x20completes;\x20node\x20advances\x20after\x20session\x20accumulates\x20weight\x20to\x20threshold','fail_result':'Forward\x20does\x20not\x20complete;\x20waits\x20for\x20resubmission\x20or\x20condition\x20satisfaction','submission_source':'The\x20party\x20submitting\x20data\x20(Customer\x20or\x20Provider)','special_constraints':['Works\x20in\x20concert\x20with\x20Forward.guard:\x20Forward.guard\x20validates\x20eligibility,\x20submission\x20guard\x20validates\x20data','retained_submission\x20stores\x20submission\x20data\x20in\x20Progress\x20session\x20for\x20audit','Common\x20queries:\x20progress.session_forward,\x20progress.session_weight,\x20etc.','Reentrancy:\x20ALLOWED\x20—\x20Multiple\x20submissions\x20accumulate\x20session\x20weight\x20toward\x20threshold\x20by\x20design.\x20Re-submission\x20is\x20the\x20intended\x20mechanism\x20for\x20reaching\x20threshold;\x20no\x20anti-reentrancy\x20primitive\x20needed'],'common_patterns':['Signature\x20validation:\x20identifier(signature_submission)\x20+\x20logic_equal(expected)','Credential\x20validation:\x20query(Repository.data)\x20+\x20logic_equal(submission_proof)','Confirmation\x20validation:\x20identifier(confirm_submission)\x20+\x20logic_equal(true)'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R8']},{'id':'reward_claim','name':'Reward\x20claim\x20validation\x20(Reward.guard)','host_object':'Reward','binding_field':'guard','validation_scene':'When\x20a\x20user\x20claims\x20from\x20a\x20reward\x20pool,\x20the\x20Guard\x20validates\x20eligibility\x20to\x20claim','pass_result':'Reward\x20is\x20distributed\x20to\x20the\x20Claimant\x20and\x20recorded\x20in\x20reward_record','fail_result':'Claim\x20rejected;\x20reward\x20is\x20not\x20distributed','submission_source':'Claimant\x20(address,\x20credentials,\x20Passport)','special_constraints':['Common\x20query_reward_record_count\x20prevents\x20duplicate\x20claims\x20(one-time\x20claim)','Guard\x20usually\x20queries\x20history\x20records\x20+\x20time\x20conditions\x20+\x20identity\x20validation','If\x20the\x20Reward\x20references\x20a\x20Service,\x20use\x20the\x20circular\x20reference\x20pattern','Reentrancy:\x20CRITICAL\x20—\x20Guard\x20pass\x20distributes\x20reward\x20funds\x20to\x20the\x20Claimant\x20AND\x20creates\x20a\x20reward_record,\x20but\x20the\x20Guard\x20conditions\x20(identity,\x20time,\x20node\x20state)\x20do\x20NOT\x20naturally\x20invalidate\x20after\x20a\x20claim.\x20Without\x20an\x20explicit\x20anti-reentrancy\x20primitive,\x20the\x20same\x20Claimant\x20can\x20repeatedly\x20pass\x20the\x20Guard\x20and\x20DRAIN\x20THE\x20ENTIRE\x20POOL.\x20This\x20is\x20the\x20most\x20severe\x20reentrancy\x20scene.\x20REQUIRED\x20anti-reentrancy\x20primitive\x20(any\x20one):\x20`reward.record\x20has`\x20(query\x201613,\x20Bool)\x20+\x20`logic_not`;\x20OR\x20`reward.record\x20count`\x20(query\x201612,\x20U64)\x20+\x20`logic_equal(0)`;\x20OR\x20`reward.record.find_first`\x20(query\x201626,\x20U64)\x20+\x20`logic_not`/`logic_equal(0)`.\x20Reference\x20template:\x20MyShop_Advanced\x20Guard\x207\x20condition\x204\x20—\x20`logic_not(query_reward_record_exists(where.storeFromId=order_id))`'],'common_patterns':['One-time\x20claim:\x20query_reward_record_count(recipient)\x20+\x20logic_equal(0)','Time\x20window:\x20context(Clock)\x20+\x20logic_as_u256_greater_or_equal(start_time)\x20opens\x20claiming\x20from\x20start\x20onwards;\x20a\x20claim\x20DEADLINE\x20needs\x20the\x20opposite\x20direction\x20—\x20logic_as_u256_lesser_or_equal(calc_number_add(start_time,\x20duration))\x20i.e.\x20Clock\x20<=\x20start+N.\x20NEVER\x20greater_or_equal(end_time)\x20(inverts:\x20whole\x20window\x20rejected,\x20everything\x20after\x20admitted).\x20See\x20pattern.deadline_window','Identity\x20validation:\x20context(Signer)\x20+\x20vec_contains_address(allowlist)','Multi-condition:\x20logic_and\x20(identity\x20+\x20time\x20+\x20not\x20claimed\x20before)'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R7','R8','R9']},{'id':'repository_write_guard','name':'Repository\x20write\x20validation\x20(write_guard)','host_object':'Repository','binding_field':'write_guard','validation_scene':'When\x20writing\x20to\x20on-chain\x20storage,\x20the\x20Guard\x20validates\x20write\x20eligibility\x20and\x20optionally\x20extracts\x20data','pass_result':'Write\x20succeeds;\x20optional\x20id_from_submission\x20extracts\x20the\x20entity\x20ID,\x20data_from_submission\x20extracts\x20the\x20data\x20value','fail_result':'Write\x20rejected','submission_source':'Writer/Reader','special_constraints':['The\x20table\x20entry\x20referenced\x20by\x20id_from_submission\x20must\x20be\x20of\x20Address\x20type','The\x20table\x20entry\x20referenced\x20by\x20data_from_submission\x20must\x20match\x20the\x20Repository\x27s\x20value_type','Type\x20mismatch\x20leads\x20to\x20write\x20failure\x20or\x20data\x20corruption','Commonly\x20used\x20for\x20oracle\x20data\x20writes,\x20third-party\x20credential\x20attestation,\x20etc.','Reentrancy:\x20LOW\x20—\x20Default\x20writes\x20are\x20idempotent\x20(same\x20ID\x20overwrites,\x20different\x20ID\x20appends);\x20no\x20fund\x20flow.\x20IF\x20business\x20intent\x20is\x20\x27one\x20write\x20per\x20ID\x27\x20(e.g.\x20voting,\x20immutable\x20credential,\x20single-attestation),\x20an\x20anti-reentrancy\x20check\x20is\x20needed.\x20Optional\x20primitive:\x20`repository.data\x20has`\x20(query\x201166,\x20Bool)\x20+\x20`logic_not`','CONTENT\x20BLIND\x20SPOT\x20(testnet\x20test-14\x20HIGH-04):\x20under\x20id_from=None\x20the\x20chain\x20asserts\x20only\x20that\x20the\x20write_guard\x20LIST\x20is\x20non-empty\x20(the\x20Repository\x20policy-creation\x20entry,\x20repository.move\x20L511-536,\x20E_POLICY_WRITE_GUARD_REQUIRED=22)\x20—\x20never\x20what\x20a\x20listed\x20Guard\x20proves.\x20A\x20guard\x20that\x20returns\x20true\x20for\x20every\x20caller\x20(constant-true\x20leaf,\x20self-comparison,\x20unsigned\x20>=\x200)\x20therefore\x20publishes\x20as\x20\x27guarded\x27\x20while\x20being\x20an\x20OPEN\x20write:\x20any\x20address\x20can\x20add\x20or\x20overwrite\x20any\x20row,\x20and\x20rows\x20carry\x20no\x20author\x20field.\x20Rule\x20R-X1-17\x20folds\x20the\x20tree\x20and\x20reports\x20it;\x20generate\x20the\x20guard\x20from\x20pattern.repository_write_authorization\x20(an\x20identity\x20leaf\x20—\x20context(Signer)\x20/\x20allowlist\x20/\x20Permission\x20staff\x20/\x20Order\x20holder\x20—\x20is\x20mandatory).\x20Under\x20id_from=Signer|Clock\x20the\x20list\x20MAY\x20stay\x20non-empty,\x20but\x20every\x20PolicyGuard\x27s\x20id_from_submission\x20must\x20be\x20None\x20(E_POLICY_ID_FROM_SUBMISSION_FORBIDDEN=23)'],'common_patterns':['Authorized\x20writer:\x20context(Signer)\x20+\x20vec_contains_address(authorized_writers)','Data\x20format\x20validation:\x20identifier(data_submission)\x20+\x20logic_string_contains(expected_prefix)','ID\x20extraction:\x20id_from_submission\x20+\x20data_from_submission\x20combination'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7']},{'id':'arbitration_usage_guard','name':'Dispute\x20initiation\x20validation\x20(usage_guard)','host_object':'Arbitration','binding_field':'usage_guard','validation_scene':'When\x20a\x20customer\x20initiates\x20a\x20dispute\x20against\x20an\x20order,\x20the\x20Guard\x20validates\x20whether\x20the\x20customer\x20is\x20eligible\x20to\x20initiate\x20the\x20dispute','pass_result':'Create\x20an\x20Arb\x20case\x20and\x20enter\x20the\x20arbitration\x20flow','fail_result':'Dispute\x20rejected;\x20Arb\x20is\x20not\x20created','submission_source':'Customer\x20(Passport\x20credential)','special_constraints':['When\x20Arbitration\x20bPaused=true,\x20it\x20blocks\x20first\x20(before\x20the\x20Guard\x20check)','The\x20customer\x20must\x20first\x20generate\x20a\x20Passport\x20(gen_passport\x20passes\x20usage_guard)','Common\x20queries:\x20order.completed,\x20order.service,\x20entity.has,\x20etc.','Guard\x20validates\x20customer\x20identity\x20+\x20order\x20status\x20+\x20dispute\x20eligibility','Reentrancy:\x20HIGH\x20—\x20Guard\x20pass\x20creates\x20a\x20new\x20Arb\x20case.\x20Without\x20anti-reentrancy,\x20a\x20customer\x20can\x20create\x20multiple\x20Arb\x20cases\x20for\x20the\x20SAME\x20Order\x20(up\x20to\x20MAX_DISPUTE_COUNT=10),\x20harassing\x20the\x20counterparty\x20and\x20inflating\x20arbitration\x20system\x20load.\x20Not\x20direct\x20fund\x20loss,\x20but\x20severe\x20system\x20abuse.\x20Note:\x20the\x20dispute\x20entry\x20point\x20deduplicates\x20by\x20Arb\x20address\x20but\x20does\x20NOT\x20prevent\x20multiple\x20distinct\x20Arbs\x20for\x20the\x20same\x20Order.\x20REQUIRED\x20anti-reentrancy\x20primitive\x20(any\x20one):\x20`order.dispute\x20has`\x20(query\x201565,\x20Bool,\x20per-Arb\x20check)\x20+\x20`logic_not`;\x20OR\x20`order.dispute\x20count`\x20(query\x201564,\x20U64)\x20+\x20`logic_equal(0)`\x20(strict:\x20block\x20any\x20prior\x20dispute)\x20or\x20`logic_as_u256_lesser_or_equal(N)`\x20(lenient:\x20allow\x20up\x20to\x20N\x20disputes)'],'common_patterns':['Order\x20status\x20validation:\x20query(Order.status)\x20+\x20logic_equal(\x27completed\x27)','Membership\x20validation:\x20query(EntityRegistrar)\x20+\x20logic_and','Dispute\x20deadline\x20window:\x20context(Clock)\x20+\x20logic_as_u256_lesser_or_equal(calc_number_add(query(Order.time),\x20N))\x20—\x20Clock\x20<=\x20order_time+N\x20closes\x20disputes\x20after\x20N;\x20a\x20bare\x20query(Order.time)\x20+\x20calc_number_add\x20+\x20context(Clock)\x20chain\x20has\x20NO\x20comparison\x20direction\x20and\x20guards\x20nothing.\x20See\x20pattern.deadline_window','Passport\x20credential:\x20identifier(passport_submission)\x20+\x20context(Signer)'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R7','R8','R9']},{'id':'arbitration_voting_guard','name':'Arbitration\x20voting\x20weight\x20validation\x20(voting_guard[])','host_object':'Arbitration','binding_field':'voting_guard','validation_scene':'When\x20an\x20arbitrator\x20votes,\x20the\x20Guard\x20validates\x20voting\x20eligibility\x20and\x20extracts\x20the\x20voting\x20weight\x20(u32)\x20from\x20GuardIdentifier','pass_result':'Vote\x20is\x20counted;\x20weight\x20is\x20the\x20value\x20extracted\x20by\x20GuardIdentifier','fail_result':'Vote\x20rejected','submission_source':'Voter\x20(Passport\x20credential\x20with\x20weight\x20data)','special_constraints':['The\x20table\x20entry\x20referenced\x20by\x20GuardIdentifier\x20must\x20be\x20of\x20a\x20numeric\x20type\x20(U8-U256),\x20cast\x20to\x20u32','Non-numeric\x20types\x20cause\x20E_GUARD_IDENTIFIER_NOT_NUMBER\x20error','b_submission\x20must\x20be\x20true\x20(weight\x20is\x20submitted\x20at\x20runtime\x20by\x20the\x20voter)','Multiple\x20voting_guards\x20can\x20be\x20configured,\x20each\x20corresponding\x20to\x20a\x20different\x20voter\x20group','When\x20Arbitration\x20bPaused=true,\x20voting\x20is\x20blocked','Reentrancy:\x20CRITICAL\x20—\x20Guard\x20pass\x20counts\x20the\x20vote\x20with\x20the\x20extracted\x20weight.\x20Without\x20anti-reentrancy,\x20the\x20same\x20voter\x20can\x20vote\x20MULTIPLE\x20times,\x20multiplying\x20their\x20weight\x20and\x20skewing\x20the\x20arbitration\x20result\x20(which\x20directly\x20determines\x20fund\x20ownership\x20via\x20compensation).\x20The\x20voter\x27s\x20eligibility\x20(identity,\x20reputation)\x20does\x20NOT\x20naturally\x20invalidate\x20after\x20voting.\x20REQUIRED\x20anti-reentrancy\x20primitive\x20(any\x20one):\x20`arb.voted\x20has`\x20(query\x201404,\x20Bool,\x20per-voter)\x20+\x20`logic_not`;\x20OR\x20`arb.voted.agree\x20has`\x20(query\x201406,\x20Bool,\x20per-voter-per-proposition)\x20+\x20`logic_not`;\x20OR\x20`arb.voted.agree\x20count`\x20(query\x201405,\x20U64,\x20per-voter)\x20+\x20`logic_equal(0)`.\x20Note:\x20`arb.voted_count`\x20(1403)\x20is\x20total\x20voter\x20count\x20(NOT\x20per-voter)\x20and\x20does\x20NOT\x20serve\x20as\x20an\x20anti-reentrancy\x20primitive\x20for\x20individual\x20voters'],'common_patterns':['Reputation\x20score\x20weight:\x20query(EntityRegistrar.records[reputation])\x20+\x20GuardIdentifier(u64)','Fixed\x20weight:\x20identifier(constant_weight)\x20+\x20GuardIdentifier','Multi-tier\x20voting:\x20different\x20voting_guards\x20correspond\x20to\x20different\x20weight\x20tiers','Eligibility\x20+\x20weight:\x20logic_and\x20(eligibility\x20check\x20+\x20GuardIdentifier\x20extracts\x20weight)'],'mutable_after_publish':!![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7','R8','R9']},{'id':'gen_passport_guard','name':'Passport\x20credential\x20generation\x20validation\x20(gen_passport)','host_object':'Standalone','binding_field':'none','validation_scene':'When\x20a\x20user\x20calls\x20gen_passport,\x20the\x20Guard\x20validates\x20user\x20eligibility\x20and\x20generates\x20a\x20Passport\x20with\x20credentials','pass_result':'Passport\x20is\x20generated,\x20containing\x20credentials\x20validated\x20by\x20the\x20Guard','fail_result':'Passport\x20generation\x20fails;\x20the\x20user\x20did\x20not\x20pass\x20validation','submission_source':'Passport\x20applicant\x20(signer\x20+\x20credentials)','special_constraints':['quote_guard\x20is\x20a\x20RIGID\x20verification\x20requirement\x20when\x20querying\x20Repository\x20data\x20(query\x201167)','Two-phase:\x20passport\x20generation\x20scans\x20guard\x20+\x20prepares\x20quote_guard,\x20passport\x20verification\x20re-checks\x20+\x20verifies','If\x20quote_guard==None:\x20Repository\x20data\x20is\x20freely\x20queryable\x20(no\x20access\x20control)','Guard\x20can\x20be\x20created\x20standalone\x20(not\x20bound\x20to\x20a\x20specific\x20Host\x20Object)','Guard\x20can\x20be\x20depended\x20on\x20by\x20other\x20Guards\x20via\x20rely\x20(requires\x20rep=true)','The\x20Passport\x20generated\x20by\x20gen_passport\x20can\x20be\x20used\x20as\x20submission\x20data\x20for\x20subsequent\x20operations','Reentrancy:\x20LOW\x20—\x20Each\x20gen_passport\x20call\x20generates\x20an\x20independent\x20Passport\x20(one\x20Passport\x20per\x20operation).\x20Multiple\x20Passports\x20for\x20the\x20same\x20user\x20are\x20usually\x20valid\x20(each\x20serves\x20a\x20different\x20subsequent\x20operation).\x20IF\x20business\x20intent\x20is\x20\x27one\x20active\x20Passport\x20per\x20user\x27,\x20an\x20anti-reentrancy\x20check\x20is\x20needed\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20—\x20use\x20off-chain\x20tracking\x20or\x20a\x20Repository\x20to\x20record\x20issued\x20Passport\x20IDs'],'common_patterns':['Identity\x20validation:\x20context(Signer)\x20+\x20logic_equal\x20(single\x20address/whitelist)','Membership\x20eligibility:\x20query(EntityRegistrar)\x20+\x20logic_equal','Reputation\x20threshold:\x20query(EntityRegistrar.records[reputation])\x20+\x20logic_as_u256_greater_or_equal','Multi-condition\x20combination:\x20logic_and\x20(identity\x20+\x20eligibility\x20+\x20reputation)'],'mutable_after_publish':![],'r_rounds_focus':['R1','R2','R3','R5','R6','R7']}];export function findScene(a,b){return GUARD_SCENES['find'](c=>c['host_object']===a&&c['binding_field']===b);}export function inferSceneFromAction(a){const b={'buy':'service_buy_guard','forward':'machine_forward_guard','allocate':'service_order_allocators_guard','claim_reward':'reward_claim','vote':'arbitration_voting_guard','dispute':'arbitration_usage_guard','write_repository':'repository_write_guard','submit_progress':'progress_submission_guard','gen_passport':'gen_passport_guard'},c=b[a];return GUARD_SCENES['find'](d=>d['id']===c);}export function getImmutableScenes(){return GUARD_SCENES['filter'](a=>!a['mutable_after_publish']);}export function getNumericIdentifierScenes(){return GUARD_SCENES['filter'](a=>a['special_constraints']['some'](b=>b['includes']('numeric')||b['includes']('GuardIdentifier')));}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GUARDQUERY}from'@wowok/wowok';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{factoryRulePack,getJudgmentDoc}from'../config/judgment.js';import{evaluateRuleBook}from'../config/rule-engine.js';function rootRaw(a){try{return JSON['stringify'](a)??'';}catch{return'';}}function hasSignerCheck(a){return a['includes']('\x22Signer\x22');}function hasClockCheck(a){return a['includes']('\x22Clock\x22');}function hasGuardSelfRef(a){return a['includes']('\x22Guard\x22');}function hasWitness(a){return a['includes']('\x22convert_witness\x22');}function extractWitnessCodes(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"convert_witness"\s*:\s*(\d+)/g);for(const e of d){const f=parseInt(e[0x1],0xa);if(f>=0x64&&f<=0x6c)b['push'](f);}return b;}const WITNESS_CHAIN={0x64:['Order','Progress'],0x65:['Order','Machine'],0x66:['Order','Service'],0x67:['Progress','Machine'],0x68:['Arb','Order'],0x69:['Arb','Arbitration'],0x6a:['Arb','Order','Progress'],0x6b:['Arb','Order','Service'],0x6c:['Arb','Order','Machine']};function extractWitnessIdentifierPairs(a){const b=[],c=new WeakSet();function d(e){if(e===null||typeof e!=='object')return;if(c['has'](e))return;c['add'](e);typeof e['convert_witness']==='number'&&typeof e['identifier']==='number'&&b['push']({'code':e['convert_witness'],'identifier':e['identifier']});for(const f of Object['keys'](e)){const g=e[f];if(Array['isArray'](g)){for(const h of g)d(h);}else g!==null&&typeof g==='object'&&d(g);}}return d(a),b;}function getChildNodes(a){if(!a||typeof a!=='object')return[];const b=[];if(Array['isArray'](a['nodes']))b['push'](...a['nodes']);if(a['left'])b['push'](a['left']);if(a['right'])b['push'](a['right']);if(a['vec'])b['push'](a['vec']);if(a['target'])b['push'](a['target']);if(a['object']&&typeof a['object']==='object')b['push'](a['object']);if(Array['isArray'](a['parameters']))b['push'](...a['parameters']);return b['filter'](d=>d&&typeof d==='object');}function findSignerLogicEqualNodes(a){const b=[];function c(d,e){if(!d||typeof d!=='object')return;if(d['type']==='logic_equal'){const f=Array['isArray'](d['nodes'])?d['nodes']:d['left']&&d['right']?[d['left'],d['right']]:[];if(f['length']===0x2){const g=f['findIndex'](h=>h?.['type']==='context'&&h?.['context']==='Signer');g>=0x0&&b['push']({'node':d,'parentType':e,'otherOperand':f[0x1-g]});}}for(const h of getChildNodes(d)){c(h,d['type']);}}return c(a,null),b;}function detectLevel1StrictBinding(a,b){const c=findSignerLogicEqualNodes(a);for(const d of c){const e=d['otherOperand'];if(e?.['type']==='identifier'){const f=b['find'](g=>g['identifier']===e['identifier']);if(f&&!f['b_submission']&&f['value_type']==='Address'&&typeof f['value']==='string'&&f['value']['length']>0x0)return{'detected':!![],'entry':{'identifier':f['identifier'],'value':f['value'],'name':f['name']}};}}return{'detected':![]};}function isSignerCheckInLogicOr(a){const b=findSignerLogicEqualNodes(a);return b['some'](c=>c['parentType']==='logic_or');}const QUERY_INVARIANT_MAP=((()=>{const a=new Map();for(const b of GUARDQUERY){b['invariant']!==undefined&&a['set'](b['id'],b['invariant']);}return a;})());function extractQueryIds(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"query"\s*:\s*(\d+)/g);for(const f of d){const g=parseInt(f[0x1],0xa);if(!b['includes'](g))b['push'](g);}const e=c['matchAll'](/"query"\s*:\s*"([^"]+)"/g);for(const h of e){const i=h[0x1],j=GUARDQUERY['find'](k=>k['name']===i);if(j&&!b['includes'](j['id']))b['push'](j['id']);}return b;}function bareBoolQueryClauses(a){const b=[],c=(d,e)=>{if(e>0x40||!d||typeof d!=='object'||typeof d['type']!=='string')return;if((d['type']==='logic_and'||d['type']==='logic_or')&&Array['isArray'](d['nodes']))for(const f of d['nodes']){if(f&&typeof f==='object'&&f['type']==='query'){const g=f['query'],h=typeof g==='number'?'#'+g:typeof g==='string'?g:'(unknown\x20query)';if(!b['includes'](h))b['push'](h);}}if(Array['isArray'](d['nodes'])){for(const i of d['nodes'])c(i,e+0x1);}if(d['node'])c(d['node'],e+0x1);};return c(a,0x0),b;}function rootAllQueriesNonZero(a){const b=extractQueryIds(a);if(b['length']===0x0)return![];return b['every'](c=>QUERY_INVARIANT_MAP['has'](c));}const REENTRANCY_SPECS=[{'sceneId':'reward_claim','level':'critical','existsPrimitives':[0x64d],'countPrimitives':[0x64c],'addressPrimitives':[0x65a],'rationale':'Guard\x20pass\x20distributes\x20reward\x20funds\x20to\x20the\x20Claimant\x20AND\x20creates\x20a\x20reward_record,\x20but\x20the\x20Guard\x20conditions\x20(identity,\x20time,\x20node\x20state)\x20do\x20NOT\x20naturally\x20invalidate\x20after\x20a\x20claim.\x20'+'Without\x20an\x20explicit\x20anti-reentrancy\x20primitive,\x20the\x20same\x20Claimant\x20can\x20repeatedly\x20pass\x20the\x20Guard\x20and\x20DRAIN\x20THE\x20ENTIRE\x20POOL.\x20'+'This\x20is\x20the\x20most\x20severe\x20reentrancy\x20scene\x20—\x20direct\x20fund\x20loss.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and\x20with\x20existing\x20conditions):\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record\x20has\x27,\x20object=reward,\x20parameters=[claimant_address]))\x20—\x20RECOMMENDED\x20(per-user\x20Bool\x20check)\x0a'+'\x20\x20-\x20logic_equal([query(\x27reward.record\x20count\x27,\x20object=reward),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20total-claim\x20count\x20is\x200\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record.find_first\x27,\x20object=reward,\x20where={...}))\x20—\x20no\x20matching\x20record\x20found\x0a'+'Reference\x20template:\x20MyShop_Advanced\x20Guard\x207\x20condition\x204\x20(logic_not(query_reward_record_exists(where.storeFromId=order_id)))'},{'sceneId':'arbitration_voting_guard','level':'critical','existsPrimitives':[0x57c,0x57e],'countPrimitives':[0x57d],'addressPrimitives':[],'rationale':'Guard\x20pass\x20counts\x20the\x20vote\x20with\x20the\x20extracted\x20weight.\x20Without\x20anti-reentrancy,\x20the\x20same\x20voter\x20can\x20vote\x20MULTIPLE\x20times,\x20'+'multiplying\x20their\x20weight\x20and\x20skewing\x20the\x20arbitration\x20result\x20—\x20which\x20directly\x20determines\x20fund\x20ownership\x20via\x20compensation.\x20'+'The\x20voter\x27s\x20eligibility\x20(identity,\x20reputation)\x20does\x20NOT\x20naturally\x20invalidate\x20after\x20voting.\x20'+'Note:\x20arb.voted_count\x20(1403)\x20is\x20total\x20voter\x20count\x20(NOT\x20per-voter)\x20and\x20does\x20NOT\x20serve\x20as\x20an\x20anti-reentrancy\x20primitive\x20for\x20an\x20individual\x20voter.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted\x20has\x27,\x20object=arb,\x20parameters=[voter_address]))\x20—\x20RECOMMENDED\x20(per-voter\x20Bool)\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted.agree\x20has\x27,\x20object=arb,\x20parameters=[voter_address,\x20proposition_index]))\x20—\x20per-voter-per-proposition\x0a'+'\x20\x20-\x20logic_equal([query(\x27arb.voted.agree\x20count\x27,\x20object=arb,\x20parameters=[voter_address]),\x20identifier(N)])\x20where\x20table[N].value=0'},{'sceneId':'arbitration_usage_guard','level':'high','existsPrimitives':[0x61d],'countPrimitives':[0x61c],'addressPrimitives':[],'rationale':'Guard\x20pass\x20creates\x20a\x20new\x20Arb\x20case.\x20Without\x20anti-reentrancy,\x20a\x20customer\x20can\x20create\x20multiple\x20Arb\x20cases\x20for\x20the\x20SAME\x20Order\x20'+'(up\x20to\x20MAX_DISPUTE_COUNT=10),\x20harassing\x20the\x20counterparty\x20and\x20inflating\x20arbitration\x20system\x20load.\x20'+'Not\x20direct\x20fund\x20loss,\x20but\x20severe\x20system\x20abuse.\x20Filing\x20a\x20dispute\x20deduplicates\x20by\x20Arb\x20address\x20but\x20does\x20NOT\x20prevent\x20multiple\x20distinct\x20Arbs.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27order.dispute\x20has\x27,\x20object=order,\x20parameters=[existing_arb_address]))\x20—\x20per-Arb\x20check\x0a'+'\x20\x20-\x20logic_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20STRICT:\x20block\x20any\x20prior\x20dispute\x0a'+'\x20\x20-\x20logic_as_u256_less_or_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=K\x20—\x20LENIENT:\x20allow\x20up\x20to\x20K\x20disputes'},{'sceneId':'service_order_allocators_guard','level':'low','existsPrimitives':[0x620],'countPrimitives':[],'addressPrimitives':[0x621],'rationale':'Protocol-level\x20protection:\x20attaching\x20an\x20Allocation\x20to\x20an\x20Order\x20asserts\x20ONE\x20Allocation\x20per\x20Order\x20(E_ALLOCATION_ALREADY_SPECIFIED).\x20'+'After\x20alloc()\x20executes,\x20typical\x20Rate-mode\x20allocators\x20(sum=10000)\x20and\x20Surplus-mode\x20allocators\x20drain\x20balance\x20to\x200,\x20making\x20reentrancy\x20unprofitable.\x20'+'EDGE\x20CASE:\x20Amount-mode-only\x20allocators\x20(no\x20Surplus,\x20total\x20<\x20full\x20balance)\x20leave\x20remainder;\x20a\x20second\x20alloc()\x20could\x20extract\x20more\x20—\x20mitigated\x20by\x20preferring\x20Rate/RateGross/Surplus\x20modes.\x20'+'External\x20deposit\x20via\x20receive()\x20is\x20possible\x20but\x20irrational\x20(attacker\x20funds\x20the\x20Allocation\x20they\x20attack).','mitigation':'Default:\x20no\x20action\x20needed\x20(protocol-level\x20guard).\x20IF\x20using\x20Amount-mode-only\x20allocators\x20without\x20Surplus:\x20'+'consider\x20adding\x20logic_not(query(\x27order.allocation\x20some\x27,\x20object=order))\x20OR\x20switch\x20to\x20Rate/Surplus\x20mode\x20to\x20drain\x20balance\x20completely.'},{'sceneId':'service_buy_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20purchase\x20creates\x20a\x20fresh\x20Order;\x20no\x20existing\x20Order\x20state\x20is\x20modified.\x20Default:\x20no\x20reentrancy\x20risk.\x20'+'IF\x20business\x20intent\x20is\x20\x27limit\x20one\x20purchase\x20per\x20user\x27\x20(limited-edition\x20goods,\x20whitelist\x20single-buy),\x20an\x20anti-reentrancy\x20check\x20is\x20REQUIRED\x20'+'but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20for\x20per-user\x20purchase\x20history.','mitigation':'IF\x20limit-purchase\x20intent:\x20record\x20purchases\x20in\x20a\x20Repository\x20and\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20...))\x20to\x20root;\x20'+'OR\x20revoke\x20EntityRegistrar\x20membership\x20after\x20first\x20buy;\x20OR\x20use\x20an\x20off-chain\x20allowlist\x20with\x20on-chain\x20Merkle\x20proof.'},{'sceneId':'repository_write_guard','level':'low','existsPrimitives':[0x48e],'countPrimitives':[],'addressPrimitives':[],'rationale':'Default\x20writes\x20are\x20idempotent\x20(same\x20ID\x20overwrites,\x20different\x20ID\x20appends);\x20no\x20fund\x20flow.\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20write\x20per\x20ID\x27\x20(voting,\x20immutable\x20credential,\x20single-attestation),\x20an\x20anti-reentrancy\x20check\x20is\x20needed.','mitigation':'IF\x20one-write-per-ID\x20intent:\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20object=repository,\x20parameters=[policy_name,\x20user_or_object_id]))\x20to\x20root.'},{'sceneId':'gen_passport_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20gen_passport\x20call\x20generates\x20an\x20independent\x20Passport\x20(one\x20Passport\x20per\x20operation).\x20'+'Multiple\x20Passports\x20for\x20the\x20same\x20user\x20are\x20usually\x20valid\x20(each\x20serves\x20a\x20different\x20subsequent\x20operation).\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20active\x20Passport\x20per\x20user\x27,\x20an\x20anti-reentrancy\x20check\x20is\x20needed\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists.','mitigation':'IF\x20one-passport-per-user\x20intent:\x20use\x20off-chain\x20tracking\x20or\x20a\x20Repository\x20to\x20record\x20issued\x20Passport\x20IDs.'}],QUERY_TYPE_ALIASES=new Map([['query_reward_record_exists',0x64d],['query_reward_record_count',0x64c],['query_reward_record_find',0x65a],['query_progress_history_find',0x4fa],['query_progress_history_session_find',0x4fb],['query_progress_history_session_forward_find',0x4fc],['query_progress_history_session_count',0x4f9],['query_progress_history_session_forward_count',0x4ee],['query_repository_data_count_where',0x495],['query_repository_data_sum_where',0x496],['query_repository_policies_keys',0x497],['query_repository_data_find_where',0x498],['query_repository_data_keys_where',0x499]]);function detectReentrancyProtection(a,b,c){const d=new Set([...c['existsPrimitives'],...c['countPrimitives'],...c['addressPrimitives']]);if(d['size']===0x0)return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20available\x20in\x20GUARDQUERY\x20for\x20this\x20scene'};const e=new Map(),f=new Map();for(const p of d){const q=GUARDQUERY['find'](r=>r['id']===p);q&&(e['set'](p,q['name']),f['set'](q['name'],p));}const g=Array['from'](f['keys']());function h(r){if(!r||typeof r!=='object')return-0x1;if(typeof r['query']==='number'&&d['has'](r['query']))return r['query'];if(typeof r['query']==='string'&&f['has'](r['query']))return f['get'](r['query']);if(typeof r['type']==='string'&&QUERY_TYPE_ALIASES['has'](r['type'])){const s=QUERY_TYPE_ALIASES['get'](r['type']);if(d['has'](s))return s;}if(typeof r['type']==='string'&&f['has'](r['type']))return f['get'](r['type']);return-0x1;}function i(r){if(!r||typeof r!=='object')return![];if(typeof r['type']==='string'&&['number','u8','u16','u32','u64','u128','u256']['includes'](r['type']))return r['value']===0x0||r['value']==='0'||r['value']===0x0n;if(r['type']==='identifier'&&typeof r['identifier']==='number'){const s=b['find'](t=>t['identifier']===r['identifier']);if(s&&!s['b_submission'])return s['value']===0x0||s['value']==='0'||s['value']===0x0n;}return![];}function j(r,s){if(!r||typeof r!=='object')return[];const t=[];if(Array['isArray'](r['nodes']))for(const u of r['nodes']){if(u!==s)t['push'](u);}if(r['left']&&r['left']!==s)t['push'](r['left']);if(r['right']&&r['right']!==s)t['push'](r['right']);return t['filter'](v=>v&&typeof v==='object');}let k=![],l=![],m='',n='';function o(r,s){if(!r||typeof r!=='object')return;const t=h(r);if(t>=0x0){k=!![];const v=e['get'](t)??'query_'+t;n=v;const w=s?.['type']??null;let x=![];const y=c['existsPrimitives']['includes'](t),z=c['addressPrimitives']['includes'](t),A=c['countPrimitives']['includes'](t);(y||z)&&w==='logic_not'&&(x=!![]);if(A&&w==='logic_equal'){const B=j(s,r);B['some'](C=>i(C))&&(x=!![]);}if(x)l=!![];else{if(!m){const C=A?'logic_equal\x20with\x20a\x20zero\x20operand':'logic_not';m='Primitive\x20\x22'+v+'\x22\x20found\x20but\x20its\x20immediate\x20parent\x20is\x20'+(w??'root')+'\x20(expected\x20'+C+').\x20The\x20primitive\x20is\x20present\x20but\x20does\x20NOT\x20actually\x20prevent\x20reentrancy\x20—\x20this\x20is\x20a\x20false\x20sense\x20of\x20security.';}}}const u=[];if(Array['isArray'](r['nodes']))u['push'](...r['nodes']);if(r['left'])u['push'](r['left']);if(r['right'])u['push'](r['right']);if(r['node'])u['push'](r['node']);if(r['vec'])u['push'](r['vec']);if(r['target'])u['push'](r['target']);if(r['object']&&typeof r['object']==='object')u['push'](r['object']);if(Array['isArray'](r['parameters']))u['push'](...r['parameters']);for(const D of u){D&&typeof D==='object'&&o(D,r);}}o(a,null);if(l)return{'state':'protected','evidence':'Anti-reentrancy\x20primitive\x20\x22'+n+'\x22\x20is\x20properly\x20wrapped','foundPrimitiveName':n};if(k)return{'state':'pseudo','evidence':m,'foundPrimitiveName':n};return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20found\x20in\x20root.\x20Expected\x20one\x20of:\x20'+g['join'](',\x20')};}function stableKey(a){if(a===null||typeof a!=='object')return JSON['stringify'](a)??'null';if(Array['isArray'](a))return'['+a['map'](stableKey)['join'](',')+']';const b=a;return'{'+Object['keys'](b)['sort']()['map'](c=>JSON['stringify'](c)+':'+stableKey(b[c]))['join'](',')+'}';}function readsContext(a){return rootRaw(a)['includes']('\x22context\x22');}const NUMERIC_VALUE_TYPE=/^u(?:8|16|32|64|128|256)$/i,NUMERIC_NODE_TYPES=new Set(['calc_number_add','calc_number_multiply','calc_number_subtract','calc_number_divide','calc_number_mod','convert_address_number','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','vec_length','calc_string_length']),REFLEXIVE_TRUE_OPS=new Set(['logic_equal','logic_as_u256_equal','logic_string_nocase_equal','calc_string_nocase_equal','logic_string_contains','calc_string_contains','logic_string_nocase_contains','calc_string_nocase_contains']),REFLEXIVE_FALSE_OPS=new Set(['logic_not_equal','logic_as_u256_greater','logic_as_u256_lesser']);function tableEntryOf(a,b){if(!a||a['type']!=='identifier')return undefined;return b['find'](c=>c['identifier']===a['identifier']);}function staticValueType(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return undefined;if(a['type']==='identifier')return tableEntryOf(a,b)?.['value_type'];const c=QUERY_TYPE_ALIASES['get'](a['type']),d=a['type']==='query'?a['query']:c;if(d!==undefined){const e=GUARDQUERY['find'](f=>f['id']===d||typeof d==='string'&&f['name']===d);if(e)return String(e['return']);}return NUMERIC_NODE_TYPES['has'](a['type'])?'U64':undefined;}function constantNumber(a,b){const c=tableEntryOf(a,b);if(!c||c['b_submission'])return undefined;if(!NUMERIC_VALUE_TYPE['test'](String(c['value_type'])))return undefined;const d=String(c['value']??'')['trim']();if(!/^\d+$/['test'](d))return undefined;try{return BigInt(d);}catch{return undefined;}}function foldCertainOutcome(c,d,e=0x0){if(e>0x40||!c||typeof c!=='object'||typeof c['type']!=='string')return undefined;const f=Array['isArray'](c['nodes'])?c['nodes']:[],g=i=>foldCertainOutcome(i,d,e+0x1),h=()=>f['length']>0x0?f['map'](g):undefined;switch(c['type']){case'identifier':{const i=tableEntryOf(c,d);if(!i||i['b_submission'])return undefined;if(/^bool$/i['test'](String(i['value_type']))){const j=String(i['value']??'')['trim']()['toLowerCase']();if(j==='true'||j==='false')return{'outcome':j,'reason':'table\x20entry\x20#'+i['identifier']+'\x20is\x20the\x20constant\x20Bool\x20'+j};}return undefined;}case'logic_and':{const k=h();if(!k)return undefined;const l=k['find'](m=>m?.['outcome']==='false');if(l)return{'outcome':'false','reason':'a\x20logic_and\x20branch\x20is\x20always\x20false:\x20'+l['reason']};if(k['every'](m=>m?.['outcome']==='true'))return{'outcome':'true','reason':'every\x20logic_and\x20branch\x20is\x20always\x20true:\x20'+(k[0x0]?.['reason']??'')};return undefined;}case'logic_or':{const m=h();if(!m)return undefined;const n=m['find'](o=>o?.['outcome']==='true');if(n)return{'outcome':'true','reason':'a\x20logic_or\x20branch\x20is\x20always\x20true:\x20'+n['reason']};if(m['every'](o=>o?.['outcome']==='false'))return{'outcome':'false','reason':'every\x20logic_or\x20branch\x20is\x20always\x20false'};return undefined;}case'logic_not':{const o=g(c['node']);if(!o)return undefined;return{'outcome':o['outcome']==='true'?'false':'true','reason':'logic_not\x20of\x20'+(o['outcome']==='true'?'an\x20always-true':'an\x20always-false')+'\x20expression:\x20'+o['reason']};}default:{if(f['length']<0x2)return undefined;const p=new Set(f['map'](stableKey));if(p['size']===0x1&&!readsContext(f[0x0])&&!rootRaw(f[0x0])['includes']('\x22query\x22')){if(REFLEXIVE_TRUE_OPS['has'](c['type']))return{'outcome':'true','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20(identifier/constant\x20subtree\x20'+stableKey(f[0x0])['slice'](0x0,0x50)+')\x20—\x20it\x20can\x20never\x20reject'};if(REFLEXIVE_FALSE_OPS['has'](c['type']))return{'outcome':'false','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20—\x20it\x20can\x20never\x20pass'};}const q=f['map'](s=>constantNumber(s,d)),r=c['type']==='logic_as_u256_greater_or_equal'?0x1:c['type']==='logic_as_u256_lesser_or_equal'?0x0:-0x1;if(r>=0x0&&f['length']===0x2){const s=0x1-r,t=f[s],u=staticValueType(t,d);if(q[r]===0x0n&&q[s]===undefined&&u!==undefined&&NUMERIC_VALUE_TYPE['test'](String(u))&&!readsContext(t))return{'outcome':'true','reason':c['type']+'\x20against\x20the\x20constant\x200\x20on\x20an\x20unsigned\x20('+u+')\x20operand\x20—\x20every\x20U-value\x20satisfies\x20it'};}if(q['length']===0x2&&q[0x0]!==undefined&&q[0x1]!==undefined){const v=q[0x0],w=q[0x1],x={'logic_equal':v===w,'logic_as_u256_equal':v===w,'logic_not_equal':v!==w,'logic_as_u256_greater':v>w,'logic_as_u256_greater_or_equal':v>=w,'logic_as_u256_lesser':v<w,'logic_as_u256_lesser_or_equal':v<=w};if(c['type']in x)return{'outcome':x[c['type']]?'true':'false','reason':c['type']+'\x20folds\x20on\x20two\x20constant\x20operands\x20('+v['toString']()+'\x20vs\x20'+w['toString']()+')'};}return undefined;}}}export function guardRiskFacts(a){const b={},c=rootRaw(a?.['root']),d=c['toLowerCase'](),f=Array['isArray'](a?.['table'])?a['table']:[],g=a?.['scene'],h=a?.['rely'];b['has_signer_check']=hasSignerCheck(c),b['has_clock_check']=hasClockCheck(c),b['has_guard_self_ref']=hasGuardSelfRef(c),b['has_witness']=hasWitness(c),b['queries_repository']=d['includes']('repository'),b['queries_progress']=d['includes']('progress'),b['root_has_query']=d['includes']('\x22query\x22'),b['root_has_clock_token']=d['includes']('clock'),b['root_has_calc_number_add']=d['includes']('calc_number_add'),b['root_has_logic_string_contains']=d['includes']('logic_string_contains'),b['root_has_logic_string_nocase']=d['includes']('logic_string_nocase'),b['root_has_logic_as_u256_greater_or_equal']=d['includes']('logic_as_u256_greater_or_equal'),b['root_has_logic_as_u256_greater']=d['includes']('logic_as_u256_greater'),b['root_has_logic_equal']=c['includes']('\x22logic_equal\x22'),b['root_has_logic_not_equal']=c['includes']('\x22logic_not_equal\x22'),b['logic_and_count']=(d['match'](/"logic_and"/g)||[])['length'],b['root_is_identifier']=a?.['root']?.['type']==='identifier';const i=b['root_is_identifier']?f['find'](D=>D['identifier']===a['root']['identifier']):undefined;b['root_identifier_is_submission']=i?.['b_submission']??![];const j=extractQueryIds(a?.['root']);b['root_query_ids_csv']=j['join'](',\x20'),b['root_has_progress_current_query']=j['includes'](0x4e5);const k=bareBoolQueryClauses(a?.['root']);k['length']>0x0&&(b['bare_bool_query_count']=k['length'],b['bare_bool_query_csv_sp']=k['join'](',\x20'));b['queries_arb_status']=d['includes']('arb.status'),b['arb_status_transient_gate']=b['queries_arb_status']&&f['some'](D=>!D['b_submission']&&/^u(8|16|32|64|128|256)$/i['test'](String(D['value_type']))&&Number(D['value'])===0x5);const l=f['some'](D=>D['b_submission']);b['has_submission']=l;const m=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&D['value']);m['length']>0x0&&(b['const_addr_count']=m['length'],b['const_addr_list']=m['map'](D=>'#'+D['identifier']+'='+D['value'])['join'](',\x20'));const n=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&typeof D['value']==='string'&&(D['value']['toLowerCase']()==='0xaab'||D['value']['toLowerCase']()==='0xaaa'));if(n['length']>0x0){b['sys_addr_list']=n['map'](E=>'#'+E['identifier']+'='+E['value']+'('+E['name']+')')['join'](',\x20');const D=n['find'](E=>E['value']==='0xaab'&&E['name']&&!E['name']['toLowerCase']()['includes']('registrar')||E['value']==='0xaaa'&&E['name']&&!E['name']['toLowerCase']()['includes']('linker'));b['sys_addr_wrong']=D!==undefined;}const o=extractWitnessCodes(a?.['root']),p=o['filter'](E=>[0x6a,0x6b,0x6c]['includes'](E));if(p['length']>0x0){const E={0x6a:'Arb→Progress\x20(two\x20hops:\x20arb.order\x20→\x20order.progress)',0x6b:'Arb→Machine\x20(two\x20hops:\x20arb.order\x20→\x20order.machine)',0x6c:'Arb→Service\x20(two\x20hops:\x20arb.order\x20→\x20order.service)'};b['witness_multihop_codes']=p,b['witness_multihop_csv']=p['join'](',\x20'),b['witness_multihop_names_block']=p['map'](F=>'\x20\x20-\x20'+F+':\x20'+E[F])['join']('\x0a');}const q=extractWitnessIdentifierPairs(a?.['root']),r=q['filter'](F=>F['code']>=0x64&&F['code']<=0x6c);if(r['length']>0x0){const F=[],G=[];for(const {code:I,identifier:J}of r){const K=WITNESS_CHAIN[I];if(!K)continue;const L=K[0x0],M=f['find'](O=>O['identifier']===J);if(!M)continue;const N=I+'\x20('+K['join']('→')+')';M['object_type']?M['object_type']!==L&&F['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type='+M['object_type']+'\x20(expected\x20'+L+')')):G['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type\x20is\x20not\x20set\x20(expected\x20'+L+')'));if(K['length']===0x3){const O=K[0x1],P=f['some'](Q=>Q['object_type']===O);!P&&G['push']('witness\x20'+N+'\x20multi-hop\x20chain\x20expects\x20intermediate\x20'+(O+'\x20in\x20table,\x20but\x20no\x20entry\x20with\x20object_type='+O+'\x20found'));}}const H=[...F,...G];H['length']>0x0&&(b['rc2_02_issue_count']=H['length'],b['rc2_02_has_hard_mismatch']=F['length']>0x0,b['rc2_02_evidence_lines']=H['map'](Q=>'\x20\x20-\x20'+Q)['join']('\x0a'),b['rc2_02_evidence_csv']=H['join'](';\x20'));}if(b['has_witness']){const Q=d['includes']('repository')&&d['includes']('\x22query\x22'),R=d['includes']('progress_history')&&d['includes']('\x22query\x22');if(Q||R){const S=d['includes']('convert_number_address')||d['includes']('convert_address_number')||d['includes']('convert_u256')||d['includes']('convert_string');b['rc2_04_queries_repo']=Q,b['rc2_04_queries_progress_history']=R,b['rc2_04_has_conversion']=S,b['rc2_04_conversion_note']=S?'\x0aThe\x20current\x20Guard\x20already\x20uses\x20type\x20conversion\x20nodes,\x20but\x20ensure\x20the\x20conversion\x20direction\x20is\x20correct.':'\x0aWarning:\x20no\x20type\x20conversion\x20node\x20detected\x20in\x20the\x20current\x20Guard;\x20parameter\x20type\x20mismatch\x20risk\x20may\x20exist.',b['rc2_04_conversion_evidence']=S?'Type\x20conversion\x20node\x20in\x20use':'No\x20type\x20conversion\x20node\x20detected';}}b['scene_present']=g!==undefined;g&&(b['scene_id']=g['id'],b['scene_host_object']=g['host_object'],b['scene_binding_field']=g['binding_field'],b['scene_mutable_after_publish']=g['mutable_after_publish']);b['rc3_01_sharing_exempt']=g?.['id']==='service_order_allocators_guard'&&Array['isArray'](a?.['sharing_recipients'])&&a['sharing_recipients']['length']>0x0&&!a['sharing_recipients']['includes']('Signer');if(g?.['binding_field']==='voting_guard'){const T=f['filter'](U=>U['b_submission']&&['U8','U16','U32','U64','U128','U256']['includes'](U['value_type']));T['length']>0x0&&(b['rc3_02_numeric_count']=T['length'],b['rc3_02_numeric_list']=T['map'](U=>'#'+U['identifier']+'('+U['value_type']+')')['join'](',\x20'));}const s=f['filter'](U=>U['b_submission']&&U['value_type']==='Address');if(s['length']>0x0){b['rc3_03_submitted_addr_count']=s['length'];const U=s['filter'](V=>!V['object_type']);b['rc3_03_no_type_count']=U['length'],b['rc3_03_evidence']=U['length']>0x0?'Missing\x20object_type:\x20'+U['map'](V=>'#'+V['identifier'])['join'](',\x20'):'Annotated:\x20'+s['map'](V=>'#'+V['identifier']+'='+V['object_type'])['join'](',\x20');}if(s['length']>0x0){const V=o['some'](a2=>[0x64,0x65,0x66]['includes'](a2)),W=o['some'](a2=>[0x67]['includes'](a2)),X=o['some'](a2=>[0x68,0x69,0x6a,0x6b,0x6c]['includes'](a2)),Y=s['filter'](a2=>a2['object_type']==='Order'||V&&!a2['object_type']),Z=s['filter'](a2=>a2['object_type']==='Progress'||W&&!a2['object_type']),a0=s['filter'](a2=>a2['object_type']==='Arb'||X&&!a2['object_type']),a1=Y['length']>0x0||Z['length']>0x0||a0['length']>0x0;if(a1){const a2=['machine_forward_guard','service_order_allocators_guard','arbitration_usage_guard','arbitration_voting_guard','reward_claim','progress_submission_guard'],a3=g?.['id'],a4=!a3||a2['includes'](a3);if(a4){const a5=new Set([0x61b,0x618,0x4e2,0x57a,0x579]),a6=j['some'](a7=>a5['has'](a7));if(!a6){const a7=[];for(const a8 of Y){a7['push']('#'+a8['identifier']+(a8['object_type']?'(Order)':'(inferred\x20Order\x20via\x20witness\x20100-102)'));}for(const a9 of Z){a7['push']('#'+a9['identifier']+(a9['object_type']?'(Progress)':'(inferred\x20Progress\x20via\x20witness\x20103)'));}for(const aa of a0){a7['push']('#'+aa['identifier']+(aa['object_type']?'(Arb)':'(inferred\x20Arb\x20via\x20witness\x20104-108)'));}b['rc3_05_applies']=!![],b['rc3_05_critical']=a3!==undefined&&(a3==='machine_forward_guard'||a3==='service_order_allocators_guard'),b['rc3_05_unbound_csv']=a7['join'](',\x20'),b['rc3_05_scene_label']=a3??'unknown\x20scene\x20(conservative\x20flag)';}}}}if(g?.['id']==='service_order_allocators_guard'&&!b['has_signer_check']){const ab=a?.['sharing_recipients'],ac=ab!==undefined&&ab['length']>0x0,ad=ac&&ab['includes']('Signer');if(!(ac&&!ad)){const ae=isUnboundSignerTheft({'recipient_is_signer':ad,'caller_identity_constrained':![]});b['rc3_06_applies']=!![],b['rc3_06_signer_sharing']=ae,b['rc3_06_recipients_label']=ac?'['+ab['join'](',\x20')+']':'(not\x20provided\x20—\x20conservative\x20flag)',b['rc3_06_title_suffix']=ad?'sharing.who=Signer\x20confirmed\x20—\x20anyone\x20can\x20steal\x20100%\x20of\x20funds':'if\x20sharing.who=Signer,\x20anyone\x20can\x20steal\x20100%\x20of\x20funds',b['rc3_06_level_rationale']=ae?'Signer\x20sharing\x20confirmed\x20→\x20critical':'sharing\x20hint\x20absent\x20→\x20conservative\x20medium';}}if(b['has_signer_check']){const af=c['includes']('\x22logic_equal\x22'),ag=c['includes']('\x22logic_not_equal\x22');b['rc4_01_comparison_detail']=(af?'logic_equal(==)':'')+'\x20'+(ag?'logic_not_equal(!=)':''),b['rc4_01_comparison_ops']=(af?'==':'')+'\x20'+(ag?'!=':'');}if(b['has_clock_check']){const ah=d['includes']('logic_as_u256_greater_or_equal'),ai=d['includes']('logic_as_u256_greater');(ah||ai)&&(b['rc4_02_has_greater_or_equal']=ah,b['rc4_02_has_greater']=ai,b['rc4_02_comparison_ops']=(ah?'>=':'')+'\x20'+(ai?'>':''));}if(b['has_signer_check']&&!isSignerCheckInLogicOr(a?.['root'])){const aj=detectLevel1StrictBinding(a?.['root'],f);if(aj['detected']&&aj['entry']){const ak=aj['entry'];b['rc4_04_detected']=!![],b['rc4_04_entry_identifier']=ak['identifier'],b['rc4_04_entry_value']=ak['value'],b['rc4_04_entry_detail']='b_submission=false,\x20value=\x22'+ak['value']+'\x22'+(ak['name']?',\x20name=\x22'+ak['name']+'\x22':'');}}const t=rootAllQueriesNonZero(a?.['root']),u=()=>{const al=j['filter'](am=>!QUERY_INVARIANT_MAP['has'](am));if(al['length']===0x0)return'';return'Queries\x20without\x20non-zero\x20invariant:\x20'+al['map'](am=>{const an=GUARDQUERY['find'](ao=>ao['id']===am);return an?an['id']+'\x20('+an['name']+')':''+am;})['join'](',\x20');};b['root_has_logic_as_u256_greater_or_equal']&&d['includes']('\x22clock\x22')&&b['root_has_calc_number_add']&&b['root_has_query']&&!t&&(b['rx1_01_trigger']=!![],b['rx1_01_evidence']=u()||'Baseline\x20query\x20may\x20return\x200');b['root_has_logic_as_u256_greater']&&b['root_has_query']&&!t&&(b['rx1_02_trigger']=!![],b['rx1_02_evidence']=u()||'Query\x20may\x20return\x200');const v=Array['isArray'](h?.['guards'])?h['guards']:[];b['rely_guards_count']=v['length'],b['rely_is_or']=h?.['logic_or']===!![],b['rely_logic']=h?.['logic_or']?'OR':'AND';const w=d['includes']('repository')&&d['includes']('\x22query\x22'),x=f['some'](al=>al['b_submission']&&al['value_type']==='Address'&&al['object_type']==='Repository'),y=w&&x;b['rx1_11_self_rep_false']=y,b['rx1_11_warning_tail']=y?'\x0aWarning:\x20the\x20current\x20Guard\x20itself\x20queries\x20repository.data\x20and\x20the\x20Repository\x20address\x20comes\x20from\x20submission,\x20'+'so\x20its\x20own\x20rep=false\x20and\x20cannot\x20be\x20depended\x20on\x20by\x20other\x20Guards.':'',b['rx1_11_evidence']=y?'Self\x20rep=false\x20(repository.data\x20query\x20depends\x20on\x20submission)':'Self\x20rep\x20status\x20to\x20be\x20confirmed';if(l){const al=f['filter'](an=>an['b_submission']),am=al['filter'](an=>(an['name']??'')==='');am['length']>0x0&&(b['rx1_12_vague_count']=am['length'],b['rx1_12_vague_csv']=am['map'](an=>'identifier='+an['identifier']+',\x20name=\x22'+(an['name']??'')+'\x22')['join'](';\x20'));}if(g){const an=f['find'](ao=>!ao['b_submission']&&ao['value_type']==='Address'&&ao['object_type']===g['host_object']);an&&(b['rx1_13_detected']=!![],b['rx1_13_identifier']=an['identifier']);}const z=REENTRANCY_SPECS['find'](ao=>ao['sceneId']===g?.['id']);if(z){const ao=detectReentrancyProtection(a?.['root'],f,z);ao['state']!=='protected'&&(b['reentry_applicable']=!![],b['reentry_state']=ao['state'],b['reentry_scene_id']=z['sceneId'],b['reentry_rationale']=z['rationale'],b['reentry_mitigation']=z['mitigation'],ao['state']==='pseudo'&&(b['reentry_found_primitive']=ao['foundPrimitiveName']??''),b['reentry_evidence']=ao['evidence']);}const A=foldCertainOutcome(a?.['root'],f),B=A?.['outcome']==='true';b['tree_folds_always_true']=B;A&&A['outcome']==='false'&&(b['tree_folds_always_false']=!![],b['tree_folds_always_false_reason']=A['reason']);if(B)b['tree_folds_always_true_reason']=A['reason'];const C=g?.['binding_field']==='write_guard'||g?.['id']==='repository_write_guard';return b['write_guard_scene']=C,C&&(b['write_guard_no_identity_check']=!b['has_signer_check'],b['write_guard_open']=B||!b['has_signer_check']),b;}function guardRuleBook(){const a=getJudgmentDoc()['rules']['domains']['guard'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27guard\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function dataSourceClassFor(a){if(a['startsWith']('R-C1-'))return'type1_onchain_constant';if(a['startsWith']('R-C2-'))return'type2_witness_derived';if(a['startsWith']('R-C3-'))return'type3_submitted_object';if(a['startsWith']('R-C4-'))return'type4_system_context';return'cross_type';}function findingToGuardRisk(a){return{'id':a['rule_id'],'data_source_class':dataSourceClassFor(a['rule_id']),'level':a['level'],'category':a['dimension']??'data_source_trust','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'',...a['evidence']!==undefined?{'evidence':a['evidence']}:{},...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export function runGuardRulePack(a){const b=guardRuleBook();let c;try{c=guardRiskFacts(a);}catch{return[];}return evaluateRuleBook(b,c)['findings']['map'](findingToGuardRisk);}export function assembleGuardAssessment(a,b){const c=getOverallRiskLevel(b),d={};for(const h of b){d[h['data_source_class']]=(d[h['data_source_class']]??0x0)+0x1;}const e=generateStakeholderAdvice(b,a['scene']),f=b['some'](i=>i['level']==='critical')||b['filter'](i=>i['level']==='high')['length']>=0x2,g=generateGuardSummary(a);return{'guard_summary':g,'scene':a['scene'],'risks':b,'overall_risk':c,'risks_by_data_source':d,'stakeholder_advice':e,'needs_human_review':f};}function getOverallRiskLevel(a){if(a['some'](b=>b['level']==='critical'))return'critical';if(a['some'](b=>b['level']==='high'))return'high';if(a['some'](b=>b['level']==='medium'))return'medium';return'low';}function generateStakeholderAdvice(a,b){const c={};for(const d of a){for(const e of d['affected_stakeholders']){if(!c[e])c[e]=[];c[e]['push']('['+d['level']['toUpperCase']()+']\x20'+d['title']+':\x20'+d['mitigation']);}}if(b)switch(b['binding_field']){case'buy_guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Before\x20purchase,\x20verify\x20the\x20buy_guard\x20logic\x20to\x20ensure\x20your\x20identity/credentials\x20can\x20pass\x20validation');break;case'order_allocators':if(!c['provider'])c['provider']=[];c['provider']['push']('Verify\x20the\x20order_allocators\x20ordering\x20to\x20ensure\x20your\x20Allocator\x20will\x20not\x20be\x20skipped\x20by\x20preceding\x20conditions');break;case'voting_guard':if(!c['arbitrator'])c['arbitrator']=[];c['arbitrator']['push']('Confirm\x20the\x20voting\x20weight\x20source\x20is\x20trustworthy;\x20prefer\x20querying\x20EntityRegistrar\x20rather\x20than\x20user-submitted\x20data');break;case'Forward.guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Verify\x20the\x20Forward.guard\x20conditions\x20to\x20ensure\x20you\x20can\x20satisfy\x20the\x20advancement\x20criteria\x20and\x20avoid\x20locked\x20funds');break;}return c;}function generateGuardSummary(a){const b=[];b['push']('table\x20entries:\x20'+a['table']['length']);const c=a['table']['filter'](d=>d['b_submission'])['length'];return b['push']('submitted\x20data:\x20'+c+'\x20entries'),b['push']('root\x20type:\x20'+(a['root']?.['type']??'unknown')),a['rely']&&b['push']('rely:\x20'+a['rely']['guards']['length']+'\x20dependencies\x20('+(a['rely']['logic_or']?'OR':'AND')+')'),b['join'](',\x20');}export function getRiskSummary(a){return{'risk_count':a['risks']['length'],'critical_count':a['risks']['filter'](b=>b['level']==='critical')['length'],'high_count':a['risks']['filter'](b=>b['level']==='high')['length'],'needs_human_review':a['needs_human_review'],'top_risks':a['risks']['filter'](b=>b['level']==='critical'||b['level']==='high')['slice'](0x0,0x3)['map'](b=>b['title'])};}export function getRiskRulesCount(){return factoryRulePack('guard')?.['rules']['length']??0x0;}export const RISK_RULES=((()=>{const a=factoryRulePack('guard');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'data_source_class':dataSourceClassFor(b['rule_id']),'trigger':b['trigger']??'','check':c=>{const d=guardRuleBook()['find'](f=>f['rule_id']===b['rule_id']);if(!d)return null;const {findings:e}=evaluateRuleBook([d],guardRiskFacts(c));return e['length']>0x0?findingToGuardRisk(e[0x0]):null;}}));})());
|
|
1
|
+
import{GUARDQUERY}from'@wowok/wowok';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{factoryRulePack,getJudgmentDoc}from'../config/judgment.js';import{evaluateRuleBook}from'../config/rule-engine.js';function rootRaw(a){try{return JSON['stringify'](a)??'';}catch{return'';}}function hasSignerCheck(a){return a['includes']('\x22Signer\x22');}function hasClockCheck(a){return a['includes']('\x22Clock\x22');}function hasGuardSelfRef(a){return a['includes']('\x22Guard\x22');}function hasWitness(a){return a['includes']('\x22convert_witness\x22');}function extractWitnessCodes(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"convert_witness"\s*:\s*(\d+)/g);for(const e of d){const f=parseInt(e[0x1],0xa);if(f>=0x64&&f<=0x6c)b['push'](f);}return b;}const WITNESS_CHAIN={0x64:['Order','Progress'],0x65:['Order','Machine'],0x66:['Order','Service'],0x67:['Progress','Machine'],0x68:['Arb','Order'],0x69:['Arb','Arbitration'],0x6a:['Arb','Order','Progress'],0x6b:['Arb','Order','Service'],0x6c:['Arb','Order','Machine']};function extractWitnessIdentifierPairs(a){const b=[],c=new WeakSet();function d(e){if(e===null||typeof e!=='object')return;if(c['has'](e))return;c['add'](e);typeof e['convert_witness']==='number'&&typeof e['identifier']==='number'&&b['push']({'code':e['convert_witness'],'identifier':e['identifier']});for(const f of Object['keys'](e)){const g=e[f];if(Array['isArray'](g)){for(const h of g)d(h);}else g!==null&&typeof g==='object'&&d(g);}}return d(a),b;}function getChildNodes(a){if(!a||typeof a!=='object')return[];const b=[];if(Array['isArray'](a['nodes']))b['push'](...a['nodes']);if(a['left'])b['push'](a['left']);if(a['right'])b['push'](a['right']);if(a['vec'])b['push'](a['vec']);if(a['target'])b['push'](a['target']);if(a['object']&&typeof a['object']==='object')b['push'](a['object']);if(Array['isArray'](a['parameters']))b['push'](...a['parameters']);return b['filter'](d=>d&&typeof d==='object');}function findSignerLogicEqualNodes(a){const b=[];function c(d,e){if(!d||typeof d!=='object')return;if(d['type']==='logic_equal'){const f=Array['isArray'](d['nodes'])?d['nodes']:d['left']&&d['right']?[d['left'],d['right']]:[];if(f['length']===0x2){const g=f['findIndex'](h=>h?.['type']==='context'&&h?.['context']==='Signer');g>=0x0&&b['push']({'node':d,'parentType':e,'otherOperand':f[0x1-g]});}}for(const h of getChildNodes(d)){c(h,d['type']);}}return c(a,null),b;}function detectLevel1StrictBinding(a,b){const c=findSignerLogicEqualNodes(a);for(const d of c){const e=d['otherOperand'];if(e?.['type']==='identifier'){const f=b['find'](g=>g['identifier']===e['identifier']);if(f&&!f['b_submission']&&f['value_type']==='Address'&&typeof f['value']==='string'&&f['value']['length']>0x0)return{'detected':!![],'entry':{'identifier':f['identifier'],'value':f['value'],'name':f['name']}};}}return{'detected':![]};}function isSignerCheckInLogicOr(a){const b=findSignerLogicEqualNodes(a);return b['some'](c=>c['parentType']==='logic_or');}const QUERY_INVARIANT_MAP=((()=>{const a=new Map();for(const b of GUARDQUERY){b['invariant']!==undefined&&a['set'](b['id'],b['invariant']);}return a;})());function extractQueryIds(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"query"\s*:\s*(\d+)/g);for(const f of d){const g=parseInt(f[0x1],0xa);if(!b['includes'](g))b['push'](g);}const e=c['matchAll'](/"query"\s*:\s*"([^"]+)"/g);for(const h of e){const i=h[0x1],j=GUARDQUERY['find'](k=>k['name']===i);if(j&&!b['includes'](j['id']))b['push'](j['id']);}return b;}function bareBoolQueryClauses(a){const b=[],c=(d,e)=>{if(e>0x40||!d||typeof d!=='object'||typeof d['type']!=='string')return;if((d['type']==='logic_and'||d['type']==='logic_or')&&Array['isArray'](d['nodes']))for(const f of d['nodes']){if(f&&typeof f==='object'&&f['type']==='query'){const g=f['query'],h=typeof g==='number'?'#'+g:typeof g==='string'?g:'(unknown\x20query)';if(!b['includes'](h))b['push'](h);}}if(Array['isArray'](d['nodes'])){for(const i of d['nodes'])c(i,e+0x1);}if(d['node'])c(d['node'],e+0x1);};return c(a,0x0),b;}function rootAllQueriesNonZero(a){const b=extractQueryIds(a);if(b['length']===0x0)return![];return b['every'](c=>QUERY_INVARIANT_MAP['has'](c));}const REENTRANCY_SPECS=[{'sceneId':'reward_claim','level':'critical','existsPrimitives':[0x64d],'countPrimitives':[0x64c],'addressPrimitives':[0x65a],'rationale':'Guard\x20pass\x20distributes\x20reward\x20funds\x20to\x20the\x20Claimant\x20AND\x20creates\x20a\x20reward_record,\x20but\x20the\x20Guard\x20conditions\x20(identity,\x20time,\x20node\x20state)\x20do\x20NOT\x20naturally\x20invalidate\x20after\x20a\x20claim.\x20'+'Without\x20an\x20explicit\x20anti-reentrancy\x20primitive,\x20the\x20same\x20Claimant\x20can\x20repeatedly\x20pass\x20the\x20Guard\x20and\x20DRAIN\x20THE\x20ENTIRE\x20POOL.\x20'+'This\x20is\x20the\x20most\x20severe\x20reentrancy\x20scene\x20—\x20direct\x20fund\x20loss.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and\x20with\x20existing\x20conditions):\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record\x20has\x27,\x20object=reward,\x20parameters=[claimant_address]))\x20—\x20RECOMMENDED\x20(per-user\x20Bool\x20check)\x0a'+'\x20\x20-\x20logic_equal([query(\x27reward.record\x20count\x27,\x20object=reward),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20total-claim\x20count\x20is\x200\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record.find_first\x27,\x20object=reward,\x20where={...}))\x20—\x20no\x20matching\x20record\x20found\x0a'+'Reference\x20template:\x20MyShop_Advanced\x20Guard\x207\x20condition\x204\x20(logic_not(query_reward_record_exists(where.storeFromId=order_id)))'},{'sceneId':'arbitration_voting_guard','level':'critical','existsPrimitives':[0x57c,0x57e],'countPrimitives':[0x57d],'addressPrimitives':[],'rationale':'Guard\x20pass\x20counts\x20the\x20vote\x20with\x20the\x20extracted\x20weight.\x20Without\x20anti-reentrancy,\x20the\x20same\x20voter\x20can\x20vote\x20MULTIPLE\x20times,\x20'+'multiplying\x20their\x20weight\x20and\x20skewing\x20the\x20arbitration\x20result\x20—\x20which\x20directly\x20determines\x20fund\x20ownership\x20via\x20compensation.\x20'+'The\x20voter\x27s\x20eligibility\x20(identity,\x20reputation)\x20does\x20NOT\x20naturally\x20invalidate\x20after\x20voting.\x20'+'Note:\x20arb.voted_count\x20(1403)\x20is\x20total\x20voter\x20count\x20(NOT\x20per-voter)\x20and\x20does\x20NOT\x20serve\x20as\x20an\x20anti-reentrancy\x20primitive\x20for\x20an\x20individual\x20voter.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted\x20has\x27,\x20object=arb,\x20parameters=[voter_address]))\x20—\x20RECOMMENDED\x20(per-voter\x20Bool)\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted.agree\x20has\x27,\x20object=arb,\x20parameters=[voter_address,\x20proposition_index]))\x20—\x20per-voter-per-proposition\x0a'+'\x20\x20-\x20logic_equal([query(\x27arb.voted.agree\x20count\x27,\x20object=arb,\x20parameters=[voter_address]),\x20identifier(N)])\x20where\x20table[N].value=0'},{'sceneId':'arbitration_usage_guard','level':'high','existsPrimitives':[0x61d],'countPrimitives':[0x61c],'addressPrimitives':[],'rationale':'Guard\x20pass\x20creates\x20a\x20new\x20Arb\x20case.\x20Without\x20anti-reentrancy,\x20a\x20customer\x20can\x20create\x20multiple\x20Arb\x20cases\x20for\x20the\x20SAME\x20Order\x20'+'(up\x20to\x20MAX_DISPUTE_COUNT=10),\x20harassing\x20the\x20counterparty\x20and\x20inflating\x20arbitration\x20system\x20load.\x20'+'Not\x20direct\x20fund\x20loss,\x20but\x20severe\x20system\x20abuse.\x20Filing\x20a\x20dispute\x20deduplicates\x20by\x20Arb\x20address\x20but\x20does\x20NOT\x20prevent\x20multiple\x20distinct\x20Arbs.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27order.dispute\x20has\x27,\x20object=order,\x20parameters=[existing_arb_address]))\x20—\x20per-Arb\x20check\x0a'+'\x20\x20-\x20logic_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20STRICT:\x20block\x20any\x20prior\x20dispute\x0a'+'\x20\x20-\x20logic_as_u256_lesser_or_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=K\x20—\x20LENIENT:\x20allow\x20up\x20to\x20K\x20disputes'},{'sceneId':'service_order_allocators_guard','level':'low','existsPrimitives':[0x620],'countPrimitives':[],'addressPrimitives':[0x621],'rationale':'Protocol-level\x20protection:\x20attaching\x20an\x20Allocation\x20to\x20an\x20Order\x20asserts\x20ONE\x20Allocation\x20per\x20Order\x20(E_ALLOCATION_ALREADY_SPECIFIED).\x20'+'After\x20alloc()\x20executes,\x20typical\x20Rate-mode\x20allocators\x20(sum=10000)\x20and\x20Surplus-mode\x20allocators\x20drain\x20balance\x20to\x200,\x20making\x20reentrancy\x20unprofitable.\x20'+'EDGE\x20CASE:\x20Amount-mode-only\x20allocators\x20(no\x20Surplus,\x20total\x20<\x20full\x20balance)\x20leave\x20remainder;\x20a\x20second\x20alloc()\x20could\x20extract\x20more\x20—\x20mitigated\x20by\x20preferring\x20Rate/RateGross/Surplus\x20modes.\x20'+'External\x20deposit\x20via\x20receive()\x20is\x20possible\x20but\x20irrational\x20(attacker\x20funds\x20the\x20Allocation\x20they\x20attack).','mitigation':'Default:\x20no\x20action\x20needed\x20(protocol-level\x20guard).\x20IF\x20using\x20Amount-mode-only\x20allocators\x20without\x20Surplus:\x20'+'consider\x20adding\x20logic_not(query(\x27order.allocation\x20some\x27,\x20object=order))\x20OR\x20switch\x20to\x20Rate/Surplus\x20mode\x20to\x20drain\x20balance\x20completely.'},{'sceneId':'service_buy_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20purchase\x20creates\x20a\x20fresh\x20Order;\x20no\x20existing\x20Order\x20state\x20is\x20modified.\x20Default:\x20no\x20reentrancy\x20risk.\x20'+'IF\x20business\x20intent\x20is\x20\x27limit\x20one\x20purchase\x20per\x20user\x27\x20(limited-edition\x20goods,\x20whitelist\x20single-buy),\x20an\x20anti-reentrancy\x20check\x20is\x20REQUIRED\x20'+'but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20for\x20per-user\x20purchase\x20history.','mitigation':'IF\x20limit-purchase\x20intent:\x20record\x20purchases\x20in\x20a\x20Repository\x20and\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20...))\x20to\x20root;\x20'+'OR\x20revoke\x20EntityRegistrar\x20membership\x20after\x20first\x20buy;\x20OR\x20use\x20an\x20off-chain\x20allowlist\x20with\x20on-chain\x20Merkle\x20proof.'},{'sceneId':'repository_write_guard','level':'low','existsPrimitives':[0x48e],'countPrimitives':[],'addressPrimitives':[],'rationale':'Default\x20writes\x20are\x20idempotent\x20(same\x20ID\x20overwrites,\x20different\x20ID\x20appends);\x20no\x20fund\x20flow.\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20write\x20per\x20ID\x27\x20(voting,\x20immutable\x20credential,\x20single-attestation),\x20an\x20anti-reentrancy\x20check\x20is\x20needed.','mitigation':'IF\x20one-write-per-ID\x20intent:\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20object=repository,\x20parameters=[policy_name,\x20user_or_object_id]))\x20to\x20root.'},{'sceneId':'gen_passport_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20gen_passport\x20call\x20generates\x20an\x20independent\x20Passport\x20(one\x20Passport\x20per\x20operation).\x20'+'Multiple\x20Passports\x20for\x20the\x20same\x20user\x20are\x20usually\x20valid\x20(each\x20serves\x20a\x20different\x20subsequent\x20operation).\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20active\x20Passport\x20per\x20user\x27,\x20an\x20anti-reentrancy\x20check\x20is\x20needed\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists.','mitigation':'IF\x20one-passport-per-user\x20intent:\x20use\x20off-chain\x20tracking\x20or\x20a\x20Repository\x20to\x20record\x20issued\x20Passport\x20IDs.'}],QUERY_TYPE_ALIASES=new Map([['query_reward_record_exists',0x64d],['query_reward_record_count',0x64c],['query_reward_record_find',0x65a],['query_progress_history_find',0x4fa],['query_progress_history_session_find',0x4fb],['query_progress_history_session_forward_find',0x4fc],['query_progress_history_session_count',0x4f9],['query_progress_history_session_forward_count',0x4ee],['query_repository_data_count_where',0x495],['query_repository_data_sum_where',0x496],['query_repository_policies_keys',0x497],['query_repository_data_find_where',0x498],['query_repository_data_keys_where',0x499]]);function detectReentrancyProtection(a,b,c){const d=new Set([...c['existsPrimitives'],...c['countPrimitives'],...c['addressPrimitives']]);if(d['size']===0x0)return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20available\x20in\x20GUARDQUERY\x20for\x20this\x20scene'};const e=new Map(),f=new Map();for(const p of d){const q=GUARDQUERY['find'](r=>r['id']===p);q&&(e['set'](p,q['name']),f['set'](q['name'],p));}const g=Array['from'](f['keys']());function h(r){if(!r||typeof r!=='object')return-0x1;if(typeof r['query']==='number'&&d['has'](r['query']))return r['query'];if(typeof r['query']==='string'&&f['has'](r['query']))return f['get'](r['query']);if(typeof r['type']==='string'&&QUERY_TYPE_ALIASES['has'](r['type'])){const s=QUERY_TYPE_ALIASES['get'](r['type']);if(d['has'](s))return s;}if(typeof r['type']==='string'&&f['has'](r['type']))return f['get'](r['type']);return-0x1;}function i(r){if(!r||typeof r!=='object')return![];if(typeof r['type']==='string'&&['number','u8','u16','u32','u64','u128','u256']['includes'](r['type']))return r['value']===0x0||r['value']==='0'||r['value']===0x0n;if(r['type']==='identifier'&&typeof r['identifier']==='number'){const s=b['find'](t=>t['identifier']===r['identifier']);if(s&&!s['b_submission'])return s['value']===0x0||s['value']==='0'||s['value']===0x0n;}return![];}function j(r,s){if(!r||typeof r!=='object')return[];const t=[];if(Array['isArray'](r['nodes']))for(const u of r['nodes']){if(u!==s)t['push'](u);}if(r['left']&&r['left']!==s)t['push'](r['left']);if(r['right']&&r['right']!==s)t['push'](r['right']);return t['filter'](v=>v&&typeof v==='object');}let k=![],l=![],m='',n='';function o(r,s){if(!r||typeof r!=='object')return;const t=h(r);if(t>=0x0){k=!![];const v=e['get'](t)??'query_'+t;n=v;const w=s?.['type']??null;let x=![];const y=c['existsPrimitives']['includes'](t),z=c['addressPrimitives']['includes'](t),A=c['countPrimitives']['includes'](t);(y||z)&&w==='logic_not'&&(x=!![]);if(A&&w==='logic_equal'){const B=j(s,r);B['some'](C=>i(C))&&(x=!![]);}if(x)l=!![];else{if(!m){const C=A?'logic_equal\x20with\x20a\x20zero\x20operand':'logic_not';m='Primitive\x20\x22'+v+'\x22\x20found\x20but\x20its\x20immediate\x20parent\x20is\x20'+(w??'root')+'\x20(expected\x20'+C+').\x20The\x20primitive\x20is\x20present\x20but\x20does\x20NOT\x20actually\x20prevent\x20reentrancy\x20—\x20this\x20is\x20a\x20false\x20sense\x20of\x20security.';}}}const u=[];if(Array['isArray'](r['nodes']))u['push'](...r['nodes']);if(r['left'])u['push'](r['left']);if(r['right'])u['push'](r['right']);if(r['node'])u['push'](r['node']);if(r['vec'])u['push'](r['vec']);if(r['target'])u['push'](r['target']);if(r['object']&&typeof r['object']==='object')u['push'](r['object']);if(Array['isArray'](r['parameters']))u['push'](...r['parameters']);for(const D of u){D&&typeof D==='object'&&o(D,r);}}o(a,null);if(l)return{'state':'protected','evidence':'Anti-reentrancy\x20primitive\x20\x22'+n+'\x22\x20is\x20properly\x20wrapped','foundPrimitiveName':n};if(k)return{'state':'pseudo','evidence':m,'foundPrimitiveName':n};return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20found\x20in\x20root.\x20Expected\x20one\x20of:\x20'+g['join'](',\x20')};}function stableKey(a){if(a===null||typeof a!=='object')return JSON['stringify'](a)??'null';if(Array['isArray'](a))return'['+a['map'](stableKey)['join'](',')+']';const b=a;return'{'+Object['keys'](b)['sort']()['map'](c=>JSON['stringify'](c)+':'+stableKey(b[c]))['join'](',')+'}';}function readsContext(a){return rootRaw(a)['includes']('\x22context\x22');}const NUMERIC_VALUE_TYPE=/^u(?:8|16|32|64|128|256)$/i,NUMERIC_NODE_TYPES=new Set(['calc_number_add','calc_number_multiply','calc_number_subtract','calc_number_divide','calc_number_mod','convert_address_number','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','vec_length','calc_string_length']),REFLEXIVE_TRUE_OPS=new Set(['logic_equal','logic_as_u256_equal','logic_string_nocase_equal','calc_string_nocase_equal','logic_string_contains','calc_string_contains','logic_string_nocase_contains','calc_string_nocase_contains']),REFLEXIVE_FALSE_OPS=new Set(['logic_not_equal','logic_as_u256_greater','logic_as_u256_lesser']);function tableEntryOf(a,b){if(!a||a['type']!=='identifier')return undefined;return b['find'](c=>c['identifier']===a['identifier']);}function staticValueType(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return undefined;if(a['type']==='identifier')return tableEntryOf(a,b)?.['value_type'];const c=QUERY_TYPE_ALIASES['get'](a['type']),d=a['type']==='query'?a['query']:c;if(d!==undefined){const e=GUARDQUERY['find'](f=>f['id']===d||typeof d==='string'&&f['name']===d);if(e)return String(e['return']);}return NUMERIC_NODE_TYPES['has'](a['type'])?'U64':undefined;}function constantNumber(a,b){const c=tableEntryOf(a,b);if(!c||c['b_submission'])return undefined;if(!NUMERIC_VALUE_TYPE['test'](String(c['value_type'])))return undefined;const d=String(c['value']??'')['trim']();if(!/^\d+$/['test'](d))return undefined;try{return BigInt(d);}catch{return undefined;}}function foldCertainOutcome(c,d,e=0x0){if(e>0x40||!c||typeof c!=='object'||typeof c['type']!=='string')return undefined;const f=Array['isArray'](c['nodes'])?c['nodes']:[],g=i=>foldCertainOutcome(i,d,e+0x1),h=()=>f['length']>0x0?f['map'](g):undefined;switch(c['type']){case'identifier':{const i=tableEntryOf(c,d);if(!i||i['b_submission'])return undefined;if(/^bool$/i['test'](String(i['value_type']))){const j=String(i['value']??'')['trim']()['toLowerCase']();if(j==='true'||j==='false')return{'outcome':j,'reason':'table\x20entry\x20#'+i['identifier']+'\x20is\x20the\x20constant\x20Bool\x20'+j};}return undefined;}case'logic_and':{const k=h();if(!k)return undefined;const l=k['find'](m=>m?.['outcome']==='false');if(l)return{'outcome':'false','reason':'a\x20logic_and\x20branch\x20is\x20always\x20false:\x20'+l['reason']};if(k['every'](m=>m?.['outcome']==='true'))return{'outcome':'true','reason':'every\x20logic_and\x20branch\x20is\x20always\x20true:\x20'+(k[0x0]?.['reason']??'')};return undefined;}case'logic_or':{const m=h();if(!m)return undefined;const n=m['find'](o=>o?.['outcome']==='true');if(n)return{'outcome':'true','reason':'a\x20logic_or\x20branch\x20is\x20always\x20true:\x20'+n['reason']};if(m['every'](o=>o?.['outcome']==='false'))return{'outcome':'false','reason':'every\x20logic_or\x20branch\x20is\x20always\x20false'};return undefined;}case'logic_not':{const o=g(c['node']);if(!o)return undefined;return{'outcome':o['outcome']==='true'?'false':'true','reason':'logic_not\x20of\x20'+(o['outcome']==='true'?'an\x20always-true':'an\x20always-false')+'\x20expression:\x20'+o['reason']};}default:{if(f['length']<0x2)return undefined;const p=new Set(f['map'](stableKey));if(p['size']===0x1&&!readsContext(f[0x0])&&!rootRaw(f[0x0])['includes']('\x22query\x22')){if(REFLEXIVE_TRUE_OPS['has'](c['type']))return{'outcome':'true','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20(identifier/constant\x20subtree\x20'+stableKey(f[0x0])['slice'](0x0,0x50)+')\x20—\x20it\x20can\x20never\x20reject'};if(REFLEXIVE_FALSE_OPS['has'](c['type']))return{'outcome':'false','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20—\x20it\x20can\x20never\x20pass'};}const q=f['map'](s=>constantNumber(s,d)),r=c['type']==='logic_as_u256_greater_or_equal'?0x1:c['type']==='logic_as_u256_lesser_or_equal'?0x0:-0x1;if(r>=0x0&&f['length']===0x2){const s=0x1-r,t=f[s],u=staticValueType(t,d);if(q[r]===0x0n&&q[s]===undefined&&u!==undefined&&NUMERIC_VALUE_TYPE['test'](String(u))&&!readsContext(t))return{'outcome':'true','reason':c['type']+'\x20against\x20the\x20constant\x200\x20on\x20an\x20unsigned\x20('+u+')\x20operand\x20—\x20every\x20U-value\x20satisfies\x20it'};}if(q['length']===0x2&&q[0x0]!==undefined&&q[0x1]!==undefined){const v=q[0x0],w=q[0x1],x={'logic_equal':v===w,'logic_as_u256_equal':v===w,'logic_not_equal':v!==w,'logic_as_u256_greater':v>w,'logic_as_u256_greater_or_equal':v>=w,'logic_as_u256_lesser':v<w,'logic_as_u256_lesser_or_equal':v<=w};if(c['type']in x)return{'outcome':x[c['type']]?'true':'false','reason':c['type']+'\x20folds\x20on\x20two\x20constant\x20operands\x20('+v['toString']()+'\x20vs\x20'+w['toString']()+')'};}return undefined;}}}export function guardRiskFacts(a){const b={},c=rootRaw(a?.['root']),d=c['toLowerCase'](),f=Array['isArray'](a?.['table'])?a['table']:[],g=a?.['scene'],h=a?.['rely'];b['has_signer_check']=hasSignerCheck(c),b['has_clock_check']=hasClockCheck(c),b['has_guard_self_ref']=hasGuardSelfRef(c),b['has_witness']=hasWitness(c),b['queries_repository']=d['includes']('repository'),b['queries_progress']=d['includes']('progress'),b['root_has_query']=d['includes']('\x22query\x22'),b['root_has_clock_token']=d['includes']('clock'),b['root_has_calc_number_add']=d['includes']('calc_number_add'),b['root_has_logic_string_contains']=d['includes']('logic_string_contains'),b['root_has_logic_string_nocase']=d['includes']('logic_string_nocase'),b['root_has_logic_as_u256_greater_or_equal']=d['includes']('logic_as_u256_greater_or_equal'),b['root_has_logic_as_u256_greater']=d['includes']('logic_as_u256_greater'),b['root_has_logic_equal']=c['includes']('\x22logic_equal\x22'),b['root_has_logic_not_equal']=c['includes']('\x22logic_not_equal\x22'),b['logic_and_count']=(d['match'](/"logic_and"/g)||[])['length'],b['root_is_identifier']=a?.['root']?.['type']==='identifier';const i=b['root_is_identifier']?f['find'](D=>D['identifier']===a['root']['identifier']):undefined;b['root_identifier_is_submission']=i?.['b_submission']??![];const j=extractQueryIds(a?.['root']);b['root_query_ids_csv']=j['join'](',\x20'),b['root_has_progress_current_query']=j['includes'](0x4e5);const k=bareBoolQueryClauses(a?.['root']);k['length']>0x0&&(b['bare_bool_query_count']=k['length'],b['bare_bool_query_csv_sp']=k['join'](',\x20'));b['queries_arb_status']=d['includes']('arb.status'),b['arb_status_transient_gate']=b['queries_arb_status']&&f['some'](D=>!D['b_submission']&&/^u(8|16|32|64|128|256)$/i['test'](String(D['value_type']))&&Number(D['value'])===0x5);const l=f['some'](D=>D['b_submission']);b['has_submission']=l;const m=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&D['value']);m['length']>0x0&&(b['const_addr_count']=m['length'],b['const_addr_list']=m['map'](D=>'#'+D['identifier']+'='+D['value'])['join'](',\x20'));const n=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&typeof D['value']==='string'&&(D['value']['toLowerCase']()==='0xaab'||D['value']['toLowerCase']()==='0xaaa'));if(n['length']>0x0){b['sys_addr_list']=n['map'](E=>'#'+E['identifier']+'='+E['value']+'('+E['name']+')')['join'](',\x20');const D=n['find'](E=>E['value']==='0xaab'&&E['name']&&!E['name']['toLowerCase']()['includes']('registrar')||E['value']==='0xaaa'&&E['name']&&!E['name']['toLowerCase']()['includes']('linker'));b['sys_addr_wrong']=D!==undefined;}const o=extractWitnessCodes(a?.['root']),p=o['filter'](E=>[0x6a,0x6b,0x6c]['includes'](E));if(p['length']>0x0){const E={0x6a:'Arb→Progress\x20(two\x20hops:\x20arb.order\x20→\x20order.progress)',0x6b:'Arb→Machine\x20(two\x20hops:\x20arb.order\x20→\x20order.machine)',0x6c:'Arb→Service\x20(two\x20hops:\x20arb.order\x20→\x20order.service)'};b['witness_multihop_codes']=p,b['witness_multihop_csv']=p['join'](',\x20'),b['witness_multihop_names_block']=p['map'](F=>'\x20\x20-\x20'+F+':\x20'+E[F])['join']('\x0a');}const q=extractWitnessIdentifierPairs(a?.['root']),r=q['filter'](F=>F['code']>=0x64&&F['code']<=0x6c);if(r['length']>0x0){const F=[],G=[];for(const {code:I,identifier:J}of r){const K=WITNESS_CHAIN[I];if(!K)continue;const L=K[0x0],M=f['find'](O=>O['identifier']===J);if(!M)continue;const N=I+'\x20('+K['join']('→')+')';M['object_type']?M['object_type']!==L&&F['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type='+M['object_type']+'\x20(expected\x20'+L+')')):G['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type\x20is\x20not\x20set\x20(expected\x20'+L+')'));if(K['length']===0x3){const O=K[0x1],P=f['some'](Q=>Q['object_type']===O);!P&&G['push']('witness\x20'+N+'\x20multi-hop\x20chain\x20expects\x20intermediate\x20'+(O+'\x20in\x20table,\x20but\x20no\x20entry\x20with\x20object_type='+O+'\x20found'));}}const H=[...F,...G];H['length']>0x0&&(b['rc2_02_issue_count']=H['length'],b['rc2_02_has_hard_mismatch']=F['length']>0x0,b['rc2_02_evidence_lines']=H['map'](Q=>'\x20\x20-\x20'+Q)['join']('\x0a'),b['rc2_02_evidence_csv']=H['join'](';\x20'));}if(b['has_witness']){const Q=d['includes']('repository')&&d['includes']('\x22query\x22'),R=d['includes']('progress_history')&&d['includes']('\x22query\x22');if(Q||R){const S=d['includes']('convert_number_address')||d['includes']('convert_address_number')||d['includes']('convert_u256')||d['includes']('convert_string');b['rc2_04_queries_repo']=Q,b['rc2_04_queries_progress_history']=R,b['rc2_04_has_conversion']=S,b['rc2_04_conversion_note']=S?'\x0aThe\x20current\x20Guard\x20already\x20uses\x20type\x20conversion\x20nodes,\x20but\x20ensure\x20the\x20conversion\x20direction\x20is\x20correct.':'\x0aWarning:\x20no\x20type\x20conversion\x20node\x20detected\x20in\x20the\x20current\x20Guard;\x20parameter\x20type\x20mismatch\x20risk\x20may\x20exist.',b['rc2_04_conversion_evidence']=S?'Type\x20conversion\x20node\x20in\x20use':'No\x20type\x20conversion\x20node\x20detected';}}b['scene_present']=g!==undefined;g&&(b['scene_id']=g['id'],b['scene_host_object']=g['host_object'],b['scene_binding_field']=g['binding_field'],b['scene_mutable_after_publish']=g['mutable_after_publish']);b['rc3_01_sharing_exempt']=g?.['id']==='service_order_allocators_guard'&&Array['isArray'](a?.['sharing_recipients'])&&a['sharing_recipients']['length']>0x0&&!a['sharing_recipients']['includes']('Signer');if(g?.['binding_field']==='voting_guard'){const T=f['filter'](U=>U['b_submission']&&['U8','U16','U32','U64','U128','U256']['includes'](U['value_type']));T['length']>0x0&&(b['rc3_02_numeric_count']=T['length'],b['rc3_02_numeric_list']=T['map'](U=>'#'+U['identifier']+'('+U['value_type']+')')['join'](',\x20'));}const s=f['filter'](U=>U['b_submission']&&U['value_type']==='Address');if(s['length']>0x0){b['rc3_03_submitted_addr_count']=s['length'];const U=s['filter'](V=>!V['object_type']);b['rc3_03_no_type_count']=U['length'],b['rc3_03_evidence']=U['length']>0x0?'Missing\x20object_type:\x20'+U['map'](V=>'#'+V['identifier'])['join'](',\x20'):'Annotated:\x20'+s['map'](V=>'#'+V['identifier']+'='+V['object_type'])['join'](',\x20');}if(s['length']>0x0){const V=o['some'](a2=>[0x64,0x65,0x66]['includes'](a2)),W=o['some'](a2=>[0x67]['includes'](a2)),X=o['some'](a2=>[0x68,0x69,0x6a,0x6b,0x6c]['includes'](a2)),Y=s['filter'](a2=>a2['object_type']==='Order'||V&&!a2['object_type']),Z=s['filter'](a2=>a2['object_type']==='Progress'||W&&!a2['object_type']),a0=s['filter'](a2=>a2['object_type']==='Arb'||X&&!a2['object_type']),a1=Y['length']>0x0||Z['length']>0x0||a0['length']>0x0;if(a1){const a2=['machine_forward_guard','service_order_allocators_guard','arbitration_usage_guard','arbitration_voting_guard','reward_claim','progress_submission_guard'],a3=g?.['id'],a4=!a3||a2['includes'](a3);if(a4){const a5=new Set([0x61b,0x618,0x4e2,0x57a,0x579]),a6=j['some'](a7=>a5['has'](a7));if(!a6){const a7=[];for(const a8 of Y){a7['push']('#'+a8['identifier']+(a8['object_type']?'(Order)':'(inferred\x20Order\x20via\x20witness\x20100-102)'));}for(const a9 of Z){a7['push']('#'+a9['identifier']+(a9['object_type']?'(Progress)':'(inferred\x20Progress\x20via\x20witness\x20103)'));}for(const aa of a0){a7['push']('#'+aa['identifier']+(aa['object_type']?'(Arb)':'(inferred\x20Arb\x20via\x20witness\x20104-108)'));}b['rc3_05_applies']=!![],b['rc3_05_critical']=a3!==undefined&&a3==='machine_forward_guard',b['rc3_05_unbound_csv']=a7['join'](',\x20'),b['rc3_05_scene_label']=a3??'unknown\x20scene\x20(conservative\x20flag)';}}}}if(g?.['id']==='service_order_allocators_guard'&&!b['has_signer_check']){const ab=a?.['sharing_recipients'],ac=ab!==undefined&&ab['length']>0x0,ad=ac&&ab['includes']('Signer');if(!(ac&&!ad)){const ae=isUnboundSignerTheft({'recipient_is_signer':ad,'caller_identity_constrained':![]});b['rc3_06_applies']=!![],b['rc3_06_signer_sharing']=ae,b['rc3_06_recipients_label']=ac?'['+ab['join'](',\x20')+']':'(not\x20provided\x20—\x20conservative\x20flag)',b['rc3_06_title_suffix']=ad?'sharing.who=Signer\x20confirmed\x20—\x20anyone\x20can\x20steal\x20100%\x20of\x20funds':'if\x20sharing.who=Signer,\x20anyone\x20can\x20steal\x20100%\x20of\x20funds',b['rc3_06_level_rationale']=ae?'Signer\x20sharing\x20confirmed\x20→\x20critical':'sharing\x20hint\x20absent\x20→\x20conservative\x20medium';}}if(b['has_signer_check']){const af=c['includes']('\x22logic_equal\x22'),ag=c['includes']('\x22logic_not_equal\x22');b['rc4_01_comparison_detail']=(af?'logic_equal(==)':'')+'\x20'+(ag?'logic_not_equal(!=)':''),b['rc4_01_comparison_ops']=(af?'==':'')+'\x20'+(ag?'!=':'');}if(b['has_clock_check']){const ah=d['includes']('logic_as_u256_greater_or_equal'),ai=d['includes']('logic_as_u256_greater');(ah||ai)&&(b['rc4_02_has_greater_or_equal']=ah,b['rc4_02_has_greater']=ai,b['rc4_02_comparison_ops']=(ah?'>=':'')+'\x20'+(ai?'>':''));}if(b['has_signer_check']&&!isSignerCheckInLogicOr(a?.['root'])){const aj=detectLevel1StrictBinding(a?.['root'],f);if(aj['detected']&&aj['entry']){const ak=aj['entry'];b['rc4_04_detected']=!![],b['rc4_04_entry_identifier']=ak['identifier'],b['rc4_04_entry_value']=ak['value'],b['rc4_04_entry_detail']='b_submission=false,\x20value=\x22'+ak['value']+'\x22'+(ak['name']?',\x20name=\x22'+ak['name']+'\x22':'');}}const t=rootAllQueriesNonZero(a?.['root']),u=()=>{const al=j['filter'](am=>!QUERY_INVARIANT_MAP['has'](am));if(al['length']===0x0)return'';return'Queries\x20without\x20non-zero\x20invariant:\x20'+al['map'](am=>{const an=GUARDQUERY['find'](ao=>ao['id']===am);return an?an['id']+'\x20('+an['name']+')':''+am;})['join'](',\x20');};b['root_has_logic_as_u256_greater_or_equal']&&d['includes']('\x22clock\x22')&&b['root_has_calc_number_add']&&b['root_has_query']&&!t&&(b['rx1_01_trigger']=!![],b['rx1_01_evidence']=u()||'Baseline\x20query\x20may\x20return\x200');b['root_has_logic_as_u256_greater']&&b['root_has_query']&&!t&&(b['rx1_02_trigger']=!![],b['rx1_02_evidence']=u()||'Query\x20may\x20return\x200');const v=Array['isArray'](h?.['guards'])?h['guards']:[];b['rely_guards_count']=v['length'],b['rely_is_or']=h?.['logic_or']===!![],b['rely_logic']=h?.['logic_or']?'OR':'AND';const w=d['includes']('repository')&&d['includes']('\x22query\x22'),x=f['some'](al=>al['b_submission']&&al['value_type']==='Address'&&al['object_type']==='Repository'),y=w&&x;b['rx1_11_self_rep_false']=y,b['rx1_11_warning_tail']=y?'\x0aWarning:\x20the\x20current\x20Guard\x20itself\x20queries\x20repository.data\x20and\x20the\x20Repository\x20address\x20comes\x20from\x20submission,\x20'+'so\x20its\x20own\x20rep=false\x20and\x20cannot\x20be\x20depended\x20on\x20by\x20other\x20Guards.':'',b['rx1_11_evidence']=y?'Self\x20rep=false\x20(repository.data\x20query\x20depends\x20on\x20submission)':'Self\x20rep\x20status\x20to\x20be\x20confirmed';if(l){const al=f['filter'](an=>an['b_submission']),am=al['filter'](an=>(an['name']??'')==='');am['length']>0x0&&(b['rx1_12_vague_count']=am['length'],b['rx1_12_vague_csv']=am['map'](an=>'identifier='+an['identifier']+',\x20name=\x22'+(an['name']??'')+'\x22')['join'](';\x20'));}if(g){const an=f['find'](ao=>!ao['b_submission']&&ao['value_type']==='Address'&&ao['object_type']===g['host_object']);an&&(b['rx1_13_detected']=!![],b['rx1_13_identifier']=an['identifier']);}const z=REENTRANCY_SPECS['find'](ao=>ao['sceneId']===g?.['id']);if(z){const ao=detectReentrancyProtection(a?.['root'],f,z);ao['state']!=='protected'&&(b['reentry_applicable']=!![],b['reentry_state']=ao['state'],b['reentry_scene_id']=z['sceneId'],b['reentry_rationale']=z['rationale'],b['reentry_mitigation']=z['mitigation'],ao['state']==='pseudo'&&(b['reentry_found_primitive']=ao['foundPrimitiveName']??''),b['reentry_evidence']=ao['evidence']);}const A=foldCertainOutcome(a?.['root'],f),B=A?.['outcome']==='true';b['tree_folds_always_true']=B;A&&A['outcome']==='false'&&(b['tree_folds_always_false']=!![],b['tree_folds_always_false_reason']=A['reason']);if(B)b['tree_folds_always_true_reason']=A['reason'];const C=g?.['binding_field']==='write_guard'||g?.['id']==='repository_write_guard';return b['write_guard_scene']=C,C&&(b['write_guard_no_identity_check']=!b['has_signer_check'],b['write_guard_open']=B||!b['has_signer_check']),b;}function guardRuleBook(){const a=getJudgmentDoc()['rules']['domains']['guard'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27guard\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function dataSourceClassFor(a){if(a['startsWith']('R-C1-'))return'type1_onchain_constant';if(a['startsWith']('R-C2-'))return'type2_witness_derived';if(a['startsWith']('R-C3-'))return'type3_submitted_object';if(a['startsWith']('R-C4-'))return'type4_system_context';return'cross_type';}function findingToGuardRisk(a){return{'id':a['rule_id'],'data_source_class':dataSourceClassFor(a['rule_id']),'level':a['level'],'category':a['dimension']??'data_source_trust','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'',...a['evidence']!==undefined?{'evidence':a['evidence']}:{},...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export function runGuardRulePack(a){const b=guardRuleBook();let c;try{c=guardRiskFacts(a);}catch{return[];}return evaluateRuleBook(b,c)['findings']['map'](findingToGuardRisk);}export function assembleGuardAssessment(a,b){const c=getOverallRiskLevel(b),d={};for(const h of b){d[h['data_source_class']]=(d[h['data_source_class']]??0x0)+0x1;}const e=generateStakeholderAdvice(b,a['scene']),f=b['some'](i=>i['level']==='critical')||b['filter'](i=>i['level']==='high')['length']>=0x2,g=generateGuardSummary(a);return{'guard_summary':g,'scene':a['scene'],'risks':b,'overall_risk':c,'risks_by_data_source':d,'stakeholder_advice':e,'needs_human_review':f};}function getOverallRiskLevel(a){if(a['some'](b=>b['level']==='critical'))return'critical';if(a['some'](b=>b['level']==='high'))return'high';if(a['some'](b=>b['level']==='medium'))return'medium';return'low';}function generateStakeholderAdvice(a,b){const c={};for(const d of a){for(const e of d['affected_stakeholders']){if(!c[e])c[e]=[];c[e]['push']('['+d['level']['toUpperCase']()+']\x20'+d['title']+':\x20'+d['mitigation']);}}if(b)switch(b['binding_field']){case'buy_guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Before\x20purchase,\x20verify\x20the\x20buy_guard\x20logic\x20to\x20ensure\x20your\x20identity/credentials\x20can\x20pass\x20validation');break;case'order_allocators':if(!c['provider'])c['provider']=[];c['provider']['push']('Verify\x20the\x20order_allocators\x20ordering\x20to\x20ensure\x20your\x20Allocator\x20will\x20not\x20be\x20skipped\x20by\x20preceding\x20conditions');break;case'voting_guard':if(!c['arbitrator'])c['arbitrator']=[];c['arbitrator']['push']('Confirm\x20the\x20voting\x20weight\x20source\x20is\x20trustworthy;\x20prefer\x20querying\x20EntityRegistrar\x20rather\x20than\x20user-submitted\x20data');break;case'Forward.guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Verify\x20the\x20Forward.guard\x20conditions\x20to\x20ensure\x20you\x20can\x20satisfy\x20the\x20advancement\x20criteria\x20and\x20avoid\x20locked\x20funds');break;}return c;}function generateGuardSummary(a){const b=[];b['push']('table\x20entries:\x20'+a['table']['length']);const c=a['table']['filter'](d=>d['b_submission'])['length'];return b['push']('submitted\x20data:\x20'+c+'\x20entries'),b['push']('root\x20type:\x20'+(a['root']?.['type']??'unknown')),a['rely']&&b['push']('rely:\x20'+a['rely']['guards']['length']+'\x20dependencies\x20('+(a['rely']['logic_or']?'OR':'AND')+')'),b['join'](',\x20');}export function getRiskSummary(a){return{'risk_count':a['risks']['length'],'critical_count':a['risks']['filter'](b=>b['level']==='critical')['length'],'high_count':a['risks']['filter'](b=>b['level']==='high')['length'],'needs_human_review':a['needs_human_review'],'top_risks':a['risks']['filter'](b=>b['level']==='critical'||b['level']==='high')['slice'](0x0,0x3)['map'](b=>b['title'])};}export function getRiskRulesCount(){return factoryRulePack('guard')?.['rules']['length']??0x0;}export const RISK_RULES=((()=>{const a=factoryRulePack('guard');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'data_source_class':dataSourceClassFor(b['rule_id']),'trigger':b['trigger']??'','check':c=>{const d=guardRuleBook()['find'](f=>f['rule_id']===b['rule_id']);if(!d)return null;const {findings:e}=evaluateRuleBook([d],guardRiskFacts(c));return e['length']>0x0?findingToGuardRisk(e[0x0]):null;}}));})());
|
|
@@ -44,5 +44,5 @@ export type FillGuardTemplateResult = {
|
|
|
44
44
|
missing?: string[];
|
|
45
45
|
};
|
|
46
46
|
export declare function fillGuardTemplate(templateId: string, params: Record<string, unknown>): FillGuardTemplateResult;
|
|
47
|
-
export declare const GUARD_TEMPLATES_VERSION = "1.
|
|
47
|
+
export declare const GUARD_TEMPLATES_VERSION = "1.1.0";
|
|
48
48
|
export declare const GUARD_TEMPLATES_COUNT: number;
|