Compare commits
79
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0df4371f7 | ||
|
|
e2be7ff6de | ||
|
|
88d9b99165 | ||
|
|
361a6f4587 | ||
|
|
e19cc7a66b | ||
|
|
d496742500 | ||
|
|
9d705ec44f | ||
|
|
17e73f246a | ||
|
|
017a0eb22c | ||
|
|
a4f499ce12 | ||
|
|
b9686af9c8 | ||
|
|
e8faf398f5 | ||
|
|
0c9731a8f9 | ||
|
|
148a0ce5e4 | ||
|
|
23a67af7db | ||
|
|
709d07775b | ||
|
|
b59791e0c5 | ||
|
|
5501dfd66d | ||
|
|
ffaa51a092 | ||
|
|
a226191c1c | ||
|
|
9d84b7164e | ||
|
|
e460bdc139 | ||
|
|
a951509350 | ||
|
|
46460fcec3 | ||
|
|
5f6e7dd40d | ||
|
|
c93de9fe41 | ||
|
|
4922e49853 | ||
|
|
c82693e9c1 | ||
|
|
772c4aad11 | ||
|
|
79c6c72fd6 | ||
|
|
e83ced0e20 | ||
|
|
5faeb77411 | ||
|
|
1d0c275a04 | ||
|
|
ea8030b707 | ||
|
|
5aab1e0131 | ||
|
|
f1b4780e2c | ||
|
|
f6889940c3 | ||
|
|
31caf922b8 | ||
|
|
c0f892c539 | ||
|
|
a5fe65021b | ||
|
|
b1eb641729 | ||
|
|
ebea5f5cfd | ||
|
|
024df31e66 | ||
|
|
11c068e03e | ||
|
|
db198c05f6 | ||
|
|
2e6bcd51a1 | ||
|
|
9e01f2d5d3 | ||
|
|
f1f7662afa | ||
|
|
b17c9826c7 | ||
|
|
086ad87296 | ||
|
|
58eeaf1dd4 | ||
|
|
c7df11210a | ||
|
|
c48e7b616d | ||
|
|
c9e5f22d03 | ||
|
|
4cea798651 | ||
|
|
11adff8278 | ||
|
|
ea6dbf3e6c | ||
|
|
bb8e6b3872 | ||
|
|
3d7de8ffb7 | ||
|
|
19a3408912 | ||
|
|
970cf5bb9d | ||
|
|
a2d0365813 | ||
|
|
e9c3f36970 | ||
|
|
98e3b9d6a5 | ||
|
|
5d352139dd | ||
|
|
d3599245f8 | ||
|
|
d1495ff2d5 | ||
|
|
12c00693f8 | ||
|
|
2e88fdb937 | ||
|
|
f49083ee96 | ||
|
|
2c58237e78 | ||
|
|
7a7a5b1612 | ||
|
|
7e687e0d5d | ||
|
|
c5f669b3c0 | ||
|
|
751d8c0bda | ||
|
|
212cb30b97 | ||
|
|
3efc252059 | ||
|
|
bd52429276 | ||
|
|
a404927a78 |
@@ -1,8 +1,9 @@
|
|||||||
name: public-benchmark-pages
|
name: public-benchmark-pages
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
workflow_run:
|
||||||
- cron: '*/15 * * * *'
|
workflows: [main-release-gate]
|
||||||
|
types: [completed]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
@@ -11,17 +12,17 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: alkane-verify
|
runs-on: alkane-pages
|
||||||
container:
|
|
||||||
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:9d2a992bbcb91014af3c85d2e1ec8c5990701cecf83fd06c8d46f9ef13dbd948
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install SSH client
|
- name: Install SSH client
|
||||||
run: |
|
run: |
|
||||||
apt-get update -qq
|
if ! command -v ssh >/dev/null 2>&1; then
|
||||||
apt-get install -y -qq --no-install-recommends openssh-client
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq --no-install-recommends openssh-client
|
||||||
|
fi
|
||||||
- name: Render measured benchmark history
|
- name: Render measured benchmark history
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
name: completed-ci-badge
|
name: completed-ci-badge
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
workflow_run:
|
||||||
- cron: '*/15 * * * *'
|
workflows: [main-release-gate, next-build]
|
||||||
|
types: [completed]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
@@ -11,7 +12,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: alkane-ci
|
runs-on: alkane-fast
|
||||||
permissions:
|
permissions:
|
||||||
actions: read
|
actions: read
|
||||||
contents: write
|
contents: write
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
name: source-pr
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [main, next]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: alkane-os-source-pr-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
source:
|
||||||
|
runs-on: alkane-fast
|
||||||
|
env:
|
||||||
|
CARGO_TARGET_DIR: target
|
||||||
|
CARGO_BUILD_JOBS: 2
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Detect README-only change
|
||||||
|
id: surface
|
||||||
|
run: |
|
||||||
|
surface=full
|
||||||
|
if [ "$GITHUB_EVENT_NAME" = pull_request ] &&
|
||||||
|
{ [ "$GITHUB_BASE_REF" = main ] || [ "$GITHUB_BASE_REF" = next ]; } &&
|
||||||
|
base="$(git merge-base HEAD "origin/$GITHUB_BASE_REF" 2>/dev/null)" &&
|
||||||
|
changed="$(git diff --name-only "$base" HEAD)" &&
|
||||||
|
[ "$changed" = README.md ]; then
|
||||||
|
surface=documentation
|
||||||
|
fi
|
||||||
|
echo "surface=$surface" >> "$GITHUB_OUTPUT"
|
||||||
|
- name: Check README-only change
|
||||||
|
if: steps.surface.outputs.surface == 'documentation'
|
||||||
|
run: |
|
||||||
|
base="$(git merge-base HEAD "origin/$GITHUB_BASE_REF")"
|
||||||
|
git diff --check "$base" HEAD
|
||||||
|
if git grep -nIE '^[[:space:]]*-----BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY-----[[:space:]]*$' --; then
|
||||||
|
echo "private key material found in tracked source" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
status=$?
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
fi
|
||||||
|
- name: Check source
|
||||||
|
if: steps.surface.outputs.surface != 'documentation'
|
||||||
|
run: |
|
||||||
|
rustup component add rustfmt
|
||||||
|
cargo fmt --check
|
||||||
|
cargo test --locked
|
||||||
|
- name: Clean generated source check
|
||||||
|
if: always()
|
||||||
|
run: python3 ci/cleanup-generated.py
|
||||||
@@ -22,8 +22,10 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install Pages SSH client
|
- name: Install Pages SSH client
|
||||||
run: |
|
run: |
|
||||||
apt-get update -qq
|
if ! command -v ssh >/dev/null 2>&1; then
|
||||||
apt-get install -y -qq --no-install-recommends openssh-client
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq --no-install-recommends openssh-client
|
||||||
|
fi
|
||||||
- name: Install Rust quality tools
|
- name: Install Rust quality tools
|
||||||
run: rustup component add rustfmt clippy
|
run: rustup component add rustfmt clippy
|
||||||
- name: Formatting
|
- name: Formatting
|
||||||
@@ -38,8 +40,6 @@ jobs:
|
|||||||
run: python3 ci/test-conformance.py
|
run: python3 ci/test-conformance.py
|
||||||
- name: Release publication checks
|
- name: Release publication checks
|
||||||
run: python3 ci/test-release.py
|
run: python3 ci/test-release.py
|
||||||
- name: Release version checks
|
|
||||||
run: python3 ci/test-version.py
|
|
||||||
- name: CI cleanup containment checks
|
- name: CI cleanup containment checks
|
||||||
run: python3 ci/test-cleanup-generated.py
|
run: python3 ci/test-cleanup-generated.py
|
||||||
- name: Quality
|
- name: Quality
|
||||||
@@ -56,12 +56,18 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
cargo test --release --locked -- --ignored --nocapture --test-threads=1 | tee bench-current.txt
|
cargo test --release --locked -- --ignored --nocapture --test-threads=1 | tee bench-current.txt
|
||||||
|
- name: Restore coverage tool
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: /root/.cargo/bin/cargo-llvm-cov
|
||||||
|
key: cargo-llvm-cov-0.8.7-rust-1.97.1-${{ runner.os }}
|
||||||
- name: Coverage tool
|
- name: Coverage tool
|
||||||
run: |
|
run: |
|
||||||
rustup component add llvm-tools-preview
|
rustup component add llvm-tools-preview
|
||||||
if ! command -v cargo-llvm-cov >/dev/null 2>&1; then
|
if [ "$(cargo llvm-cov --version 2>/dev/null || true)" != 'cargo-llvm-cov 0.8.7' ]; then
|
||||||
cargo install --locked cargo-llvm-cov --version 0.8.7
|
cargo install --locked --force cargo-llvm-cov --version 0.8.7
|
||||||
fi
|
fi
|
||||||
|
[ "$(cargo llvm-cov --version)" = 'cargo-llvm-cov 0.8.7' ]
|
||||||
- name: Unit test coverage
|
- name: Unit test coverage
|
||||||
run: |
|
run: |
|
||||||
mkdir -p coverage
|
mkdir -p coverage
|
||||||
|
|||||||
@@ -4,19 +4,22 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [next]
|
branches: [next]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: alkane-os-next
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: alkane-verify
|
runs-on: alkane-fast
|
||||||
container:
|
|
||||||
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:9d2a992bbcb91014af3c85d2e1ec8c5990701cecf83fd06c8d46f9ef13dbd948
|
|
||||||
env:
|
env:
|
||||||
CARGO_TARGET_DIR: target
|
CARGO_TARGET_DIR: target
|
||||||
|
CARGO_BUILD_JOBS: 2
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Build release candidate
|
- name: Build release candidate
|
||||||
run: cargo build --release --offline --locked
|
run: cargo build --release --locked
|
||||||
- name: Select candidate version
|
- name: Select candidate version
|
||||||
id: version
|
id: version
|
||||||
run: python3 ci/version.py next >> "$GITHUB_OUTPUT"
|
run: python3 ci/version.py next >> "$GITHUB_OUTPUT"
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
name: source-pr
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches: [next, main]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: alkane-os-source-pr-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
source:
|
|
||||||
runs-on: alkane-fast
|
|
||||||
container:
|
|
||||||
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:9d2a992bbcb91014af3c85d2e1ec8c5990701cecf83fd06c8d46f9ef13dbd948
|
|
||||||
env:
|
|
||||||
CARGO_TARGET_DIR: target
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Install source formatter
|
|
||||||
run: rustup component add rustfmt
|
|
||||||
- name: Check source formatting
|
|
||||||
run: cargo fmt --check
|
|
||||||
- name: Check release numbering
|
|
||||||
run: python3 ci/test-version.py
|
|
||||||
- name: Build source
|
|
||||||
run: cargo build --release --offline --locked
|
|
||||||
- name: Clean generated build
|
|
||||||
if: always()
|
|
||||||
run: python3 ci/cleanup-generated.py
|
|
||||||
@@ -21,9 +21,6 @@ Stratum V1. Tests have replayed 33 captured BM1366 shares and one BM1362
|
|||||||
share to a loopback pool with matching ACCEPT responses. Production board
|
share to a loopback pool with matching ACCEPT responses. Production board
|
||||||
control is still under development.
|
control is still under development.
|
||||||
|
|
||||||
The BM1370 module encodes a captured S21 Pro job and parses captured nonce
|
|
||||||
frames. Work-ID mapping, chain control, and pool acceptance remain open.
|
|
||||||
|
|
||||||
The HAL client requests PSU shutdown on sensor faults and reserves work IDs
|
The HAL client requests PSU shutdown on sensor faults and reserves work IDs
|
||||||
until a confirmed reset or shutdown. A production backend still needs a
|
until a confirmed reset or shutdown. A production backend still needs a
|
||||||
power lease, watchdog, and validated temperature limits. SHA-256d and
|
power lease, watchdog, and validated temperature limits. SHA-256d and
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ def publish(api: str, repo: str, branch: str, data: bytes, token: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
if os.environ["GITHUB_EVENT_NAME"] not in ("schedule", "workflow_dispatch"):
|
if os.environ["GITHUB_EVENT_NAME"] not in ("workflow_run", "workflow_dispatch"):
|
||||||
raise RuntimeError("badge publisher must run on a timer or manual dispatch")
|
raise RuntimeError("badge publisher must follow CI completion or manual dispatch")
|
||||||
if os.environ["GITHUB_REF"] != "refs/heads/main":
|
if os.environ["GITHUB_REF"] != "refs/heads/main":
|
||||||
raise RuntimeError("badge publisher must use the main branch")
|
raise RuntimeError("badge publisher must use the main branch")
|
||||||
repo = os.environ["GITHUB_REPOSITORY"]
|
repo = os.environ["GITHUB_REPOSITORY"]
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ PAGES_HOST_KEY = "[gitea.bluefla.re]:2222 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO
|
|||||||
|
|
||||||
def run(*args: str, env: dict[str, str] | None = None,
|
def run(*args: str, env: dict[str, str] | None = None,
|
||||||
cwd: Path | None = None) -> subprocess.CompletedProcess[str]:
|
cwd: Path | None = None) -> subprocess.CompletedProcess[str]:
|
||||||
return subprocess.run(args, env=env, cwd=cwd, text=True,
|
result = subprocess.run(args, env=env, cwd=cwd, text=True,
|
||||||
capture_output=True, check=True)
|
capture_output=True, check=False)
|
||||||
|
if result.returncode:
|
||||||
|
detail = result.stderr.strip()[:2000]
|
||||||
|
raise RuntimeError(f"{args[0]} {args[1]} exited {result.returncode}: {detail}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def current_main_sha() -> str:
|
def current_main_sha() -> str:
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ assert b">fail</text>" in svg
|
|||||||
assert b"#d1242f" in svg
|
assert b"#d1242f" in svg
|
||||||
assert b">pass</text>" in module.badge("next", "success", 108)
|
assert b">pass</text>" in module.badge("next", "success", 108)
|
||||||
environment = {
|
environment = {
|
||||||
"GITHUB_EVENT_NAME": "schedule",
|
"GITHUB_EVENT_NAME": "workflow_run",
|
||||||
"GITHUB_REF": "refs/heads/main",
|
"GITHUB_REF": "refs/heads/main",
|
||||||
"GITHUB_REPOSITORY": "owner/repo",
|
"GITHUB_REPOSITORY": "owner/repo",
|
||||||
"GITHUB_API_URL": "https://example.invalid/api/v1",
|
"GITHUB_API_URL": "https://example.invalid/api/v1",
|
||||||
@@ -49,13 +49,19 @@ with patch.dict(os.environ, environment), \
|
|||||||
module.main()
|
module.main()
|
||||||
assert latest.call_count == 2
|
assert latest.call_count == 2
|
||||||
assert [call.args[2] for call in published.call_args_list] == ["main", "next"]
|
assert [call.args[2] for call in published.call_args_list] == ["main", "next"]
|
||||||
with patch.dict(os.environ, {**environment, "GITHUB_EVENT_NAME": "workflow_run"}):
|
with patch.dict(os.environ, {**environment, "GITHUB_EVENT_NAME": "workflow_dispatch"}), \
|
||||||
|
patch.object(module, "latest_completed", side_effect=[(201, "success"),
|
||||||
|
(202, "failure")]), \
|
||||||
|
patch.object(module, "publish") as published:
|
||||||
|
module.main()
|
||||||
|
assert published.call_count == 2
|
||||||
|
with patch.dict(os.environ, {**environment, "GITHUB_EVENT_NAME": "schedule"}):
|
||||||
try:
|
try:
|
||||||
module.main()
|
module.main()
|
||||||
except RuntimeError as error:
|
except RuntimeError as error:
|
||||||
assert "timer or manual dispatch" in str(error)
|
assert "CI completion or manual dispatch" in str(error)
|
||||||
else:
|
else:
|
||||||
raise AssertionError("workflow_run event entered badge publisher")
|
raise AssertionError("scheduled event entered badge publisher")
|
||||||
for invalid in ("", "/main.svg", "../main.svg", "badges//main.svg"):
|
for invalid in ("", "/main.svg", "../main.svg", "badges//main.svg"):
|
||||||
try:
|
try:
|
||||||
publish_file("https://example.invalid/api/v1", "owner/repo", invalid,
|
publish_file("https://example.invalid/api/v1", "owner/repo", invalid,
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
"""Check candidate numbering and covered-commit reruns with real Git tags."""
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
import subprocess
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
|
|
||||||
VERSION = Path(__file__).with_name("version.py")
|
|
||||||
|
|
||||||
|
|
||||||
def git(root: Path, *args: str) -> str:
|
|
||||||
result = subprocess.run(
|
|
||||||
["git", *args], cwd=root, text=True, check=True, capture_output=True
|
|
||||||
)
|
|
||||||
return result.stdout.strip()
|
|
||||||
|
|
||||||
|
|
||||||
def selected(root: Path, branch: str) -> dict[str, str]:
|
|
||||||
result = subprocess.run(
|
|
||||||
["python3", str(VERSION), branch], cwd=root,
|
|
||||||
text=True, check=True, capture_output=True
|
|
||||||
)
|
|
||||||
return dict(line.split("=", 1) for line in result.stdout.splitlines())
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
with tempfile.TemporaryDirectory(prefix="alkane-os-version-") as path:
|
|
||||||
root = Path(path)
|
|
||||||
(root / "ci").mkdir()
|
|
||||||
(root / "ci/version-x.txt").write_text("0\n")
|
|
||||||
git(root, "init", "-q")
|
|
||||||
git(root, "config", "user.name", "Alkane CI")
|
|
||||||
git(root, "config", "user.email", "ci@example.invalid")
|
|
||||||
git(root, "add", ".")
|
|
||||||
git(root, "commit", "-qm", "First source")
|
|
||||||
first = git(root, "rev-parse", "HEAD")
|
|
||||||
assert selected(root, "next") == {
|
|
||||||
"release": "true", "tag": "v0.1.0-rc.1", "version": "0.1.0-rc.1"
|
|
||||||
}
|
|
||||||
git(root, "tag", "v0.1.0-rc.1")
|
|
||||||
assert selected(root, "next") == {"release": "false"}
|
|
||||||
|
|
||||||
(root / "README.md").write_text("A later merge.\n")
|
|
||||||
git(root, "add", ".")
|
|
||||||
git(root, "commit", "-qm", "Later source")
|
|
||||||
assert selected(root, "next") == {
|
|
||||||
"release": "true", "tag": "v0.1.0-rc.2", "version": "0.1.0-rc.2"
|
|
||||||
}
|
|
||||||
git(root, "tag", "v0.1.0-rc.2")
|
|
||||||
assert selected(root, "next") == {"release": "false"}
|
|
||||||
git(root, "checkout", "-q", first)
|
|
||||||
assert selected(root, "next") == {"release": "false"}
|
|
||||||
print("PASS: exact and superseded candidate reruns do not publish")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -27,13 +27,6 @@ def main():
|
|||||||
parser.add_argument("branch", choices=("main", "next"))
|
parser.add_argument("branch", choices=("main", "next"))
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
major = int(pathlib.Path("ci/version-x.txt").read_text().strip())
|
major = int(pathlib.Path("ci/version-x.txt").read_text().strip())
|
||||||
# A rerun of a commit already covered by a published tag must not issue
|
|
||||||
# a newer candidate number for older source.
|
|
||||||
tagged_descendants = set(git("tag", "--contains", "HEAD", "-l", "v*").splitlines())
|
|
||||||
known_tags = {tag for _, tag in versions("main") + versions("next")}
|
|
||||||
if tagged_descendants & known_tags:
|
|
||||||
print("release=false")
|
|
||||||
return
|
|
||||||
finals = versions("main")
|
finals = versions("main")
|
||||||
previous = finals[-1] if finals else None
|
previous = finals[-1] if finals else None
|
||||||
if previous and previous[0][0] > major:
|
if previous and previous[0][0] > major:
|
||||||
|
|||||||
-203
@@ -1,203 +0,0 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
|
||||||
//! BM1370 wire frames observed on an S21 Pro. This module does not control power.
|
|
||||||
|
|
||||||
use crate::bm13xx::{crc16, crc5};
|
|
||||||
|
|
||||||
pub use crate::bm1362::Job;
|
|
||||||
|
|
||||||
pub const JOB_BYTES: usize = 88;
|
|
||||||
pub const REPORT_BYTES: usize = 11;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
||||||
pub struct NonceReport {
|
|
||||||
pub nonce: u32,
|
|
||||||
pub byte6: u8,
|
|
||||||
pub byte7: u8,
|
|
||||||
pub byte8: u8,
|
|
||||||
pub byte9: u8,
|
|
||||||
/// Raw trailer: bit 7 marks a nonce response; bits 4:0 carry CRC5.
|
|
||||||
/// No chip identity is inferred from this byte.
|
|
||||||
pub trailer: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NonceReport {
|
|
||||||
/// Work ID observed in the Braiins S21 Pro capture. Chip and version
|
|
||||||
/// attribution remain unknown, and this has no accepted-share proof.
|
|
||||||
pub fn observed_work_id(&self) -> u8 {
|
|
||||||
(self.byte7 & 0xf0) >> 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
||||||
pub enum ReportError {
|
|
||||||
Length,
|
|
||||||
Preamble,
|
|
||||||
RegisterResponse,
|
|
||||||
Checksum,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encode only the job shape observed in the S21 Pro capture. `Job` fields
|
|
||||||
/// are in wire order; this does not validate a pool header or start a chain.
|
|
||||||
pub fn encode_job(job: &Job) -> Option<[u8; JOB_BYTES]> {
|
|
||||||
if job.work_id & 7 != 0 || job.num_midstates != 1 || job.start_nonce != 0 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let mut frame = crate::bm1362::encode_job(job);
|
|
||||||
frame[3] = 0x36;
|
|
||||||
let checksum = crc16(&frame[2..86]);
|
|
||||||
frame[86..88].copy_from_slice(&checksum.to_be_bytes());
|
|
||||||
Some(frame)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Keep the five trailing bytes raw. The work-ID expression is correlated with
|
|
||||||
/// same-UART jobs in one capture; chip and version mapping remain unverified.
|
|
||||||
/// The marker bit distinguishes nonce reports from register replies.
|
|
||||||
pub fn decode_nonce_report(frame: &[u8]) -> Result<NonceReport, ReportError> {
|
|
||||||
if frame.len() != REPORT_BYTES {
|
|
||||||
return Err(ReportError::Length);
|
|
||||||
}
|
|
||||||
if frame[..2] != [0xaa, 0x55] {
|
|
||||||
return Err(ReportError::Preamble);
|
|
||||||
}
|
|
||||||
if frame[10] & 0x80 == 0 {
|
|
||||||
return Err(ReportError::RegisterResponse);
|
|
||||||
}
|
|
||||||
if crc5(&frame[2..]) != 0 {
|
|
||||||
return Err(ReportError::Checksum);
|
|
||||||
}
|
|
||||||
Ok(NonceReport {
|
|
||||||
nonce: u32::from_le_bytes(frame[2..6].try_into().expect("four-byte nonce")),
|
|
||||||
byte6: frame[6],
|
|
||||||
byte7: frame[7],
|
|
||||||
byte8: frame[8],
|
|
||||||
byte9: frame[9],
|
|
||||||
trailer: frame[10],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
// firmware-analysis/prong-b/s21-192/c2-steady.strace, SHA-256
|
|
||||||
// c0aac1222e05e95bdcbd1de5a8ee244a581256e8f28e3dadf5300df6110229c7.
|
|
||||||
const CAPTURED_JOB: &str = concat!(
|
|
||||||
"55aa21366001000000008f060217834f276af0f09aafc588165b7fbfc56f8f09a55d3d0de5",
|
|
||||||
"798bd87460278af180c4696fc200000000000000008af701003acc10cdebe5bc3c90f095e5",
|
|
||||||
"03c6b7de69ca8b5d00000020e769"
|
|
||||||
);
|
|
||||||
|
|
||||||
fn captured_bytes<const N: usize>(hex: &str) -> [u8; N] {
|
|
||||||
assert_eq!(hex.len(), N * 2);
|
|
||||||
let mut bytes = [0; N];
|
|
||||||
for (index, pair) in hex.as_bytes().chunks_exact(2).enumerate() {
|
|
||||||
bytes[index] = u8::from_str_radix(std::str::from_utf8(pair).unwrap(), 16).unwrap();
|
|
||||||
}
|
|
||||||
bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
fn with_valid_crc(mut frame: [u8; REPORT_BYTES]) -> [u8; REPORT_BYTES] {
|
|
||||||
for checksum in 0..32 {
|
|
||||||
frame[10] = (frame[10] & 0xe0) | checksum;
|
|
||||||
if crc5(&frame[2..]) == 0 {
|
|
||||||
return frame;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic!("no valid CRC5 trailer");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn live_job_matches_all_88_bytes() {
|
|
||||||
let captured = captured_bytes::<JOB_BYTES>(CAPTURED_JOB);
|
|
||||||
let mut merkle_root = [0; 32];
|
|
||||||
merkle_root.copy_from_slice(&captured[18..50]);
|
|
||||||
let mut previous_hash = [0; 32];
|
|
||||||
previous_hash.copy_from_slice(&captured[50..82]);
|
|
||||||
let job = Job {
|
|
||||||
work_id: captured[4],
|
|
||||||
num_midstates: captured[5],
|
|
||||||
start_nonce: u32::from_le_bytes(captured[6..10].try_into().unwrap()),
|
|
||||||
nbits: u32::from_le_bytes(captured[10..14].try_into().unwrap()),
|
|
||||||
ntime: u32::from_le_bytes(captured[14..18].try_into().unwrap()),
|
|
||||||
merkle_root,
|
|
||||||
previous_hash,
|
|
||||||
version: u32::from_le_bytes(captured[82..86].try_into().unwrap()),
|
|
||||||
};
|
|
||||||
assert_eq!(encode_job(&job), Some(captured));
|
|
||||||
let mut invalid = job;
|
|
||||||
invalid.work_id |= 1;
|
|
||||||
assert_eq!(encode_job(&invalid), None);
|
|
||||||
invalid = job;
|
|
||||||
invalid.num_midstates = 2;
|
|
||||||
assert_eq!(encode_job(&invalid), None);
|
|
||||||
invalid = job;
|
|
||||||
invalid.start_nonce = 1;
|
|
||||||
assert_eq!(encode_job(&invalid), None);
|
|
||||||
assert_eq!(
|
|
||||||
crc16(&captured[2..86]),
|
|
||||||
u16::from_be_bytes([captured[86], captured[87]])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn live_nonce_reports_preserve_raw_tags() {
|
|
||||||
for hex in [
|
|
||||||
"aa555804a92a041e133e86",
|
|
||||||
"aa55771def23001c16fc82",
|
|
||||||
"aa5574480ae6021417b492",
|
|
||||||
] {
|
|
||||||
let frame = captured_bytes::<REPORT_BYTES>(hex);
|
|
||||||
let report = decode_nonce_report(&frame).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
report.nonce,
|
|
||||||
u32::from_le_bytes(frame[2..6].try_into().unwrap())
|
|
||||||
);
|
|
||||||
assert_eq!(report.byte6, frame[6]);
|
|
||||||
assert_eq!(report.byte7, frame[7]);
|
|
||||||
assert_eq!(report.byte8, frame[8]);
|
|
||||||
assert_eq!(report.byte9, frame[9]);
|
|
||||||
assert_eq!(report.trailer, frame[10]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn observed_work_id_matches_same_uart_job() {
|
|
||||||
// c2-steady.strace lines 1287 and 1352: job byte 4 is 0x10.
|
|
||||||
let frame = captured_bytes::<REPORT_BYTES>("aa554a3488c70022013291");
|
|
||||||
let report = decode_nonce_report(&frame).unwrap();
|
|
||||||
assert_eq!(report.observed_work_id(), 0x10);
|
|
||||||
assert_eq!(report.byte7, 0x22);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn invalid_report_fails_closed() {
|
|
||||||
let mut frame = captured_bytes::<REPORT_BYTES>("aa555804a92a041e133e86");
|
|
||||||
assert_eq!(decode_nonce_report(&frame[..10]), Err(ReportError::Length));
|
|
||||||
frame[0] = 0;
|
|
||||||
assert_eq!(decode_nonce_report(&frame), Err(ReportError::Preamble));
|
|
||||||
frame[0] = 0xaa;
|
|
||||||
frame[10] &= 0x60;
|
|
||||||
frame = with_valid_crc(frame);
|
|
||||||
assert_eq!(crc5(&frame[2..]), 0);
|
|
||||||
assert_eq!(
|
|
||||||
decode_nonce_report(&frame),
|
|
||||||
Err(ReportError::RegisterResponse)
|
|
||||||
);
|
|
||||||
frame[10] |= 0x80;
|
|
||||||
frame = with_valid_crc(frame);
|
|
||||||
frame[4] ^= 1;
|
|
||||||
assert_eq!(decode_nonce_report(&frame), Err(ReportError::Checksum));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn trailer_low_bits_are_checksum_not_chip_identity() {
|
|
||||||
let original = captured_bytes::<REPORT_BYTES>("aa555804a92a041e133e86");
|
|
||||||
let mut changed_nonce = original;
|
|
||||||
changed_nonce[2] ^= 1;
|
|
||||||
changed_nonce = with_valid_crc(changed_nonce);
|
|
||||||
assert_eq!(crc5(&changed_nonce[2..]), 0);
|
|
||||||
assert_ne!(changed_nonce[10] & 0x1f, original[10] & 0x1f);
|
|
||||||
assert_eq!(changed_nonce[10] & 0xe0, original[10] & 0xe0);
|
|
||||||
assert!(decode_nonce_report(&changed_nonce).is_ok());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
pub mod bm1362;
|
pub mod bm1362;
|
||||||
pub mod bm1366;
|
pub mod bm1366;
|
||||||
pub mod bm1370;
|
|
||||||
pub mod bm13xx;
|
pub mod bm13xx;
|
||||||
pub mod difficulty;
|
pub mod difficulty;
|
||||||
pub mod hal_wire;
|
pub mod hal_wire;
|
||||||
|
|||||||
Reference in New Issue
Block a user