Skip to content

Commit 6f49993

Browse files
committed
change error value to bytes1
1 parent be35cd5 commit 6f49993

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

contracts/utils/Base64.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {SafeCast} from "./math/SafeCast.sol";
1111
library Base64 {
1212
using SafeCast for bool;
1313

14-
error InvalidBase64Digit(uint8);
14+
error InvalidBase64Digit(bytes1);
1515

1616
/**
1717
* @dev Converts a `bytes` to its Bytes64 `string` representation.
@@ -187,21 +187,21 @@ library Base64 {
187187
// slither-disable-next-line incorrect-shift
188188
if iszero(and(shl(a, 1), 0xffffffd0ffffffc47ff5)) {
189189
mstore(0, errorSelector)
190-
mstore(4, add(a, 43))
190+
mstore(4, shl(248, add(a, 43)))
191191
revert(0, 0x24)
192192
}
193193
let b := sub(byte(29, input), 43)
194194
// slither-disable-next-line incorrect-shift
195195
if iszero(and(shl(b, 1), 0xffffffd0ffffffc47ff5)) {
196196
mstore(0, errorSelector)
197-
mstore(4, add(b, 43))
197+
mstore(4, shl(248, add(b, 43)))
198198
revert(0, 0x24)
199199
}
200200
let c := sub(byte(30, input), 43)
201201
// slither-disable-next-line incorrect-shift
202202
if iszero(and(shl(c, 1), 0xffffffd0ffffffc47ff5)) {
203203
mstore(0, errorSelector)
204-
mstore(4, add(c, 43))
204+
mstore(4, shl(248, add(c, 43)))
205205
revert(0, 0x24)
206206
}
207207
let d := sub(byte(31, input), 43)

test/utils/Base64.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ describe('Base64', function () {
5151
});
5252

5353
it('Decode invalid base64 string', async function () {
54-
const helper = { interface: ethers.Interface.from(['error InvalidBase64Digit(uint8)']) };
54+
const helper = { interface: ethers.Interface.from(['error InvalidBase64Digit(bytes1)']) };
5555

5656
// ord('$') < 43
5757
await expect(this.mock.$decode('dGVzd$=='))
5858
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
59-
.withArgs('$'.charCodeAt(0));
59+
.withArgs(`0x${'$'.charCodeAt(0).toString(16)}`);
6060
// ord('~') > 122
6161
await expect(this.mock.$decode('dGVzd~=='))
6262
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
63-
.withArgs('~'.charCodeAt(0));
63+
.withArgs(`0x${'~'.charCodeAt(0).toString(16)}`);
6464
// ord('@') in range, but '@' not in the dictionary
6565
await expect(this.mock.$decode('dGVzd@=='))
6666
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
67-
.withArgs('@'.charCodeAt(0));
67+
.withArgs(`0x${'@'.charCodeAt(0).toString(16)}`);
6868
});
6969

7070
it('Encode reads beyond the input buffer into dirty memory', async function () {

0 commit comments

Comments
 (0)