# Zero-value allowance and ownership checks

Auth checks comparing against unset/zero values or reversed mapping keys, letting anyone pass

_Area: Smart contract access control and control flow. Seen in 2 disclosed reports; latest 2022-09-12. Updated 2026-11-22._

## How it works
An authorization check compares a caller-derived value against something that is zero or unset, so the comparison is trivially satisfied. Three shapes: (1) the stored owner is `address(0)` because the record was never initialized, and the signature-recovery helper also returns `address(0)` on malformed input, so the two zeros match [E1](https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md); (2) the allowance check compares against a return variable that is still `0` at that point instead of the real spend amount, so it always passes [E2](https://bugbountylibrary.com/r/c4%3A2022-06-illuminate%3AH-04.md); (3) an access mapping is keyed in the wrong direction (`owner=>token` instead of `token=>owner`), so the per-resource check keyed on `msg.sender` authorizes the wrong party [E3](https://bugbountylibrary.com/r/c4%3A2024-12-secondswap%3AM-04.md). The broken assumption in every case: that the value being compared is the intended, initialized, correctly-keyed one.

## Where it shows up
- Signature checks comparing `recoverKey(...)` output to a stored owner, where the owner may be an uninitialized mapping entry [E1](https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md)
- Recovery helpers that can return `address(0)` on malformed signature length or `v` not 27/28 [E1](https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md)
- User-supplied IDs (e.g. `_communityID`) used to index state without an existence check against a counter [E1](https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md)
- Allowance/approval checks comparing against a return parameter or shadowed local that defaults to zero [E2](https://bugbountylibrary.com/r/c4%3A2022-06-illuminate%3AH-04.md)
- Mappings written as `map[owner] = resource` where lookups later assume `map[resource] = owner` [E3](https://bugbountylibrary.com/r/c4%3A2024-12-secondswap%3AM-04.md)
- Authorization checks of the form `map[msg.sender] == resource` with no check that `msg.sender` is the resource's actual creator [E3](https://bugbountylibrary.com/r/c4%3A2024-12-secondswap%3AM-04.md)

## How to review
For every auth check, name the exact value the caller must prove and confirm it is initialized and non-zero on the path taken. Invariant: a check must never pass when the stored reference is `address(0)` or the compared amount is `0` by default. For signature checks, require the recovered signer to be non-zero and the stored owner to be set. For allowance checks, confirm the compared variable is the actual spend amount, not a return value or shadowed local. For mappings, confirm the key direction matches every read site, and that per-resource authorization verifies the caller is that resource's creator, not merely that the caller maps to the resource.

## How finders spotted it
- Traced a user-supplied `_communityID` and noticed it was never checked against `communityCount`, so the owner slot read as `address(0)`; then followed `checkSignatureValidity`/`recoverKey` to confirm `address(0)` could be returned and would match [E1](https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md)
- Read the redeem function and saw the allowance comparison used the wrong variable (return param instead of `principalAmount`) [E2](https://bugbountylibrary.com/r/c4%3A2022-06-illuminate%3AH-04.md)
- Noticed `setTokenOwner` keyed the mapping by owner instead of token, then traced `createVesting`/`transferVesting` and the downstream `safeTransferFrom(tokenIssuer,...)` to confirm the wrong party's funds move [E3](https://bugbountylibrary.com/r/c4%3A2024-12-secondswap%3AM-04.md)

## Variants seen
- Uninitialized owner plus zero-returning signature recovery [E1](https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md)
- Allowance check against an uninitialized return variable [E2](https://bugbountylibrary.com/r/c4%3A2022-06-illuminate%3AH-04.md)
- Reversed mapping key direction in access control [E3](https://bugbountylibrary.com/r/c4%3A2024-12-secondswap%3AM-04.md)

## Impact and severity
Unauthorized actions on other users' assets: pre-adding members to a not-yet-created community [E1](https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md); redeeming another user's principal without approval [E2](https://bugbountylibrary.com/r/c4%3A2022-06-illuminate%3AH-04.md); creating/transferring vestings on another owner's plan and pulling the wrong issuer's funds [E3](https://bugbountylibrary.com/r/c4%3A2024-12-secondswap%3AM-04.md). Severity is high where the bypass reaches other users' funds or state; impact scales with how many records share the zero/unset or mis-keyed value.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2022-08-rigor%3AH-05.md
- E2: https://bugbountylibrary.com/r/c4%3A2022-06-illuminate%3AH-04.md
- E3: https://bugbountylibrary.com/r/c4%3A2024-12-secondswap%3AM-04.md
