Skip to content

Commit be35cd5

Browse files
committed
fix custom error arg
1 parent 5ff607d commit be35cd5

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

contracts/utils/Base64.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,28 +187,28 @@ 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, 49))
190+
mstore(4, 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, 49))
197+
mstore(4, 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, 49))
204+
mstore(4, add(c, 43))
205205
revert(0, 0x24)
206206
}
207207
let d := sub(byte(31, input), 43)
208208
// slither-disable-next-line incorrect-shift
209209
if iszero(and(shl(d, 1), 0xffffffd0ffffffc47ff5)) {
210210
mstore(0, errorSelector)
211-
mstore(4, add(d, 49))
211+
mstore(4, add(d, 43))
212212
revert(0, 0x24)
213213
}
214214

test/utils/Base64.test.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +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)']) };
55+
5456
// ord('$') < 43
55-
await expect(this.mock.$decode('dGVzd$==')).to.be.reverted;
57+
await expect(this.mock.$decode('dGVzd$=='))
58+
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
59+
.withArgs('$'.charCodeAt(0));
5660
// ord('~') > 122
57-
await expect(this.mock.$decode('dGVzd~==')).to.be.reverted;
61+
await expect(this.mock.$decode('dGVzd~=='))
62+
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
63+
.withArgs('~'.charCodeAt(0));
5864
// ord('@') in range, but '@' not in the dictionary
59-
await expect(this.mock.$decode('dGVzd@==')).to.be.reverted;
65+
await expect(this.mock.$decode('dGVzd@=='))
66+
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
67+
.withArgs('@'.charCodeAt(0));
6068
});
6169

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

0 commit comments

Comments
 (0)