diff --git a/README.md b/README.md index 64abedd..251a27b 100644 --- a/README.md +++ b/README.md @@ -33,14 +33,12 @@ backend, with bounded frames, two-second I/O timeouts, and fail-closed response validation. The matching SDK server framing library exists, but no board adapter is installed in an image yet. The library can also verify an ASIC-reported SHA-256d share against an exact -pool target, including BM13xx version rolling. A test checks a BM1366 nonce -captured from real silicon at difficulty 1588. This verifies reports only; -end-to-end pool mining and continuous job scheduling are still pending. -The `simulator_replay_probe` example sends that captured job through the Rust -HAL client to the SDK's host-only C/Python replay server, then verifies the -returned nonce. From this repository, run it with -`cargo run --example simulator_replay_probe -- SOCKET_PATH` after starting -the SDK server. It is a simulator check and sends work to the named socket. +pool target, including BM13xx version rolling. Host probes check captured +BM1362 and BM1366 nonces through the SDK's C/Python HAL replay server. From +this repository, run `cargo run --example simulator_replay_probe -- SOCKET_PATH +BM1362` or use `BM1366` after starting the corresponding SDK server. This +checks shared work/report framing and share validation for those two chips; +it does not initialize a physical chip chain. The first BM1366 mining session sequences fan, temperature, PSU, reset, work submission, and nonce polling through the HAL. It rejects stale work IDs, malformed reports, and hashes above the caller's pool target. A sensor fault diff --git a/examples/simulator_replay_probe.rs b/examples/simulator_replay_probe.rs index 13fe867..ff17b83 100644 --- a/examples/simulator_replay_probe.rs +++ b/examples/simulator_replay_probe.rs @@ -1,9 +1,10 @@ // SPDX-License-Identifier: MIT -//! Exercise the SDK's host-only BM1366 HAL simulator with a captured job. +//! Exercise the SDK's host-only BM13xx HAL simulator with a captured job. use alkane_os::hal_wire::HalClient; use alkane_os::miner::Bm1366Miner; use std::error::Error; +use std::io; const HEADER: [u8; 80] = [ 0x00, 0x00, 0x00, 0x20, 0xfc, 0x3a, 0xb8, 0xd4, 0x30, 0x21, 0xf4, 0x5e, 0xb6, 0x62, 0x38, 0x9d, @@ -13,20 +14,48 @@ const HEADER: [u8; 80] = [ 0x2c, 0x5b, 0x4c, 0x74, 0xc1, 0x01, 0x2e, 0x6a, 0x8f, 0x06, 0x02, 0x17, 0x00, 0x00, 0x00, 0x00, ]; +const BM1362_HEADER_HEX: &str = concat!( + "00000020fc3ab8d43021f45eb662389d0f791f657dbf75a5cb93670b57b6c22503", + "b4213a0503969b7384e1215aace8cfc65dae22d8493ad48fec0b7ac3b0ad7b4e7", + "fb0c5c0012e6a8f06021700000000" +); + +fn bm1362_header() -> Result<[u8; 80], io::Error> { + let mut header = [0_u8; 80]; + for (index, pair) in BM1362_HEADER_HEX.as_bytes().chunks_exact(2).enumerate() { + let digits = std::str::from_utf8(pair).map_err(io::Error::other)?; + header[index] = u8::from_str_radix(digits, 16).map_err(io::Error::other)?; + } + Ok(header) +} + fn main() -> Result<(), Box> { - let path = std::env::args() - .nth(1) - .ok_or("usage: simulator_replay_probe SOCKET_PATH")?; + let mut args = std::env::args().skip(1); + let path = args + .next() + .ok_or("usage: simulator_replay_probe SOCKET_PATH [BM1366|BM1362]")?; + let chip = args.next().unwrap_or_else(|| "BM1366".to_owned()); + if args.next().is_some() { + return Err("unexpected argument".into()); + } + let (header, nonce) = match chip.as_str() { + "BM1366" => (HEADER, 0xedad_ff38), + "BM1362" => (bm1362_header()?, 0x630b_2533), + _ => return Err("unsupported captured chip".into()), + }; let mut backend = HalClient::connect(path)?; + // BM1362 and BM1366 share the observed 88-byte job and 11-byte report + // framing exercised by this miner. Chip initialization is outside this + // host-only check. let mut miner = Bm1366Miner::new(&mut backend, 0, 0, 0, 100, 80_000) .ok_or("invalid simulator probe configuration")?; miner.start()?; let mut target = [0_u8; 32]; target[26..28].fill(0xff); - miner.submit(HEADER, target, 0x18)?; - let share = miner.poll()?.ok_or("missing BM1366 nonce report")?; + miner.submit(header, target, 0x18)?; + let share = miner.poll()?.ok_or("missing captured nonce report")?; miner.stop()?; - assert_eq!(share.nonce, 0xedad_ff38); - println!("BM1366 captured report verified at difficulty 1"); + assert_eq!(share.nonce, nonce); + println!("{chip} captured report verified at difficulty 1"); Ok(()) }