Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contracts/utils/Base64.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {SafeCast} from "./math/SafeCast.sol";
library Base64 {
using SafeCast for bool;

error InvalidBase64Digit(uint8);
error InvalidBase64Digit(bytes1);

/**
* @dev Converts a `bytes` to its Bytes64 `string` representation.
Expand Down Expand Up @@ -187,21 +187,21 @@ library Base64 {
// slither-disable-next-line incorrect-shift
if iszero(and(shl(a, 1), 0xffffffd0ffffffc47ff5)) {
mstore(0, errorSelector)
mstore(4, add(a, 43))
mstore(4, shl(248, add(a, 43)))
revert(0, 0x24)
}
let b := sub(byte(29, input), 43)
// slither-disable-next-line incorrect-shift
if iszero(and(shl(b, 1), 0xffffffd0ffffffc47ff5)) {
mstore(0, errorSelector)
mstore(4, add(b, 43))
mstore(4, shl(248, add(b, 43)))
revert(0, 0x24)
}
let c := sub(byte(30, input), 43)
// slither-disable-next-line incorrect-shift
if iszero(and(shl(c, 1), 0xffffffd0ffffffc47ff5)) {
mstore(0, errorSelector)
mstore(4, add(c, 43))
mstore(4, shl(248, add(c, 43)))
revert(0, 0x24)
}
let d := sub(byte(31, input), 43)
Expand Down
8 changes: 4 additions & 4 deletions test/utils/Base64.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ describe('Base64', function () {
});

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

// ord('$') < 43
await expect(this.mock.$decode('dGVzd$=='))
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
.withArgs('$'.charCodeAt(0));
.withArgs(`0x${'$'.charCodeAt(0).toString(16)}`);
// ord('~') > 122
await expect(this.mock.$decode('dGVzd~=='))
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
.withArgs('~'.charCodeAt(0));
.withArgs(`0x${'~'.charCodeAt(0).toString(16)}`);
// ord('@') in range, but '@' not in the dictionary
await expect(this.mock.$decode('dGVzd@=='))
.to.be.revertedWithCustomError(helper, 'InvalidBase64Digit')
.withArgs('@'.charCodeAt(0));
.withArgs(`0x${'@'.charCodeAt(0).toString(16)}`);
});

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