Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code quality checks #51

Merged
merged 9 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
---
BasedOnStyle: Google
IndentWidth: 4
---
Language: Cpp
ColumnLimit: 100
PointerAlignment: Right
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AllowAllParametersOfDeclarationOnNextLine: false
SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
BinPackParameters: false
---
InsertBraces: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
...
1 change: 0 additions & 1 deletion .github/workflows/build_and_functional_tests_baking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ jobs:
with:
download_app_binaries_artifact: "compiled_app_binaries"
test_dir: test/python

19 changes: 19 additions & 0 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: cppcheck
on: [pull_request]

jobs:
cppchceck:
name: Cppcheck
runs-on: ubuntu-latest
steps:
- name: Setup
run: sudo apt-get install -y -q cppcheck

- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.ref }}

- name: Check
run: cppcheck --addon=misra.json --quiet --error-exitcode=1 src/
17 changes: 14 additions & 3 deletions .github/workflows/lint-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
name: Code style check

on: [push, pull_request]
# Use:
# LedgerHQ/ledger-app-workflows/.github/workflows/reusable_lint.yml
# once their lint-checker has been updated

on:
workflow_dispatch:
push:
branches:
- master
- main
- develop
pull_request:

jobs:
job_lint:
Expand All @@ -12,8 +23,8 @@ jobs:
uses: actions/checkout@v2

- name: Lint
uses: DoozyX/clang-format-lint-action@v0.11
uses: DoozyX/clang-format-lint-action@v0.17
with:
source: "./"
extensions: "h,c"
clangFormatVersion: 10
clangFormatVersion: 17
16 changes: 16 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: pre-commit

on: [pull_request]

jobs:
pre-commit:
name: Pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: python -m pip install pre-commit
- run: python -m pip freeze --local
- run: SKIP=clang-format pre-commit run --all-files
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ bin
debug
build
# python environment used for testing
env
# cache files
env
# cache files
*__pycache__*
#ide
*.code-workspace
Expand Down
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# To install hooks, run:
# pre-commit install --hook-type pre-commit
# pre-commit install --hook-type commit-msg

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.4
hooks:
- id: clang-format
name: clang-format
description: Run `clang-format` on C/C++/CUDA files.
entry: clang-format -i
language: system
files: ^
types: [file, c]
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"string": "c"
},
"editor.formatOnSave": true
}
}
1 change: 0 additions & 1 deletion APDUs.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,3 @@ There are some limitations for Michelson parsing that should be noted.
- “contract-to-contract” requires that you use:
- the default endpoint for your destination contract
- the parameters must be of type unit

23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Download the source code for application from github repository [App-tezos-bakin
$ git clone https://github.com/LedgerHQ/app-tezos.git
$ cd app-tezos
```
Then run the following command to enter into docker container provided by Ledger. You will need to have docker cli installed.
Then run the following command to enter into docker container provided by Ledger. You will need to have docker cli installed.
Use the docker container `ledger-app-dev-tools` provided by Ledger to build the app.

```
Expand Down Expand Up @@ -255,17 +255,17 @@ Wallet application on the same Ledger device should suffice.
### Setup Ledger with Tezos client

To connect ledger with Tezos client, you need to download [Tezos](https://www.gitlab.com/tezos/tezos).
You need to have nix installed on your system. Build tezos with following commands:
You need to have nix installed on your system. Build tezos with following commands:
```
$ git clone https://gitlab.com/tezos/tezos.git
$ cd tezos
$ nix-shell -j auto
$ make
$ make
```
This will build the latest version of tezos repo.
Now connect the ledger device to USB port of your computer and run following command:
```
$ ./octez-client list connected ledgger
$ ./octez-client list connected ledgger
```
It will given output as follows:
```
Expand All @@ -286,23 +286,23 @@ $ ./octez-client import secret key ledger_username "ledger://masculine-pig-stupe
```
Here we have chosen the last key type bip25519. You can choose any one of the available keys.

You can verify that you have successfully setup ledger with following command:
You can verify that you have successfully setup ledger with following command:
```
$ ./octez-client list known addresses
```
It will show output as follows:
It will show output as follows:
```
ledger_<...>: tz1N4GQ8gYgMdq6gUsja783KJButHUHn5K7z (ledger sk known)
```
You can use the address ledger_<...> for further commands to setup the baking operations with Ledger.

### Setup Node and baker

It is recommended to practice baking on tezos testnet before you acutally start baking on mainnet with real money. You can get more information
It is recommended to practice baking on tezos testnet before you acutally start baking on mainnet with real money. You can get more information
about baking on testnet at [Baking-setup-Tutorial](https://docs.tezos.com/tutorials/join-dal-baker).
Here we only give information about changes you have to make in above tutorial to bake with Ledger instead of an auto generated key.

In the tutorial skip the command `octez-client gen keys my_baker` and instead use the ledger_<...> in place of my_baker.
In the tutorial skip the command `octez-client gen keys my_baker` and instead use the ledger_<...> in place of my_baker.
Use the following command to store your address in environmental variable `MY_BAKER`
```
$ MY_BAKER="$(./octez-client show address ledger_<...> | head -n 1 | cut -d ' ' -f 2)"
Expand Down Expand Up @@ -344,10 +344,10 @@ $ octez-client register key ledger_<...> as delegate
```

This command is intended to inform the blockchain itself of your intention to
bake with this key.
bake with this key.

### Stake tez to get baking rights
Currently baking app does not support signing transactions. You need to stake certain amount of tez to get baking rights. Install Tezos wallet app on the same ledger device and run following command. No setup is needed as we have already setup the address from which we are deducting the amount.
Currently baking app does not support signing transactions. You need to stake certain amount of tez to get baking rights. Install Tezos wallet app on the same ledger device and run following command. No setup is needed as we have already setup the address from which we are deducting the amount.
```
$ octez-client stake <amount> ledger_<...>
```
Expand Down Expand Up @@ -381,7 +381,7 @@ attempt at signing; this operation is designed to be used unsupervised. As menti

### Security during baking

The Tezos-Baking app needs to be kept open during baking and ledger is unlocked during that time. To prevent screen burn, the baking app goes into blank screen when it starts signing blocks/attestation as baker. But the app remains unlocked. One can not sign any transaction operation using baking app, therefore there is no need of any concern. But to exit the baking app, one needs to enter PIN. This restriction is in place to avoid misuse of physical ledger device when its kept unattended during baking process.
The Tezos-Baking app needs to be kept open during baking and ledger is unlocked during that time. To prevent screen burn, the baking app goes into blank screen when it starts signing blocks/attestation as baker. But the app remains unlocked. One can not sign any transaction operation using baking app, therefore there is no need of any concern. But to exit the baking app, one needs to enter PIN. This restriction is in place to avoid misuse of physical ledger device when its kept unattended during baking process.

### Reset High Watermark

Expand Down Expand Up @@ -529,4 +529,3 @@ If you install a Ledger application, such as Tezos Wallet or Tezos Baking, outsi

## Feedback
To give feedback and report an error, create an issue on github repository [Trillitech-App-Tezos](https://github.com/trillitech/ledger-app-tezos-baking).

7 changes: 7 additions & 0 deletions misra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"script": "misra.py",
"args": [
"--rule-texts=misra.md",
"--suppress-rules 2.7,3.1,7.2,7.4,8.2,8.4,8.9,8.14,9.2,10.1,10.3,10.4,10.5,10.6,11.1,11.3,11.5,11.8,12.1,12.3,13.3,13.4,14.2,14.4,15.5,16.3,16.4,16.5,16.6,17.7,17.8,18.4,18.8,19.2,20.5,20.7,21.15,21.16"
]
}
Loading
Loading