Skip to content

Commit 8a43352

Browse files
authored
Merge pull request #15 from arr00/chore/change-base64-error
Change error param to `bytes1`
2 parents be35cd5 + fe87e49 commit 8a43352

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,21 @@ 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 getHexCode = str => ethers.hexlify(ethers.toUtf8Bytes(str));
55+
const helper = { interface: ethers.Interface.from(['error InvalidBase64Digit(bytes1)']) };
5556

5657
// ord('$') < 43
5758
await expect(this.mock.$decode('dGVzd$=='))
5859
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
59-
.withArgs('$'.charCodeAt(0));
60+
.withArgs(getHexCode('$'));
6061
// ord('~') > 122
6162
await expect(this.mock.$decode('dGVzd~=='))
6263
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
63-
.withArgs('~'.charCodeAt(0));
64+
.withArgs(getHexCode('~'));
6465
// ord('@') in range, but '@' not in the dictionary
6566
await expect(this.mock.$decode('dGVzd@=='))
6667
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
67-
.withArgs('@'.charCodeAt(0));
68+
.withArgs(getHexCode('@'));
6869
});
6970

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

0 commit comments

Comments
 (0)