Skip to content

Commit fda3410

Browse files
authored
Merge pull request #183 from Zondax/feat/improvements
Feat/improvements
2 parents 858f9a0 + a78ae07 commit fda3410

35 files changed

+843
-647
lines changed

.clang-format

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 4
3+
ColumnLimit: 125
4+
DerivePointerAlignment: false
5+
PointerAlignment: Right
6+
AllowShortFunctionsOnASingleLine: None
7+
AlignConsecutiveMacros:
8+
Enabled: true
9+
AcrossEmptyLines: true
10+
AcrossComments: false

.clang-tidy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Checks: "-*,
2+
clang-diagnostic-*,
3+
clang-analyzer-*,
4+
cppcoreguidelines-init-variables,
5+
google-runtime-int,
6+
google-readability-avoid-underscore-in-googletest-name,
7+
misc-*,
8+
performance-*,
9+
portability-*,
10+
readability-*,
11+
-misc-no-recursion,
12+
-readability-function-cognitive-complexity
13+
-readability-magic-numbers"
14+
WarningsAsErrors: "*"
15+
CheckOptions:
16+
- key: readability-identifier-length.MinimumVariableNameLength
17+
value: 2
18+
- key: readability-identifier-length.MinimumParameterNameLength
19+
value: 2
20+
- key: readability-identifier-length.MinimumLoopCounterNameLength
21+
value: 1
22+
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
23+
value: true

.github/workflows/check_version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- main
88
- develop
99
- master # for safety reasons
10-
- dev # for safety reasons
10+
# - dev # for safety reasons
1111

1212
jobs:
1313
configure:

.github/workflows/lint.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@ name: Lint and format 💅
22

33
on:
44
workflow_dispatch:
5-
# push:
6-
# pull_request:
7-
# branches:
8-
# - main
9-
# - develop
5+
push:
6+
pull_request:
7+
branches:
8+
- main
9+
- develop
10+
- master # for safety reasons
11+
- dev # for safety reasons
1012

1113
jobs:
1214
lint:
13-
runs-on: ubuntu-latest
15+
runs-on: ${{ github.repository_owner == 'zondax' && 'zondax-runners' || 'ubuntu-latest' }}
1416
container: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-legacy:latest
1517
steps:
1618
- uses: actions/checkout@v4
1719
with:
1820
submodules: recursive
1921
- name: Add missing deps
22+
env:
23+
DEBIAN_FRONTEND: noninteractive
2024
run: |
21-
DEBIAN_FRONTEND=noninteractive
2225
apt-get update
2326
apt-get install -y bear sudo
2427
- name: Generate compilation database
2528
run: bear -- make -j BOLOS_SDK="$NANOSP_SDK"
29+
- name: Setup python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.11"
2633
- name: Lint and format 💅
2734
uses: cpp-linter/cpp-linter-action@v2
2835
id: linter

.github/workflows/main.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ jobs:
5757
run: |
5858
cd ./app/rust
5959
cargo clippy --all-targets --features "clippy"
60+
- name: cargo fmt
61+
run: |
62+
cd ./app/rust
63+
cargo fmt
6064
6165
build_ledger:
6266
needs: configure
@@ -264,3 +268,84 @@ jobs:
264268
tag_name: ${{ steps.flex.outputs.tag_name }}
265269
draft: false
266270
prerelease: false
271+
272+
fuzzing:
273+
name: fuzzing
274+
runs-on: ${{ github.repository_owner == 'zondax' && 'zondax-runners' || 'ubuntu-latest' }}
275+
container:
276+
image: rust:latest
277+
steps:
278+
- uses: actions/checkout@v3
279+
280+
# Install only the additional dependencies needed for honggfuzz
281+
- name: Install system dependencies
282+
run: |
283+
apt-get update && apt-get install -y \
284+
binutils-dev \
285+
libunwind-dev \
286+
libblocksruntime-dev \
287+
liblzma-dev
288+
289+
- name: Install honggfuzz
290+
run: cargo install honggfuzz
291+
292+
- name: Generate corpus
293+
run: |
294+
cd app/hfuzz-parser/corpus
295+
cargo run
296+
297+
# Different fuzzing durations based on trigger
298+
- name: Quick fuzz (PR)
299+
if: github.event_name == 'push'
300+
run: |
301+
cd app/hfuzz-parser
302+
timeout --preserve-status 5m cargo hfuzz run transaction ../hfuzz_corpus/
303+
304+
- name: Medium fuzz (main)
305+
if: github.event_name == 'pull_request'
306+
run: |
307+
cd app/hfuzz-parser
308+
timeout --preserve-status 15m cargo hfuzz run transaction ../hfuzz_corpus/
309+
310+
- name: Extended fuzz (weekly)
311+
if: github.event_name == 'schedule'
312+
run: |
313+
cd app/hfuzz-parser
314+
timeout --preserve-status 30m cargo hfuzz run transaction ../hfuzz_corpus/
315+
316+
- name: Check for crashes
317+
run: |
318+
if ls app/hfuzz-parser/hfuzz_workspace/transaction/SIGABRT.PC.* 1> /dev/null 2>&1; then
319+
echo "::error::Crashes found during fuzzing!"
320+
exit 1
321+
fi
322+
323+
- name: Upload crash artifacts
324+
if: failure()
325+
uses: actions/upload-artifact@v3
326+
with:
327+
name: crash-reports
328+
path: |
329+
app/hfuzz-parser/hfuzz_workspace/transaction/SIGABRT.PC.*
330+
app/hfuzz-parser/hfuzz_workspace/transaction/HONGGFUZZ.REPORT.TXT
331+
app/hfuzz-parser/hfuzz_workspace/transaction/input/
332+
333+
- name: Cache corpus
334+
uses: actions/cache@v3
335+
with:
336+
path: app/hfuzz_corpus
337+
key: ${{ runner.os }}-fuzz-corpus-${{ github.sha }}
338+
restore-keys: |
339+
${{ runner.os }}-fuzz-corpus-
340+
341+
- name: Notify on failure
342+
if: failure()
343+
uses: actions/github-script@v6
344+
with:
345+
script: |
346+
github.rest.issues.create({
347+
owner: context.repo.owner,
348+
repo: context.repo.repo,
349+
title: 'Fuzzing found crashes',
350+
body: 'Fuzzing job failed. Check the artifacts in the workflow run.'
351+
})

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ app/output/*.sha256
9090
app/pkg/*
9191

9292
app/rust/.cargo/.package-cache-mutate
93+
app/hfuzz_corpus
9394

9495

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ prod:
4545
make PRODUCTION_BUILD=1
4646

4747
rust_fuzz:
48-
cd app/hfuzz-parser/ && cargo hfuzz run transaction
48+
cd app/hfuzz-parser/corpus/ && cargo run
49+
cd app/hfuzz-parser/ && cargo hfuzz run transaction app/hfuzz_corpus
4950

5051

5152

app/FUZZING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ cargo hfuzz run-debug transaction hfuzz_workspace/*/*.fuzz
3535

3636
```
3737

38-
This will deploy a gdb console with a backtrace with the first crash
38+
To opt to use _gdb_ instead of `lldb`, you can configure it before running the debugger with:
39+
40+
```bash
41+
export HFUZZ_DEBUGGER="rust-gdb"
42+
43+
```
44+
45+
This will deploy a **gdb** console with a backtrace with the first crash
3946

4047
_note_: There could be more than one _.fuzz_ file.

app/hfuzz-parser/Cargo.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/hfuzz-parser/corpus/Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)