Skip to content

Commit

Permalink
add check for math/rand usage in production code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarak Ben Youssef committed Jun 22, 2023
1 parent 14df98f commit 4820fa6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ jobs:
cache: true
- name: Run tidy
run: make tidy
- name: Emulator no relic check
run: make emulator-norelic-check
- name: code sanity check
run: make code-sanity-check

shell-check:
name: ShellCheck
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ emulator-norelic-check:
# test the fvm package compiles with Relic library disabled (required for the emulator build)
cd ./fvm && go test ./... -run=NoTestHasThisPrefix

.SILENT: go-math-rand-check
go-math-rand-check:
# check that the insecure math/rand Go package isn't used by production code.
# `exclude` should only specify non production code (test, bench..).
# If this check fails, try updating your code by using:
# - "crypto/rand" or "flow-go/utils/rand" for non-deterministic randomness
# - "flow-go/crypto/random" for deterministic randomness
grep --include=\*.go --exclude={*test*,*helper*,*example*,*fixture*,*benchmark*,*profiler*} -rnw '"math/rand"'; \
if [ $$? -ne 1 ]; \
then \
echo "[Error] Go production code should not use math/rand package"; \
exit 1; \
fi

.PHONY: code-sanity-check
code-sanity-check: go-math-rand-check emulator-norelic-check

.PHONY: fuzz-fvm
fuzz-fvm:
# run fuzz tests in the fvm package
Expand Down

0 comments on commit 4820fa6

Please sign in to comment.