TealQL is an SAST powered by GitHub Advanced Security's CodeQL, bringing the latest in Static Analysis tooling to the Algorand Virtual Machine's native language.
git clone https://github.com/Argimirodelpozo/codeql-TEAL.git
cd codeql-TEALThe script handles dependency linking and permissions automatically:
cd teal/scripts
./create-extractor-pack.sh
cd ../..rm -rf .codeql-extractors
mkdir -p .codeql-extractors/teal
cp -R teal/extractor-pack/* .codeql-extractors/teal/codeql database create test-projects/gen-dbs/my-db --overwrite -l teal -s test-projects/teal-contracts/fee-validation --search-path "$(pwd)/.codeql-extractors"CLI:
codeql query run teal/ql/lib/codeql/missingTxnFeeValidation.ql --database test-projects/gen-dbs/my-dbOr use the CodeQL VS Code extension for an interactive UI experience.
All tests require the extractor to be built and registered first (steps 2-3 above).
The tealer-detections/ directory contains a pytest suite that validates 12 security detections. Each detection is tested against a vulnerable contract (must produce findings) and a fixed contract (must produce zero findings).
1. Build the test databases:
bash tealer-detections/build_test_databases.sh2. Run the full test suite:
pytest tealer-detections/test_tealer_detections.py -vThis runs 24 tests (2 per detection: vuln + fixed) covering: is-deletable, is-updatable, unprotected-deletable, unprotected-updatable, group-size-check, can-close-account, can-close-asset, missing-fee-check, rekey-to, constant-gtxn, self-access, sender-access.
Run a single detection:
pytest tealer-detections/test_tealer_detections.py -v -k "is-deletable"Note: If databases haven't been pre-built, the test suite will build them automatically on first run (slower).
You can run any .ql query file against a database:
codeql query run teal/ql/lib/codeql/<query>.ql --database test-projects/<db>To export results to JSON:
python codeql-analysis-tools/codeql-analysis.py -d test-projects/<db> -q teal/ql/lib/codeql/<query>.ql -o results.json- CodeQL CLI (
codeqlon PATH) - Rust toolchain (for building the extractor)
- Python 3 with
pytest(for running tests)
When encountering parsing errors, a grammar update is probably needed.
- Fix the appropriate rule in the grammar
- Commit and push to main
- Rebuild:
cd teal/scripts
./create-extractor-pack.shThis will rebuild the Rust extractor, regenerate teal.dbscheme and TreeSitter.qll, and move them into the correct folders.
Made with love.
If you're into this kind of stuff, check out TEALFuzz — a custom fuzzer for TEAL programs that uses TealQL to aid in fuzzing campaign setup.