Download scripts/analyze_chat_crosshair.py from nmarshall/urt-rs: direct link, hf CLI and curl.
- Browser
- Download file 6.73 kB
-
https://huggingface.co/nmarshall/urt-rs/resolve/main/scripts/analyze_chat_crosshair.py
- Command line
-
hf download hf://nmarshall/urt-rs/scripts/analyze_chat_crosshair.py
-
curl -L -o analyze_chat_crosshair.py https://huggingface.co/nmarshall/urt-rs/resolve/main/scripts/analyze_chat_crosshair.py
6.73 kB
| #!/usr/bin/env python3 | |
| """Recover bounded crosshair gates, finite float arithmetic and result routing.""" | |
| import json | |
| import math | |
| import struct | |
| from pathlib import Path | |
| from analyze_deferred_auth import partition_function,trace_slice,signed32 | |
| from analyze_game_cvars import vm_string | |
| from analyze_qvm import decode,write_json | |
| from analyze_vm_extensions import verified | |
| BASE=0x40000000 | |
| def bits(value): | |
| if not math.isfinite(value):raise ValueError('nonfinite float input') | |
| try:raw=struct.pack('<f',value) | |
| except (OverflowError,struct.error) as e:raise ValueError('float outside finite binary32') from e | |
| if not math.isfinite(struct.unpack('<f',raw)[0]):raise ValueError('float outside finite binary32') | |
| return signed32(struct.unpack('<I',raw)[0]) | |
| def number(word): | |
| value=struct.unpack('<f',struct.pack('<I',word&0xffffffff))[0] | |
| if not math.isfinite(value):raise ValueError('nonfinite float word') | |
| return value | |
| def float_slice(ins,start,stop,memory,locals_map,limit=256): | |
| """Isolated straight-line finite arithmetic, not a full QVM float runtime.""" | |
| if not 0<=start<=stop<=len(ins) or stop-start>limit:raise ValueError('invalid float slice bounds') | |
| m=dict(memory);m.update({BASE+k:v for k,v in locals_map.items()});stack=[];trace=[] | |
| def read(address): | |
| if address not in m:raise ValueError('unknown float-slice word') | |
| return m[address] | |
| for pc in range(start,stop): | |
| x=ins[pc];op,v=x['opcode'],x['operand'];trace.append(pc) | |
| needed={'LOAD4':1,'STORE4':2,'ADD':2,'MULF':2,'ADDF':2,'NEGF':1,'CVIF':1,'BLOCK_COPY':2}.get(op,0) | |
| if len(stack)<needed:raise ValueError('float-slice stack underflow') | |
| if op=='CONST':stack.append(v) | |
| elif op=='LOCAL':stack.append(BASE+v) | |
| elif op=='LOAD4':stack.append(read(stack.pop())) | |
| elif op=='STORE4': | |
| value,address=stack.pop(),stack.pop();m[address]=signed32(value) | |
| elif op=='ADD': | |
| b,a=stack.pop(),stack.pop();stack.append(signed32(a+b)) | |
| elif op in ['MULF','ADDF']: | |
| b,a=number(stack.pop()),number(stack.pop());stack.append(bits(a*b if op=='MULF' else a+b)) | |
| elif op=='NEGF':stack.append(bits(-number(stack.pop()))) | |
| elif op=='CVIF':stack.append(bits(float(signed32(stack.pop())))) | |
| elif op=='BLOCK_COPY': | |
| if v!=12:raise ValueError('unsupported block-copy width') | |
| source,destination=stack.pop(),stack.pop() | |
| if source%4 or destination%4:raise ValueError('unaligned block-copy fixture') | |
| values=[read(source+i) for i in [0,4,8]] | |
| for i,val in zip([0,4,8],values):m[destination+i]=val | |
| else:raise ValueError('unsupported float-slice opcode '+op) | |
| return {'trace':trace,'memory':m,'stack':stack} | |
| def main(): | |
| q=json.loads(Path('docs/research/qvm/qagame.json').read_text()) | |
| d=verified(Path(q['source']['member']['output']).read_bytes(),q['sha256']);h,ins=decode(d) | |
| obj,record=0x10000,0x20000 | |
| gates=[] | |
| for state,override in [(0,0),(2,0),(3,0),(4,0),(0,1)]: | |
| t=trace_slice(ins,186046,186084,{obj+520:record,record+4:state,record+4324:override}, | |
| {1144:obj},halt_on_leave=True,capture_stack=True) | |
| gates.append({'raw_state':state,'override':override,'trace':t}) | |
| origins=[] | |
| for position,height in [([1,2,3],0),([10,20,30],26),([-1,-2,-3],-8)]: | |
| output=0x30000;m={obj+24+4*i:bits(v) for i,v in enumerate(position)} | |
| m.update({obj+520:record,record+164:height}) | |
| t=float_slice(ins,288872,288901,m,{20:obj,24:output}) | |
| origins.append({'position':position,'height_integer':height,'trace':t, | |
| 'origin':[number(t['memory'][output+4*i]) for i in range(3)]}) | |
| vectors=[] | |
| # Supplied trig outputs: cardinal yaw/pitch and roll variation, not syscall execution. | |
| for label,sp,cp,sy,cy,sr,cr in [('forward',0,1,0,1,0,1),('yaw90',0,1,1,0,0,1), | |
| ('pitch90',1,0,0,1,0,1),('yaw180',0,1,0,-1,0,1),('roll90',0,1,0,1,1,0)]: | |
| trig={1092:bits(sp),1108:bits(cp),1096:bits(sy),1104:bits(cy),1088:bits(sr),1100:bits(cr)} | |
| t=float_slice(ins,186186,186297,{},trig) | |
| basis=[[number(t['memory'][BASE+k]) for k in offsets] for offsets in | |
| [[84,88,92],[96,100,104],[108,112,116]]] | |
| ep=float_slice(ins,186305,186332,{}, {120:bits(10),124:bits(20),128:bits(30), | |
| **{k:t['memory'][BASE+k] for k in [84,88,92]}}) | |
| vectors.append({'label':label,'supplied_trig_words':trig,'basis':basis,'trace':t, | |
| 'origin':[10,20,30],'endpoint_trace':ep, | |
| 'endpoint':[number(ep['memory'][BASE+k]) for k in [132,136,140]]}) | |
| trace_args=trace_slice(ins,186332,186356,{obj+520:record,record+140:7},{1144:obj}) | |
| results=[] | |
| for flag in [0,1,2]: | |
| t=trace_slice(ins,186356,186431,{}, {148:flag,156:bits(100),160:bits(200),164:bits(300),1144:obj}) | |
| results.append({'trace_word_offset4':flag,'endpoint':[100,200,300],'trace':t}) | |
| comparisons=[] | |
| for result in [0,1,-1]: | |
| t=trace_slice(ins,186411,186431,{}, {1084:result,1144:obj}) | |
| comparisons.append({'supplied_comparison_return':result,'trace':t}) | |
| abi=json.loads(Path('docs/research/qvm/qagame.abi-candidates.json').read_text()) | |
| if abi['sha256']!=q['sha256']:raise ValueError('ABI provenance mismatch') | |
| out={'source':q['source'],'sha256':q['sha256'],'dead_gate_traces':gates,'origin_traces':origins, | |
| 'basis_endpoint_traces':vectors,'trace_argument_trace':trace_args,'result_traces':results, | |
| 'comparison_return_traces':comparisons,'abi_reference_revision':abi['reference_revision'], | |
| 'trace_service_candidate':next(x for x in abi['syscalls'] if x['number']==24), | |
| 'constants':{'angle_scale_bits':1016003125,'angle_scale_float':number(1016003125), | |
| 'distance_bits':1189765120,'distance_float':number(1189765120)}, | |
| 'strings':{'78120':vm_string(d,h,78120)}, | |
| 'functions':{str(e):partition_function(ins,e,d,h) for e in [185212,288871,36306]}, | |
| 'limitations':'Bounded synthetic integer and separate finite binary32 straight-line arithmetic, not ' | |
| 'original runtime/full QVM. Trig outputs, trace status/endpoints and isolated comparison returns are ' | |
| 'supplied. CALLs return zero placeholders. Native trigonometry/collision, floating-point exceptional ' | |
| 'domains, actual string comparison/format/location output and platform parity remain open.'} | |
| write_json(Path('docs/research/chat-crosshair.json'),out) | |
| print('Recovered crosshair gate, origin/basis/endpoint arithmetic and trace-result routing') | |
| if __name__=='__main__':main() | |