Skip to content
Merged
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
185 changes: 97 additions & 88 deletions barretenberg/cpp/scripts/line_count.py
Original file line number Diff line number Diff line change
@@ -1,101 +1,110 @@
# Dependency: The line counting utility cloc https://github.com/AlDanial/cloc
import csv
from os import listdir, system
from os import listdir, system, path
from pathlib import Path
import shutil

# Dependency: The line counting utility cloc https://github.com/AlDanial/cloc
# Check if cloc is installed
if not shutil.which("cloc"):
raise EnvironmentError(
"cloc is not installed. On Ubuntu, you can install with 'sudo apt install cloc'.")

BASE_DIR = Path("src/barretenberg")
PER_FILE_REPORT_PATH = Path("build/per_file_report.csv")

# validate that directory structure hasn't changed since last run
all_dirs = listdir("src/barretenberg")
last_all_dirs = ['bb', 'benchmark', 'commitment_schemes', 'common', 'crypto', 'dsl', 'ecc', 'eccvm', 'env', 'examples', 'flavor', 'goblin', 'grumpkin_srs_gen', 'honk', 'numeric', 'plonk', 'polynomials', 'protogalaxy', 'relations', 'serialize',
'smt_verification', 'solidity_helpers', 'srs', 'stdlib', 'sumcheck', 'transcript', 'ultra_honk', 'wasi', 'circuit_checker', 'client_ivc', 'translator_vm', 'vm', 'execution_trace', 'plonk_honk_shared', 'stdlib_circuit_builders', 'proof_system', 'build']
assert (all_dirs == last_all_dirs)
all_dirs = sorted([d for d in listdir("src/barretenberg")
if path.isdir(path.join("src/barretenberg", d))])
weights = {"acir_formal_proofs": 0,
"api": 1,
"bb": 0,
"benchmark": 0,
"boomerang_value_detection": 0,
"circuit_checker": 1,
"client_ivc": 1,
"commitment_schemes": 1,
"commitment_schemes_recursion": 1,
"common": 0,
"crypto": 1,
"dsl": 1,
"ecc": 1,
"eccvm": 1,
"env": 0,
"examples": 0,
"flavor": 1,
"goblin": 1,
"grumpkin_srs_gen": 0,
"honk": 1,
"lmdblib": 0,
"messaging": 0,
"nodejs_module": 0,
"numeric": 1,
"plonk": 0,
"plonk_honk_shared": 1,
"polynomials": 1,
"protogalaxy": 1,
"relations": 1,
"serialize": 1,
"smt_verification": 0,
"solidity_helpers": 1,
"srs": 1,
"stdlib": 1,
"stdlib_circuit_builders": 1,
"sumcheck": 1,
"trace_to_polynomials": 1,
"transcript": 1,
"translator_vm": 1,
"ultra_honk": 1,
"ultra_vanilla_client_ivc": 0,
"vm": 0,
"vm2": 0,
"wasi": 0,
"world_state": 0, }

new_dirs = list(filter(lambda x: x not in sorted(all_dirs), all_dirs))
if new_dirs:
raise Exception("New directories without weights: ", new_dirs)

missing_dirs = list(
filter(lambda x: x not in all_dirs, sorted(all_dirs)))
if missing_dirs:
raise Exception("Weighted directory not found: ", missing_dirs)

# mark directories that will be covered in an audit of Barretenberg
# calculated the total number of lines weighted by complexity, with maximum complexity equal to 1
dirs_to_audit = [
'bb',
# 'benchmark',
'commitment_schemes',
# 'common',
'crypto',
# 'dsl',
'ecc',
'eccvm',
# 'env',
# 'examples',
'flavor',
'goblin',
'grumpkin_srs_gen',
'honk',
'numeric',
# 'plonk',
'polynomials',
'protogalaxy',
'relations',
# 'serialize',
# 'smt_verification',
# 'solidity_helpers',
'srs',
'stdlib',
'sumcheck',
'transcript',
'ultra_honk',
# 'wasi',
'circuit_checker',
'client_ivc',
'translator_vm',
'vm',
'execution_trace',
'plonk_honk_shared',
'stdlib_circuit_builders',
'proof_system'
]
weights = {directory: 1 for directory in dirs_to_audit}
weights["circuit_checker"] = 0.3
weights["srs"] = 0.3
weights["polynomials"] = 0.5
weights["numeric"] = 0.3
weights["ecc"] = 0.5
weights["crypto"] = 0.5
weights["bb"] = 0.3
print(
f"Excluding the following directories from the audit: {[name for name, weight in weights.items() if weight == 0]}")

print(
f"Dirs with higher weight: {[name for name, weight in weights.items() if ((weight != 0) & (weight != 1))]}")

TOTAL_NUM_CODE_LINES = 0
# use cloc to count the lines in every file to be audited in the current agreement
system(
f"cloc --include-lang='C++','C/C++ Header' --by-file --csv --out='{PER_FILE_REPORT_PATH}' {BASE_DIR}")
with open(PER_FILE_REPORT_PATH, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['language'] != 'SUM':
path = Path(row['filename']).relative_to(BASE_DIR).parts[0]
if path in dirs_to_audit:
TOTAL_NUM_CODE_LINES += int(row['code']) * weights[path]

TO_AUDIT_NOW = [
"src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp",
"src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp",
"src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp",
"src/barretenberg/stdlib/primitives/field/field.hpp",
"src/barretenberg/stdlib/primitives/field/field.cpp",
"src/barretenberg/stdlib/primitives/field/field.test.cpp",
"src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp",
"src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp",
"src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp",
"src/barretenberg/relations/delta_range_constraint_relation.hpp",
"src/barretenberg/relations/ultra_arithmetic_relation.hpp",
"src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp",
"src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp"]
counts = {}
with open(PER_FILE_REPORT_PATH, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row["filename"] in TO_AUDIT_NOW:
counts[row["filename"]] = row["code"]
total = 0
for filename, count in counts.items():
total += int(count)

# print the percentage to be audited
print(f"Audit covers {total/float(TOTAL_NUM_CODE_LINES):.2%}")
def count_weighted_lines():
weighted_lines = 0
# use cloc to count the lines in every file to be audited in the current agreement
with open(PER_FILE_REPORT_PATH, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['language'] != 'SUM':
path = Path(row['filename']).relative_to(BASE_DIR).parts[0]
if path in all_dirs:
weighted_lines += (int(row['code']) * weights[path])
return int(weighted_lines)


print(
f"Total number of unweighted code lines to be audited: {count_weighted_lines()}")

weights["client_ivc"] = 1.5
weights["eccvm"] = 2
weights["goblin"] = 1.5
weights["protogalaxy"] = 1.5
weights["relations"] = 2
weights["stdlib"] = 1 # partially audited so not reweighting for complexity
weights["stdlib_circuit_builders"]
weights["sumcheck"] = 1.2 # already soft-audited by Sergei; old and stableish
weights["translator_vm"] = 2

print(
f"Total number of weighted code lines to be audited: {count_weighted_lines()}")
Loading