Skip to content

fix: add nesting depth guard for ledger ADT types#255

Open
RomarQ wants to merge 4 commits intoLFDT-Minokawa:mainfrom
RomarQ:fix/adt-nesting-depth-guard
Open

fix: add nesting depth guard for ledger ADT types#255
RomarQ wants to merge 4 commits intoLFDT-Minokawa:mainfrom
RomarQ:fix/adt-nesting-depth-guard

Conversation

@RomarQ
Copy link
Copy Markdown
Contributor

@RomarQ RomarQ commented Mar 25, 2026

Add a compile-time check that rejects ledger types nested deeper than max-adt-nesting-depth (4). This prevents the compiler from crashing with OOM on deeply nested Map types like Map<K, Map<K, Map<...>>>.

The guard checks the structural depth of already-resolved type arguments in apply-ledger-ADT before expansion, following the same pattern as the existing MerkleTree depth check.

@RomarQ RomarQ requested review from a team as code owners March 25, 2026 00:33
Add a compile-time check that rejects ledger types nested deeper than
max-adt-nesting-depth (4). This prevents the compiler from crashing
with OOM on deeply nested Map types like Map<K, Map<K, Map<...>>>.

The guard checks the structural depth of already-resolved type
arguments in apply-ledger-ADT before expansion, following the same
pattern as the existing MerkleTree depth check.

Signed-off-by: Rodrigo Quelhas <rodrigo_quelhas@outlook.pt>
@RomarQ RomarQ force-pushed the fix/adt-nesting-depth-guard branch from 05a6505 to 2817546 Compare March 25, 2026 00:45
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 25, 2026

Compactc E2E Tests Results

  1 files  ±     0   48 suites  +47   2m 31s ⏱️ - 27m 28s
467 tests  - 14 533  461 ✅  - 14 539  6 💤 +6  0 ❌ ±0 
478 runs   - 14 522  472 ✅  - 14 528  6 💤 +6  0 ❌ ±0 

Results for commit 8f5581c. ± Comparison against base commit fd5310c.

This pull request removes 15000 and adds 467 tests. Note that renamed tests count towards both.
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_0.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_1.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_10.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_100.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_101.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_102.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_103.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_104.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_105.compact'
src/tests/fuzzer.e2e.test.ts ‑ [E2E] Fuzzer tests for compiler > should be able to compile synthetic contract: 'assert_contract_106.compact'
…
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[MFG-413] should compile and not thro…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-12371] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-15405] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-15733] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-15826] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16040] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16059] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16447] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16853] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16999] should return an error if …'
…

♻️ This comment has been updated with latest results.

type-adt-depth did not handle talias nodes wrapping tadt, returning 0
for any aliased Map type. This allowed bypassing the nesting depth
guard via type aliases (e.g. type MyMap = Map<Field, Boolean>).

Add a talias clause that recurses through the alias before checking
depth, consistent with how public-adt? uses de-alias.

Signed-off-by: Rodrigo Quelhas <rodrigo_quelhas@outlook.pt>
@github-actions
Copy link
Copy Markdown

Plugin Test Summary

 1 files   3 suites   1s ⏱️
21 tests 21 ✅ 0 💤 0 ❌
23 runs  23 ✅ 0 💤 0 ❌

Results for commit 10f0bb4.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

Compactc E2E Test Summary

    1 files  ±    0      1 suites   - 47   5m 51s ⏱️ + 3m 16s
2 827 tests +2 360  2 827 ✅ +2 366  0 💤  - 6  0 ❌ ±0 
2 827 runs  +2 349  2 827 ✅ +2 355  0 💤  - 6  0 ❌ ±0 

Results for commit 10f0bb4. ± Comparison against base commit b2a2f08.

This pull request removes 467 and adds 2827 tests. Note that renamed tests count towards both.
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[MFG-413] should compile and not thro…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-12371] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-15405] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-15733] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-15826] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16040] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16059] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16447] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16853] should compile and not thr…'
src/tests/bugs/compiler.bugs.e2e.test.ts ‑ [Bugs] Compiler > '[PM-16999] should return an error if …'
…
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_0.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_1.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_10.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_100.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_1000.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_1001.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_1002.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_1003.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_1004.compact'
src/tests/extracted.e2e.test.ts ‑ [E2E] Extracted unit tests for compiler > should be able to compile extracted contract: '/home/runner/work/_temp/nix-shell.yrPt8Z/temp-test-KXeio0/contract_1005.compact'
…

♻️ This comment has been updated with latest results.

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