STRINGLIB¶
Overview¶
STRINGLIB provides string manipulation utilities including palindrome checking, string reversal, acronym validation, and random acronym generation for the gaming/voting system.
- Inherits: DYSNOMIA V2
- License: Sharia
- Solidity: ^0.8.21
What This Means For Players¶
Plain English Summary: STRINGLIB powers the word games - it's used for the acronym guessing game where players submit phrases that match random letter combinations. The system generates random acronyms (like "FBI") and players submit phrases ("Federal Bureau of Investigation") that match.
Real-World Analogy: It's like a game of Scrabble meets word association. The system shows you random letters (an acronym), and you have to come up with a clever phrase where each word starts with those letters in order.
How It Affects Your Gameplay: - Acronym game - Submit phrases that match the generated acronym - Validation - STRINGLIB checks if your phrase actually matches the acronym - Random challenges - Each round generates a new random acronym to guess - Palindrome fun - Can check if strings are palindromes (reads same forwards and backwards)
State Variables¶
| Variable | Type | Visibility | Description |
|---|---|---|---|
| Type | string | public constant | "LibStrings" |
Read Functions (Pure)¶
CheckPalindrome¶
function CheckPalindrome(string memory S) public pure returns (bool)
function CheckPalindrome(bytes memory S) public pure returns (bool)
public pure
- Parameters:
- S (string or bytes): Input to check
- Returns:
- bool: True if input reads the same forwards and backwards
- Description: Compares characters from both ends moving inward.
- Logic Flow:
1. Create reversed copy of input
2. Compare each position: if any mismatch, return false
3. Return true if all match
- In Plain English: Check if a word or phrase is a palindrome (reads the same forwards and backwards, like "racecar" or "kayak").
Reverse¶
function Reverse(string memory S) public pure returns (string memory)
function Reverse(bytes memory S) public pure returns (bytes memory)
public pure
- Parameters:
- S (string or bytes): Input to reverse
- Returns:
- Reversed version of input
- Description: Creates a new array and populates it backwards.
- Logic Flow:
1. Allocate new bytes array of same length
2. Iterate source backwards (j from length-1 to 0)
3. Assign to output (i from 0 to length-1)
- In Plain English: Flip a string backwards. "hello" becomes "olleh".
CaseInsensitiveCompare¶
- Access:public pure
- Parameters:
- A (bytes1): First character
- B (bytes1): Second character
- Returns:
- bool: True if characters match ignoring case
- Description: Uses ASCII offset (32) to compare uppercase/lowercase equivalents.
- Computation Details:
- ASCII uppercase: 65-90, lowercase: 97-122
- Difference between cases: 32
- Checks: A == B or A == B ± 32
- In Plain English: Compare two letters ignoring case. 'A' matches 'a', 'B' matches 'b', etc.
CheckAcronym¶
function CheckAcronym(string memory _A, string memory _B) public pure returns (bool)
function CheckAcronym(bytes memory _acronym, string memory _Beta) public pure returns (bool)
public pure
- Parameters:
- _A / _acronym (string or bytes): The acronym to validate (e.g., "FBI")
- _B / _Beta (string): The phrase to check against (e.g., "Federal Bureau of Investigation")
- Returns:
- bool: True if phrase's first letters spell the acronym
- Description: Validates that each word's first letter matches the next acronym letter.
- Logic Flow:
1. Compare first character of phrase to first acronym letter (case-insensitive)
2. For each space in phrase, next letter must match next acronym letter
3. Return true only if all acronym letters are matched
- In Plain English: Check if a phrase matches an acronym. "Federal Bureau of Investigation" matches "FBI" because each word starts with F, B, I in order.
log10¶
- Access:public pure
- Parameters:
- value (uint256): Number to compute log of
- Returns:
- uint256: Floor of log base 10 (number of digits minus 1)
- Description: Uses iterative halving to compute logarithm efficiently.
- Logic Flow:
1. Start with exponent = 64, halve each iteration
2. If value >= 10^exponent, divide value and accumulate exponent
3. Return final accumulated exponent
- In Plain English: Count how many digits a number has, minus one. log10(1000) = 3.
String¶
- Access:public pure
- Parameters:
- value (uint256): Number to convert
- Returns:
- buffer (string): Decimal string representation
- Description: Converts integer to string by extracting digits.
- Logic Flow:
1. Calculate length via log10 + 1
2. Allocate buffer
3. Use assembly to populate backwards: modulo 10 gives digit, divide by 10 shifts
- In Plain English: Convert a number to text. 12345 becomes "12345".
Hex (multiple overloads)¶
function Hex(address account) public pure returns (string memory)
function Hex(uint256 value) public pure returns (string memory)
function Hex(bytes32 value) public pure returns (string memory)
function Hex(bytes memory data) public pure returns (string memory)
public pure
- Returns:
- Hexadecimal string with "0x" prefix
- Description: Converts various types to hex by mapping each nibble to "0123456789abcdef".
- In Plain English: Convert data to hexadecimal format like "0x1a2b3c...".
Write Functions¶
RandomAcronym¶
- Access:public
- Parameters:
- MaxLength (uint8): Maximum acronym length (minimum 3)
- Returns:
- Acronym (bytes): Random uppercase letter sequence (2 to MaxLength chars)
- Description: Generates random uppercase letters using VMREQ.Random().
- Logic Flow:
1. Validate: if(MaxLength < 3) revert MinimumLength3
2. Generate random length: Xiao.Random() % (MaxLength - 2) + 2
3. For each position: letter = bytes1(uint8(Xiao.Random() % 26) + 65) (A=65 in ASCII)
4. Return random acronym bytes
- Side Effects: Consumes VMREQ randomness
- In Plain English: Generate a random letter combination for the acronym game. Returns something like "ABC" or "XYZ" that players then have to match with creative phrases.
Errors¶
| Error | Parameters | Description |
|---|---|---|
| MinimumLength3 | - | MaxLength must be at least 3 |
Contract Interactions¶
Depends On¶
- DYSNOMIA V2 - Base functionality
- VOID - Library registration
- VMREQ - Random number generation
Registered In¶
- VOID library registry as "strings"
Special Mechanisms¶
Acronym Validation Algorithm¶
1. Check first letter matches (case-insensitive)
2. For each space in phrase:
- Next letter after space must match next acronym letter
3. All acronym letters must be matched exactly
Example: - Acronym: "FBI" - Valid: "Federal Bureau of Investigation" ✓ - Invalid: "Fabulous Blue Ice" ✗ (wrong structure)
Case-Insensitive Comparison¶
Uses ASCII math to compare:
if(uint8(B) <= 90) // B is uppercase
return(A == B || uint8(A) == (uint8(B) + 32)); // A matches B or lowercase B
else
return(A == B || (uint8(A) + 32) == uint8(B)); // A matches B or uppercase B
Random Acronym Generation¶
- Generate random length (3 to MaxLength)
- For each position:
- Generate random number 0-25
- Map to letter A-Z
Usage Pattern¶
// Check palindrome
bool isPalindrome = stringLib.CheckPalindrome("racecar"); // true
// Validate acronym
bool valid = stringLib.CheckAcronym("LOL", "Laugh Out Loud"); // true
// Generate random acronym
bytes memory acronym = stringLib.RandomAcronym(5); // e.g., "ABXZ"
// Convert to string/hex
string memory numStr = stringLib.String(12345); // "12345"
string memory addrHex = stringLib.Hex(someAddress); // "0x1234..."
Gaming Integration¶
The acronym functions support a game mechanic where: 1. System generates random acronym (e.g., "ABC") 2. Users submit phrases ("A Big Cat") 3. System validates submissions using CheckAcronym 4. Valid submissions can earn rewards
Contract Verification¶
| Property | Value |
|---|---|
| Keccak256 Hash | 0x0e5bf088357a8b8d0cce341a0633531380290525c279d3fcb9fd6b2ed7560c1e |
| Source URL | https://raw.githubusercontent.com/busytoby/atropa_pulsechain/main/solidity/dysnomia/lib/stringlib.sol |
| Hash Generated | 2026-02-08T00:29:08Z |