diff --git a/crates/console/prometeu-bytecode/src/assembler.rs b/crates/console/prometeu-bytecode/src/assembler.rs index d39bd10..97282e6 100644 --- a/crates/console/prometeu-bytecode/src/assembler.rs +++ b/crates/console/prometeu-bytecode/src/assembler.rs @@ -379,18 +379,26 @@ pub fn assemble(src: &str) -> Result, AsmError> { emit_u16(op as u16, &mut out); emit_u32(parse_u32_any(ops)?, &mut out); } - "DYN_PACK" | "DYN_UNPACK" | "DYN_CAN_UNPACK" => { + "DYN_PACK" | "DYN_UNPACK" | "DYN_CAN_UNPACK" | "REF_IDENTITY_HASH" => { if ops.is_empty() { return Err(AsmError::MissingOperand(line.into())); } let opcode = match mn { "DYN_PACK" => CoreOpCode::DynPack, "DYN_UNPACK" => CoreOpCode::DynUnpack, + "REF_IDENTITY_HASH" => CoreOpCode::RefIdentityHash, _ => CoreOpCode::DynCanUnpack, }; emit_u16(opcode as u16, &mut out); emit_u32(parse_u32_any(ops)?, &mut out); } + "REF_IDENTITY_EQ" => { + let (a, b) = parse_keyvals(ops)?; + let (left, right) = parse_pair(a, "left", b, "right")?; + emit_u16(CoreOpCode::RefIdentityEq as u16, &mut out); + emit_u32(left, &mut out); + emit_u32(right, &mut out); + } "REF_IS_EXACT" | "REF_IMPLEMENTS" | "REF_TO_TRAIT" | "REF_CAST" => { if ops.is_empty() { return Err(AsmError::MissingOperand(line.into())); diff --git a/crates/console/prometeu-bytecode/src/disassembler.rs b/crates/console/prometeu-bytecode/src/disassembler.rs index 8d55d6f..f8ffecb 100644 --- a/crates/console/prometeu-bytecode/src/disassembler.rs +++ b/crates/console/prometeu-bytecode/src/disassembler.rs @@ -21,9 +21,9 @@ //! - Floats use exact bit-pattern format to prevent locale/rounding differences. //! - Ordering is the canonical decode order; no address prefixes are emitted. -use crate::DecodeError; use crate::decode_next; use crate::isa::core::{CoreOpCode, CoreOpCodeSpecExt}; +use crate::DecodeError; fn fmt_f64_bits(bits: u64) -> String { // Fixed-width 16 hex digits, lowercase. @@ -65,6 +65,7 @@ fn format_operand(op: CoreOpCode, imm: &[u8]) -> String { | CoreOpCode::Hostcall | CoreOpCode::DynPack | CoreOpCode::DynUnpack + | CoreOpCode::RefIdentityHash | CoreOpCode::DynCanUnpack | CoreOpCode::StructNew | CoreOpCode::ArrayNew @@ -88,6 +89,11 @@ fn format_operand(op: CoreOpCode, imm: &[u8]) -> String { let field = u32::from_le_bytes(imm[4..].try_into().unwrap()); format!("type={}, field={}", ty, field) } + CoreOpCode::RefIdentityEq => { + let left = u32::from_le_bytes(imm[..4].try_into().unwrap()); + let right = u32::from_le_bytes(imm[4..].try_into().unwrap()); + format!("left={}, right={}", left, right) + } CoreOpCode::RefIsExact | CoreOpCode::RefImplements | CoreOpCode::RefToTrait diff --git a/crates/console/prometeu-bytecode/src/opcode.rs b/crates/console/prometeu-bytecode/src/opcode.rs index b9d379e..9706952 100644 --- a/crates/console/prometeu-bytecode/src/opcode.rs +++ b/crates/console/prometeu-bytecode/src/opcode.rs @@ -192,6 +192,10 @@ pub enum OpCode { RefToTrait = 0x95, /// REF_CAST: source:TypeId, target:TypeId; requires validated Registry metadata. RefCast = 0x96, + /// Query a complete typed reference identity; source TypeId. + RefIdentityHash = 0x97, + /// Compare two complete typed references; left/right TypeIds. + RefIdentityEq = 0x98, // Registry-backed collection operations. cycles() is their base component. StructNew = 0xA0, @@ -278,6 +282,8 @@ impl TryFrom for OpCode { 0x94 => Ok(OpCode::RefImplements), 0x95 => Ok(OpCode::RefToTrait), 0x96 => Ok(OpCode::RefCast), + 0x97 => Ok(OpCode::RefIdentityHash), + 0x98 => Ok(OpCode::RefIdentityEq), 0xA0 => Ok(OpCode::StructNew), 0xA1 => Ok(OpCode::StructGet), 0xA2 => Ok(OpCode::StructSet), @@ -360,6 +366,8 @@ impl OpCode { OpCode::RefImplements => 4, OpCode::RefToTrait => 5, OpCode::RefCast => 4, + OpCode::RefIdentityHash => 8, + OpCode::RefIdentityEq => 4, OpCode::StructNew => 8, OpCode::StructGet => 3, OpCode::StructSet => 4, diff --git a/crates/console/prometeu-bytecode/src/opcode_spec.rs b/crates/console/prometeu-bytecode/src/opcode_spec.rs index 2e6132c..f98292a 100644 --- a/crates/console/prometeu-bytecode/src/opcode_spec.rs +++ b/crates/console/prometeu-bytecode/src/opcode_spec.rs @@ -596,6 +596,26 @@ impl OpCodeSpecExt for OpCode { may_trap: true, is_safepoint: false, }, + OpCode::RefIdentityHash => OpcodeSpec { + name: "REF_IDENTITY_HASH", + imm_bytes: 4, + pops: None, + pushes: None, + is_branch: false, + is_terminator: false, + may_trap: true, + is_safepoint: false, + }, + OpCode::RefIdentityEq => OpcodeSpec { + name: "REF_IDENTITY_EQ", + imm_bytes: 8, + pops: None, + pushes: None, + is_branch: false, + is_terminator: false, + may_trap: true, + is_safepoint: false, + }, OpCode::StructNew => OpcodeSpec { name: "STRUCT_NEW", imm_bytes: 4, diff --git a/crates/console/prometeu-bytecode/src/registry.rs b/crates/console/prometeu-bytecode/src/registry.rs index 475b123..a1648ba 100644 --- a/crates/console/prometeu-bytecode/src/registry.rs +++ b/crates/console/prometeu-bytecode/src/registry.rs @@ -52,6 +52,19 @@ pub enum TypeKind { Trait(Vec), Fn(Signature), } +impl TypeKind { + /// Categories supported by identity queries, not by legacy REF_* conversions. + pub fn is_identity_reference(&self) -> bool { + matches!( + self, + Self::Struct(_) + | Self::Array(_) + | Self::Fn(_) + | Self::Trait(_) + | Self::Builtin(BuiltinId::RANDOM) + ) + } +} #[derive(Debug, Clone, PartialEq, Eq)] pub struct TypeDecl { pub name: Option, diff --git a/crates/console/prometeu-bytecode/src/registry_instruction.rs b/crates/console/prometeu-bytecode/src/registry_instruction.rs index 51c6223..4433bd5 100644 --- a/crates/console/prometeu-bytecode/src/registry_instruction.rs +++ b/crates/console/prometeu-bytecode/src/registry_instruction.rs @@ -133,6 +133,23 @@ impl DecodedInstr<'_> { }; (source_layout.storage.slots, pushes) } + Op::RefIdentityHash | Op::RefIdentityEq => { + let (left, right) = if self.opcode == Op::RefIdentityHash { + (self.imm_u32().map_err(|_| malformed())?, None) + } else { + let (a, b) = self.imm_u32x2().map_err(|_| malformed())?; + (a, Some(b)) + }; + let mut pops = 0; + for id in std::iter::once(left).chain(right) { + let (decl, layout) = type_info(id)?; + if !decl.kind.is_identity_reference() { + return Err(bad_category(id)); + } + pops += layout.storage.slots; + } + (pops, 1) + } Op::FieldsPublish => { let schema = self.imm_u32().map_err(|_| malformed())?; let (decl, _) = type_info(schema)?; @@ -210,7 +227,11 @@ impl DecodedInstr<'_> { .get(field as usize) .ok_or_else(|| bad_category(id).member(field))?; let w = registry.type_layout(f.type_id).unwrap().storage.slots; - if op == Op::StructGet { (1, w) } else { (1 + w, 0) } + if op == Op::StructGet { + (1, w) + } else { + (1 + w, 0) + } } } } else { diff --git a/crates/console/prometeu-bytecode/tests/registry_isa.rs b/crates/console/prometeu-bytecode/tests/registry_isa.rs index 94d28b8..4a14ee2 100644 --- a/crates/console/prometeu-bytecode/tests/registry_isa.rs +++ b/crates/console/prometeu-bytecode/tests/registry_isa.rs @@ -34,6 +34,8 @@ fn all_typed_instructions_match_independent_bytes_and_costs() { ("REF_IMPLEMENTS source=16909060, target=84281096", &[0x94, 0, 4, 3, 2, 1, 8, 7, 6, 5], 4), ("REF_TO_TRAIT source=16909060, target=84281096", &[0x95, 0, 4, 3, 2, 1, 8, 7, 6, 5], 5), ("REF_CAST source=16909060, target=84281096", &[0x96, 0, 4, 3, 2, 1, 8, 7, 6, 5], 4), + ("REF_IDENTITY_HASH 16909060", &[0x97, 0, 4, 3, 2, 1], 8), + ("REF_IDENTITY_EQ left=16909060, right=84281096", &[0x98, 0, 4, 3, 2, 1, 8, 7, 6, 5], 4), ]; for &(text, bytes, cycles) in cases { assert_eq!(assemble(text).unwrap(), bytes); @@ -49,8 +51,8 @@ fn all_typed_instructions_match_independent_bytes_and_costs() { } } assert!(matches!( - decode_next(0, &[0x97, 0]), - Err(DecodeError::UnknownOpcode { opcode: 0x97, .. }) + decode_next(0, &[0x99, 0]), + Err(DecodeError::UnknownOpcode { opcode: 0x99, .. }) )); } #[test] @@ -68,6 +70,8 @@ fn slot_effects_resolve_semantic_widths_and_reference_categories() { ("REF_TO_TRAIT source=4, target=6", 1, 2), ("REF_TO_TRAIT source=6, target=6", 2, 2), ("REF_CAST source=6, target=4", 2, 1), + ("REF_IDENTITY_HASH 6", 2, 1), + ("REF_IDENTITY_EQ left=6, right=4", 3, 1), ] { let bytes = assemble(text).unwrap(); assert_eq!( @@ -94,6 +98,9 @@ fn invalid_type_immediates_are_contextual_load_errors() { "REF_IS_EXACT source=4, target=6", "REF_TO_TRAIT source=4, target=0", "REF_IMPLEMENTS source=0, target=6", + "REF_IDENTITY_HASH 0", + "REF_IDENTITY_HASH 3", + "REF_IDENTITY_EQ left=4, right=1", ] { let bytes = assemble(text).unwrap(); let e = decode_next(0, &bytes).unwrap().registry_stack_effect(®istry).unwrap_err(); @@ -114,6 +121,10 @@ fn assembler_rejects_missing_overflowing_or_ambiguous_type_ids() { "REF_CAST source=4", "REF_CAST source=4, target=5, target=6", "REF_CAST source=4, trait=6", + "REF_IDENTITY_HASH", + "REF_IDENTITY_HASH -1", + "REF_IDENTITY_EQ left=4", + "REF_IDENTITY_EQ left=4, target=5", ] { assert!(assemble(text).is_err(), "{text}"); } diff --git a/crates/console/prometeu-vm/src/builtins.rs b/crates/console/prometeu-vm/src/builtins.rs index 56748ae..84d92bc 100644 --- a/crates/console/prometeu-vm/src/builtins.rs +++ b/crates/console/prometeu-vm/src/builtins.rs @@ -235,12 +235,13 @@ pub type IntrinsicHostImplementation = pub enum IntrinsicImplementation { Host(IntrinsicHostImplementation), VmOwned, + BorrowedInline(crate::IntrinsicInlineImplementation), } impl IntrinsicImplementation { pub fn host_callback(self) -> Option { match self { Self::Host(f) => Some(f), - Self::VmOwned => None, + Self::VmOwned | Self::BorrowedInline(_) => None, } } } @@ -249,12 +250,14 @@ impl IntrinsicImplementation { pub enum IntrinsicCostModel { Fixed, RandomRejectionV1, + ArgumentUtf8BytesV1, } impl IntrinsicCostModel { pub const fn name(self) -> &'static str { match self { Self::Fixed => "fixed", Self::RandomRejectionV1 => "random_rejection_v1", + Self::ArgumentUtf8BytesV1 => "argument_utf8_bytes_v1", } } } @@ -266,11 +269,14 @@ pub struct IntrinsicMeta { pub name: &'static str, pub version: u16, pub arg_layout: &'static [AbiType], + pub arg_nullable: &'static [bool], pub ret_layout: &'static [AbiType], pub parameter_names: &'static [&'static str], /// Full fixed cost, or base cost for a variable model. pub cost_cycles: u64, pub cost_model: IntrinsicCostModel, + pub cost_arg_index: Option, + pub cost_per_byte: u64, pub attempt_cost_cycles: u64, pub max_attempts: u32, pub mutates_guest_state: bool, @@ -300,7 +306,16 @@ impl IntrinsicMeta { &self, values: &[Value], ) -> Result<(), IntrinsicExecutionError> { - Self::validate_values(values, self.arg_layout) + Self::validate_values(values, self.arg_layout)?; + for (index, (value, nullable)) in values.iter().zip(self.arg_nullable).enumerate() { + if matches!(value, Value::Null) && !nullable { + return Err(IntrinsicExecutionError::TypeMismatch { + index, + expected: self.arg_layout[index], + }); + } + } + Ok(()) } fn validate_values( @@ -563,10 +578,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "dot", version: 1, arg_layout: &VEC2_DOT_ARGS, + arg_nullable: &[false; VEC2_DOT_ARGS.len()], ret_layout: &SINGLE_FLOAT_RET, parameter_names: &["ax", "ay", "bx", "by"], cost_cycles: 10, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -580,10 +598,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "length", version: 1, arg_layout: &VEC2_LENGTH_ARGS, + arg_nullable: &[false; VEC2_LENGTH_ARGS.len()], ret_layout: &SINGLE_FLOAT_RET, parameter_names: &["x", "y"], cost_cycles: 40, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -597,10 +618,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "from_raw", version: 1, arg_layout: &INT_RET, + arg_nullable: &[false; INT_RET.len()], ret_layout: &COLOR_RET, parameter_names: &["raw"], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -614,10 +638,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "rgb", version: 1, arg_layout: &COLOR_RGB_ARGS, + arg_nullable: &[false; COLOR_RGB_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &["r", "g", "b"], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -631,10 +658,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "rgba", version: 1, arg_layout: &COLOR_RGBA_ARGS, + arg_nullable: &[false; COLOR_RGBA_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &["r", "g", "b", "a"], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -648,10 +678,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "html_rgba", version: 1, arg_layout: &COLOR_HTML_RGBA_ARGS, + arg_nullable: &[false; COLOR_HTML_RGBA_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &["value"], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -665,10 +698,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "gray_scale", version: 1, arg_layout: &INT_RET, + arg_nullable: &[false; INT_RET.len()], ret_layout: &COLOR_RET, parameter_names: &["value"], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -682,10 +718,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "hex", version: 1, arg_layout: &COLOR_ARGS, + arg_nullable: &[false; COLOR_ARGS.len()], ret_layout: &INT_RET, parameter_names: &["color"], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -699,10 +738,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "alpha", version: 1, arg_layout: &COLOR_ARGS, + arg_nullable: &[false; COLOR_ARGS.len()], ret_layout: &INT_RET, parameter_names: &["color"], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -716,10 +758,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "black", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -733,10 +778,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "white", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -750,10 +798,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "red", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -767,10 +818,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "green", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -784,10 +838,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "blue", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -801,10 +858,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "yellow", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -818,10 +878,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "orange", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -835,10 +898,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "indigo", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -852,10 +918,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "gray", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -869,10 +938,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "cyan", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -886,10 +958,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "magenta", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -903,10 +978,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [ name: "transparent", version: 1, arg_layout: &NO_ARGS, + arg_nullable: &[false; NO_ARGS.len()], ret_layout: &COLOR_RET, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, @@ -944,6 +1022,7 @@ pub fn lookup_intrinsic(owner: &str, name: &str, version: u16) -> Option<&'stati .chain(crate::input_intrinsics::INPUT_INTRINSICS.iter()) .chain(crate::math_intrinsics::MATH_INTRINSICS.iter()) .chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter()) + .chain(crate::hash_intrinsics::HASH_INTRINSICS.iter()) .find(|meta| meta.owner == owner && meta.name == name && meta.version == version) } @@ -953,6 +1032,7 @@ pub fn lookup_intrinsic_by_id(id: u32) -> Option<&'static IntrinsicMeta> { .chain(crate::input_intrinsics::INPUT_INTRINSICS.iter()) .chain(crate::math_intrinsics::MATH_INTRINSICS.iter()) .chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter()) + .chain(crate::hash_intrinsics::HASH_INTRINSICS.iter()) .find(|meta| meta.id == id) } @@ -1254,9 +1334,17 @@ pub(crate) fn metered_lookup_intrinsic( .chain(crate::input_intrinsics::INPUT_INTRINSICS.iter()) .chain(crate::math_intrinsics::MATH_INTRINSICS.iter()) .chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter()) + .chain(crate::hash_intrinsics::HASH_INTRINSICS.iter()) { budget.work(1)?; if meta.id == id { + budget.work(meta.arg_slots() + 1)?; + meta.validate_descriptor().map_err(|_| { + prometeu_bytecode::load_limits::LoadFailure::new( + prometeu_bytecode::load_limits::LoadCode::InvalidCode, + prometeu_bytecode::load_limits::LoadReason::NativeId, + ) + })?; return Ok(Some(meta)); } } @@ -1270,6 +1358,7 @@ pub fn intrinsic_catalog() -> impl Iterator { .chain(crate::input_intrinsics::INPUT_INTRINSICS.iter()) .chain(crate::math_intrinsics::MATH_INTRINSICS.iter()) .chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter()) + .chain(crate::hash_intrinsics::HASH_INTRINSICS.iter()) } pub fn builtin_constant_catalog() -> impl Iterator { BUILTIN_CONSTS.iter() diff --git a/crates/console/prometeu-vm/src/catalog.rs b/crates/console/prometeu-vm/src/catalog.rs index 1c49041..163cfb5 100644 --- a/crates/console/prometeu-vm/src/catalog.rs +++ b/crates/console/prometeu-vm/src/catalog.rs @@ -16,14 +16,15 @@ fn atom(t: AbiType) -> String { } pub fn intrinsic_catalog_csv() -> String { let mut out = String::from( - "final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts\n", + "final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts,schema_version,arg_nullable,invocation_model,scratch_model,context_access,cost_arg_index,cost_per_byte\n", ); let mut entries: Vec<_> = intrinsic_catalog().collect(); entries.sort_by_key(|m| m.id); for m in entries { + m.validate_descriptor().expect("valid canonical intrinsic descriptor"); writeln!( &mut out, - "0x{:04X},{},{}.{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}", + "0x{:04X},{},{}.{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},2,{},{},{},{},{},{}", m.id, m.id, m.owner, @@ -42,7 +43,13 @@ pub fn intrinsic_catalog_csv() -> String { m.mutates_guest_state, m.cost_model.name(), m.attempt_cost_cycles, - m.max_attempts + m.max_attempts, + m.arg_nullable.iter().map(bool::to_string).collect::>().join("|"), + m.invocation_model(), + m.scratch_model(), + m.context_access(), + m.cost_arg_index.map_or_else(String::new, |i| i.to_string()), + m.cost_per_byte ) .unwrap(); } diff --git a/crates/console/prometeu-vm/src/hash_intrinsics.rs b/crates/console/prometeu-vm/src/hash_intrinsics.rs new file mode 100644 index 0000000..fa60868 --- /dev/null +++ b/crates/console/prometeu-vm/src/hash_intrinsics.rs @@ -0,0 +1,66 @@ +use crate::{ + AbiType, BuiltinScalarType as S, IntrinsicCostModel as C, IntrinsicExecutionError as E, + IntrinsicImplementation as I, IntrinsicMeta, IntrinsicResults, +}; +use prometeu_bytecode::Value; + +const fn entry( + id: u32, + name: &'static str, + abi: AbiType, + nullable: bool, + handler: crate::IntrinsicInlineImplementation, +) -> IntrinsicMeta { + IntrinsicMeta { + id, + owner: "hash", + name, + version: 1, + arg_layout: match abi { + AbiType::Scalar(S::Int64) => &[AbiType::Scalar(S::Int64)], + AbiType::Scalar(S::Float) => &[AbiType::Scalar(S::Float)], + AbiType::Scalar(S::String) => &[AbiType::Scalar(S::String)], + _ => panic!("unsupported hash input ABI"), + }, + ret_layout: &[AbiType::Scalar(S::Int64)], + arg_nullable: if nullable { &[true] } else { &[false] }, + parameter_names: &["value"], + cost_cycles: 8, + cost_model: if matches!(abi, AbiType::Scalar(S::String)) { + C::ArgumentUtf8BytesV1 + } else { + C::Fixed + }, + cost_arg_index: if matches!(abi, AbiType::Scalar(S::String)) { Some(0) } else { None }, + cost_per_byte: if matches!(abi, AbiType::Scalar(S::String)) { 1 } else { 0 }, + attempt_cost_cycles: 0, + max_attempts: 0, + mutates_guest_state: false, + deterministic: true, + may_allocate: false, + implementation: I::BorrowedInline(handler), + } +} +pub(crate) const HASH_INTRINSICS: [IntrinsicMeta; 3] = [ + entry(0x4100, "i64", AbiType::Scalar(S::Int64), false, hash_i64), + entry(0x4101, "float", AbiType::Scalar(S::Float), false, hash_float), + entry(0x4102, "string", AbiType::Scalar(S::String), true, hash_string), +]; +fn hash_i64(args: &[Value], out: &mut IntrinsicResults) -> Result<(), E> { + let Value::Int64(value) = args[0] else { unreachable!("exact validated Int64") }; + out.push(Value::Int64(crate::hashing::xxh64(&value.to_le_bytes()) as i64)) +} +fn hash_float(args: &[Value], out: &mut IntrinsicResults) -> Result<(), E> { + let Value::Float(value) = args[0] else { unreachable!("exact validated Float") }; + crate::numeric::check_inputs(&[value])?; + let bits = if value == 0.0 { 0 } else { value.to_bits() }; + out.push(Value::Int64(crate::hashing::xxh64(&bits.to_le_bytes()) as i64)) +} +fn hash_string(args: &[Value], out: &mut IntrinsicResults) -> Result<(), E> { + let hash = match &args[0] { + Value::Null => 0, + Value::String(s) => crate::hashing::xxh64(s.as_bytes()) as i64, + _ => unreachable!("exact validated nullable String"), + }; + out.push(Value::Int64(hash)) +} diff --git a/crates/console/prometeu-vm/src/hashing.rs b/crates/console/prometeu-vm/src/hashing.rs new file mode 100644 index 0000000..878b19f --- /dev/null +++ b/crates/console/prometeu-vm/src/hashing.rs @@ -0,0 +1,131 @@ +//! Hash-v1: portable XXH64, seed zero, over explicit machine byte encodings. +use prometeu_bytecode::HeapRef; + +const P1: u64 = 0x9E3779B185EBCA87; +const P2: u64 = 0xC2B2AE3D27D4EB4F; +const P3: u64 = 0x165667B19E3779F9; +const P4: u64 = 0x85EBCA77C2B2AE63; +const P5: u64 = 0x27D4EB2F165667C5; + +fn word(bytes: &[u8]) -> u64 { + u64::from_le_bytes(bytes[..8].try_into().expect("complete XXH64 lane")) +} +fn round(acc: u64, lane: u64) -> u64 { + acc.wrapping_add(lane.wrapping_mul(P2)).rotate_left(31).wrapping_mul(P1) +} +fn merge(acc: u64, lane: u64) -> u64 { + (acc ^ round(0, lane)).wrapping_mul(P1).wrapping_add(P4) +} + +pub(crate) fn xxh64(mut bytes: &[u8]) -> u64 { + let length = bytes.len() as u64; + let mut hash = if bytes.len() >= 32 { + let mut acc = [P1.wrapping_add(P2), P2, 0, 0u64.wrapping_sub(P1)]; + while bytes.len() >= 32 { + for (index, value) in acc.iter_mut().enumerate() { + *value = round(*value, word(&bytes[index * 8..])); + } + bytes = &bytes[32..]; + } + let mut hash = acc[0] + .rotate_left(1) + .wrapping_add(acc[1].rotate_left(7)) + .wrapping_add(acc[2].rotate_left(12)) + .wrapping_add(acc[3].rotate_left(18)); + for value in acc { + hash = merge(hash, value); + } + hash + } else { + P5 + }; + hash = hash.wrapping_add(length); + while bytes.len() >= 8 { + hash ^= round(0, word(bytes)); + hash = hash.rotate_left(27).wrapping_mul(P1).wrapping_add(P4); + bytes = &bytes[8..]; + } + if bytes.len() >= 4 { + hash ^= u64::from(u32::from_le_bytes(bytes[..4].try_into().unwrap())).wrapping_mul(P1); + hash = hash.rotate_left(23).wrapping_mul(P2).wrapping_add(P3); + bytes = &bytes[4..]; + } + for byte in bytes { + hash ^= u64::from(*byte).wrapping_mul(P5); + hash = hash.rotate_left(11).wrapping_mul(P1); + } + hash ^= hash >> 33; + hash = hash.wrapping_mul(P2); + hash ^= hash >> 29; + hash = hash.wrapping_mul(P3); + hash ^ (hash >> 32) +} + +pub(crate) fn reference(value: Option) -> i64 { + value.map_or(0, |reference| { + let mut bytes = [0; 8]; + bytes[..4].copy_from_slice(&reference.index.to_le_bytes()); + bytes[4..].copy_from_slice(&reference.generation.to_le_bytes()); + xxh64(&bytes) as i64 + }) +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn matches_all_independent_c_reference_vectors() { + let mut count = 0; + for row in include_str!("../tests/fixtures/hash-conformance.tsv").lines().skip(1) { + let f: Vec<_> = row.split('\t').collect(); + let expected = u64::from_str_radix(f[2], 16).unwrap(); + let actual = match f[0] { + "bytes" | "string" => { + let bytes: Vec<_> = (0..f[1].len()) + .step_by(2) + .map(|i| u8::from_str_radix(&f[1][i..i + 2], 16).unwrap()) + .collect(); + xxh64(&bytes) + } + "i64" => xxh64(&f[1].parse::().unwrap().to_le_bytes()), + "float" => { + let bits = u64::from_str_radix(f[1], 16).unwrap(); + let bits = if f64::from_bits(bits) == 0.0 { 0 } else { bits }; + xxh64(&bits.to_le_bytes()) + } + "reference" => { + let (index, generation) = f[1].split_once(',').unwrap(); + reference(Some(HeapRef { + index: index.parse().unwrap(), + generation: generation.parse().unwrap(), + })) as u64 + } + "null" => reference(None) as u64, + kind => panic!("unknown vector {kind}"), + }; + assert_eq!(actual, expected, "{row}"); + count += 1; + } + assert_eq!(count, 118); + } + + #[test] + fn sequential_handles_spread_and_bucket_collisions_do_not_imply_identity() { + let mut buckets = [0; 256]; + let mut first = [None; 256]; + let mut collisions = 0; + for index in 1..=16384 { + let handle = HeapRef { index, generation: 1 }; + let bucket = reference(Some(handle)) as u64 as usize & 255; + buckets[bucket] += 1; + if let Some(previous) = first[bucket] { + assert_ne!(previous, handle); + collisions += 1; + } else { + first[bucket] = Some(handle); + } + } + assert!(buckets.iter().all(|&count| (32..=100).contains(&count)), "{buckets:?}"); + assert_eq!(collisions, 16384 - 256); + } +} diff --git a/crates/console/prometeu-vm/src/input_intrinsics.rs b/crates/console/prometeu-vm/src/input_intrinsics.rs index f0d1d71..5c6311b 100644 --- a/crates/console/prometeu-vm/src/input_intrinsics.rs +++ b/crates/console/prometeu-vm/src/input_intrinsics.rs @@ -20,10 +20,13 @@ const fn query( name, version: 1, arg_layout: &[], + arg_nullable: &[], ret_layout, parameter_names: &[], cost_cycles: 1, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, diff --git a/crates/console/prometeu-vm/src/intrinsic_contract.rs b/crates/console/prometeu-vm/src/intrinsic_contract.rs new file mode 100644 index 0000000..2df2ab2 --- /dev/null +++ b/crates/console/prometeu-vm/src/intrinsic_contract.rs @@ -0,0 +1,143 @@ +//! The native handler variant and descriptor jointly define the invocation contract. +use crate::{ + AbiType, BuiltinScalarType, IntrinsicCostModel, IntrinsicExecutionError as E, + IntrinsicImplementation as I, IntrinsicMeta, +}; +use prometeu_bytecode::Value; + +pub type IntrinsicInlineImplementation = fn(&[Value], &mut IntrinsicResults) -> Result<(), E>; +const INLINE_SLOTS: usize = 3; + +/// Fixed native staging only; no heap buffer or mutable execution context. +#[derive(Debug)] +pub struct IntrinsicResults { + values: [Value; INLINE_SLOTS], + len: usize, + limit: usize, + overflowed: bool, +} +impl IntrinsicResults { + pub(crate) fn new(limit: usize) -> Self { + assert!(limit <= INLINE_SLOTS); + Self { values: [const { Value::Null }; INLINE_SLOTS], len: 0, limit, overflowed: false } + } + pub fn push(&mut self, value: Value) -> Result<(), E> { + if self.len >= self.limit { + self.overflowed = true; + return Err(E::ArityMismatch { expected: self.limit, got: self.len + 1 }); + } + self.values[self.len] = value; + self.len += 1; + Ok(()) + } + pub(crate) fn validate(&self, meta: &IntrinsicMeta) -> Result<(), E> { + if self.overflowed { + return Err(E::ArityMismatch { expected: self.limit, got: self.limit + 1 }); + } + meta.validate_result_values(&self.values[..self.len]) + } + pub(crate) fn as_slice(&self) -> &[Value] { + &self.values[..self.len] + } + pub(crate) fn into_values(self) -> impl Iterator { + self.values.into_iter().take(self.len) + } +} + +impl IntrinsicMeta { + pub fn invocation_model(&self) -> &'static str { + match self.implementation { + I::Host(_) => "host_buffered_v1", + I::VmOwned => "vm_owned_v1", + I::BorrowedInline(_) => "borrowed_inline_v1", + } + } + pub fn scratch_model(&self) -> &'static str { + match self.implementation { + I::BorrowedInline(_) => "none", + _ => "existing_contract_v1", + } + } + pub fn context_access(&self) -> &'static str { + match self.implementation { + I::Host(_) => "host", + I::VmOwned => "vm_state", + I::BorrowedInline(_) => "none", + } + } + /// Derivation from the handler variant makes incompatible profile claims unrepresentable. + pub fn validate_descriptor(&self) -> Result<(), &'static str> { + if self.arg_nullable.len() != self.arg_slots() + || self.parameter_names.len() != self.arg_slots() + { + return Err("argument metadata widths disagree"); + } + for abi in self.arg_layout.iter().chain(self.ret_layout) { + if !matches!(abi, AbiType::Scalar(_)) + && !matches!(abi, AbiType::Builtin(key) if (key.name == "Random" || key.name == "color") && key.version == 1) + { + return Err("unsupported intrinsic ABI layout"); + } + } + for (abi, nullable) in self.arg_layout.iter().zip(self.arg_nullable) { + let permits_null = matches!(abi, AbiType::Scalar(BuiltinScalarType::String)) + || matches!(abi, AbiType::Builtin(key) if key.name == "Random" && key.version == 1); + if *nullable && !permits_null { + return Err("non-nullable ABI carrier declared nullable"); + } + } + match self.cost_model { + IntrinsicCostModel::Fixed => { + if self.cost_arg_index.is_some() + || self.cost_per_byte != 0 + || self.attempt_cost_cycles != 0 + || self.max_attempts != 0 + { + return Err("fixed cost has variable parameters"); + } + } + IntrinsicCostModel::RandomRejectionV1 => { + if !matches!(self.implementation, I::VmOwned) + || self.cost_arg_index.is_some() + || self.cost_per_byte != 0 + || self.attempt_cost_cycles == 0 + || self.max_attempts == 0 + { + return Err("invalid random rejection cost parameters"); + } + } + IntrinsicCostModel::ArgumentUtf8BytesV1 => { + if !matches!(self.implementation, I::BorrowedInline(_)) + || self.cost_arg_index.and_then(|i| self.arg_layout.get(i)) + != Some(&AbiType::Scalar(BuiltinScalarType::String)) + || self.cost_per_byte == 0 + || self.attempt_cost_cycles != 0 + || self.max_attempts != 0 + { + return Err("invalid String byte-cost parameters"); + } + } + } + if matches!(self.implementation, I::BorrowedInline(_)) + && (self.ret_slots() > INLINE_SLOTS + || self.ret_slots() > self.arg_slots() + || self.may_allocate + || self.mutates_guest_state + || !self.deterministic) + { + return Err("handler violates bounded invocation capabilities"); + } + Ok(()) + } + /// None is checked cost overflow. Wrong/missing carriers have no inferred length. + pub(crate) fn attempted_cost(&self, args: &[Value]) -> Option { + if self.cost_model != IntrinsicCostModel::ArgumentUtf8BytesV1 { + return Some(self.cost_cycles); + } + let bytes = match self.cost_arg_index.and_then(|i| args.get(i)) { + Some(Value::String(value)) => value.len() as u64, + _ => 0, + }; + bytes.checked_mul(self.cost_per_byte)?.checked_add(self.cost_cycles) + } +} diff --git a/crates/console/prometeu-vm/src/lib.rs b/crates/console/prometeu-vm/src/lib.rs index 7616b11..14d6515 100644 --- a/crates/console/prometeu-vm/src/lib.rs +++ b/crates/console/prometeu-vm/src/lib.rs @@ -2,7 +2,11 @@ extern crate self as prometeu_vm; mod builtins; mod catalog; +mod hash_intrinsics; +mod hashing; +mod intrinsic_contract; pub use catalog::{builtin_constant_catalog_csv, intrinsic_catalog_csv}; +pub use intrinsic_contract::{IntrinsicInlineImplementation, IntrinsicResults}; mod call_frame; mod input_intrinsics; mod math_intrinsics; diff --git a/crates/console/prometeu-vm/src/math_intrinsics.rs b/crates/console/prometeu-vm/src/math_intrinsics.rs index 0018f2b..cb6c0ff 100644 --- a/crates/console/prometeu-vm/src/math_intrinsics.rs +++ b/crates/console/prometeu-vm/src/math_intrinsics.rs @@ -20,10 +20,17 @@ const fn entry( name, version: 1, arg_layout, + arg_nullable: match arg_layout.len() { + 1 => &[false], + 2 => &[false, false], + _ => &[false, false, false], + }, ret_layout, parameter_names, cost_cycles, cost_model: crate::IntrinsicCostModel::Fixed, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: 0, max_attempts: 0, mutates_guest_state: false, diff --git a/crates/console/prometeu-vm/src/random_intrinsics.rs b/crates/console/prometeu-vm/src/random_intrinsics.rs index be96113..4a2793d 100644 --- a/crates/console/prometeu-vm/src/random_intrinsics.rs +++ b/crates/console/prometeu-vm/src/random_intrinsics.rs @@ -21,6 +21,13 @@ const fn entry( name, version: 1, arg_layout: args, + arg_nullable: if id == 0x4000 { + &[false] + } else if rejection { + &[true, false, false] + } else { + &[true] + }, ret_layout: ret, parameter_names: names, cost_cycles: cost, @@ -29,6 +36,8 @@ const fn entry( } else { IntrinsicCostModel::Fixed }, + cost_arg_index: None, + cost_per_byte: 0, attempt_cost_cycles: if rejection { 8 } else { 0 }, max_attempts: if rejection { crate::random::MAX_ATTEMPTS } else { 0 }, deterministic: true, diff --git a/crates/console/prometeu-vm/src/registry_verifier/types.rs b/crates/console/prometeu-vm/src/registry_verifier/types.rs index 9e95025..de32346 100644 --- a/crates/console/prometeu-vm/src/registry_verifier/types.rs +++ b/crates/console/prometeu-vm/src/registry_verifier/types.rs @@ -485,6 +485,10 @@ fn transfer( group(&mut working[base..], registry, ty, (instruction.pc as u64) << 32, budget)?; } } + Op::RefIdentityHash => { + budget.work(1)?; + working[base] = Fact::Carrier(I64); + } Op::RefCast | Op::RefToTrait => { group( &mut working[base..], @@ -503,6 +507,7 @@ fn transfer( | Op::And | Op::Or | Op::Not + | Op::RefIdentityEq | Op::RefIsExact | Op::RefImplements | Op::DynCanUnpack => { @@ -818,6 +823,21 @@ fn check( return Err(mismatch(1)); } } + Op::RefIdentityHash | Op::RefIdentityEq => { + let (left, right) = if instruction.opcode == Op::RefIdentityHash { + (instruction.imm_u32().unwrap(), None) + } else { + let (a, b) = instruction.imm_u32x2().unwrap(); + (a, Some(b)) + }; + let lw = registry.type_layout(TypeId(left)).unwrap().storage.slots as usize; + let rw = right + .map_or(0, |id| registry.type_layout(TypeId(id)).unwrap().storage.slots as usize); + check_group(&working[end - lw - rw..end - rw], TypeId(left), registry, budget)?; + if let Some(id) = right { + check_group(&working[end - rw..end], TypeId(id), registry, budget)?; + } + } Op::RefCast | Op::RefToTrait | Op::RefIsExact | Op::RefImplements => { budget.work(1)?; let ty = TypeId(instruction.imm_u32x2().unwrap().0); @@ -830,7 +850,12 @@ fn check( .unwrap(); let base = end - native.arg_slots(); for (part, abi) in native.arg_layout.iter().enumerate() { - require(working[base + part], abi_mask(*abi), part, registry, budget)?; + let accepted = if native.arg_nullable[part] { + abi_mask(*abi) | NULL + } else { + abi_mask(*abi) & !NULL + }; + require(working[base + part], accepted, part, registry, budget)?; } } Op::JmpIfTrue | Op::JmpIfFalse | Op::Not => { diff --git a/crates/console/prometeu-vm/src/value_contract.rs b/crates/console/prometeu-vm/src/value_contract.rs index 71b8264..9d54211 100644 --- a/crates/console/prometeu-vm/src/value_contract.rs +++ b/crates/console/prometeu-vm/src/value_contract.rs @@ -221,6 +221,24 @@ pub(crate) fn unpack_dynamic( // All reference operations validate complete source values before querying the // underlying concrete object. Invalid handles/pairs never become false or null. +pub(crate) fn identity_reference( + registry: &Registry, + heap: &Heap, + source: TypeId, + values: &[Value], +) -> Result, ValueError> { + let kind = registry.declarations().types.get(source.0 as usize).ok_or(ValueError::Type)?; + if !kind.kind.is_identity_reference() { + return Err(ValueError::Type); + } + validate(registry, heap, source, values)?; + match values.first() { + Some(Value::Null) => Ok(None), + Some(Value::HeapRef(reference)) => Ok(Some(*reference)), + _ => Err(ValueError::Type), + } +} + fn reference( registry: &Registry, heap: &Heap, diff --git a/crates/console/prometeu-vm/src/virtual_machine.rs b/crates/console/prometeu-vm/src/virtual_machine.rs index addf494..fb267a0 100644 --- a/crates/console/prometeu-vm/src/virtual_machine.rs +++ b/crates/console/prometeu-vm/src/virtual_machine.rs @@ -7,6 +7,8 @@ mod collections_tests; mod control; mod dynamic; mod gc; +mod identity; +mod intrinsic; mod lifecycle; mod loader; mod native_arrays; @@ -330,8 +332,10 @@ impl VirtualMachine { } let charged_math = if opcode == OpCode::Intrinsic { - lookup_intrinsic_by_id(instr.imm_u32().unwrap()) - .filter(|m| m.owner == "vec2" || m.owner == "mathf" || m.owner.starts_with("math.")) + lookup_intrinsic_by_id(instr.imm_u32().unwrap()).filter(|m| { + matches!(m.implementation, crate::IntrinsicImplementation::Host(_)) + && (m.owner == "vec2" || m.owner == "mathf" || m.owner.starts_with("math.")) + }) } else { None }; @@ -955,6 +959,12 @@ impl VirtualMachine { ) })?; + if matches!( + intrinsic.implementation, + crate::IntrinsicImplementation::BorrowedInline(_) + ) { + return self.execute_inline_intrinsic(intrinsic, pc_at_intrinsic); + } if matches!(intrinsic.implementation, crate::IntrinsicImplementation::VmOwned) { return self.execute_random(intrinsic, pc_at_intrinsic); } @@ -1086,6 +1096,15 @@ impl VirtualMachine { let (source, target) = instr.imm_u32x2().unwrap(); return self.execute_reference(opcode, source, target, start_pc as u32); } + OpCode::RefIdentityHash | OpCode::RefIdentityEq => { + let (left, right) = if opcode == OpCode::RefIdentityHash { + (instr.imm_u32().unwrap(), None) + } else { + let (left, right) = instr.imm_u32x2().unwrap(); + (left, Some(right)) + }; + return self.execute_identity(opcode, left, right, start_pc as u32); + } OpCode::FieldsPublish => { return self.execute_fields_publication(instr.imm_u32().unwrap(), start_pc as u32); } @@ -3910,3 +3929,7 @@ mod callable_tests; #[cfg(feature = "resource-diagnostics")] pub mod string_provenance_qualification; + +#[cfg(test)] +#[path = "virtual_machine/identity_tests.rs"] +mod identity_tests; diff --git a/crates/console/prometeu-vm/src/virtual_machine/identity.rs b/crates/console/prometeu-vm/src/virtual_machine/identity.rs new file mode 100644 index 0000000..c4c128b --- /dev/null +++ b/crates/console/prometeu-vm/src/virtual_machine/identity.rs @@ -0,0 +1,59 @@ +use super::*; +use crate::value_contract; +use prometeu_bytecode::registry::TypeId; + +impl VirtualMachine { + pub(super) fn execute_identity( + &mut self, + opcode: OpCode, + left: u32, + right: Option, + pc: u32, + ) -> Result<(), LogicalFrameEndingReason> { + let image = self.validated_image.clone().ok_or_else(|| { + self.trap( + prometeu_bytecode::TRAP_ILLEGAL_INSTRUCTION, + opcode as u16, + "Identity instruction requires a validated Registry".into(), + pc, + ) + })?; + let registry = image.registry(); + let left = TypeId(left); + let right = right.map(TypeId); + let lw = registry.type_layout(left).unwrap().storage.slots as usize; + let rw = right.map_or(0, |ty| registry.type_layout(ty).unwrap().storage.slots as usize); + self.cycles += opcode.cycles() + (lw + rw) as u64; + if self.temporary_slots() < lw + rw { + return Err(self.trap( + TRAP_STACK_UNDERFLOW, + opcode as u16, + "Incomplete identity operands".into(), + pc, + )); + } + let base = self.operand_stack.len() - lw - rw; + let first = value_contract::identity_reference( + registry, + &self.heap, + left, + &self.operand_stack[base..base + lw], + ) + .map_err(|e| self.value_trap(e, opcode, pc))?; + let result = if let Some(ty) = right { + let second = value_contract::identity_reference( + registry, + &self.heap, + ty, + &self.operand_stack[base + lw..], + ) + .map_err(|e| self.value_trap(e, opcode, pc))?; + Value::Boolean(first == second) + } else { + Value::Int64(crate::hashing::reference(first)) + }; + self.operand_stack.truncate(base); + self.operand_stack.push(result).expect("identity result replaces existing inputs"); + Ok(()) + } +} diff --git a/crates/console/prometeu-vm/src/virtual_machine/identity_tests.rs b/crates/console/prometeu-vm/src/virtual_machine/identity_tests.rs new file mode 100644 index 0000000..2f17a41 --- /dev/null +++ b/crates/console/prometeu-vm/src/virtual_machine/identity_tests.rs @@ -0,0 +1,236 @@ +use super::*; +#[path = "../../tests/support/identity.rs"] +mod support; +use crate::{ + IntrinsicExecutionError, IntrinsicImplementation, IntrinsicMeta, IntrinsicResults, + hash_intrinsics::HASH_INTRINSICS, +}; +use prometeu_bytecode::{HeapRef, RuntimeResource as Q, registry::TypeId}; +use std::sync::Arc; +use support::*; + +fn empty() -> VirtualMachine { + vm(&[("RET", sig(&[], &[]))], &[]) +} +fn push(v: &mut VirtualMachine, values: &[Value]) { + for value in values { + v.operand_stack.push(value.clone()).unwrap(); + } +} +fn usage(v: &VirtualMachine) -> Vec { + [ + Q::GuestBytes, + Q::HandleSlots, + Q::AuxiliaryBytes, + Q::TemporaryBytes, + Q::StringBytes, + Q::StringAllocations, + ] + .map(|q| v.budget.used(q)) + .to_vec() +} +fn fault(result: Result<(), LogicalFrameEndingReason>, expected: u32) { + assert!( + matches!(result,Err(LogicalFrameEndingReason::Trap(ref t)) if t.code==expected), + "{result:?}" + ); +} +fn hash(v: &mut VirtualMachine, ty: u32, values: &[Value]) -> i64 { + push(v, values); + v.execute_identity(OpCode::RefIdentityHash, ty, None, 0).unwrap(); + let Value::Int64(value) = v.operand_stack.pop().unwrap() else { panic!() }; + value +} + +#[test] +fn identity_faults_preserve_complete_groups_and_charge_once_in_left_to_right_order() { + let mut v = empty(); + let registry = v.validated_image.as_ref().unwrap().registry().clone(); + let live = v.heap.allocate_typed_struct(registry.clone(), TypeId(5)).unwrap(); + let wrong = v.heap.allocate_typed_struct(registry, TypeId(11)).unwrap(); + let stale = HeapRef { index: 999999, generation: 1 }; + for (left, right, values, code) in [ + (5, None, vec![Value::HeapRef(stale)], TRAP_INVALID_HANDLE), + (5, None, vec![Value::HeapRef(wrong)], TRAP_TYPE), + (5, None, vec![Value::HeapRef(HeapRef::NULL)], TRAP_TYPE), + (6, None, vec![Value::HeapRef(live)], TRAP_TYPE), + (9, None, vec![Value::HeapRef(HeapRef::NULL)], TRAP_TYPE), + (10, None, vec![Value::HeapRef(HeapRef::NULL)], TRAP_INVALID_HANDLE), + (7, None, vec![Value::Null, Value::Int64(0)], TRAP_TYPE), + (7, None, vec![Value::HeapRef(live), Value::Null], TRAP_TYPE), + (7, None, vec![Value::HeapRef(live), Value::Int64(1)], TRAP_TYPE), + (7, None, vec![Value::HeapRef(live), Value::Int64(-1)], TRAP_TYPE), + (7, None, vec![Value::HeapRef(live), Value::Int64(999)], TRAP_TYPE), + (7, None, vec![Value::HeapRef(stale), Value::Int64(0)], TRAP_INVALID_HANDLE), + // A null left side still validates the complete right group. + (5, Some(7), vec![Value::Null, Value::HeapRef(live), Value::Int64(1)], TRAP_TYPE), + (5, Some(11), vec![Value::Null, Value::HeapRef(stale)], TRAP_INVALID_HANDLE), + // Both invalid: left TYPE takes precedence over right INVALID_HANDLE. + (5, Some(5), vec![Value::HeapRef(wrong), Value::HeapRef(stale)], TRAP_TYPE), + ] { + v.operand_stack.truncate(8); // Entry's eight reserved local slots. + push(&mut v, &values); + let operands = v.operand_stack.as_slice().to_vec(); + let before = usage(&v); + let cycles = v.cycles; + let op = if right.is_some() { OpCode::RefIdentityEq } else { OpCode::RefIdentityHash }; + let width = if left == 7 { 2 } else { 1 } + right.map_or(0, |r| if r == 7 { 2 } else { 1 }); + fault(v.execute_identity(op, left, right, 0), code); + assert_eq!(v.operand_stack.as_slice(), operands); + assert_eq!(usage(&v), before); + assert_eq!(v.cycles - cycles, op.cycles() + width); + } + v.operand_stack.truncate(8); + let before = v.cycles; + fault(v.execute_identity(OpCode::RefIdentityEq, 7, Some(7), 0), TRAP_STACK_UNDERFLOW); + assert_eq!(v.cycles - before, 8); +} + +#[test] +fn gc_preserves_live_aliases_but_hashes_do_not_root_collected_handles() { + let mut v = empty(); + let registry = v.validated_image.as_ref().unwrap().registry().clone(); + let live = v.heap.allocate_typed_struct(registry.clone(), TypeId(5)).unwrap(); + let dead = v.heap.allocate_typed_struct(registry.clone(), TypeId(5)).unwrap(); + let live_hash = hash(&mut v, 5, &[Value::HeapRef(live)]); + let dead_hash = hash(&mut v, 5, &[Value::HeapRef(dead)]); + v.globals.push(Value::HeapRef(live)).unwrap(); + v.globals.push(Value::Int64(dead_hash)).unwrap(); + v.gc_alloc_threshold = 1; + v.handle_safepoint().unwrap(); + assert!(v.heap.is_valid(live)); + assert!(!v.heap.is_valid(dead)); + assert_eq!(hash(&mut v, 7, &[Value::HeapRef(live), Value::Int64(0)]), live_hash); + let replacement = v.heap.allocate_typed_struct(registry, TypeId(5)).unwrap(); + assert_eq!(replacement.index, dead.index); + assert_ne!(replacement.generation, dead.generation); + push(&mut v, &[Value::HeapRef(dead), Value::HeapRef(replacement)]); + fault(v.execute_identity(OpCode::RefIdentityEq, 5, Some(5), 0), TRAP_INVALID_HANDLE); +} + +#[test] +fn new_queries_ignore_exhausted_guest_and_scratch_quotas_and_do_not_collect() { + let mut v = empty(); + let registry = v.validated_image.as_ref().unwrap().registry().clone(); + let live = v.heap.allocate_typed_struct(registry, TypeId(5)).unwrap(); + push(&mut v, &[Value::HeapRef(live)]); + for q in [ + Q::GuestBytes, + Q::HandleSlots, + Q::AuxiliaryBytes, + Q::TemporaryBytes, + Q::StringBytes, + Q::StringAllocations, + ] { + v.budget.test_lower_limit(q, v.budget.used(q)); + } + let before = usage(&v); + let allocations = v.heap.allocation_count(); + v.gc_alloc_threshold = 1; + v.execute_identity(OpCode::RefIdentityHash, 5, None, 0).unwrap(); + v.execute_inline_intrinsic(&HASH_INTRINSICS[0], 0).unwrap(); + assert_eq!(v.heap.allocation_count(), allocations); + assert!(v.heap.is_valid(live)); // No root remains, but neither operation is a safepoint. + assert_eq!(usage(&v), before); +} + +#[test] +fn inline_faults_preserve_float_bits_owners_and_attempted_cost() { + let mut v = empty(); + for bits in [f64::INFINITY.to_bits(), f64::NEG_INFINITY.to_bits(), 0x7ff8000000001234] { + push(&mut v, &[Value::Float(f64::from_bits(bits))]); + let before = usage(&v); + let cycles = v.cycles; + fault( + v.execute_inline_intrinsic(&HASH_INTRINSICS[1], 0), + prometeu_bytecode::TRAP_NON_FINITE, + ); + assert!(matches!(v.operand_stack.last(),Some(Value::Float(f)) if f.to_bits()==bits)); + assert_eq!(usage(&v), before); + assert_eq!(v.cycles - cycles, 8); + v.operand_stack.pop(); + } + let foreign: Arc = Arc::from("owner outside image and session"); + push(&mut v, &[Value::String(foreign.clone())]); + let refs = Arc::strong_count(&foreign); + let before = usage(&v); + let cycles = v.cycles; + fault(v.execute_inline_intrinsic(&HASH_INTRINSICS[2], 0), TRAP_TYPE); + assert_eq!(Arc::strong_count(&foreign), refs); + assert_eq!(usage(&v), before); + assert_eq!(v.cycles - cycles, 8 + foreign.len() as u64); + let mut overflow = HASH_INTRINSICS[2].clone(); + overflow.cost_per_byte = u64::MAX; + let cycles = v.cycles; + fault(v.execute_inline_intrinsic(&overflow, 0), TRAP_RESOURCE_LIMIT); + assert_eq!(v.cycles - cycles, 8); + assert_eq!(Arc::strong_count(&foreign), refs); + v.operand_stack.pop(); + let cycles = v.cycles; + fault(v.execute_inline_intrinsic(&HASH_INTRINSICS[2], 0), TRAP_STACK_UNDERFLOW); + assert_eq!(v.cycles - cycles, 8); + push(&mut v, &[Value::Int64(7)]); + let cycles = v.cycles; + fault(v.execute_inline_intrinsic(&HASH_INTRINSICS[2], 0), TRAP_TYPE); + assert_eq!(v.cycles - cycles, 8); + assert_eq!(v.operand_stack.last(), Some(&Value::Int64(7))); +} + +#[test] +fn equal_string_content_hashes_across_image_session_and_import_owners() { + use prometeu_bytecode::model::ConstantPoolEntry as K; + let mut v = vm( + &[("PUSH_CONST 0\nINTRINSIC 0x4102\nRET", sig(&[], &[0]))], + &[K::String("same\0π".into())], + ); + step(&mut v).unwrap(); + let Value::String(image_owner) = v.operand_stack.last().unwrap().clone() else { panic!() }; + v.strings = Some(crate::string_ledger::StringLedger::new(v.budget.clone()).unwrap()); + let session = v.strings.as_ref().unwrap().concat("same", "\0π").unwrap(); + let imported = v.strings.as_ref().unwrap().import("same\0π").unwrap(); + assert!(!Arc::ptr_eq(&session, &imported)); + let mut hashes = vec![]; + v.operand_stack.pop(); + for owner in [&image_owner, &session, &imported] { + push(&mut v, &[Value::String(owner.clone())]); + let before = usage(&v); + let count = Arc::strong_count(owner); + v.execute_inline_intrinsic(&HASH_INTRINSICS[2], 0).unwrap(); + assert_eq!(usage(&v), before); + assert_eq!(Arc::strong_count(owner), count - 1); + hashes.push(v.operand_stack.pop().unwrap()); + } + assert!(hashes.windows(2).all(|pair| pair[0] == pair[1])); +} + +fn missing(_: &[Value], _: &mut IntrinsicResults) -> Result<(), IntrinsicExecutionError> { + Ok(()) +} +fn wrong(_: &[Value], out: &mut IntrinsicResults) -> Result<(), IntrinsicExecutionError> { + out.push(Value::Boolean(true)) +} +fn excess(_: &[Value], out: &mut IntrinsicResults) -> Result<(), IntrinsicExecutionError> { + out.push(Value::Int64(1))?; + let _ = out.push(Value::Int64(2)); // Ignoring the error cannot publish a partial result. + Ok(()) +} +#[test] +fn shared_invocation_rejects_bad_outputs_without_consuming_original_string_owner() { + let mut v = empty(); + let Value::String(content) = v.import_string_value(&Value::String(Arc::from("kept"))).unwrap() + else { + panic!() + }; + push(&mut v, &[Value::String(content.clone())]); + let count = Arc::strong_count(&content); + let before = usage(&v); + for handler in [missing, wrong, excess] { + let mut meta: IntrinsicMeta = HASH_INTRINSICS[2].clone(); + meta.owner = "test"; // The shared executor is independent of the hash namespace. + meta.implementation = IntrinsicImplementation::BorrowedInline(handler); + fault(v.execute_inline_intrinsic(&meta, 0), TRAP_INVALID_INTRINSIC); + assert_eq!(Arc::strong_count(&content), count); + assert_eq!(usage(&v), before); + assert!(matches!(v.operand_stack.last(),Some(Value::String(s)) if Arc::ptr_eq(s,&content))); + } +} diff --git a/crates/console/prometeu-vm/src/virtual_machine/intrinsic.rs b/crates/console/prometeu-vm/src/virtual_machine/intrinsic.rs new file mode 100644 index 0000000..1f4db92 --- /dev/null +++ b/crates/console/prometeu-vm/src/virtual_machine/intrinsic.rs @@ -0,0 +1,113 @@ +//! Shared borrowed invocation; algorithms receive no host/VM context. +use super::*; +use crate::{ + AbiType, IntrinsicExecutionError as E, IntrinsicImplementation as I, IntrinsicMeta, + IntrinsicResults, +}; + +impl VirtualMachine { + fn inline_values( + &self, + values: &[Value], + layout: &[AbiType], + ) -> Result<(), crate::value_contract::ValueError> { + use crate::value_contract::ValueError; + for (value, abi) in values.iter().zip(layout) { + match value { + Value::String(content) if self.validated_image.is_some() => { + if !self.validated_image.as_ref().unwrap().retains_string(content) + && !self.strings.as_ref().is_some_and(|domain| domain.retains(content)) + { + return Err(ValueError::Type); + } + } + Value::HeapRef(reference) if matches!(abi, AbiType::Builtin(key) if key.name == "Random") => + { + self.heap.random_state(*reference)?; + } + _ => {} + } + } + Ok(()) + } + + pub(super) fn execute_inline_intrinsic( + &mut self, + meta: &IntrinsicMeta, + pc: u32, + ) -> Result<(), LogicalFrameEndingReason> { + let op = OpCode::Intrinsic; + let consumed = meta.arg_slots(); + let enough = self.temporary_slots() >= consumed; + let args = + if enough { &self.operand_stack[self.operand_stack.len() - consumed..] } else { &[] }; + let Some(cost) = meta.attempted_cost(args) else { + self.cycles += meta.cost_cycles; + return Err(self.trap( + TRAP_RESOURCE_LIMIT, + op as u16, + "Intrinsic attempted cost overflow".into(), + pc, + )); + }; + self.cycles += cost; + meta.validate_descriptor() + .map_err(|message| self.trap(TRAP_INVALID_INTRINSIC, op as u16, message.into(), pc))?; + if !enough { + return Err(self.trap( + TRAP_STACK_UNDERFLOW, + op as u16, + "Incomplete intrinsic operands".into(), + pc, + )); + } + let I::BorrowedInline(handler) = meta.implementation else { + return Err(self.trap( + TRAP_INVALID_INTRINSIC, + op as u16, + "Wrong invocation profile".into(), + pc, + )); + }; + let base = self.operand_stack.len() - consumed; + let args = &self.operand_stack[base..]; + meta.validate_argument_values(args).map_err(|_| { + self.trap(TRAP_TYPE, op as u16, "Invalid intrinsic argument carrier".into(), pc) + })?; + self.inline_values(args, meta.arg_layout) + .map_err(|error| self.value_trap(error, op, pc))?; + let mut out = IntrinsicResults::new(meta.ret_slots()); + handler(args, &mut out).map_err(|error| match error { + E::Numeric(error) => { + self.trap(error.code, op as u16, format!("Intrinsic numeric fault: {error:?}"), pc) + } + _ => self.trap( + TRAP_INVALID_INTRINSIC, + op as u16, + format!("Invalid intrinsic handler output: {error:?}"), + pc, + ), + })?; + out.validate(meta).map_err(|error| { + self.trap( + TRAP_INVALID_INTRINSIC, + op as u16, + format!("Invalid intrinsic result: {error:?}"), + pc, + ) + })?; + self.inline_values(out.as_slice(), meta.ret_layout).map_err(|_| { + self.trap( + TRAP_INVALID_INTRINSIC, + op as u16, + "Invalid intrinsic result ownership".into(), + pc, + ) + })?; + self.operand_stack.truncate(base); + for value in out.into_values() { + self.operand_stack.push(value).expect("bounded result replaces admitted inputs"); + } + Ok(()) + } +} diff --git a/crates/console/prometeu-vm/tests/execution_allocations.rs b/crates/console/prometeu-vm/tests/execution_allocations.rs index 8e1d1f1..205e576 100644 --- a/crates/console/prometeu-vm/tests/execution_allocations.rs +++ b/crates/console/prometeu-vm/tests/execution_allocations.rs @@ -134,3 +134,96 @@ fn provenance_queries_allocate_nothing_at_all_qualification_sizes() { assert_eq!(counts, (1, 1), "only snapshot Value storage allocates"); } } + +#[path = "support/identity.rs"] +mod identity_support; + +#[test] +fn identity_and_borrowed_hash_instruction_regions_do_not_allocate() { + use prometeu_bytecode::model::ConstantPoolEntry as K; + for (name, initialize, operand, operation, steps, closure) in [ + ("hash_i64", "PUSH_I64 -73\nSET_LOCAL 0", "GET_LOCAL 0", "INTRINSIC 0x4100", 4, false), + ("hash_float", "PUSH_CONST 0\nSET_LOCAL 0", "GET_LOCAL 0", "INTRINSIC 0x4101", 4, false), + ("hash_string", "PUSH_CONST 1\nSET_LOCAL 0", "GET_LOCAL 0", "INTRINSIC 0x4102", 4, false), + ( + "struct_hash", + "STRUCT_NEW 5\nSET_LOCAL 0", + "GET_LOCAL 0", + "REF_IDENTITY_HASH 5", + 4, + false, + ), + ( + "array_hash", + "PUSH_I64 0\nARRAY_NEW 6\nSET_LOCAL 0", + "GET_LOCAL 0", + "REF_IDENTITY_HASH 6", + 4, + false, + ), + ( + "fn_hash", + "MAKE_CLOSURE fn=1,type=9\nSET_LOCAL 0", + "GET_LOCAL 0", + "REF_IDENTITY_HASH 9", + 4, + true, + ), + ( + "random_hash", + "PUSH_I64 1\nINTRINSIC 0x4000\nSET_LOCAL 0", + "GET_LOCAL 0", + "REF_IDENTITY_HASH 10", + 4, + false, + ), + ( + "trait_hash", + "STRUCT_NEW 5\nREF_TO_TRAIT source=5,target=7\nSET_LOCAL 1\nSET_LOCAL 0", + "GET_LOCAL 0\nGET_LOCAL 1", + "REF_IDENTITY_HASH 7", + 5, + false, + ), + ( + "struct_eq", + "STRUCT_NEW 5\nSET_LOCAL 0", + "GET_LOCAL 0\nGET_LOCAL 0", + "REF_IDENTITY_EQ left=5,right=5", + 5, + false, + ), + ( + "trait_eq", + "STRUCT_NEW 5\nREF_TO_TRAIT source=5,target=7\nSET_LOCAL 1\nSET_LOCAL 0", + "GET_LOCAL 0\nGET_LOCAL 1\nGET_LOCAL 0\nGET_LOCAL 1", + "REF_IDENTITY_EQ left=7,right=7", + 7, + false, + ), + ] { + let start = assemble(initialize).unwrap().len(); + let text = format!("{initialize}\n{operand}\n{operation}\nPOP\nJMP {start}"); + let mut bodies = vec![(text.as_str(), identity_support::sig(&[], &[]))]; + if closure { + bodies.push(("RET", identity_support::sig(&[], &[]))); + } + let mut vm = + identity_support::vm(&bodies, &[K::Float64(-0.0), K::String("π\0".repeat(512))]); + let mut host = HostContext::new(None); + while vm.pc() != start { + vm.step(&mut identity_support::Native, &mut host).unwrap(); + } + for _ in 0..steps * 10 { + vm.step(&mut identity_support::Native, &mut host).unwrap(); + } + let heap_allocations = vm.heap().allocation_count(); + COUNTS.with(|c| c.set(Some((0, 0)))); + for _ in 0..steps * 1000 { + vm.step(&mut identity_support::Native, &mut host).unwrap(); + } + let counts = COUNTS.with(|c| c.replace(None).unwrap()); + assert_eq!(counts, (0, 0), "{name}: allocations and deallocations"); + assert_eq!(vm.heap().allocation_count(), heap_allocations, "{name}: guest allocations"); + } +} diff --git a/crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv b/crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv new file mode 100644 index 0000000..e5f3491 --- /dev/null +++ b/crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv @@ -0,0 +1,119 @@ +kind input expected_hash_hex +bytes EF46DB3751D8E999 +bytes 11 AD10CD9780AC4FF7 +bytes 1194 B22635899E8F2235 +bytes 119417 40626D96276E4594 +bytes 1194179a 882207C122C76E23 +bytes 1194179a1d A3DA885EEC618BB4 +bytes 1194179a1da0 AD9C2ECD863325F1 +bytes 1194179a1da023 CFC90033AA9DAC4F +bytes 1194179a1da023a6 90FDA2F089FA86DE +bytes 1194179a1da023a629 A80DEB192B8C5215 +bytes 1194179a1da023a629ac 3AAF07FC10721C6D +bytes 1194179a1da023a629ac2f D2953E1354CAEF18 +bytes 1194179a1da023a629ac2fb2 333861B25FD6348B +bytes 1194179a1da023a629ac2fb235 4E8F0D349A6F20EF +bytes 1194179a1da023a629ac2fb235b8 4DF943FE248C8BBA +bytes 1194179a1da023a629ac2fb235b83b 59F95BAD12D14C9D +bytes 1194179a1da023a629ac2fb235b83bbe 3A5B1165D151AA50 +bytes 1194179a1da023a629ac2fb235b83bbe41 C0BBB6AC5DBEFE29 +bytes 1194179a1da023a629ac2fb235b83bbe41c4 A43333C50C99A7B9 +bytes 1194179a1da023a629ac2fb235b83bbe41c447 F919C24061C10223 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca BD5C3B7ACE1CF9C6 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4d 2718C52BDD650ABF +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd0 955BDFDEB57244D6 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053 B2D26D6E52E62480 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d6 22A0F61ABE725BF4 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659 2E7D73F3896A812E +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc 05286F7B4D3669BA +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5f 581E8369415863B4 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe2 3BEE93D5A57498CA +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265 186A89BD8A211C92 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e8 C2FE19097A329DE7 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86b 44CC9EFE5D2D0233 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee 0E1AAB1D173CF196 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71 5C820B4B4FE28FDC +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f4 674271278616AB41 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477 22DE45605909B372 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa 4085F13B32C5FEB0 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d 92E43D6D89A524DE +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d00 36BD670CD3955867 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d0083 D0AB734277760E45 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306 C0441297B12D2395 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d00830689 77DEC64A3B3BC5C3 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c 32AC8537AA1EE157 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f 533C78D7B4373E03 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f12 0D95EE4190E08749 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295 A05508CB6737D409 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f129518 C87DD14C48FE91C1 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b A4D02F0326869446 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1e 8E7952E9DB8EAE71 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea1 4C5A1F7910733F74 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124 4D87691089AA979B +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a7 7B9CF9C7EE42EDFF +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72a C1A02E8D0A24430D +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad 1B90E8100ED94B5E +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30 BD61FC2BF492D4DD +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b3 910E8A09EEB42EC5 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336 88576C889955FCE8 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b9 247644B2BC54C238 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93c F30240A3A869130B +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf 319659E04033E85D +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42 137A5DEB3F660384 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c5 159B99D9E0929A9A +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548 D73D713C67CE4B7A +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb 1153D36CADE87066 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4e D4C20EF54CBC9F67 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed1 AC086C9B87BAEA67 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154 1B497BB2FD3D5691 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d7 087FA05DC97EEEBD +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75a F9394FBD99B2B1E1 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add 4F755863C483139B +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60 56F7033D775AE682 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82b D8137F7D8598EB90 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae C0331DAE6E064E2C +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31 BC3294E0954E656F +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b 5493AA81F81FD0D9 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e 9441529208FCB7EC +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e91 81755BB24BDE67E2 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b FC0C21A234C0A092 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e FA7639C7A1C6E86E +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e11 750F529A50862B96 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e 858367D2F49055A4 +bytes 1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e1194179a1da023a629ac2fb235b83bbe41c447ca4dd053d659dc5fe265e86bee71f477fa7d008306890c8f1295189b1ea124a72aad30b336b93cbf42c548cb4ed154d75add60e366e96cef72f578fb7e0184078a0d901396199c1fa225a82bae31b437ba3dc043c649cc4fd255d85bde61e467ea6df073f679fc7f0285088b0e9114971a9d20a326a92caf32b538bb3ec144c74acd50d356d95cdf62e568eb6ef174f77afd800386098c0f9215981b9e21a427aa2db033b639bc3fc245c84bce51d457da5de063e669ec6ff275f87bfe8104870a8d109316991c9f22a528ab2eb134b73abd40c346c94ccf52d558db5ee164e76aed70f376f97cff8205880b8e11 1C81641E680C8227 +i64 0 34C96ACDCADB1BBB +i64 1 9F29CB17A2A49995 +i64 -1 85D136ADB773C6C9 +i64 2 EAC73E4044E82DB0 +i64 -2 BAB3B83CF164D97F +i64 -9223372036854775808 3F425EACF01544E0 +i64 9223372036854775807 FF70CC60366E770C +i64 9007199254740993 E61780137AF44266 +i64 4294967296 CA6084DF268EA2A9 +float 0000000000000000 34C96ACDCADB1BBB +float 8000000000000000 34C96ACDCADB1BBB +float 3FF0000000000000 949522F153A1A395 +float BFF0000000000000 A12F6FC677BC860E +float 3FE0000000000000 48CB5E118059DA42 +float BFE0000000000000 EAE223A5665F292E +float 0000000000000001 9F29CB17A2A49995 +float 8000000000000001 044E434D0C94F9C4 +float 000FFFFFFFFFFFFF 4E2C69F1F7F6CB63 +float 0010000000000000 177C9E1BA22DCD5A +float 7FEFFFFFFFFFFFFF 2B67450CEDC2D98B +float FFEFFFFFFFFFFFFF BF1A70DEAECB5D63 +float 4340000000000000 A5716302E37132C7 +string EF46DB3751D8E999 +string 68656c6c6f 26C7827D889F6DA3 +string 00 E934A84ADB052768 +string 61c3a7c3a36f20f09f9880 47D0DCD7A1C3868D +string 61616161616161616161616161616161616161616161616161616161616161 FE47067CDA802916 +string 6161616161616161616161616161616161616161616161616161616161616161 856E843298F99AD7 +string 616161616161616161616161616161616161616161616161616161616161616161 18F3FF0C21E3B24B +string 7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a 92FD8D6AD9EE4549 +reference 0,1 CA6084DF268EA2A9 +reference 1,1 288EC41B1AB5A63C +reference 1,2 CD3D4C871EE4183A +reference 1024,1 25BF80C69CB54435 +reference 4294967295,4294967295 85D136ADB773C6C9 +null null 0000000000000000 diff --git a/crates/console/prometeu-vm/tests/fixtures/hash-oracle.md b/crates/console/prometeu-vm/tests/fixtures/hash-oracle.md new file mode 100644 index 0000000..cc1221e --- /dev/null +++ b/crates/console/prometeu-vm/tests/fixtures/hash-oracle.md @@ -0,0 +1,23 @@ +# Hash-v1 oracle provenance + +`hash-conformance.tsv` is generated by `hash-oracle.py` against the official C +XXH64 reference, not the Rust VM implementation. Ordinary tests read the checked-in +vectors and need no library, network or Python dependency. + +Reference: https://github.com/Cyan4973/xxHash/blob/v0.8.3/xxhash.h + +Header SHA-256: `17973c0dc49d9854ca26caa191f0e12f7a424b68858d9a78de3860d959d85e4b`. +The generator verifies both the header digest and `XXH_versionNumber()==803`. + +Example reproduction on macOS, after downloading that pinned header: + +```sh +clang -dynamiclib -O2 -x c -DXXH_IMPLEMENTATION -DXXH_STATIC_LINKING_ONLY xxhash.h -o libxxhash-oracle.dylib +python3 hash-oracle.py --header xxhash.h --library ./libxxhash-oracle.dylib +``` + +On Linux, use `-shared -fPIC` instead of `-dynamiclib`. The generator explicitly +encodes little-endian integers/reference components and finite Float bit patterns, +canonicalizes signed zeros, and uses seed zero. The null row is the machine +contract's direct zero result, not a hash of an empty message. Arbitrary `bytes` +rows exercise the internal algorithm; they do not expose guest byte strings. diff --git a/crates/console/prometeu-vm/tests/fixtures/hash-oracle.py b/crates/console/prometeu-vm/tests/fixtures/hash-oracle.py new file mode 100644 index 0000000..3c946ba --- /dev/null +++ b/crates/console/prometeu-vm/tests/fixtures/hash-oracle.py @@ -0,0 +1,51 @@ +"""Regenerate hash-v1 vectors using upstream XXH64, never the Rust executor.""" +import argparse +import ctypes +import hashlib +from pathlib import Path +import struct + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--library", required=True, type=Path) + parser.add_argument("--header", required=True, type=Path) + parser.add_argument("--output", type=Path, default=Path(__file__).with_name("hash-conformance.tsv")) + args = parser.parse_args() + expected = "17973c0dc49d9854ca26caa191f0e12f7a424b68858d9a78de3860d959d85e4b" + assert hashlib.sha256(args.header.read_bytes()).hexdigest() == expected + library = ctypes.CDLL(str(args.library.resolve())) + assert library.XXH_versionNumber() == 803 + digest = library.XXH64 + digest.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_uint64] + digest.restype = ctypes.c_uint64 + rows = ["kind\tinput\texpected_hash_hex"] + + def emit(kind, value, data): + buffer = ctypes.create_string_buffer(data) + result = digest(ctypes.cast(buffer, ctypes.c_void_p), len(data), 0) + rows.append(f"{kind}\t{value}\t{result:016X}") + + for size in list(range(71)) + [95, 96, 97, 127, 128, 129, 255, 256, 257, 1024, 4097]: + data = bytes((i * 131 + 17) & 255 for i in range(size)) + emit("bytes", data.hex(), data) + for value in [0, 1, -1, 2, -2, -(2**63), 2**63 - 1, 2**53 + 1, 2**32]: + emit("i64", value, struct.pack(" = row.split('\t').collect(); + let expected = u64::from_str_radix(fields[2], 16).unwrap() as i64; + let (value, id, bytes) = match fields[0] { + "i64" => (K::Int64(fields[1].parse().unwrap()), 0x4100, 0), + "float" => { + (K::Float64(f64::from_bits(u64::from_str_radix(fields[1], 16).unwrap())), 0x4101, 0) + } + "string" => { + let bytes = hex_bytes(fields[1]); + let size = bytes.len(); + (K::String(String::from_utf8(bytes).unwrap()), 0x4102, size) + } + "null" => (K::Null, 0x4102, 0), + _ => continue, + }; + let source = format!("PUSH_CONST 0\nINTRINSIC {id}\nRET"); + let mut vm = vm(&[(&source, sig(&[], &[0]))], &[value]); + step(&mut vm).unwrap(); + let report = vm.run_budget(1, &mut Native, &mut HostContext::new(None)).unwrap(); + assert_eq!(report.reason, End::BudgetExhausted); + assert_eq!(report.cycles_used, 8 + bytes as u64, "{row}"); + assert_eq!(&*vm.operand_stack_top(1), &[Value::Int64(expected)], "{row}"); + assert_eq!(run(&mut vm).reason, End::EndOfRom); + count += 1; + } + assert_eq!(count, 31); +} + +#[test] +fn identities_survive_mutation_and_views_validate_implementation_zero() { + let source = "STRUCT_NEW 5\nSET_LOCAL 0\nGET_LOCAL 0\nREF_IDENTITY_HASH 5\nSET_LOCAL 1\nGET_LOCAL 0\nPUSH_I64 73\nSTRUCT_SET type=5,field=0\nGET_LOCAL 0\nREF_IDENTITY_HASH 5\nGET_LOCAL 1\nEQ\nGET_LOCAL 0\nREF_TO_TRAIT source=5,target=7\nREF_IDENTITY_HASH 7\nGET_LOCAL 1\nEQ\nGET_LOCAL 0\nREF_TO_TRAIT source=5,target=7\nGET_LOCAL 0\nREF_TO_TRAIT source=5,target=8\nREF_IDENTITY_EQ left=7,right=8\nGET_LOCAL 0\nSTRUCT_NEW 5\nREF_IDENTITY_EQ left=5,right=5\nRET"; + let mut vm = vm(&[(source, sig(&[], &[2, 2, 2, 2]))], &[]); + assert_eq!(run(&mut vm).reason, End::EndOfRom); + assert_eq!( + &*vm.operand_stack_top(4), + &[Value::Boolean(false), Value::Boolean(true), Value::Boolean(true), Value::Boolean(true)] + ); +} + +#[test] +fn array_closure_and_random_have_instance_identity() { + for (source, bodies) in [ + ( + "PUSH_I64 1\nARRAY_NEW 6\nSET_LOCAL 0\nGET_LOCAL 0\nREF_IDENTITY_HASH 6\nSET_LOCAL 1\nGET_LOCAL 0\nPUSH_I64 0\nPUSH_I64 42\nARRAY_SET 6\nGET_LOCAL 0\nREF_IDENTITY_HASH 6\nGET_LOCAL 1\nEQ\nRET", + false, + ), + ( + "PUSH_I64 42\nINTRINSIC 0x4000\nSET_LOCAL 0\nGET_LOCAL 0\nREF_IDENTITY_HASH 10\nSET_LOCAL 1\nGET_LOCAL 0\nINTRINSIC 0x4001\nPOP\nGET_LOCAL 0\nREF_IDENTITY_HASH 10\nGET_LOCAL 1\nEQ\nRET", + false, + ), + ( + "MAKE_CLOSURE fn=1,type=9\nSET_LOCAL 0\nGET_LOCAL 0\nGET_LOCAL 0\nREF_IDENTITY_EQ left=9,right=9\nGET_LOCAL 0\nMAKE_CLOSURE fn=1,type=9\nREF_IDENTITY_EQ left=9,right=9\nNOT\nAND\nRET", + true, + ), + ] { + let mut functions = vec![(source, sig(&[], &[2]))]; + if bodies { + functions.push(("RET", sig(&[], &[]))); + } + let mut vm = vm(&functions, &[]); + assert_eq!(run(&mut vm).reason, End::EndOfRom); + assert_eq!(&*vm.operand_stack_top(1), &[Value::Boolean(true)]); + } +} + +#[test] +fn canonical_null_groups_compare_and_hash_without_instance_faults() { + let source = "PUSH_CONST 0\nPUSH_CONST 0\nREF_IDENTITY_HASH 7\nPUSH_CONST 0\nPUSH_CONST 0\nPUSH_CONST 0\nREF_IDENTITY_EQ left=6,right=7\nRET"; + let mut vm = vm(&[(source, sig(&[], &[0, 2]))], &[K::Null]); + assert_eq!(run(&mut vm).reason, End::EndOfRom); + assert_eq!(&*vm.operand_stack_top(2), &[Value::Boolean(true), Value::Int64(0)]); +} + +#[test] +fn admission_rejects_ineligible_sources_and_bad_native_ids_even_when_dead() { + for instruction in [ + "REF_IDENTITY_HASH 0", + "REF_IDENTITY_HASH 3", + "REF_IDENTITY_HASH 4", + "REF_IDENTITY_HASH 12", + "REF_IDENTITY_HASH 13", + "REF_IDENTITY_HASH 14", + "REF_IDENTITY_HASH 9999", + "REF_IDENTITY_EQ left=5,right=3", + "INTRINSIC 0x41FF", + ] { + let text = format!("HALT\n{instruction}"); + assert!(image(&[(&text, sig(&[], &[]))], &[]).is_err(), "{instruction}"); + } + assert!(image(&[("PUSH_CONST 0\nINTRINSIC 0x4102\nRET", sig(&[], &[0]))], &[K::Null]).is_ok()); + for id in [0x1103, 0x4100, 0x4101] { + let text = format!("PUSH_CONST 0\nINTRINSIC {id}\nPOP\nRET"); + assert!(image(&[(&text, sig(&[], &[]))], &[K::Null]).is_err(), "{id}"); + } + assert!(image(&[("PUSH_I64 3\nREF_IDENTITY_HASH 5\nRET", sig(&[], &[0]))], &[]).is_err()); +} + +#[test] +fn whole_instruction_budget_admission_preserves_zero_and_overshoot() { + let mut vm = vm( + &[("PUSH_CONST 0\nINTRINSIC 0x4102\nRET", sig(&[], &[0]))], + &[K::String("x".repeat(65))], + ); + step(&mut vm).unwrap(); + let before = vm.pc(); + let zero = vm.run_budget(0, &mut Native, &mut HostContext::new(None)).unwrap(); + assert_eq!(zero.cycles_used, 0); + assert_eq!(vm.pc(), before); + let one = vm.run_budget(1, &mut Native, &mut HostContext::new(None)).unwrap(); + assert_eq!(one.reason, End::BudgetExhausted); + assert_eq!(one.cycles_used, 73); + assert_eq!(one.steps_executed, 1); +} + +#[test] +fn every_eligible_absence_has_zero_hash_and_exact_identity_instruction_cost() { + for (ty, width) in [(5, 1), (6, 1), (7, 2), (9, 1), (10, 1)] { + let source = format!("{}REF_IDENTITY_HASH {ty}\nRET", "PUSH_CONST 0\n".repeat(width)); + let mut vm = vm(&[(&source, sig(&[], &[0]))], &[K::Null]); + for _ in 0..width { + step(&mut vm).unwrap(); + } + let before = vm.pc(); + let zero = vm.run_budget(0, &mut Native, &mut HostContext::new(None)).unwrap(); + assert_eq!((zero.cycles_used, zero.steps_executed), (0, 0)); + assert_eq!(vm.pc(), before); + let one = vm.run_budget(1, &mut Native, &mut HostContext::new(None)).unwrap(); + assert_eq!((one.cycles_used, one.steps_executed), (8 + width as u64, 1)); + assert_eq!(&*vm.operand_stack_top(1), &[Value::Int64(0)]); + } + for source in [ + "PUSH_CONST 0\nSTRUCT_NEW 5\nREF_IDENTITY_EQ left=6,right=5\nRET", + "STRUCT_NEW 5\nSTRUCT_NEW 11\nREF_IDENTITY_EQ left=5,right=11\nRET", + ] { + let mut vm = vm(&[(source, sig(&[], &[2]))], &[K::Null]); + step(&mut vm).unwrap(); + step(&mut vm).unwrap(); + let one = vm.run_budget(1, &mut Native, &mut HostContext::new(None)).unwrap(); + assert_eq!((one.cycles_used, one.steps_executed), (6, 1)); + assert_eq!(&*vm.operand_stack_top(1), &[Value::Boolean(false)]); + } +} diff --git a/crates/console/prometeu-vm/tests/intrinsic_profiles.rs b/crates/console/prometeu-vm/tests/intrinsic_profiles.rs new file mode 100644 index 0000000..486cf9f --- /dev/null +++ b/crates/console/prometeu-vm/tests/intrinsic_profiles.rs @@ -0,0 +1,105 @@ +use prometeu_bytecode::Value; +use prometeu_vm::{ + AbiType, BuiltinScalarType as S, IntrinsicCostModel as C, intrinsic_catalog, + intrinsic_catalog_csv, lookup_intrinsic_by_id, +}; +use std::collections::BTreeSet; + +#[test] +fn schema_two_has_exact_columns_profiles_and_per_slot_nullable_lists() { + let csv = intrinsic_catalog_csv(); + assert_eq!(csv, include_str!("../../../../docs/vm-arch/INTRINSICS.csv")); + let mut rows = csv.lines(); + assert_eq!( + rows.next().unwrap(), + "final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts,schema_version,arg_nullable,invocation_model,scratch_model,context_access,cost_arg_index,cost_per_byte" + ); + let mut ids = BTreeSet::new(); + let mut keys = BTreeSet::new(); + let mut previous = 0; + for row in rows { + let f: Vec<_> = row.split(',').collect(); + assert_eq!(f.len(), 25); + assert_eq!(f[18], "2"); + let id = f[1].parse::().unwrap(); + assert!(id > previous); + previous = id; + assert!(ids.insert(id)); + assert!(keys.insert((f[2], f[3]))); + let meta = lookup_intrinsic_by_id(id).unwrap(); + meta.validate_descriptor().unwrap(); + assert_eq!(f[19].split('|').filter(|s| !s.is_empty()).count(), meta.arg_slots()); + assert_eq!(f[20], meta.invocation_model()); + assert_eq!(f[21], meta.scratch_model()); + assert_eq!(f[22], meta.context_access()); + if id < 0x4100 { + assert_eq!(f[21], "existing_contract_v1"); + assert_eq!(f[23], ""); + assert_eq!(f[24], "0"); + assert_eq!(f[20], if f[4] == "random" { "vm_owned_v1" } else { "host_buffered_v1" }); + for (abi, nullable) in meta.arg_layout.iter().zip(meta.arg_nullable) { + assert_eq!(*nullable, matches!(abi,AbiType::Builtin(key) if key.name=="Random")); + } + } else { + assert_eq!(&f[20..23], &["borrowed_inline_v1", "none", "none"]); + assert_eq!(meta.cost_cycles, 8); + assert_eq!(meta.ret_layout, &[AbiType::Scalar(S::Int64)]); + assert_eq!(meta.arg_nullable, &[id == 0x4102]); + } + } + assert_eq!(ids.len(), 108); + assert_eq!(intrinsic_catalog().count(), 108); +} + +#[test] +fn incompatible_descriptors_fail_instead_of_gaining_implicit_capabilities() { + let original = *lookup_intrinsic_by_id(0x4102).unwrap(); + for variant in 0..14 { + let mut meta = original; + match variant { + 0 => meta.arg_nullable = &[], + 1 => meta.parameter_names = &[], + 2 => meta.cost_arg_index = None, + 3 => meta.cost_arg_index = Some(1), + 4 => meta.cost_per_byte = 0, + 5 => meta.attempt_cost_cycles = 1, + 6 => meta.max_attempts = 1, + 7 => meta.may_allocate = true, + 8 => meta.mutates_guest_state = true, + 9 => meta.deterministic = false, + 10 => meta.ret_layout = &[AbiType::Scalar(S::Int64); 4], + 11 => meta.ret_layout = &[AbiType::Scalar(S::Int64); 2], + 12 => meta.ret_layout = &[AbiType::DynamicPayload], + 13 => meta.arg_layout = &[AbiType::DynamicTag], + _ => unreachable!(), + } + assert!(meta.validate_descriptor().is_err(), "variant {variant}"); + } + let mut meta = *lookup_intrinsic_by_id(0x4100).unwrap(); + meta.arg_nullable = &[true]; + assert!(meta.validate_descriptor().is_err()); + meta.arg_nullable = &[false]; + meta.cost_arg_index = Some(0); + assert!(meta.validate_descriptor().is_err()); + meta.cost_model = C::ArgumentUtf8BytesV1; + meta.cost_per_byte = 1; + assert!(meta.validate_descriptor().is_err()); + meta.cost_model = C::RandomRejectionV1; + meta.cost_arg_index = None; + meta.cost_per_byte = 0; + meta.attempt_cost_cycles = 8; + meta.max_attempts = 64; + assert!(meta.validate_descriptor().is_err()); +} + +#[test] +fn nullability_does_not_relax_existing_string_or_numeric_arguments() { + for id in [0x4100, 0x4101, 0x1103] { + assert!( + lookup_intrinsic_by_id(id).unwrap().validate_argument_values(&[Value::Null]).is_err() + ); + } + assert!( + lookup_intrinsic_by_id(0x4102).unwrap().validate_argument_values(&[Value::Null]).is_ok() + ); +} diff --git a/crates/console/prometeu-vm/tests/support/identity.rs b/crates/console/prometeu-vm/tests/support/identity.rs new file mode 100644 index 0000000..060401a --- /dev/null +++ b/crates/console/prometeu-vm/tests/support/identity.rs @@ -0,0 +1,114 @@ +#![allow(dead_code)] +use prometeu_bytecode::{ + assemble, load_limits::LoadBudget, model::ConstantPoolEntry, registry::*, + registry_codec::PbxModule, +}; +use prometeu_vm::{ + HostContext, HostReturn, LogicalFrameEndingReason, NativeInterface, ValidatedProgramImage, + VirtualMachine, VmInitError, +}; +use std::sync::Arc; + +pub struct Native; +impl NativeInterface for Native { + fn syscall( + &mut self, + _: u32, + _: &[prometeu_bytecode::Value], + _: &mut HostReturn, + _: &mut HostContext, + ) -> Result<(), prometeu_hal::vm_fault::VmFault> { + panic!("identity corpus uses no host syscall") + } +} +pub fn sig(parameters: &[u32], results: &[u32]) -> Signature { + Signature { + parameters: parameters + .iter() + .map(|&id| NamedType { type_id: TypeId(id), name: None }) + .collect(), + results: results.iter().copied().map(TypeId).collect(), + } +} +pub fn types() -> Vec { + let field = || NamedType { type_id: TypeId(0), name: None }; + vec![ + TypeKind::Builtin(BuiltinId::INT64), + TypeKind::Builtin(BuiltinId::FLOAT), + TypeKind::Builtin(BuiltinId::BOOL), + TypeKind::Builtin(BuiltinId::STRING), + TypeKind::Builtin(BuiltinId::DYNAMIC), + TypeKind::Struct(vec![field()]), + TypeKind::Array(TypeId(0)), + TypeKind::Trait(vec![]), + TypeKind::Trait(vec![]), + TypeKind::Fn(sig(&[], &[])), + TypeKind::Builtin(BuiltinId::RANDOM), + TypeKind::Struct(vec![field()]), + TypeKind::Builtin(BuiltinId::COLOR), + TypeKind::Builtin(BuiltinId::VEC2), + TypeKind::Builtin(BuiltinId::PIXEL), + TypeKind::Builtin(BuiltinId::INT32), + ] + .into_iter() + .map(|kind| TypeDecl { name: None, kind }) + .collect() +} +pub fn image( + bodies: &[(&str, Signature)], + constants: &[ConstantPoolEntry], +) -> Result, VmInitError> { + let mut code = vec![]; + let mut functions = vec![]; + for (source, signature) in bodies { + let body = assemble(source).unwrap(); + functions.push(FunctionDecl { + signature: signature.clone(), + local_slots: 8, + max_stack_slots: 64, + code_offset: code.len() as u32, + code_len: body.len() as u32, + ..Default::default() + }); + code.extend(body); + } + let mut budget = LoadBudget::new(Default::default()); + let registry = Registry::resolve( + RegistryDeclarations { + types: types(), + functions, + implementations: vec![ + ImplementationDecl { owner: TypeId(5), trait_id: TypeId(7), methods: vec![] }, + ImplementationDecl { owner: TypeId(5), trait_id: TypeId(8), methods: vec![] }, + ], + }, + code.len(), + &mut budget, + ) + .unwrap(); + let bytes = PbxModule { + registry: ®istry, + code: &code, + constants, + debug: None, + exports: &[], + syscalls: &[], + } + .serialize(&mut budget) + .unwrap(); + ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(Default::default()), 0) +} +pub fn vm(bodies: &[(&str, Signature)], constants: &[ConstantPoolEntry]) -> VirtualMachine { + let mut vm = VirtualMachine::from_image(image(bodies, constants).unwrap(), Default::default()); + vm.prepare_boot_call().unwrap(); + vm +} +pub fn run(vm: &mut VirtualMachine) -> prometeu_vm::BudgetReport { + vm.run_budget(1_000_000, &mut Native, &mut HostContext::new(None)).unwrap() +} +pub fn step(vm: &mut VirtualMachine) -> Result<(), LogicalFrameEndingReason> { + vm.step(&mut Native, &mut HostContext::new(None)) +} +pub fn hex_bytes(value: &str) -> Vec { + (0..value.len()).step_by(2).map(|i| u8::from_str_radix(&value[i..i + 2], 16).unwrap()).collect() +} diff --git a/discussion/lessons/DSC-0066-vm-identity-and-value-hashing/LSN-0071-identity-domains-and-borrowed-intrinsic-invocation.md b/discussion/lessons/DSC-0066-vm-identity-and-value-hashing/LSN-0071-identity-domains-and-borrowed-intrinsic-invocation.md new file mode 100644 index 0000000..101df5d --- /dev/null +++ b/discussion/lessons/DSC-0066-vm-identity-and-value-hashing/LSN-0071-identity-domains-and-borrowed-intrinsic-invocation.md @@ -0,0 +1,146 @@ +--- +id: LSN-0071 +ticket: vm-identity-and-value-hashing +title: Identity domains and borrowed intrinsic invocation +created: 2026-10-23 +tags: [vm, identity, hashing, values, compiler] +--- + +## Context + +The runtime needed stable identity queries and scalar/content hashing while +preserving typed values, faults, owners and execution accounting. Existing +Host intrinsics buffered arguments/results and exposed mutable context. That +path could not establish the required no-scratch/no-guest-allocation contract +by adding a purity flag alone. + +The executed decision was DEC-0066, originating in AGD-0069; PLN-0197 delivered +the independent runtime provider. Their permanent lifecycle provenance is in +[the discussion index](../../index.ndjson). Workflow control artifacts are +removed after completion. Published authority is the +[canonical identity/hash specification](../../../docs/specs/runtime/02f-vm-identity-and-value-hashing.md), +with the [qualification record](../../../docs/vm-arch/IDENTITY_HASHING_QUALIFICATION.md) +and [producer handoff](../../../docs/vm-arch/identity-hashing-producer-handoff.md). +This lesson explains the published design; it does not replace its contract. + +## Key decisions + +### Equality belongs to a selected domain + +**What:** The VM provides exact reference identity plus separate Int64, Float +and String hashes. SDK/producer policy selects equality, numeric canonicalization, +component composition and optional/Dynamic behavior. + +**Why:** Sharing a physical carrier does not establish a semantic equality domain. +Two Trait views can share one receiver even with different implementation IDs; +two closures with identical code/captures still have separate instance identity. +Conversely, separately owned Strings can share content and therefore a content +hash. A universal equality layer would silently choose language policy. + +**Trade-offs:** Producers need coherent wrappers and composition. They gain +explicit control without duplicating the machine's handle validation or hash +algorithm. A hypothetical Lua consumer was a design stress test; no Lua frontend +was implemented or needed for provider qualification. + +### Improve intrinsic invocation with an executable profile + +**What:** borrowed_inline_v1 borrows the original stack arguments, computes into +fixed native output slots, validates complete output and commits once. Its +handler receives no mutable HostContext or VM access. Invocation/scratch/context +metadata derive from the handler representation, preventing inconsistent claims. +The new profile is shared infrastructure, not a hash-namespace branch. + +**Why:** deterministic, allocation and mutation flags describe separate concerns. +A deterministic function can still allocate scratch or mutate seeded state. +Purity metadata cannot make a buffered callback transactional. The invocation +interface and commit protocol must enforce the resource/ownership story. + +**Trade-offs:** The profile deliberately supports bounded output replacement. +Unsupported capacities, ABI layouts and effect/cost combinations fail rather +than falling back to dynamic storage. Existing Host and VM-owned Random handlers +retain their established contract; they were not broadly migrated. + +### Fault order and charging are part of semantics + +**What:** Charge from safe carrier/Registry metadata before validation; preserve +both groups until complete validation and computation succeed. Validate left +before right even when a result seems obvious. String's known byte length is +charged before ownership refusal; overflow charges base and traps. + +**Why:** Early false/null results can conceal malformed or stale references. +Popping operands before work makes failures change roots or drop String owners. +Partial fuel checks or duplicate generic INTRINSIC costs change deterministic +execution traces and compiler optimization obligations. + +**Trade-offs:** An admitted instruction can overshoot positive fuel, and invalid +long Strings still pay traversal-sized virtual cost without being traversed. +The contract makes that explicit and testable. Zero fuel executes nothing. + +## Patterns and algorithms + +Reference identity is validated index plus generation, serialized as two LE u32s +for XXH64 seed zero. The hash excludes fields, captures, generator state, trait +metadata and native addresses. It is stable for a live object but creates no +root or persistent cross-session identity. GC may collect an object while an +Int64 hash remains; generation advancement still invalidates old handles. + +Scalar hashing uses explicit LE messages. Float hashes binary64 bits, with both +zeros canonicalized, and rejects non-finite values. It never performs numerical +Float-to-integer conversion. String uses exact UTF-8 bytes, including NUL; +accepted absence returns zero directly and empty String hashes the empty message. +Signed Int64 carries the unchanged unsigned digest bits. + +Schema 2 appends capability, nullability and cost fields to the original 18 CSV +columns. Runtime descriptors generate the catalog, validate consistency and feed +static per-entry nullability. Known null for hash.string does not relax older +String entries. Explicit legacy profile tokens document the existing contract +without claiming the bounded profile's guarantees for every intrinsic. + +## Independent evidence + +The Rust algorithm agrees with 118 vectors generated from the pinned official C +XXH64 reference. Raw instruction bytes are checked independently of round-trip +assembly. Serialized PBX exercises admission and actual VM dispatch; private +fault injection reaches stale handles, NaN payloads and deliberately broken +handlers that production admission prevents. + +Ten warmed instruction regions each ran 1,000 iterations without native +allocation/deallocation or guest heap allocation. Resource refusal tests preserve +operands/owners/accounting. GC/reuse tests distinguish live identity, stale +identity and hashes that do not root their source. Distribution tests use reduced +buckets and deliberately observe collisions without substituting hash equality +for reference equality. + +The default bytecode/VM suites passed 453 tests; the VM diagnostic suite passed +401; quality/layer checks passed 19; selected release suites passed 12. Local +target/toolchain, existing ignored tests, source fingerprints, catalog/constant +checks and exact commands are retained in the qualification record. Those +results do not assert cross-target or source frontend integration. + +## Pitfalls + +- Inferring no scratch, no context or purity from deterministic loses independent + capability information. Stateful Random is reproducible but still mutates. +- Comparing only a Trait receiver without validating its implementation pair + accepts malformed views; treating implementation zero as absence breaks valid views. +- Reusing physical HeapRef rules for String, Dynamic or arbitrary builtins expands + semantic domains without a contract. Eligibility needs its own precise predicate. +- Canonical stack null and HeapRef(0,0) have different validation behavior. +- Numerical conversion of Float, host-endian messages or native hashing defaults + breaks reproducible bit-level results. +- Allocation-free algorithms can still hide argument/result buffers in generic + invocation. Count the real instruction region, including reallocations. +- Updating a catalog mirror alone does not migrate the compiler or installed SDK. + Metadata, IR, emission, pinning, resources and normal/optimized source evidence + each need a named consumer acceptance target. + +## Takeaways + +Make the safe execution profile an implementation capability and validate its +metadata. Preserve original operands as roots through the last fallible step. +Separate identity, content and language equality policy. Qualify encoding, +algorithm, invocation, ownership and scheduling with independent evidence. + +The runtime provider is complete independently of Studio source integration, +Set/Map, storage publication and future frontends. Consumer obligations remain +concrete handoff targets rather than an unbounded extension of this delivery. diff --git a/docs/specs/runtime/01-time-model-and-cycles.md b/docs/specs/runtime/01-time-model-and-cycles.md index b3e7bd9..6027c3f 100644 --- a/docs/specs/runtime/01-time-model-and-cycles.md +++ b/docs/specs/runtime/01-time-model-and-cycles.md @@ -192,3 +192,13 @@ remain unchanged. CPU timings never change guest-visible cycle weights. ## Random core integration The [random core](02e-vm-owned-random-core.md) charges fixed calls before checks and bounded range calls as 4+8*N (at most 64 draws), retaining fault cycles and whole-instruction overshoot. + +## Identity and hash attempts + +The [identity/hash contract](02f-vm-identity-and-value-hashing.md) charges +8+w(T) for reference hash, 4+w(A)+w(B) for identity comparison, eight for scalar +numeric hashes, and 8+n resident UTF-8 bytes for String. Known lengths charge +before traversal/refusal; null/wrong/unavailable String carriers charge eight. +Checked cost overflow charges base and faults. These are total attempted costs, +without a generic extra INTRINSIC cycle or refunds. Existing whole-instruction +overshoot and zero-budget rules apply; the operations introduce no safepoint. diff --git a/docs/specs/runtime/02-vm-instruction-set.md b/docs/specs/runtime/02-vm-instruction-set.md index 3a1e260..0adefd7 100644 --- a/docs/specs/runtime/02-vm-instruction-set.md +++ b/docs/specs/runtime/02-vm-instruction-set.md @@ -253,3 +253,11 @@ entry and one per destination field execution slot for the complete declared attempt, including skipped destinations. Quotas are unchanged. This is a generic typed storage mechanism; collection algorithms and node topology remain source-owned, with no collection-specific VM instruction or syscall. + +## Identity and value hashing + +[Identity and value hashing](02f-vm-identity-and-value-hashing.md) defines +REF_IDENTITY_HASH 0x0097 and REF_IDENTITY_EQ 0x0098, complete typed source +groups, one/two TypeId immediates, exact attempted costs and operand-preserving +faults. It also defines intrinsics 0x4100–0x4102 and their shared bounded +invocation profile. Old EQ and REF_* categories retain their contracts. diff --git a/docs/specs/runtime/02c-program-registry-and-pbx-v0.md b/docs/specs/runtime/02c-program-registry-and-pbx-v0.md index 2c6a5cd..187838d 100644 --- a/docs/specs/runtime/02c-program-registry-and-pbx-v0.md +++ b/docs/specs/runtime/02c-program-registry-and-pbx-v0.md @@ -315,3 +315,13 @@ STORAGE_PUBLISH (0xAA) provide generic logical validation, complete stored-group transfer and prepared atomic publication. Their encoding, typed operands, exact faults, overlap semantics, costs and preflight/commit guarantees are defined by the [canonical instruction contract](02-vm-instruction-set.md#logical-guards-and-atomic-storage-publication). No new Registry category, syscall, collection algorithm or safepoint is introduced. + +## Identity queries + +[Identity queries](02f-vm-identity-and-value-hashing.md) add opcodes 0x0097 +(source TypeId, six bytes) and 0x0098 (left/right TypeIds, ten bytes). Sources +are Struct, Array, Fn, Trait and Random; validate complete groups before +consulting handles. They add no PBX section, value type or layout change. The +older REF_IS_EXACT/IMPLEMENTS/TO_TRAIT/CAST category restrictions remain intact. +Intrinsic argument nullability is explicit per entry: hash.string admits known +null at load without relaxing the static masks of existing String intrinsics. diff --git a/docs/specs/runtime/02f-vm-identity-and-value-hashing.md b/docs/specs/runtime/02f-vm-identity-and-value-hashing.md new file mode 100644 index 0000000..4e84e5c --- /dev/null +++ b/docs/specs/runtime/02f-vm-identity-and-value-hashing.md @@ -0,0 +1,178 @@ +# VM Identity, Value Hashing and Bounded Intrinsic Invocation + +Domain: VM values/intrinsics. Function: normative. + +## Operations + +| Operation | ID | Immediate/inputs, bottom to top | Result | Attempt cycles | +| --- | --- | --- | --- | --- | +| REF_IDENTITY_HASH | opcode 0x0097 | source:TypeId; complete source group | Int64 | 8+w(source) | +| REF_IDENTITY_EQ | opcode 0x0098 | left:TypeId,right:TypeId; left group,right group | Bool | 4+w(left)+w(right) | +| hash.i64@1 | intrinsic 0x4100 | value:Int64 | Int64 | 8 | +| hash.float@1 | intrinsic 0x4101 | value:Float | Int64 | 8 | +| hash.string@1 | intrinsic 0x4102 | value:String, nullable | Int64 | 8+n | + +Opcodes are u16 LE, immediate TypeIds u32 LE. The reference instructions occupy +six/ten bytes. INTRINSIC remains opcode 0x0072 followed by u32 ID, six bytes. +w(T) is resolved Registry slot width; n is present UTF-8 byte length, zero for +null. Success consumes complete groups and publishes one result; failure retains +inputs/owners. TypeIds are static metadata, never arbitrary guest selectors. + +## Identity and equality domains + +Identity sources MUST be Struct, Array, Fn, Trait or Random. String, Dynamic, +internal boxes and other builtins are invalid categories. The old REF_* source +rules and global EQ are unchanged. Validate the complete left group before the +right, and both before comparing: exact type/category, liveness/generation and +Registry. An invalid right input cannot be hidden by an unequal/absent left. + +Struct/Array identity is instance identity, without traversing fields/elements. +Fn identity is Closure identity, including empty captures; distinct creation +stays distinct even with identical code/captures. Random identity is generator +identity, independent of seed/state; the query neither advances nor hashes state. + +Trait identity is the receiver after validating the entire receiver and +ImplementationId against owner/trait metadata. ImplementationId zero is valid +for a coherent present view. Static trait type and implementation do not enter +the hash. Valid views through different traits and their concrete reference +agree. This adds no implicit trait implementation to Fn/Random. + +Canonical stack absence is Null for one-slot references/String and [Null,Null] +for Trait. Two eligible absences compare true, absence/present false; absence +hashes to Int64(0). Zero is not exclusive to absence. HeapRef(0,0) is not stack +absence: existing validators classify it TYPE for Struct/Array/Fn/Trait and +INVALID_HANDLE for Random. Malformed/stale values never become false/null. + +The producer controls comparisons across static types and the equality used by +collections. Within the selected domain/context, equals(a,b) implies equal +hashes; equal hashes do not imply equality. No universal cross-numeric, Dynamic +box or object-content equality is introduced. A producer joining integer/Float +equality must define coherent canonicalization. Int32 can widen exactly to Int64, +Bool map to 0/1; SDK component mixing must preserve order and boundaries. +Fold to 32 bits is explicit, not abs or lossy numeric conversion. Equality/hash +must remain stable while used as a key; the VM cannot prove custom callbacks. + +## Hash-v1 + +Use XXH64, seed u64 zero, per the +[upstream v0.8.3 specification](https://github.com/Cyan4973/xxHash/blob/v0.8.3/doc/xxhash_spec.md). +Return the digest's identical 64-bit pattern in Int64, including negative values. +All algorithm arithmetic wraps modulo 2^64; host word size/endianness is irrelevant. + +| Input | Exact message | +| --- | --- | +| Int64 | Eight LE two's-complement bytes. | +| Finite Float zero | Eight zero bytes for either sign. | +| Other finite Float | Eight LE IEEE 754 binary64 bit-pattern bytes. | +| Present String | Exact resident UTF-8 bytes and their message length, without terminator/prefix/normalization. | +| Present reference | index:u32 LE followed by generation:u32 LE after validation. | +| Accepted absence | Return zero directly; do not hash an empty message. | + +Float MUST NOT be numerically converted to integer. NaN/infinity trap NON_FINITE. +Empty String hashes the empty message and remains unequal to null. String owners, +origin/retention and allocation history do not affect content hashing. Reference +hash excludes fields, Random state, FunctionId, captures, view type and native +addresses. There is no cryptographic, uniqueness, capability or confidentiality +guarantee. The hash cannot be converted into a guest reference and creates no root. + +Same scalar data/content and contract produce identical bits across hosts and +sessions. An object's hash remains stable while alive, independently of mutation; +reproduction depends on the same VM revision and allocation/collection sequence. +Objects have no shared/persistent identity across sessions/revisions. Time, native +addresses and host entropy are excluded. Existing entry boundaries preserve heap/ +session provenance; the handle encoding gains no global session identifier. + +## Shared bounded invocation + +The three scalar hashes declare invocation_model=borrowed_inline_v1, +scratch_model=none, context_access=none, deterministic=true, may_allocate=false, +mutates_guest_state=false. Protocol/cost selection follows descriptors, not the +owner name. Native Rust handler functions are allowed; guest calls/reentry are not. + +1. Resolve metadata and charge using safe carrier inspection. +2. Check temporaries above the frame floor and validate borrowed inputs in order. +3. Admit resources declared by that entry's profile. +4. Compute into bounded local output storage derived from ret_layout. +5. Validate the complete result's width and carriers. +6. Replace/consume inputs and publish output in an infallible commit. + +Inputs remain original stack roots/owners until commit. No argument BudgetVec, +Vec-returning callback or mutable HostContext implements this profile. Unsupported +inline result capacity or inconsistent descriptor/handler is rejected without +dynamic-buffer fallback. Each new hash replaces one slot with one and requires +no stack growth, guest allocation or dynamic scratch. No GC, safepoint, guest +callback or scheduling occurs inside the operation. Faults retain inputs and +discard partial results. Stateful handlers retain their own preparation/commit; +Random keeps its existing candidate-state, allocation and bounded-attempt rules. + +## Costs, faults and admission + +Charge each decoded attempt once, including refusal, without an extra generic +INTRINSIC cycle. Numeric hashes use fixed cost eight. String costs 8+n for an +available String carrier, before traversal or provenance/ownership refusal. +Null/wrong/unavailable carrier and underflow cost eight. Checked cost overflow +charges base and traps RESOURCE_LIMIT without wrap or traversal. Reference costs +use resolved widths even on underflow/refusal. Charge before height/group checks; +validate left then right, and Float finitude after its exact carrier. No refunds. + +| Cause | Outcome | +| --- | --- | +| Invalid immediate TypeId/category | LOAD_INVALID_REFERENCE. | +| Invalid encoding/unknown intrinsic/proven static conflict | Existing structured load rejection, including dead code, no guest cycles. | +| Incomplete temporary inputs | STACK_UNDERFLOW 0x08. | +| Wrong carrier/type/malformed group/view | TYPE 0x04. | +| Dead/stale/invalid reference | INVALID_HANDLE 0x0F under existing typed validation. | +| Non-finite Float reaching execution | NON_FINITE 0x14. | +| Checked cost/resource overflow | RESOURCE_LIMIT 0x10 with applicable resource detail. | +| Handler result violates descriptor | INVALID_INTRINSIC 0x0D; original operands retained. | + +Accepted null does not trap NULL_REFERENCE; Null to a numeric hash is TYPE. +TrapInfo retains attempted PC/opcode, available source span and resource context. +Budget zero executes nothing; positive fuel admits a whole instruction and can +overshoot. There is no per-byte preemption, quota-rescue GC, hash cache/table, +new String limit or relaxed ownership/resource quota. + +## Intrinsic catalog schema 2 + +Schema version is independent of canonical intrinsic version. INTRINSICS.csv is +generated from descriptors, ordered by ID, UTF-8/LF. The exact header is: + +```csv +final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts,schema_version,arg_nullable,invocation_model,scratch_model,context_access,cost_arg_index,cost_per_byte +``` + +schema_version is 2 on every row. arg_nullable is one lowercase boolean per +argument slot, pipe-separated, empty only for no arguments; widths must match +arg_layout. cost_arg_index is a zero-based String slot for the byte model and +empty for other models. cost_per_byte is one for String hashing and zero for +fixed/random_rejection_v1. Base/fixed cost remains cost_cycles. Unsupported or +inconsistent schema, profile, model, layout, index or capacity fails explicitly. + +```csv +0x4100,16640,hash.i64,1,hash,i64,1,1,Int64,Int64,true,false,value,8,false,fixed,0,0,2,false,borrowed_inline_v1,none,none,,0 +0x4101,16641,hash.float,1,hash,float,1,1,Float,Int64,true,false,value,8,false,fixed,0,0,2,false,borrowed_inline_v1,none,none,,0 +0x4102,16642,hash.string,1,hash,string,1,1,String,Int64,true,false,value,8,false,argument_utf8_bytes_v1,0,0,2,true,borrowed_inline_v1,none,none,0,1 +``` + +Static admission and native validation use per-entry arg_nullable. Known null +is valid for hash.string; other String intrinsics retain their old static masks. +Nullable structural admission does not remove domain preconditions such as a +Random mutation requiring a present generator. + +Old Host entries use host_buffered_v1/existing_contract_v1/host; old VM-owned +entries vm_owned_v1/existing_contract_v1/vm_state. These retain existing effects, +accounting, limits, IDs, signatures, versions and costs, not the new profile's +guarantees. Old scalar/color args have false nullability, Random args true; +no-arg lists are empty. Legacy cost_arg_index is empty and cost_per_byte zero. +No broad migration is required. The builtin constant catalog remains unchanged. + +## Producer boundary + +Publish exact provider revision, schema and catalog digests. Consumers explicitly +port metadata, admission, lowering/emission, mirrors, packaged provenance and +normal/optimized conformance. CSV-only updates are not completed integration. +Reject unsupported data without inferring purity/nullability/zero scratch from +deterministic or names. Preserve faults, ordering and charged work even when +results are discarded. Collections, defaults and custom/Dynamic strategies remain +consumer-owned. Set/Map, storage publication, Lua FE, arbitrary byte strings, +a new Float domain and general structural hashing are outside this contract. diff --git a/docs/specs/runtime/03-memory-stack-heap-and-allocation.md b/docs/specs/runtime/03-memory-stack-heap-and-allocation.md index 623b337..76158be 100644 --- a/docs/specs/runtime/03-memory-stack-heap-and-allocation.md +++ b/docs/specs/runtime/03-memory-stack-heap-and-allocation.md @@ -232,3 +232,12 @@ roots throughout preparation; the commit phase has no allocation, GC, scheduler callback boundary. Refusal changes neither destinations nor input groups, and releases temporary reservations. Consumer return carriers must be prepared before publication. See [the instruction contract](02c-program-registry-and-pbx-v0.md#logical-guards-and-atomic-storage-publication). + +## Borrowed intrinsic invocation + +The [bounded intrinsic profile](02f-vm-identity-and-value-hashing.md) keeps +original arguments/owners rooted until result validation and stack commit. Hash +intrinsics use no guest allocation, dynamic scratch or stack growth; native +output storage is bounded by the declared result layout. They do not collect, +reenter or call guest code. Hash values create no roots. Legacy intrinsic +resource/effect contracts remain explicit and do not inherit these guarantees. diff --git a/docs/specs/runtime/README.md b/docs/specs/runtime/README.md index 73743b2..8e27fed 100644 --- a/docs/specs/runtime/README.md +++ b/docs/specs/runtime/README.md @@ -132,3 +132,7 @@ In those cases: ## Random core integration The [VM-owned random core](02e-vm-owned-random-core.md) defines opaque Random references, PCG64 and the random intrinsic surface. + +## Identity and hashing integration + +The [identity and value hashing contract](02f-vm-identity-and-value-hashing.md) defines typed reference queries, scalar/content hash-v1, bounded intrinsic invocation and catalog schema 2. See the [producer handoff](../../vm-arch/identity-hashing-producer-handoff.md) and [qualification record](../../vm-arch/IDENTITY_HASHING_QUALIFICATION.md) for implementation evidence and consumer integration targets. diff --git a/docs/vm-arch/IDENTITY_HASHING_QUALIFICATION.md b/docs/vm-arch/IDENTITY_HASHING_QUALIFICATION.md new file mode 100644 index 0000000..6a18f25 --- /dev/null +++ b/docs/vm-arch/IDENTITY_HASHING_QUALIFICATION.md @@ -0,0 +1,110 @@ +# Identity and hashing qualification + +Qualification date: 2026-10-23. Target: aarch64-apple-darwin. Toolchain: +rustc 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1 (797e8a9bc 2026-08-05). +The [machine-readable record](identity-hashing-qualification.json) contains exact +source/artifact SHA-256 values and commands. The +[canonical contract](../specs/runtime/02f-vm-identity-and-value-hashing.md) is normative; +the [producer handoff](identity-hashing-producer-handoff.md) defines consumer work. + +## Delivery identity + +Base revision: `57992cf214e8a5f9de53a40dba9aaa7fab038c91`. This qualification +covers working-tree changes identified by source fingerprint +`a0d202e46fbca3319d7b04fe09906388c015da7b606216e75bd7c62041011885`. +The base revision alone does not contain this delivery. The JSON lists the +29 source/test files and their individual digests. To reproduce the aggregate, +visit sorted paths and hash the concatenation of path UTF-8, NUL, exact file +bytes and NUL for each file. + +| Artifact | SHA-256 | +| --- | --- | +| Cargo.lock | cffad9ed62f38a591538abd81dd39270d6022397342c8189f4ac6c7baaa8e795 | +| INTRINSICS.csv | 7c1c363f5f0f941b3ab27cfc72af41e13e44cd4371c687db8300721288f47e63 | +| BUILTIN_CONSTANTS.csv | e407e4718127aa7ef7b1097b5b4b67d86dd979235e73a551a7c36b628cddc039 | +| hash-conformance.tsv | a863486eaea14ab1a010f076f355eed0d5738207dad3651f7d10e92fc09f74d4 | + +Schema 2 has 25 columns and 108 intrinsic rows. Comparison against the base +revision confirms that all 18 prior fields of each of the 105 old entries are +unchanged. Three hash entries were added. Builtin constants are byte-identical. +Existing historical math/random qualification records retain their original +revision claims. + +## Executed checks + +All commands use the checked-in lockfile and offline dependency cache. + +| Command | Result | +| --- | --- | +| `cargo test --locked --offline -p prometeu-bytecode -p prometeu-vm --no-fail-fast` | 453 passed, 0 failed, 3 existing ignored. | +| `cargo test --locked --offline -p prometeu-vm --features resource-diagnostics --no-fail-fast` | 401 passed, 0 failed, 2 existing ignored. | +| `cargo test --locked --offline -p prometeu-quality-checks -p prometeu-layer-tests --no-fail-fast` | 19 passed, 0 failed. | +| `cargo test --locked --offline --release -p prometeu-vm --test identity_hashing --test intrinsic_profiles --test execution_allocations` | 12 passed, 0 failed. | +| `cargo check --locked --offline --workspace --all-targets` | Passed, including headless/desktop, firmware, tools and shared consumers. | +| `cargo fmt --all --check` | Passed. | +| `git diff --check` | Passed. | + +## Independent oracles and covered behavior + +The [118 vectors](../../crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv) +come from the official C XXH64 v0.8.3 reference, not the Rust implementation. +The [generator and provenance](../../crates/console/prometeu-vm/tests/fixtures/hash-oracle.md) +pin the upstream header by SHA-256 and verify its version. Raw byte vectors +cover every length through 70 and longer stripe/tail boundaries through 4097; +the remaining cases cover signed integer extremes, finite binary64 bit patterns, +UTF-8/NUL/empty strings, reference index/generation pairs and direct null zero. +Every vector is checked by the Rust algorithm. Scalar/String/null vectors also +execute through serialized PBX, typed admission and the real interpreter. + +Independent raw instruction bytes check IDs, LE immediates, truncations, +assembler/disassembler behavior and Registry widths. Neutral PBX tests cover +Struct/Array/Fn/Random identity, distinct closure creation, aliases, mutation, +Random advancement, multiple Trait views, valid implementation zero, all eligible +null groups and exact successful instruction costs. Admission rejects ineligible +source types, bad immediates/IDs, wrong numeric carriers and old String nulls, +including invalid metadata in unreachable code where appropriate. + +Private fault injection covers non-finite Float bits, stale/malformed references, +wrong concrete types, invalid/partial Trait pairs, left-before-right validation, +invalid right operands despite null left, underflow, foreign String ownership, +checked String cost overflow and malformed/missing/excess handler results. +Assertions preserve complete operands and String owners, resource usage, Float +NaN payload bits and charged cycles. Misbehaving output handlers use a different +owner namespace to exercise the shared invocation protocol. Descriptor tests +reject unsupported layouts, inconsistent metadata and undeclared capabilities. + +Real GC retains live aliases and permits collection when only an Int64 hash is +retained; reuse increments the generation and old handles still fault. Existing +generation-exhaustion tests cover retirement without wrap. Hashing equal String +content across image, session concatenation and explicit import owners agrees. +Sequential handle distribution exercises 256 reduced buckets; deliberate bucket +collisions still require reference equality. This is distribution evidence, +not a uniqueness or adversarial-resistance claim. + +## Allocation, resources and scheduling + +Ten new warmed instruction regions cover three scalar hashes, five reference +hash categories, Struct equality and Trait equality. After ten warmup iterations, +1,000 measured iterations per region allocate/deallocate nothing natively, +including reallocations, and create no guest heap objects. Original values remain +in locals so owner destruction does not contaminate the measured region. The +same checks pass in debug, resource-diagnostics and selected release execution. + +Quota-injection tests exhaust guest/handle/auxiliary/temporary/String budgets +before reference/scalar queries and check unchanged resource use. New queries do +not trigger GC, grow their result stack, request scratch or call the host. Fault +checks cover guest resource/owner preservation; the native allocator measurement +covers successful warmed execution, not the existing diagnostic formatting path. +Zero fuel leaves PC/state unchanged; one positive cycle admits the entire +instruction, including a 65-byte String hash costing 73, with no extra generic +INTRINSIC cycle. Foreign String owners are rejected only after full byte cost. + +## Scope of evidence + +This record covers the local target and configurations above. Other hosts, +architectures and cross-host execution comparisons were not run. The explicit +LE implementation and independent vectors support portability but do not replace +qualification on additional advertised targets. Studio source compilation, +normal/optimized source conformance, catalog pins/mirrors and packaged SDK +resources remain the [consumer handoff](identity-hashing-producer-handoff.md). +No Lua frontend, Set/Map or structural/Dynamic equality is reported as delivered. diff --git a/docs/vm-arch/INTRINSICS.csv b/docs/vm-arch/INTRINSICS.csv index 1c93cd0..61a38da 100644 --- a/docs/vm-arch/INTRINSICS.csv +++ b/docs/vm-arch/INTRINSICS.csv @@ -1,106 +1,109 @@ -final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts -0x1000,4096,vec2.dot,1,vec2,dot,4,1,Float|Float|Float|Float,Float,true,false,ax|ay|bx|by,10,false,fixed,0,0 -0x1001,4097,vec2.length,1,vec2,length,2,1,Float|Float,Float,true,false,x|y,40,false,fixed,0,0 -0x1100,4352,color.from_raw,1,color,from_raw,1,1,Int64,builtin:color,true,false,raw,1,false,fixed,0,0 -0x1101,4353,color.rgb,1,color,rgb,3,1,Int64|Int64|Int64,builtin:color,true,false,r|g|b,1,false,fixed,0,0 -0x1102,4354,color.rgba,1,color,rgba,4,1,Int64|Int64|Int64|Int64,builtin:color,true,false,r|g|b|a,1,false,fixed,0,0 -0x1103,4355,color.html_rgba,1,color,html_rgba,1,1,String,builtin:color,true,false,value,1,false,fixed,0,0 -0x1104,4356,color.gray_scale,1,color,gray_scale,1,1,Int64,builtin:color,true,false,value,1,false,fixed,0,0 -0x1105,4357,color.hex,1,color,hex,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0 -0x1106,4358,color.alpha,1,color,alpha,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0 -0x1120,4384,color.black,1,color,black,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1121,4385,color.white,1,color,white,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1122,4386,color.red,1,color,red,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1123,4387,color.green,1,color,green,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1124,4388,color.blue,1,color,blue,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1125,4389,color.yellow,1,color,yellow,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1126,4390,color.orange,1,color,orange,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1127,4391,color.indigo,1,color,indigo,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1128,4392,color.gray,1,color,gray,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x1129,4393,color.cyan,1,color,cyan,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x112A,4394,color.magenta,1,color,magenta,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x112B,4395,color.transparent,1,color,transparent,0,1,,builtin:color,true,false,,1,false,fixed,0,0 -0x2100,8448,input.pad.up.pressed,1,input.pad.up,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2101,8449,input.pad.up.released,1,input.pad.up,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2102,8450,input.pad.up.down,1,input.pad.up,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2103,8451,input.pad.up.hold,1,input.pad.up,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2104,8452,input.pad.down.pressed,1,input.pad.down,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2105,8453,input.pad.down.released,1,input.pad.down,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2106,8454,input.pad.down.down,1,input.pad.down,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2107,8455,input.pad.down.hold,1,input.pad.down,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2108,8456,input.pad.left.pressed,1,input.pad.left,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2109,8457,input.pad.left.released,1,input.pad.left,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x210A,8458,input.pad.left.down,1,input.pad.left,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x210B,8459,input.pad.left.hold,1,input.pad.left,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x210C,8460,input.pad.right.pressed,1,input.pad.right,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x210D,8461,input.pad.right.released,1,input.pad.right,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x210E,8462,input.pad.right.down,1,input.pad.right,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x210F,8463,input.pad.right.hold,1,input.pad.right,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2110,8464,input.pad.a.pressed,1,input.pad.a,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2111,8465,input.pad.a.released,1,input.pad.a,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2112,8466,input.pad.a.down,1,input.pad.a,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2113,8467,input.pad.a.hold,1,input.pad.a,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2114,8468,input.pad.b.pressed,1,input.pad.b,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2115,8469,input.pad.b.released,1,input.pad.b,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2116,8470,input.pad.b.down,1,input.pad.b,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2117,8471,input.pad.b.hold,1,input.pad.b,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2118,8472,input.pad.x.pressed,1,input.pad.x,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2119,8473,input.pad.x.released,1,input.pad.x,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x211A,8474,input.pad.x.down,1,input.pad.x,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x211B,8475,input.pad.x.hold,1,input.pad.x,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x211C,8476,input.pad.y.pressed,1,input.pad.y,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x211D,8477,input.pad.y.released,1,input.pad.y,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x211E,8478,input.pad.y.down,1,input.pad.y,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x211F,8479,input.pad.y.hold,1,input.pad.y,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2120,8480,input.pad.l.pressed,1,input.pad.l,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2121,8481,input.pad.l.released,1,input.pad.l,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2122,8482,input.pad.l.down,1,input.pad.l,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2123,8483,input.pad.l.hold,1,input.pad.l,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2124,8484,input.pad.r.pressed,1,input.pad.r,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2125,8485,input.pad.r.released,1,input.pad.r,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2126,8486,input.pad.r.down,1,input.pad.r,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2127,8487,input.pad.r.hold,1,input.pad.r,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2128,8488,input.pad.start.pressed,1,input.pad.start,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2129,8489,input.pad.start.released,1,input.pad.start,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x212A,8490,input.pad.start.down,1,input.pad.start,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x212B,8491,input.pad.start.hold,1,input.pad.start,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x212C,8492,input.pad.select.pressed,1,input.pad.select,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x212D,8493,input.pad.select.released,1,input.pad.select,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x212E,8494,input.pad.select.down,1,input.pad.select,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x212F,8495,input.pad.select.hold,1,input.pad.select,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2130,8496,input.touch.button.pressed,1,input.touch.button,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2131,8497,input.touch.button.released,1,input.touch.button,released,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2132,8498,input.touch.button.down,1,input.touch.button,down,0,1,,Bool,true,false,,1,false,fixed,0,0 -0x2133,8499,input.touch.button.hold,1,input.touch.button,hold,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2134,8500,input.touch.x,1,input.touch,x,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x2135,8501,input.touch.y,1,input.touch,y,0,1,,Int64,true,false,,1,false,fixed,0,0 -0x3000,12288,math.i32.min,1,math.i32,min,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0 -0x3001,12289,math.i32.max,1,math.i32,max,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0 -0x3002,12290,math.i32.clamp,1,math.i32,clamp,3,1,Int32|Int32|Int32,Int32,true,false,value|min|max,4,false,fixed,0,0 -0x3003,12291,math.i32.abs,1,math.i32,abs,1,1,Int32,Int32,true,false,value,2,false,fixed,0,0 -0x3004,12292,math.i64.min,1,math.i64,min,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0 -0x3005,12293,math.i64.max,1,math.i64,max,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0 -0x3006,12294,math.i64.clamp,1,math.i64,clamp,3,1,Int64|Int64|Int64,Int64,true,false,value|min|max,4,false,fixed,0,0 -0x3007,12295,math.i64.abs,1,math.i64,abs,1,1,Int64,Int64,true,false,value,2,false,fixed,0,0 -0x3008,12296,mathf.min,1,mathf,min,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0 -0x3009,12297,mathf.max,1,mathf,max,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0 -0x300A,12298,mathf.clamp,1,mathf,clamp,3,1,Float|Float|Float,Float,true,false,value|min|max,4,false,fixed,0,0 -0x300B,12299,mathf.abs,1,mathf,abs,1,1,Float,Float,true,false,value,2,false,fixed,0,0 -0x300C,12300,mathf.floor,1,mathf,floor,1,1,Float,Float,true,false,value,4,false,fixed,0,0 -0x300D,12301,mathf.ceil,1,mathf,ceil,1,1,Float,Float,true,false,value,4,false,fixed,0,0 -0x300E,12302,mathf.trunc,1,mathf,trunc,1,1,Float,Float,true,false,value,4,false,fixed,0,0 -0x300F,12303,mathf.round,1,mathf,round,1,1,Float,Float,true,false,value,4,false,fixed,0,0 -0x3010,12304,mathf.sqrt,1,mathf,sqrt,1,1,Float,Float,true,false,value,16,false,fixed,0,0 -0x3011,12305,mathf.sin,1,mathf,sin,1,1,Float,Float,true,false,angle,32,false,fixed,0,0 -0x3012,12306,mathf.cos,1,mathf,cos,1,1,Float,Float,true,false,angle,32,false,fixed,0,0 -0x3013,12307,mathf.atan2,1,mathf,atan2,2,1,Float|Float,Float,true,false,y|x,48,false,fixed,0,0 -0x3014,12308,math.i32.to_i64,1,math.i32,to_i64,1,1,Int32,Int64,true,false,value,2,false,fixed,0,0 -0x3015,12309,math.i64.to_i32,1,math.i64,to_i32,1,1,Int64,Int32,true,false,value,2,false,fixed,0,0 -0x3016,12310,math.i32.to_float,1,math.i32,to_float,1,1,Int32,Float,true,false,value,2,false,fixed,0,0 -0x3017,12311,math.i64.to_float,1,math.i64,to_float,1,1,Int64,Float,true,false,value,2,false,fixed,0,0 -0x3018,12312,mathf.to_i32,1,mathf,to_i32,1,1,Float,Int32,true,false,value,2,false,fixed,0,0 -0x3019,12313,mathf.to_i64,1,mathf,to_i64,1,1,Float,Int64,true,false,value,2,false,fixed,0,0 -0x4000,16384,random.new,1,random,new,1,1,Int64,builtin:Random,true,true,seed,32,true,fixed,0,0 -0x4001,16385,random.next,1,random,next,1,1,builtin:Random,Int64,true,false,rng,8,true,fixed,0,0 -0x4002,16386,random.nextf,1,random,nextf,1,1,builtin:Random,Float,true,false,rng,12,true,fixed,0,0 -0x4003,16387,random.range,1,random,range,3,1,builtin:Random|Int64|Int64,Int64,true,false,rng|min|max,4,true,random_rejection_v1,8,64 +final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts,schema_version,arg_nullable,invocation_model,scratch_model,context_access,cost_arg_index,cost_per_byte +0x1000,4096,vec2.dot,1,vec2,dot,4,1,Float|Float|Float|Float,Float,true,false,ax|ay|bx|by,10,false,fixed,0,0,2,false|false|false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x1001,4097,vec2.length,1,vec2,length,2,1,Float|Float,Float,true,false,x|y,40,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x1100,4352,color.from_raw,1,color,from_raw,1,1,Int64,builtin:color,true,false,raw,1,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x1101,4353,color.rgb,1,color,rgb,3,1,Int64|Int64|Int64,builtin:color,true,false,r|g|b,1,false,fixed,0,0,2,false|false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x1102,4354,color.rgba,1,color,rgba,4,1,Int64|Int64|Int64|Int64,builtin:color,true,false,r|g|b|a,1,false,fixed,0,0,2,false|false|false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x1103,4355,color.html_rgba,1,color,html_rgba,1,1,String,builtin:color,true,false,value,1,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x1104,4356,color.gray_scale,1,color,gray_scale,1,1,Int64,builtin:color,true,false,value,1,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x1105,4357,color.hex,1,color,hex,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x1106,4358,color.alpha,1,color,alpha,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x1120,4384,color.black,1,color,black,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1121,4385,color.white,1,color,white,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1122,4386,color.red,1,color,red,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1123,4387,color.green,1,color,green,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1124,4388,color.blue,1,color,blue,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1125,4389,color.yellow,1,color,yellow,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1126,4390,color.orange,1,color,orange,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1127,4391,color.indigo,1,color,indigo,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1128,4392,color.gray,1,color,gray,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x1129,4393,color.cyan,1,color,cyan,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x112A,4394,color.magenta,1,color,magenta,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x112B,4395,color.transparent,1,color,transparent,0,1,,builtin:color,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2100,8448,input.pad.up.pressed,1,input.pad.up,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2101,8449,input.pad.up.released,1,input.pad.up,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2102,8450,input.pad.up.down,1,input.pad.up,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2103,8451,input.pad.up.hold,1,input.pad.up,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2104,8452,input.pad.down.pressed,1,input.pad.down,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2105,8453,input.pad.down.released,1,input.pad.down,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2106,8454,input.pad.down.down,1,input.pad.down,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2107,8455,input.pad.down.hold,1,input.pad.down,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2108,8456,input.pad.left.pressed,1,input.pad.left,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2109,8457,input.pad.left.released,1,input.pad.left,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x210A,8458,input.pad.left.down,1,input.pad.left,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x210B,8459,input.pad.left.hold,1,input.pad.left,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x210C,8460,input.pad.right.pressed,1,input.pad.right,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x210D,8461,input.pad.right.released,1,input.pad.right,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x210E,8462,input.pad.right.down,1,input.pad.right,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x210F,8463,input.pad.right.hold,1,input.pad.right,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2110,8464,input.pad.a.pressed,1,input.pad.a,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2111,8465,input.pad.a.released,1,input.pad.a,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2112,8466,input.pad.a.down,1,input.pad.a,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2113,8467,input.pad.a.hold,1,input.pad.a,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2114,8468,input.pad.b.pressed,1,input.pad.b,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2115,8469,input.pad.b.released,1,input.pad.b,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2116,8470,input.pad.b.down,1,input.pad.b,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2117,8471,input.pad.b.hold,1,input.pad.b,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2118,8472,input.pad.x.pressed,1,input.pad.x,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2119,8473,input.pad.x.released,1,input.pad.x,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x211A,8474,input.pad.x.down,1,input.pad.x,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x211B,8475,input.pad.x.hold,1,input.pad.x,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x211C,8476,input.pad.y.pressed,1,input.pad.y,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x211D,8477,input.pad.y.released,1,input.pad.y,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x211E,8478,input.pad.y.down,1,input.pad.y,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x211F,8479,input.pad.y.hold,1,input.pad.y,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2120,8480,input.pad.l.pressed,1,input.pad.l,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2121,8481,input.pad.l.released,1,input.pad.l,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2122,8482,input.pad.l.down,1,input.pad.l,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2123,8483,input.pad.l.hold,1,input.pad.l,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2124,8484,input.pad.r.pressed,1,input.pad.r,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2125,8485,input.pad.r.released,1,input.pad.r,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2126,8486,input.pad.r.down,1,input.pad.r,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2127,8487,input.pad.r.hold,1,input.pad.r,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2128,8488,input.pad.start.pressed,1,input.pad.start,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2129,8489,input.pad.start.released,1,input.pad.start,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x212A,8490,input.pad.start.down,1,input.pad.start,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x212B,8491,input.pad.start.hold,1,input.pad.start,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x212C,8492,input.pad.select.pressed,1,input.pad.select,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x212D,8493,input.pad.select.released,1,input.pad.select,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x212E,8494,input.pad.select.down,1,input.pad.select,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x212F,8495,input.pad.select.hold,1,input.pad.select,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2130,8496,input.touch.button.pressed,1,input.touch.button,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2131,8497,input.touch.button.released,1,input.touch.button,released,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2132,8498,input.touch.button.down,1,input.touch.button,down,0,1,,Bool,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2133,8499,input.touch.button.hold,1,input.touch.button,hold,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2134,8500,input.touch.x,1,input.touch,x,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x2135,8501,input.touch.y,1,input.touch,y,0,1,,Int64,true,false,,1,false,fixed,0,0,2,,host_buffered_v1,existing_contract_v1,host,,0 +0x3000,12288,math.i32.min,1,math.i32,min,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3001,12289,math.i32.max,1,math.i32,max,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3002,12290,math.i32.clamp,1,math.i32,clamp,3,1,Int32|Int32|Int32,Int32,true,false,value|min|max,4,false,fixed,0,0,2,false|false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3003,12291,math.i32.abs,1,math.i32,abs,1,1,Int32,Int32,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3004,12292,math.i64.min,1,math.i64,min,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3005,12293,math.i64.max,1,math.i64,max,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3006,12294,math.i64.clamp,1,math.i64,clamp,3,1,Int64|Int64|Int64,Int64,true,false,value|min|max,4,false,fixed,0,0,2,false|false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3007,12295,math.i64.abs,1,math.i64,abs,1,1,Int64,Int64,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3008,12296,mathf.min,1,mathf,min,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3009,12297,mathf.max,1,mathf,max,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x300A,12298,mathf.clamp,1,mathf,clamp,3,1,Float|Float|Float,Float,true,false,value|min|max,4,false,fixed,0,0,2,false|false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x300B,12299,mathf.abs,1,mathf,abs,1,1,Float,Float,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x300C,12300,mathf.floor,1,mathf,floor,1,1,Float,Float,true,false,value,4,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x300D,12301,mathf.ceil,1,mathf,ceil,1,1,Float,Float,true,false,value,4,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x300E,12302,mathf.trunc,1,mathf,trunc,1,1,Float,Float,true,false,value,4,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x300F,12303,mathf.round,1,mathf,round,1,1,Float,Float,true,false,value,4,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3010,12304,mathf.sqrt,1,mathf,sqrt,1,1,Float,Float,true,false,value,16,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3011,12305,mathf.sin,1,mathf,sin,1,1,Float,Float,true,false,angle,32,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3012,12306,mathf.cos,1,mathf,cos,1,1,Float,Float,true,false,angle,32,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3013,12307,mathf.atan2,1,mathf,atan2,2,1,Float|Float,Float,true,false,y|x,48,false,fixed,0,0,2,false|false,host_buffered_v1,existing_contract_v1,host,,0 +0x3014,12308,math.i32.to_i64,1,math.i32,to_i64,1,1,Int32,Int64,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3015,12309,math.i64.to_i32,1,math.i64,to_i32,1,1,Int64,Int32,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3016,12310,math.i32.to_float,1,math.i32,to_float,1,1,Int32,Float,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3017,12311,math.i64.to_float,1,math.i64,to_float,1,1,Int64,Float,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3018,12312,mathf.to_i32,1,mathf,to_i32,1,1,Float,Int32,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x3019,12313,mathf.to_i64,1,mathf,to_i64,1,1,Float,Int64,true,false,value,2,false,fixed,0,0,2,false,host_buffered_v1,existing_contract_v1,host,,0 +0x4000,16384,random.new,1,random,new,1,1,Int64,builtin:Random,true,true,seed,32,true,fixed,0,0,2,false,vm_owned_v1,existing_contract_v1,vm_state,,0 +0x4001,16385,random.next,1,random,next,1,1,builtin:Random,Int64,true,false,rng,8,true,fixed,0,0,2,true,vm_owned_v1,existing_contract_v1,vm_state,,0 +0x4002,16386,random.nextf,1,random,nextf,1,1,builtin:Random,Float,true,false,rng,12,true,fixed,0,0,2,true,vm_owned_v1,existing_contract_v1,vm_state,,0 +0x4003,16387,random.range,1,random,range,3,1,builtin:Random|Int64|Int64,Int64,true,false,rng|min|max,4,true,random_rejection_v1,8,64,2,true|false|false,vm_owned_v1,existing_contract_v1,vm_state,,0 +0x4100,16640,hash.i64,1,hash,i64,1,1,Int64,Int64,true,false,value,8,false,fixed,0,0,2,false,borrowed_inline_v1,none,none,,0 +0x4101,16641,hash.float,1,hash,float,1,1,Float,Int64,true,false,value,8,false,fixed,0,0,2,false,borrowed_inline_v1,none,none,,0 +0x4102,16642,hash.string,1,hash,string,1,1,String,Int64,true,false,value,8,false,argument_utf8_bytes_v1,0,0,2,true,borrowed_inline_v1,none,none,0,1 diff --git a/docs/vm-arch/ISA_CORE.md b/docs/vm-arch/ISA_CORE.md index a2263af..c43d187 100644 --- a/docs/vm-arch/ISA_CORE.md +++ b/docs/vm-arch/ISA_CORE.md @@ -107,9 +107,10 @@ Example: - Rows must remain unique by both `(canonical_name, canonical_version)` and `final_id_hex` / `final_id_dec`. - Rows must remain deterministically ordered by final ID. - parameter_names uses ordered | separated names for flattened argument slots. -- cost_model is fixed or random_rejection_v1. cost_cycles is the full fixed +- cost_model is fixed, random_rejection_v1, or argument_utf8_bytes_v1. cost_cycles is the full fixed cost or the variable base. attempt_cost_cycles/max_attempts are zero for - fixed entries; random.range publishes base 4, attempt 8, maximum 64. + fixed and String byte-cost entries; random.range publishes base 4, attempt 8, maximum 64. + hash.string publishes base 8, argument index 0 and one cycle per UTF-8 byte. - Mathematical and random attempts charge upfront, including failure, without an additional generic INTRINSIC cycle. Random draws retain attempt costs. - mutates_guest_state distinguishes reproducible stateful calls from pure @@ -207,3 +208,17 @@ source-selected Struct destinations. Its schema is an ordinary Registry Struct; no new category, request object, syscall or safepoint is introduced. Exact nullable destination rules, stack effects, validation, costs and commit semantics are in the [canonical instruction contract](../specs/runtime/02-vm-instruction-set.md#atomic-publication-of-multiple-struct-instances). + +## Identity/hash and catalog schema 2 + +The [identity/hash specification](../specs/runtime/02f-vm-identity-and-value-hashing.md) +defines opcodes 0x0097/0x0098, intrinsics 0x4100–0x4102, XXH64 hash-v1 and +borrowed_inline_v1. INTRINSICS.csv schema 2 retains its original eighteen columns +and appends schema_version, arg_nullable, invocation_model, scratch_model, +context_access, cost_arg_index and cost_per_byte. Descriptors remain authoritative; +unknown or inconsistent schemas/profiles/models must fail explicitly. Existing +canonical versions, signatures, effects and costs remain unchanged. + +See the [identity/hash producer handoff](identity-hashing-producer-handoff.md) and +[qualification record](IDENTITY_HASHING_QUALIFICATION.md) for emitted PBX, catalog +provenance and consumer acceptance evidence. diff --git a/docs/vm-arch/identity-hashing-producer-handoff.md b/docs/vm-arch/identity-hashing-producer-handoff.md new file mode 100644 index 0000000..7aa2b9a --- /dev/null +++ b/docs/vm-arch/identity-hashing-producer-handoff.md @@ -0,0 +1,104 @@ +# Identity and hashing producer handoff + +The runtime provides the five operations in the +[identity/hash contract](../specs/runtime/02f-vm-identity-and-value-hashing.md). +The [catalog](INTRINSICS.csv) uses schema 2. Compiler/SDK integration is pending +consumer work; the neutral PBX corpus qualifies the provider independently of +any source language. No host, firmware, syscall or Lua frontend is required. + +## Provider identity + +The [qualification record](IDENTITY_HASHING_QUALIFICATION.md) identifies the +source base revision, source fingerprint, toolchain, catalog/constant/vector +SHA-256 values and executed commands. Pin the delivered runtime revision and +catalog digest together when importing this provider. A catalog-only copy does +not establish consumer compatibility. The hash contract version remains one; +schema version two changes metadata representation, not old intrinsic versions. + +## Representation and emission + +| Operation | Encoding | Complete input group(s) | Output | Cycles | +| --- | --- | --- | --- | --- | +| REF_IDENTITY_HASH | u16 0x0097, u32 source TypeId | source | Int64 | 8+w(source) | +| REF_IDENTITY_EQ | u16 0x0098, u32 left TypeId, u32 right TypeId | left then right | Bool | 4+w(left)+w(right) | +| hash.i64@1 | INTRINSIC u32 0x4100 | Int64 | Int64 | 8 | +| hash.float@1 | INTRINSIC u32 0x4101 | Float | Int64 | 8 | +| hash.string@1 | INTRINSIC u32 0x4102 | nullable String | Int64 | 8+UTF-8 bytes | + +All fields are little-endian. TypeIds are program-local Registry indices. +Reference eligibility is exactly Struct/Array/Fn/Trait/Random; preserve complete +Trait pairs and source evaluation order. Valid trait views hash/compare their +receiver, including ImplementationId zero. Do not project String/Dynamic through +these opcodes or widen the older REF_* category rules. + +For example, with TypeId 5 a Struct and TypeId 7 its Trait, emit: + +```text +STRUCT_NEW 5 +SET_LOCAL 0 +GET_LOCAL 0 +REF_IDENTITY_HASH 5 +GET_LOCAL 0 +REF_TO_TRAIT source=5,target=7 +REF_IDENTITY_HASH 7 +EQ +RET +``` + +The result is true. Trait conversion must have a coherent Registry implementation. +Hash values use signed Int64 carriers with unchanged digest bits; negative results +are valid. SDK code must define ordered component composition, optional/Dynamic +strategies, 32-bit folding, and coherent equality domains. Integer/Float equality +across domains requires explicit canonicalization; numerical Float-to-Int64 +conversion is not the Float hashing algorithm. + +## Metadata import and rejection + +Import all 25 exact columns, including schema_version=2 on every row and ordered +arg_nullable booleans matching flattened argument slots. Preserve the existing +18 fields. Validate: + +- borrowed_inline_v1/none/none is the hash profile; deterministic=true, + may_allocate=false and mutates_guest_state=false are separate claims. +- fixed numeric costs have no cost_arg_index and cost_per_byte=0. +- argument_utf8_bytes_v1 uses String slot zero, cost_per_byte=1 and base eight; + attempt_cost_cycles/max_attempts are zero. +- Old Host and VM-owned entries retain their explicit profiles and existing + contract; their metadata does not promise the bounded profile's execution model. +- Known null is admitted for hash.string only among String arguments; previous + String intrinsics and numeric hashes keep non-nullable admission. Random + nullable admission still allows runtime receiver precondition faults. + +Reject unsupported schemas, profiles, cost models, capacities and inconsistent +layouts/nullable widths/indexes explicitly. Do not infer nullability, scratch, +context access or purity from names or deterministic alone. Preserve observable +faults and charged work when results are unused. Optimization must not skip +complete right-side validation because a left operand is null or differs. + +## Studio consumer ownership and acceptance + +The following targets belong to the Studio/compiler delivery, outside this +runtime implementation: + +| Target | Required result and acceptance evidence | +| --- | --- | +| Manual IRVMIntrinsicDefinition and intrinsic registry | Represent/import schema, nullable mask, invocation/scratch/context and cost parameters; reject unknown or inconsistent entries. | +| IR, verifier, lowering and emitter | Represent both typed reference instructions, complete operand groups and exact IDs; admit nullable String per entry; preserve fault order and costs. | +| Catalog mirrors and runtime-catalog pin | Copy generated schema 2 artifacts, record runtime revision and SHA-256, retain all old IDs/versions/contracts and constant bytes. | +| Packaged compiler and SDK resources | Installed resources and generated code use the same pin, schema and definitions as development execution. | +| SDK equality/hash wrappers | Explicit domain policy, null handling, Float zero normalization, Int32 widening, Bool mapping, composition and 32-bit folding. No implicit object-content or universal Dynamic equality. | +| Normal and optimized source corpus | Execute emitted PBX against the runtime and compare result bits, faults, retained operands and cycles. Include the neutral cases below and packaged execution. | + +Consumer corpus coverage must include signed Int64 extremes and negative digests; +finite Float subnormals/extremes/2^53, both zeros and injected non-finite faults; +UTF-8, NUL, empty/null and equal content with different owners; aliases versus +distinct objects/closures/generators; mutation and Random advancement; Trait +views and implementation zero; absent and malformed groups; stale handles after +GC/reuse; rejected right groups despite null/different left groups; zero fuel, +positive overshoot and discarded results. Reuse the +[reference vectors](../../crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv) +with their [independent oracle provenance](../../crates/console/prometeu-vm/tests/fixtures/hash-oracle.md). + +Set/Map implementation, source frontend integration, general structural equality, +storage-publication integration and any future Lua frontend retain their own +scope and validation. This handoff does not report those consumers as delivered. diff --git a/docs/vm-arch/identity-hashing-qualification.json b/docs/vm-arch/identity-hashing-qualification.json new file mode 100644 index 0000000..387e3ef --- /dev/null +++ b/docs/vm-arch/identity-hashing-qualification.json @@ -0,0 +1,126 @@ +{ + "date": "2026-10-23", + "target": "aarch64-apple-darwin", + "rustc": "1.98.1 (48a229cea 2026-09-01)", + "cargo": "1.98.1 (797e8a9bc 2026-08-05)", + "base_revision": "57992cf214e8a5f9de53a40dba9aaa7fab038c91", + "delivery_state": "working tree; source and artifact digests identify this qualification", + "source_fingerprint_encoding": "For sorted source_files paths, SHA256(path UTF-8 + NUL + file bytes + NUL), concatenated in order.", + "source_fingerprint_sha256": "a0d202e46fbca3319d7b04fe09906388c015da7b606216e75bd7c62041011885", + "source_files": { + "crates/console/prometeu-bytecode/src/assembler.rs": "f6167c76402dda95e32e12d801791625be0232864df96eab6857bedbc94cfe95", + "crates/console/prometeu-bytecode/src/disassembler.rs": "c75a82b46d7845ea08d3fdee7abba4ce4f8bfb589c787d8ce72728da973947c7", + "crates/console/prometeu-bytecode/src/opcode.rs": "ec3ae01e521190757c882df5119ad86ee35204986bbf894cc57c6a565f31c097", + "crates/console/prometeu-bytecode/src/opcode_spec.rs": "cf393b2681bc7326fb79f1646bfbaf507b371e45648a6ef0d835eccbb6b9adba", + "crates/console/prometeu-bytecode/src/registry.rs": "6fe288fe41bf753279a8dcbe4b62d8878c82c7c0e7227ef10764af1b4f37e13d", + "crates/console/prometeu-bytecode/src/registry_instruction.rs": "957a06d9d9d801021af9341a01b84a21299e2ffe8c1bc50dfcec867ea7e18030", + "crates/console/prometeu-bytecode/tests/registry_isa.rs": "c67183a8b7100690fdd3b723b43024fc63afe63b8fb50bbcd1fb61f3f0e75323", + "crates/console/prometeu-vm/src/builtins.rs": "061785b356373f92c69cb6c774344b3e6ae77d33014061529e4ce905da5afe33", + "crates/console/prometeu-vm/src/catalog.rs": "d4f53cd5da6e7b90a3454aefd696baac1d49b2a4cf8cada2d563a6f3c190f81a", + "crates/console/prometeu-vm/src/hash_intrinsics.rs": "40c307e78e773908a42a187ca7a0b42667d38f72a480208d2b8255d8c322e324", + "crates/console/prometeu-vm/src/hashing.rs": "5f81f74560fd126e4344fdb47e4a6ba916b94954ccf8ce70af796adbacf10ab1", + "crates/console/prometeu-vm/src/input_intrinsics.rs": "5d0f6985f1bb0038405dd853816d9e16b636a3157d870a282aeaf742c30700ae", + "crates/console/prometeu-vm/src/intrinsic_contract.rs": "09908ccff4586c0985cdf5b3b65b0844dd175dffa301ed5902d4e0b83f16bc49", + "crates/console/prometeu-vm/src/lib.rs": "c69e7fcb9dd6a6d3c174c1ec6ed61d0c3a884254aa3882438bfe1b99e22c273f", + "crates/console/prometeu-vm/src/math_intrinsics.rs": "22101a563b5fd5f4a47b463b3482be80d39483a8a0cea285453cff385174cb19", + "crates/console/prometeu-vm/src/random_intrinsics.rs": "dfc398ed6a62c2fb50d9316d1ec9e03c04fa1651f6087e8c108ded5668894a2a", + "crates/console/prometeu-vm/src/registry_verifier/types.rs": "4a3af80df86c01cdad4d2f78c7e0578cb8e4afab9ff5148d13c431cf4cbc8d85", + "crates/console/prometeu-vm/src/value_contract.rs": "69bb9dc6921e3a5ef2f4fc0d36a952ae7717335859ee864afd0744799314ae81", + "crates/console/prometeu-vm/src/virtual_machine.rs": "cbe860aaec823400bd3657f6d4fb2cf2b18d65295527ad63a58021e7cf117b03", + "crates/console/prometeu-vm/src/virtual_machine/identity.rs": "0f16d16030fd4b233185abc140346fe89134bd1cd783e652c7f2bafa4ce7030a", + "crates/console/prometeu-vm/src/virtual_machine/identity_tests.rs": "859d8db588de45129dd70c86260f864fa8412581de3972080dc772bb5e306800", + "crates/console/prometeu-vm/src/virtual_machine/intrinsic.rs": "1b7ac3a384b4dee22906d9bfb274a4375eefefe3ce3ba80e1c34b0cc120816e2", + "crates/console/prometeu-vm/tests/execution_allocations.rs": "ab21890759be059c93b3b8a54cfbe33f8372b41e608e461fe0923c8f15a5434f", + "crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv": "a863486eaea14ab1a010f076f355eed0d5738207dad3651f7d10e92fc09f74d4", + "crates/console/prometeu-vm/tests/fixtures/hash-oracle.md": "2001e073c610a78df79d21fb973aa017ddf23312751716445f106d60b71e4113", + "crates/console/prometeu-vm/tests/fixtures/hash-oracle.py": "48bb6cae67b96f9bd8c306236d74ef61dc9aa0309c846c289298f870ceb367a1", + "crates/console/prometeu-vm/tests/identity_hashing.rs": "9ec0c42354fb5cc0eaa440aa2405e2fdffea3b91a98f2d8399275d2d1ebf8304", + "crates/console/prometeu-vm/tests/intrinsic_profiles.rs": "3bc549f666e4b3b30789704fa7a9f050273a370340e1f40ca33fcd10cc61402c", + "crates/console/prometeu-vm/tests/support/identity.rs": "cd8407f94d8c3b4782eaacbd5a934f278f25ee20d604c2f6862e7646bca54069" + }, + "artifact_sha256": { + "Cargo.lock": "cffad9ed62f38a591538abd81dd39270d6022397342c8189f4ac6c7baaa8e795", + "docs/vm-arch/INTRINSICS.csv": "7c1c363f5f0f941b3ab27cfc72af41e13e44cd4371c687db8300721288f47e63", + "docs/vm-arch/BUILTIN_CONSTANTS.csv": "e407e4718127aa7ef7b1097b5b4b67d86dd979235e73a551a7c36b628cddc039", + "crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv": "a863486eaea14ab1a010f076f355eed0d5738207dad3651f7d10e92fc09f74d4" + }, + "checks": [ + { + "command": "cargo test --locked --offline -p prometeu-bytecode -p prometeu-vm --no-fail-fast", + "result": "passed", + "passed": 453, + "failed": 0, + "ignored": 3 + }, + { + "command": "cargo test --locked --offline -p prometeu-vm --features resource-diagnostics --no-fail-fast", + "result": "passed", + "passed": 401, + "failed": 0, + "ignored": 2 + }, + { + "command": "cargo test --locked --offline -p prometeu-quality-checks -p prometeu-layer-tests --no-fail-fast", + "result": "passed", + "passed": 19, + "failed": 0, + "ignored": 0 + }, + { + "command": "cargo test --locked --offline --release -p prometeu-vm --test identity_hashing --test intrinsic_profiles --test execution_allocations", + "result": "passed", + "passed": 12, + "failed": 0, + "ignored": 0 + }, + { + "command": "cargo check --locked --offline --workspace --all-targets", + "result": "passed" + }, + { + "command": "cargo fmt --all --check", + "result": "passed" + }, + { + "command": "git diff --check", + "result": "passed" + }, + { + "command": "Regenerate catalog from runtime descriptors and compare exact bytes", + "result": "passed" + }, + { + "command": "Regenerate 118 vectors from the pinned official C reference and compare exact bytes", + "result": "passed" + }, + { + "command": "Compare all 105 legacy catalog entries first 18 fields and constant catalog bytes against base revision", + "result": "passed" + }, + { + "command": "Verify source/artifact SHA-256 values, changed Markdown links, published workflow references and lesson links", + "result": "passed" + } + ], + "oracle": { + "algorithm": "XXH64 seed 0", + "upstream": "xxHash v0.8.3 official C header", + "header_sha256": "17973c0dc49d9854ca26caa191f0e12f7a424b68858d9a78de3860d959d85e4b", + "vectors": 118 + }, + "legacy": { + "intrinsic_entries_preserved": 105, + "previous_fields_per_entry_preserved": 18, + "new_entries": 3, + "constant_catalog_byte_identical": true + }, + "allocator": { + "new_instruction_regions": 10, + "warmup_iterations": 10, + "measured_iterations_per_region": 1000, + "native_allocations": 0, + "native_deallocations": 0, + "guest_allocations": 0 + }, + "limits": "Local debug/default, debug/resource-diagnostics, and selected release evidence only. No source compiler, Studio packaging, other host/target, or GUI execution qualified." +}