stacks-network / stacks-network/stacks-core

Bug: `concretize` logic mis-handles `Trait` vs `Principal` types

Open
#6,485 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug clarity
Dominant language
Rust
Stars
3.1k
Forks
762
Avg merge
4d 6h
Merged PRs (30d)
76

Description

While reviewing the concretize function in clarity, I noticed what appears to be a bug in the way it initializes and checks the is_principal flag.

Currently, the code initializes is_principal = true before iterating through the set of types. This means that if the set contains a Trait, the function will always throw an error, because the check assumes principals were already present even when they were not.

If the ListUnionType contains a Trait, the function may incorrectly raise an error.

This behavior looks unintended, since the initialization does not reflect the actual contents of the set.

Multiple traits are also silently collapsed, which may not be correct?

Impact:

Fixing this would change the type-checking behavior of Clarity. Because of this, a fix would likely be consensus-breaking (maybe?). Could we release a fix as part of Clarity 4?

https://github.com/stacks-network/stacks-core/blob/e6487f6aa8de3cb97cf20fb7ce1c3fd2d931b773/clarity/src/vm/types/signatures.rs#L829-L871

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in clarity/src/vm/types/signatures.rs around lines 829-871 and trace how concretize initializes and checks is_principal for ListUnionType inputs. Reproduce cases containing Trait, Principal, and multiple Traits, then add or update focused Clarity type-checking tests so the intended behavior is explicit and the possible consensus-breaking impact is reviewed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.