Skip to content

mixclient: remove shadowed roots declaration - #3780

Open
yzxcj797 wants to merge 1 commit into
decred:masterfrom
yzxcj797:fix/mixclient-roots-shadowing-3777
Open

mixclient: remove shadowed roots declaration#3780
yzxcj797 wants to merge 1 commit into
decred:masterfrom
yzxcj797:fix/mixclient-roots-shadowing-3777

Conversation

@yzxcj797

Copy link
Copy Markdown

Fixes #3777.

Problem

In mixing/mixclient/client.go (receiveOwnRoots wait loop), each factored-polynomial iteration begins with roots = roots[:0] on the outer roots, then declares a fresh inner roots := make([]*big.Int, 0, sesRun.mtot) that shadows it (#3777):

roots = roots[:0]                                  // resets the outer slice — uselessly
...
if len(fp.Roots) != len(a)-1 { continue }
roots := make([]*big.Int, 0, sesRun.mtot)          // shadows the outer variable
if len(fp.Roots) <= len(roots) {                   // len(roots) is always 0 → dead check
    continue
}

The len(fp.Roots) <= len(roots) guard compares against a freshly-created slice, so it is dead code; and the per-iteration reset of the outer slice does nothing.

Fix

Remove the shadowing declaration and the dead length check. The loop appends to the reset outer roots (capacity len(a)-1, exactly the number of roots a valid factored polynomial carries), and the return roots, nil at the bottom of the loop returns the same slice that was built. Behavior is unchanged — the returned values are identical — but there is one variable, one reset, and no dead branch left to mislead.

Validation

go build ./... and go vet ./... in the mixing module are clean.

The receiveOwnRoots loop declared a fresh inner 'roots' (capacity
sesRun.mtot) that shadowed the outer 'roots' which had just been reset
with roots[:0], and guarded it with a comparison against the new
slice's length, which is always zero and therefore dead. Remove the
shadowing declaration and the dead check so the loop appends to the
reset outer slice and the return at the bottom of the loop hands back
the same slice that was built, as intended.

Fixes decred#3777.
@davecgh
davecgh requested a review from jrick August 22, 2026 06: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.

mixclient: roots variable shadowed bug

1 participant