@@ -259,6 +259,43 @@ contract Base58Test is SoladyTest {
259259 this .decodeWord ("JEKNVnkbo3jma5nREBBJCDoXFVeKkD56V3xKrvRmWxFH@ " );
260260 }
261261
262+ function testDecodeWordLowCharacterReverts () public {
263+ // 0 - 48 (before '1')
264+ for (uint256 i = 0 ; i < 48 ; i++ ) {
265+ vm.expectRevert (Base58.Base58DecodingError.selector );
266+ this .decodeWord (LibString.toHexString (i));
267+ }
268+ // 58 - 64 (: ; < = > ? @)
269+ for (uint256 i = 58 ; i <= 64 ; ++ i) {
270+ vm.expectRevert (Base58.Base58DecodingError.selector );
271+ this .decodeWord (LibString.toHexString (i));
272+ }
273+ vm.expectRevert (Base58.Base58DecodingError.selector );
274+ this .decodeWord ("I " );
275+ vm.expectRevert (Base58.Base58DecodingError.selector );
276+ this .decodeWord ("O " );
277+ // 91 - 96 ([ \ ] ^ _ `)
278+ for (uint256 i = 91 ; i <= 96 ; ++ i) {
279+ vm.expectRevert (Base58.Base58DecodingError.selector );
280+ this .decodeWord (LibString.toHexString (i));
281+ }
282+ vm.expectRevert (Base58.Base58DecodingError.selector );
283+ this .decodeWord ("l " );
284+
285+ // 123 - 127 ({ | } ~ DEL)
286+ for (uint256 i = 123 ; i <= 255 ; ++ i) {
287+ vm.expectRevert (Base58.Base58DecodingError.selector );
288+ this .decodeWord (LibString.toHexString (i));
289+ }
290+ vm.expectRevert (Base58.Base58DecodingError.selector );
291+ this .decodeWord ("\x00 " );
292+
293+ // Also cover an underflowing byte after a valid character, where
294+ // `result` is already nonzero (loop position > 0).
295+ vm.expectRevert (Base58.Base58DecodingError.selector );
296+ this .decodeWord ("z0 " );
297+ }
298+
262299 function decodeWord (string memory encoded ) public pure returns (bytes32 ) {
263300 return Base58.decodeWord (encoded);
264301 }
0 commit comments