From 7c5cf72d73ce98cdea72477a4187750e8b269a98 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Tue, 27 May 2025 10:04:57 -0600 Subject: [PATCH 1/3] [WIP] cargo-checkct --- .github/workflows/cargo-checkct.yml | 23 +++++++ checkct/.cargo/config.toml | 10 +++ checkct/Cargo.lock | 98 +++++++++++++++++++++++++++++ checkct/Cargo.toml | 7 +++ checkct/driver/Cargo.toml | 10 +++ checkct/driver/src/driver.rs | 7 +++ checkct/driver/src/main.rs | 17 +++++ checkct/driver/src/rng.rs | 83 ++++++++++++++++++++++++ checkct/rust-toolchain.toml | 5 ++ 9 files changed, 260 insertions(+) create mode 100644 .github/workflows/cargo-checkct.yml create mode 100644 checkct/.cargo/config.toml create mode 100644 checkct/Cargo.lock create mode 100644 checkct/Cargo.toml create mode 100644 checkct/driver/Cargo.toml create mode 100644 checkct/driver/src/driver.rs create mode 100644 checkct/driver/src/main.rs create mode 100644 checkct/driver/src/rng.rs create mode 100644 checkct/rust-toolchain.toml diff --git a/.github/workflows/cargo-checkct.yml b/.github/workflows/cargo-checkct.yml new file mode 100644 index 00000000..52ef2727 --- /dev/null +++ b/.github/workflows/cargo-checkct.yml @@ -0,0 +1,23 @@ +name: cargo-checkct + +on: + pull_request: + paths-ignore: + - README.md + push: + branches: + - master + paths-ignore: + - README.md + +env: + CARGO_INCREMENTAL: 0 + RUSTFLAGS: "-Dwarnings" + RUSTDOCFLAGS: "-Dwarnings" + +jobs: + build: + runs-on: ubuntu-latest + uses: Ledger-Donjon/action-cargo-checkct + with: + directory: . diff --git a/checkct/.cargo/config.toml b/checkct/.cargo/config.toml new file mode 100644 index 00000000..9c036e0a --- /dev/null +++ b/checkct/.cargo/config.toml @@ -0,0 +1,10 @@ +[build] +target = ["thumbv7em-none-eabihf", "riscv32imac-unknown-none-elf", "x86_64-unknown-linux-gnu"] + +[target.'cfg(target_os = "linux")'] +rustflags = ["-C", "link-arg=-nostartfiles", "-C", "relocation-model=static"] + +[unstable] +unstable-options = true +build-std = ["core", "panic_abort"] +build-std-features = ["panic_immediate_abort", "compiler-builtins-mem"] diff --git a/checkct/Cargo.lock b/checkct/Cargo.lock new file mode 100644 index 00000000..4c5ab104 --- /dev/null +++ b/checkct/Cargo.lock @@ -0,0 +1,98 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "checkct_macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "crypto-bigint" +version = "0.7.0-pre.3" +dependencies = [ + "num-traits", + "rand_core 0.9.3", + "subtle", +] + +[[package]] +name = "driver" +version = "0.0.0" +dependencies = [ + "checkct_macros", + "crypto-bigint", + "rand_core 0.6.4", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" diff --git a/checkct/Cargo.toml b/checkct/Cargo.toml new file mode 100644 index 00000000..2c89b753 --- /dev/null +++ b/checkct/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] +members = ["driver"] +resolver = "2" + +[profile.release] +debug = true +panic = "abort" diff --git a/checkct/driver/Cargo.toml b/checkct/driver/Cargo.toml new file mode 100644 index 00000000..116a459f --- /dev/null +++ b/checkct/driver/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "driver" +version = "0.0.0" +publish = false +edition = "2021" + +[dependencies] +rand_core = "0.6.4" +checkct_macros = { path = "../../../../cargo-checkct/checkct_macros" } +crypto-bigint = { path = "../.." } diff --git a/checkct/driver/src/driver.rs b/checkct/driver/src/driver.rs new file mode 100644 index 00000000..ad8cee04 --- /dev/null +++ b/checkct/driver/src/driver.rs @@ -0,0 +1,7 @@ +use crate::rng::{CryptoRng, PrivateRng, PublicRng, RngCore}; +use checkct_macros::checkct; + +#[checkct] +pub fn checkct() { + // USER CODE GOES HERE +} diff --git a/checkct/driver/src/main.rs b/checkct/driver/src/main.rs new file mode 100644 index 00000000..6c25eeb5 --- /dev/null +++ b/checkct/driver/src/main.rs @@ -0,0 +1,17 @@ +//----- AUTOGENERATED BY CARGO-CHECKCT: DO NOT MODIFY ----- +// +#![no_std] +#![no_main] + +mod driver; +mod rng; + +#[no_mangle] +pub extern "C" fn _start() -> ! { + panic!() +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/checkct/driver/src/rng.rs b/checkct/driver/src/rng.rs new file mode 100644 index 00000000..5a1f188b --- /dev/null +++ b/checkct/driver/src/rng.rs @@ -0,0 +1,83 @@ +//----- AUTOGENERATED BY CARGO-CHECKCT: DO NOT MODIFY ----- +// +#[no_mangle] +#[inline(never)] +pub fn __checkct_private_rand() -> u8 { + unsafe { core::ptr::read_volatile(0xcafe as *const u8) } +} + +#[no_mangle] +#[inline(never)] +pub fn __checkct_public_rand() -> u8 { + unsafe { core::ptr::read_volatile(0xf00d as *const u8) } +} + +pub use rand_core::{CryptoRng, RngCore}; + +pub struct PrivateRng; + +impl PrivateRng { + pub const fn new() -> Self { + Self + } +} + +impl RngCore for PrivateRng { + fn next_u32(&mut self) -> u32 { + (__checkct_private_rand() as u32) << 24 + | (__checkct_private_rand() as u32) << 16 + | (__checkct_private_rand() as u32) << 8 + | (__checkct_private_rand() as u32) + } + + fn next_u64(&mut self) -> u64 { + (self.next_u32() as u64) << 32 | (self.next_u32() as u64) + } + + fn fill_bytes(&mut self, dest: &mut [u8]) { + for d in dest { + *d = __checkct_private_rand(); + } + } + + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { + self.fill_bytes(dest); + Ok(()) + } +} + +impl CryptoRng for PrivateRng {} + +pub struct PublicRng; + +impl PublicRng { + pub const fn new() -> Self { + Self + } +} + +impl RngCore for PublicRng { + fn next_u32(&mut self) -> u32 { + (__checkct_public_rand() as u32) << 24 + | (__checkct_public_rand() as u32) << 16 + | (__checkct_public_rand() as u32) << 8 + | (__checkct_public_rand() as u32) + } + + fn next_u64(&mut self) -> u64 { + (self.next_u32() as u64) << 32 | (self.next_u32() as u64) + } + + fn fill_bytes(&mut self, dest: &mut [u8]) { + for d in dest { + *d = __checkct_public_rand(); + } + } + + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { + self.fill_bytes(dest); + Ok(()) + } +} + +impl CryptoRng for PublicRng {} diff --git a/checkct/rust-toolchain.toml b/checkct/rust-toolchain.toml new file mode 100644 index 00000000..e1fba38c --- /dev/null +++ b/checkct/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly" +targets = ["thumbv7em-none-eabihf", "riscv32imac-unknown-none-elf", "x86_64-unknown-linux-gnu"] +profile = "minimal" +components = ["rustfmt", "rust-src"] From e3224e008c30f093943666aea6963388dabd6b80 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Thu, 29 May 2025 09:53:26 -0600 Subject: [PATCH 2/3] Update .github/workflows/cargo-checkct.yml Co-authored-by: Baptistin Boilot <159285987+bboilot-ledger@users.noreply.github.com> --- .github/workflows/cargo-checkct.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cargo-checkct.yml b/.github/workflows/cargo-checkct.yml index 52ef2727..4986ebdf 100644 --- a/.github/workflows/cargo-checkct.yml +++ b/.github/workflows/cargo-checkct.yml @@ -18,6 +18,6 @@ env: jobs: build: runs-on: ubuntu-latest - uses: Ledger-Donjon/action-cargo-checkct + uses: Ledger-Donjon/action-cargo-checkct@v1 with: directory: . From 1c7e79e318f8a8189b3cb4d7318840415211cca4 Mon Sep 17 00:00:00 2001 From: Baptistin Boilot <159285987+bboilot-ledger@users.noreply.github.com> Date: Thu, 29 May 2025 23:01:18 +0200 Subject: [PATCH 3/3] Fix cargo-checkct action (#830) Hello @tarcieri :wave: This PR should fix your action. It'll still [fail](https://github.com/bboilot-ledger/crypto-bigint/actions/runs/15332758658/job/43143257617?pr=1) because the driver hasn't been implemented yet. I am not a fan of the modification I had to do to the manifest in order for the tool to run. I'll discuss this matter with the team. --- .github/workflows/cargo-checkct.yml | 13 +++++++++---- checkct/driver/Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cargo-checkct.yml b/.github/workflows/cargo-checkct.yml index 4986ebdf..fa527d0e 100644 --- a/.github/workflows/cargo-checkct.yml +++ b/.github/workflows/cargo-checkct.yml @@ -16,8 +16,13 @@ env: RUSTDOCFLAGS: "-Dwarnings" jobs: - build: + checkct: + name: Run cargo-checkct runs-on: ubuntu-latest - uses: Ledger-Donjon/action-cargo-checkct@v1 - with: - directory: . + + steps: + - uses: actions/checkout@v4 + + - uses: Ledger-Donjon/action-cargo-checkct@v1 + with: + directory: . diff --git a/checkct/driver/Cargo.toml b/checkct/driver/Cargo.toml index 116a459f..67cf950e 100644 --- a/checkct/driver/Cargo.toml +++ b/checkct/driver/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" [dependencies] rand_core = "0.6.4" -checkct_macros = { path = "../../../../cargo-checkct/checkct_macros" } +checkct_macros = { path = "../../cargo-checkct/checkct_macros" } crypto-bigint = { path = "../.." }