Skip to content

refactor(skills): collapse redundant Cairo modules and sync upstream optimization#7

Closed
omarespejel wants to merge 2 commits into
codex/audit-corpus-wave1from
codex/cairo-skill-collapse-pr
Closed

refactor(skills): collapse redundant Cairo modules and sync upstream optimization#7
omarespejel wants to merge 2 commits into
codex/audit-corpus-wave1from
codex/cairo-skill-collapse-pr

Conversation

@omarespejel

Copy link
Copy Markdown
Contributor

Summary

This PR applies the Cairo skill collapse/update plan on top of codex/audit-corpus-wave1.

What changed

  • Removed redundant openzeppelin-cairo/ skill module.
  • Expanded cairo-contract-authoring:
    • Added references/language.md (PR #295 cairo language content).
    • Enriched references/legacy-full.md with component wiring checklist, cross-contract dispatcher guidance, and OZ hardening checklist.
    • Updated SKILL metadata/router/workflow to surface language fundamentals.
  • Synced cairo-optimization to feltroidprime latest:
    • Replaced references/legacy-full.md with upstream-synced content (rules 1-12 + BoundedInt updates).
    • Added references/profiling.md from benchmarking-cairo.
    • Added scripts: scripts/profile.py, scripts/bounded_int_calc.py.
    • Updated metadata with upstream, upstream_commit, sync_date, upstream_paths, and permission_ref.
  • Updated root docs/router/site generator for 7 modules:
    • SKILL.md, README.md, llms.txt, scripts/site/build_site.py
    • Regenerated website/data/site-data.json and website/index.html.
  • Added attribution/governance docs:
    • New THIRD_PARTY.md.
    • Updated README.md and CONTRIBUTING.md with third-party sync/attribution instructions.

Validation

  • python3 scripts/site/build_site.py --domain starkskills.org
  • python scripts/quality/validate_skills.py (OK: validated 8 SKILL.md files)

Attribution

  • Upstream content from feltroidprime/cairo-skills is retained with author metadata and explicit upstream commit pinning.
  • Repo-level third-party attribution workflow is documented in THIRD_PARTY.md.

@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 67340abc-5ceb-401e-a87d-93e5e18ffd86

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/cairo-skill-collapse-pr

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Mar 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR collapses the standalone openzeppelin-cairo skill module (its content is now folded into cairo-contract-authoring), syncs cairo-optimization to the feltroidprime/cairo-skills upstream (commit 7fde29f), adds a Cairo language fundamentals reference, introduces a profiling CLI (profile.py) and BoundedInt calculator (bounded_int_calc.py), and establishes a third-party attribution governance workflow. The structural changes and documentation additions are well-considered, but several concrete issues were found in the new Python scripts and the synced reference content:

  • Timestamp race in profile.py: _profile_filename calls datetime.now() independently for the .pb.gz and .png output filenames. If the two calls cross a minute boundary the files get different timestamps — directly contradicting the documented guarantee in profiling.md ("The CLI computes the timestamp once so both files always match"). The timestamp should be computed once in main() and passed to both calls.
  • Dead-code format_bound in bounded_int_calc.py: Both branches of the if value < 0 conditional return str(value), making the function a transparent wrapper around str() with misleading "handling negatives" documentation.
  • Rule 11 dangling in legacy-full.md: The upstream sync deleted the ### 11. Always use hades_permutation detailed section but left its row in the Quick Reference table, creating a broken internal reference.
  • Ambiguous script path in SKILL.md and profiling.md: The CLI is documented as python3 scripts/profile.py profile, but the script lives at cairo-optimization/scripts/profile.py. The unqualified path silently fails when invoked from the repository root, which is the expected execution context for skill agents.
  • curl | sh install patterns in profiling.md: Piping remote installer scripts directly to sh without verification is present in three installation commands in a repository whose explicit purpose is teaching secure Starknet/Cairo practices.

Confidence Score: 3/5

  • Safe to merge for documentation/skill content, but the profiling CLI has a verifiable timestamp bug and a dead-code issue that should be fixed before the scripts are actively used.
  • The bulk of the PR is documentation and reference content which is high quality. The two Python scripts introduce real logic bugs (timestamp race, no-op format_bound) and the reference table/section mismatch in legacy-full.md leaves an incomplete optimization guide. None of these issues affect Cairo smart contract security directly, but they undermine the determinism and correctness guarantees the CLI explicitly promises, and the scripts are intended to be used by developers making performance-critical decisions on Cairo contracts.
  • cairo-optimization/scripts/profile.py (timestamp bug), cairo-optimization/scripts/bounded_int_calc.py (dead format_bound), cairo-optimization/references/legacy-full.md (Rule 11 table/section mismatch), cairo-optimization/SKILL.md (wrong script path)

Important Files Changed

Filename Overview
cairo-optimization/scripts/profile.py New Cairo profiling CLI — solid overall structure, but has a timestamp bug where pb.gz and png filenames can diverge if a minute boundary is crossed between the two _profile_filename calls, contradicting the documented guarantee.
cairo-optimization/scripts/bounded_int_calc.py BoundedInt bound calculator — logic is correct for add/sub/mul/div, but format_bound() is a dead-code no-op with identical branches for positive and negative values.
cairo-optimization/references/legacy-full.md Upstream-synced optimization reference — Rule 12 (felt252→BoundedInt via u128) added correctly, but Rule 11 (hades_permutation) row remains in the Quick Reference table while its detailed explanation section was deleted, leaving a dangling reference.
cairo-optimization/SKILL.md Updated cairo-optimization skill metadata and quick-start — version bumped, upstream provenance fields added correctly, but the script path in step 2 (scripts/profile.py) is missing the cairo-optimization/ prefix needed for repo-root invocation.
cairo-optimization/references/profiling.md New profiling reference guide — comprehensive and well-structured; tool installation section includes curl
cairo-contract-authoring/references/language.md New Cairo language fundamentals reference — well-structured with accurate type system, ownership, traits, generics, and module layout coverage; no issues found.
cairo-contract-authoring/references/legacy-full.md Enriched authoring reference — adds component wiring checklist, cross-contract dispatcher guidance, and OZ hardening checklist; all additions are accurate and the path fixes (../../ prefixes) are correct.
THIRD_PARTY.md New third-party attribution registry — correctly documents feltroidprime upstream with commit pinning and permission reference; workflow instructions align with CONTRIBUTING.md additions.
scripts/site/build_site.py Site builder updated to drop openzeppelin-cairo from MODULES list (now 7 modules); HTML generation uses html.escape correctly and no security regressions observed.
CONTRIBUTING.md Added third-party sync rules section — clear provenance metadata requirements and permission traceability gate; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Developer runs profile.py] --> B{mode?}
    B -->|snforge| C[snforge test --save-trace-data]
    B -->|scarb| D[scarb execute --save-profiler-trace-data]
    C --> E{returncode == 0?}
    D --> E
    E -->|no| F[exit 2: execution failed]
    E -->|yes| G{snforge or scarb?}
    G -->|snforge| H[glob snfoundry_trace/*.json]
    G -->|scarb| I[target/execute/pkg/execution1/cairo_profiler_trace.json]
    H --> J{trace found?}
    I --> J
    J -->|no| K[exit 3: trace not found]
    J -->|yes| L[cairo-profiler build-profile --show-libfuncs]
    L --> M{pb.gz written?}
    M -->|no| N[exit 4: profiler failed]
    M -->|yes| O[cairo-profiler view top-20 functions]
    O --> P[pprof -png output png_path]
    P --> Q{PNG written?}
    Q -->|no| R[exit 5: pprof failed]
    Q -->|yes| S[print profile + PNG paths]

    style F fill:#f87171
    style K fill:#f87171
    style N fill:#f87171
    style R fill:#f87171
    style S fill:#86efac
Loading

Comments Outside Diff (1)

  1. cairo-optimization/references/legacy-full.md, line 30-32 (link)

    Rule 11 row retained in Quick Reference table but the detailed section was deleted

    The Quick Reference table still lists:

    | 11 | Fast 2-input Poseidon | `poseidon_hash_span([x,y])` | `hades_permutation(x, y, 2)` |
    

    However, the upstream-sync diff deleted the entire ### 11. Always use \hades_permutation` for 2-input Poseidon hashes` section that contained the BAD/GOOD code examples and the explanation. The table now points to guidance that no longer exists in this file, leaving readers without the supporting rationale and code examples for this optimization rule.

    Either restore the deleted section or remove row 11 from the table to keep the reference consistent.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: cairo-optimization/references/legacy-full.md
    Line: 30-32
    
    Comment:
    **Rule 11 row retained in Quick Reference table but the detailed section was deleted**
    
    The Quick Reference table still lists:
    
    ```
    | 11 | Fast 2-input Poseidon | `poseidon_hash_span([x,y])` | `hades_permutation(x, y, 2)` |
    ```
    
    However, the upstream-sync diff deleted the entire `### 11. Always use \`hades_permutation\` for 2-input Poseidon hashes` section that contained the BAD/GOOD code examples and the explanation. The table now points to guidance that no longer exists in this file, leaving readers without the supporting rationale and code examples for this optimization rule.
    
    Either restore the deleted section or remove row 11 from the table to keep the reference consistent.
    
    How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: f376747

@omarespejel
omarespejel deleted the branch codex/audit-corpus-wave1 March 8, 2026 21:48
@omarespejel omarespejel closed this Mar 8, 2026
Comment on lines +79 to +82
def _profile_filename(output_dir: str, package: str, name: str, metric: str, commit: str, ext: str) -> str:
"""Generate deterministic profile filename."""
ts = datetime.now().strftime("%y-%m-%d-%H:%M")
return os.path.join(output_dir, f"{ts}_{package}_{name}_{metric}_{commit}.{ext}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp computed separately for pb.gz and png, breaking the "computed once" guarantee

_profile_filename calls datetime.now() on every invocation. In main() (lines 323–324), it is called twice in succession:

pb_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, "pb.gz")
png_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, "png")

If execution crosses a minute boundary between these two calls, the .pb.gz and .png files will receive different timestamps — exactly the mismatch the documentation in references/profiling.md claims the CLI prevents:

"When running steps manually, the pb.gz and png may get different timestamps if they cross a minute boundary. The CLI computes the timestamp once so both files always match."

The fix is to compute the timestamp once and pass it explicitly:

def _profile_filename(output_dir: str, package: str, name: str, metric: str, commit: str, ts: str, ext: str) -> str:
    return os.path.join(output_dir, f"{ts}_{package}_{name}_{metric}_{commit}.{ext}")

Then in main():

ts = datetime.now().strftime("%y-%m-%d-%H:%M")
pb_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, ts, "pb.gz")
png_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, ts, "png")
Prompt To Fix With AI
This is a comment left during a code review.
Path: cairo-optimization/scripts/profile.py
Line: 79-82

Comment:
**Timestamp computed separately for pb.gz and png, breaking the "computed once" guarantee**

`_profile_filename` calls `datetime.now()` on every invocation. In `main()` (lines 323–324), it is called twice in succession:

```python
pb_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, "pb.gz")
png_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, "png")
```

If execution crosses a minute boundary between these two calls, the `.pb.gz` and `.png` files will receive **different** timestamps — exactly the mismatch the documentation in `references/profiling.md` claims the CLI prevents:

> "When running steps manually, the pb.gz and png may get different timestamps if they cross a minute boundary. The CLI computes the timestamp once so both files always match."

The fix is to compute the timestamp once and pass it explicitly:

```python
def _profile_filename(output_dir: str, package: str, name: str, metric: str, commit: str, ts: str, ext: str) -> str:
    return os.path.join(output_dir, f"{ts}_{package}_{name}_{metric}_{commit}.{ext}")
```

Then in `main()`:

```python
ts = datetime.now().strftime("%y-%m-%d-%H:%M")
pb_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, ts, "pb.gz")
png_path = _profile_filename(output_dir, args.package, args.name, args.metric, commit, ts, "png")
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +33 to +37
def format_bound(value: int) -> str:
"""Format a bound value, handling negatives."""
if value < 0:
return str(value)
return str(value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format_bound is a no-op — both branches return the same value

Both branches of the conditional return an identical expression (str(value)), making the function equivalent to simply calling str(). The docstring says "handling negatives" but no actual special handling is implemented:

def format_bound(value: int) -> str:
    """Format a bound value, handling negatives."""
    if value < 0:
        return str(value)  # same as the else branch
    return str(value)      # identical

This looks like an incomplete implementation. BoundedInt bounds cannot actually be negative in Cairo (the Sierra specializer requires MIN >= 0), so this function likely just needs to remain str(value). If the intent was to validate or format negatives differently, the logic is missing.

Suggested change
def format_bound(value: int) -> str:
"""Format a bound value, handling negatives."""
if value < 0:
return str(value)
return str(value)
def format_bound(value: int) -> str:
"""Format a bound value."""
return str(value)
Prompt To Fix With AI
This is a comment left during a code review.
Path: cairo-optimization/scripts/bounded_int_calc.py
Line: 33-37

Comment:
**`format_bound` is a no-op — both branches return the same value**

Both branches of the conditional return an identical expression (`str(value)`), making the function equivalent to simply calling `str()`. The docstring says "handling negatives" but no actual special handling is implemented:

```python
def format_bound(value: int) -> str:
    """Format a bound value, handling negatives."""
    if value < 0:
        return str(value)  # same as the else branch
    return str(value)      # identical
```

This looks like an incomplete implementation. BoundedInt bounds cannot actually be negative in Cairo (the Sierra specializer requires `MIN >= 0`), so this function likely just needs to remain `str(value)`. If the intent was to validate or format negatives differently, the logic is missing.

```suggestion
def format_bound(value: int) -> str:
    """Format a bound value."""
    return str(value)
```

How can I resolve this? If you propose a fix, please make it concise.


1. Confirm baseline behavior with tests.
2. Identify hotspots via resource reports.
2. Profile target paths with `python3 scripts/profile.py profile`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect script path — scripts/profile.py is not resolvable from the repo root

The Quick Start instruction says:

2. Profile target paths with `python3 scripts/profile.py profile`.

But the script lives at cairo-optimization/scripts/profile.py. A user (or an AI agent) running this from the repository root would need:

python3 cairo-optimization/scripts/profile.py profile

The same mismatch appears in cairo-optimization/references/profiling.md (line 12 and throughout), which says "use python3 scripts/profile.py profile (from this repository)". The instruction in profiling.md is contextually anchored to the cairo-optimization/ subdirectory — but SKILL.md is loaded in repo-root context. The path is ambiguous and will silently fail for agents running commands from the repo root.

Consider using the fully qualified path cairo-optimization/scripts/profile.py or a repo-relative instruction like "from the cairo-optimization/ directory, run python3 scripts/profile.py profile".

Prompt To Fix With AI
This is a comment left during a code review.
Path: cairo-optimization/SKILL.md
Line: 29

Comment:
**Incorrect script path — `scripts/profile.py` is not resolvable from the repo root**

The Quick Start instruction says:

```
2. Profile target paths with `python3 scripts/profile.py profile`.
```

But the script lives at `cairo-optimization/scripts/profile.py`. A user (or an AI agent) running this from the repository root would need:

```
python3 cairo-optimization/scripts/profile.py profile
```

The same mismatch appears in `cairo-optimization/references/profiling.md` (line 12 and throughout), which says "use `python3 scripts/profile.py profile` (from this repository)". The instruction in `profiling.md` is contextually anchored to the `cairo-optimization/` subdirectory — but `SKILL.md` is loaded in repo-root context. The path is ambiguous and will silently fail for agents running commands from the repo root.

Consider using the fully qualified path `cairo-optimization/scripts/profile.py` or a repo-relative instruction like "from the `cairo-optimization/` directory, run `python3 scripts/profile.py profile`".

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +161 to +163
# Via snfoundryup installer
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
snfoundryup

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl | sh install patterns in a security-focused reference

Two of the tool installation commands pipe remote content directly into a shell without any integrity check:

curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
curl -L https://raw.githubusercontent.com/software-mansion/cairo-profiler/main/scripts/install.sh | sh

For a repository whose explicit purpose is teaching secure Cairo/Starknet practices, recommending curl | sh without noting the security trade-off sends a mixed message. Consider adding a brief note recommending the asdf path (which is listed first and avoids piping remote scripts) or suggesting users inspect the script before running it.

Prompt To Fix With AI
This is a comment left during a code review.
Path: cairo-optimization/references/profiling.md
Line: 161-163

Comment:
**`curl | sh` install patterns in a security-focused reference**

Two of the tool installation commands pipe remote content directly into a shell without any integrity check:

```bash
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
```

```bash
curl -L https://raw.githubusercontent.com/software-mansion/cairo-profiler/main/scripts/install.sh | sh
```

For a repository whose explicit purpose is teaching secure Cairo/Starknet practices, recommending `curl | sh` without noting the security trade-off sends a mixed message. Consider adding a brief note recommending the `asdf` path (which is listed first and avoids piping remote scripts) or suggesting users inspect the script before running it.

How can I resolve this? If you propose a fix, please make it concise.

@omarespejel
omarespejel deleted the codex/cairo-skill-collapse-pr branch March 9, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant