Skip to content

Commit

Permalink
Merge pull request #41 from LedgerHQ/ci-improvements
Browse files Browse the repository at this point in the history
Compile Vanadium VM app in CI
  • Loading branch information
bigspider authored Nov 25, 2024
2 parents b025d08 + 761170e commit 2f42b86
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 59 deletions.
90 changes: 89 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run unit tests
name: CI

on:
push:
Expand All @@ -14,6 +14,8 @@ env:
CARGO_TERM_COLOR: always

jobs:
# Native tests

test_app_sdk:
name: Run V-App SDK tests
runs-on: ubuntu-latest
Expand Down Expand Up @@ -109,3 +111,89 @@ jobs:
working-directory: apps/test/client
run: |
cargo +nightly test --target x86_64-unknown-linux-gnu
# build Vanadium VM app

build_application:
name: Build application using the reusable workflow
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
upload_app_binaries_artifact: "vanadium_binaries"
builder: ledger-app-builder

### Risc-V tests

# build test V-App
build_vapp_test:
name: Build vnd-test on Risc-V target
runs-on: ubuntu-latest
steps:
- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: riscv32i-unknown-none-elf
components: rustfmt, clippy
profile: minimal
- name: Clone
uses: actions/checkout@v4
- name: Build app
working-directory: apps/test/app
run: |
cargo +nightly build --release --target riscv32i-unknown-none-elf
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: vnd_test_riscv_binary
path: apps/test/app/target/riscv32i-unknown-none-elf/release/vnd-test

run_speculos_integration_tests:
name: Integration tests on Speculos

strategy:
matrix:
include:
# - model: nanox # TODO: reenable once compilation is fixed
- model: nanosplus
- model: flex
- model: stax

runs-on: ubuntu-latest
needs: [build_application, build_vapp_test]
steps:
- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: x86_64-unknown-linux-gnu
components: rustfmt, clippy
profile: minimal
- name: Install Speculos
run: |
pip install speculos
- name: Install dependencies
run: |
sudo apt-get update && \
sudo apt-get install -y libudev-dev pkg-config && \
sudo apt-get install -y qemu-user-static libvncserver-dev
- name: Clone
uses: actions/checkout@v4
- name: Download Vanadium binaries
uses: actions/download-artifact@v4
with:
name: vanadium_binaries
path: ./vanadium_binaries

- name: Download vnd_test_riscv_binary
uses: actions/download-artifact@v4
with:
name: vnd_test_riscv_binary
path: ./vnd_test_riscv_binary

- name: Run integration tests
working-directory: apps/test/client
env:
VANADIUM_BINARY: ../../../vanadium_binaries/${{ matrix.model }}/release/app-vanadium
VAPP_BINARY: ../../../vnd_test_riscv_binary/vnd-test
run: |
cargo test --features speculos-tests
18 changes: 9 additions & 9 deletions app-sdk/src/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<'a, const N: usize> BigNumMod<'a, N> {
}
// reduce the buffer my the modulus
let mut buffer = buffer;
if !Ecall::bn_modm(
if 1 != Ecall::bn_modm(
buffer.as_mut_ptr(),
buffer.as_ptr(),
N,
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'a, const N: usize> BigNumMod<'a, N> {
let mut buffer = [0u8; N];
buffer[N - 4..N].copy_from_slice(&value.to_be_bytes());

if !Ecall::bn_modm(
if 1 != Ecall::bn_modm(
buffer.as_mut_ptr(),
buffer.as_ptr(),
N,
Expand Down Expand Up @@ -251,7 +251,7 @@ impl<'a, const N: usize> BigNumMod<'a, N> {
self.modulus.m.as_ptr(),
N,
);
if !res {
if res != 1 {
panic!("Exponentiation failed");
}
Self::from_be_bytes(result, self.modulus)
Expand Down Expand Up @@ -298,7 +298,7 @@ impl<'a, const N: usize> Add for &BigNumMod<'a, N> {
self.modulus.m.as_ptr(),
N,
);
if !res {
if res != 1 {
panic!("Addition failed");
}
BigNumMod::from_be_bytes(result, self.modulus)
Expand All @@ -318,7 +318,7 @@ impl<'a, const N: usize> AddAssign for BigNumMod<'a, N> {
self.modulus.m.as_ptr(),
N,
);
if !res {
if res != 1 {
panic!("Addition failed");
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ impl<'a, const N: usize> Sub for &BigNumMod<'a, N> {
self.modulus.m.as_ptr(),
N,
);
if !res {
if res != 1 {
panic!("Subtraction failed");
}
BigNumMod::from_be_bytes(result, self.modulus)
Expand All @@ -382,7 +382,7 @@ impl<'a, const N: usize> SubAssign for BigNumMod<'a, N> {
self.modulus.m.as_ptr(),
N,
);
if !res {
if res != 1 {
panic!("Subtraction failed");
}
}
Expand Down Expand Up @@ -418,7 +418,7 @@ impl<'a, const N: usize> core::ops::Mul for &BigNumMod<'a, N> {
self.modulus.m.as_ptr(),
N,
);
if !res {
if res != 1 {
panic!("Multiplication failed");
}
BigNumMod::from_be_bytes(result, self.modulus)
Expand All @@ -438,7 +438,7 @@ impl<'a, const N: usize> MulAssign<&Self> for BigNumMod<'a, N> {
self.modulus.m.as_ptr(),
N,
);
if !res {
if res != 1 {
panic!("Multiplication failed");
}
}
Expand Down
12 changes: 6 additions & 6 deletions app-sdk/src/ecalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub(crate) trait EcallsInterface {
/// - `len_m`: Length of `m`.
///
/// # Returns
/// `true` on success, `false` on error.
fn bn_modm(r: *mut u8, n: *const u8, len: usize, m: *const u8, len_m: usize) -> bool;
/// 1 on success, 0 on error.
fn bn_modm(r: *mut u8, n: *const u8, len: usize, m: *const u8, len_m: usize) -> u32;

/// Adds two big numbers `a` and `b` modulo `m`, storing the result in `r`.
///
Expand All @@ -69,7 +69,7 @@ pub(crate) trait EcallsInterface {
///
/// # Returns
/// `true` on success, `false` on error.
fn bn_addm(r: *mut u8, a: *const u8, b: *const u8, m: *const u8, len: usize) -> bool;
fn bn_addm(r: *mut u8, a: *const u8, b: *const u8, m: *const u8, len: usize) -> u32;

/// Subtracts two big numbers `a` and `b` modulo `m`, storing the result in `r`.
///
Expand All @@ -82,7 +82,7 @@ pub(crate) trait EcallsInterface {
///
/// # Returns
/// `true` on success, `false` on error.
fn bn_subm(r: *mut u8, a: *const u8, b: *const u8, m: *const u8, len: usize) -> bool;
fn bn_subm(r: *mut u8, a: *const u8, b: *const u8, m: *const u8, len: usize) -> u32;

/// Multiplies two big numbers `a` and `b` modulo `m`, storing the result in `r`.
///
Expand All @@ -95,7 +95,7 @@ pub(crate) trait EcallsInterface {
///
/// # Returns
/// `true` on success, `false` on error.
fn bn_multm(r: *mut u8, a: *const u8, b: *const u8, m: *const u8, len: usize) -> bool;
fn bn_multm(r: *mut u8, a: *const u8, b: *const u8, m: *const u8, len: usize) -> u32;

/// Computes `a` to the power of `e` modulo `m`, storing the result in `r`.
///
Expand All @@ -116,7 +116,7 @@ pub(crate) trait EcallsInterface {
len_e: usize,
m: *const u8,
len: usize,
) -> bool;
) -> u32;
}

pub(crate) use ecalls_module::*;
Loading

0 comments on commit 2f42b86

Please sign in to comment.