The range of iteratePRNG limits the number of Zalgo distortions
The pseudo-random generator used to build Zalgo text distortions reduces its state modulo a small constant, so only a tiny fraction of the possible distortions can ever be produced. An attacker could not gain anything directly; the effect is that the visual variety of generated names is far smaller than intended.
Submitted by d3e4
https://github.com/code-423n4/2023-03-canto-identity/blob/077372297fc419ea7688ab62cc3fd4e8f4e24e66/canto-namespace-protocol/src/Utils.sol#L136-L174 https://github.com/code-423n4/2023-03-canto-identity/blob/077372297fc419ea7688ab62cc3fd4e8f4e24e66/canto-namespace-protocol/src/Utils.sol#L256-L261
Only a tiny fraction of all Zalgo distortions are accessible.
Proof of Concept
In characterToUnicodeBytes, for font class 7 (i.e. Zalgo), the _characterModifier determines the Zalgo distortion. The distortion is pseudo-randomly calculated by using _characterModifier as a seed and iteratively passing it through iteratePRNG, each intermediate value being used to set, in turn, each component of the distortion.
} else if (_fontClass == 7) {
// Zalgo
uint8 asciiStartingIndex = 97;
uint256 numAbove = (_characterModifier % 7) + 1;
// We do not reuse the same seed for the following generations to avoid any symmetries, e.g. that 2 chars above would also always result in 2 chars below
_characterModifier = iteratePRNG(_characterModifier);
uint256 numMiddle = _characterModifier % 2;
_characterModifier = iteratePRNG(_characterModifier);
uint256 numBelow = (_characterModifier % 7) + 1;
// ...
This has the effect that the initial seed value generates a stream of values, equidistributed within their respective ranges.
A Zalgo tile is defined by a letter and a modification consisting of a combination of characters above, over and below the letter. The modification consists of a selection of 1 up to 7 characters from a set of 46 characters above the letter, 0 or 1 from 5 over the letter, and 1 to 7 from 47 below the letter. Thus there is a total of $(46^1 + 46^2 + ... + 46^7)(5^0 + 5^1)(47^1 + 47^2 + ... + 47^7) = 1.38e24$ different Zalgo modifications possible per letter.
However, iteratePRNG modulates its return value by 2038074743:
function iteratePRNG(uint256 _currState) internal pure returns (uint256 iteratedState) {
unchecked {
iteratedState = _currState * 15485863;
iteratedState = (iteratedState * iteratedState * iteratedState) % 2038074743;
}
}
This means that after the first pass through iteratePRNG we only have 2038074743 different possibilities which will determine the rest of the distortion. The original _characterModifier is first used to set to uint256 numAbove = (_characterModifier % 7) + 1;. The remaining combinations are therefore 1.38e24 / 7 = 1.98e+23, which is vastly greater than 2038074743.
characterToUnicodeBytes can thus only return 7 * 2038074743 = 14266523201 different distortions per letter, which is only a tiny fraction of the actual number of distortions.
Note that it is similarly an issue that the range of _characterModifier is only 0..255, which issue is reportedly separately.
Recommended Mitigation Steps
iteratePRNG must have a range of at least 1.98e+23 different values.
OpenCoreCH (Canto Identity) acknowledged
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the PRNG's modulo constant caps the state space, so the seed stream cannot reach the full combinatorial range of distortions.
Impact
Only a tiny fraction of the intended Zalgo distortions can be generated, reducing the variety of names; no security impact is claimed.
What the attacker needed
None
The fix
iteratePRNG should be changed so its output range is at least about 1.98e+23 values.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract generates decorative 'Zalgo' text, where letters get extra marks above and below them. The code that picks those marks uses a random-looking number generator, but that generator can only ever produce about two billion different values. Since the full set of possible decorations is enormously larger, most combinations can never appear, so the output is much less varied than the design intended.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.