Add checkpoint variant with uint256 keys and values (#5748)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Arr00
2025-06-23 11:55:24 -04:00
committed by GitHub
parent 6079eb3f01
commit b84db20fb2
7 changed files with 337 additions and 15 deletions

View File

@ -223,7 +223,7 @@ function _unsafeAccess(
) private pure returns (${opts.checkpointTypeName} storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
result.slot := add(keccak256(0, 0x20), ${opts.checkpointSize === 1 ? 'pos' : `mul(pos, ${opts.checkpointSize})`})
}
}
`;

View File

@ -1,11 +1,12 @@
// OPTIONS
const VALUE_SIZES = [224, 208, 160];
const VALUE_SIZES = [256, 224, 208, 160];
const defaultOpts = size => ({
historyTypeName: `Trace${size}`,
checkpointTypeName: `Checkpoint${size}`,
checkpointFieldName: '_checkpoints',
keyTypeName: `uint${256 - size}`,
checkpointSize: size < 256 ? 1 : 2,
keyTypeName: size < 256 ? `uint${256 - size}` : 'uint256',
keyFieldName: '_key',
valueTypeName: `uint${size}`,
valueFieldName: '_value',

View File

@ -24,7 +24,11 @@ Checkpoints.${opts.historyTypeName} internal _ckpts;
function _bound${capitalize(opts.keyTypeName)}(${opts.keyTypeName} x, ${opts.keyTypeName} min, ${
opts.keyTypeName
} max) internal pure returns (${opts.keyTypeName}) {
return SafeCast.to${capitalize(opts.keyTypeName)}(bound(uint256(x), uint256(min), uint256(max)));
return ${
opts.keyTypeName === 'uint256'
? 'bound(x, min, max)'
: `SafeCast.to${capitalize(opts.keyTypeName)}(bound(uint256(x), uint256(min), uint256(max)))`
};
}
function _prepareKeys(${opts.keyTypeName}[] memory keys, ${opts.keyTypeName} maxSpread) internal pure {