Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BOOST-4785] Correctly masking leading bits for incentives in SignerValidator #138

Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion packages/evm/contracts/validators/SignerValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ library IncentiveBits {
function setOrThrow(IncentiveMap storage bitmap, bytes32 hash, uint256 incentive) internal {
bytes4 invalidSelector = BoostError.IncentiveToBig.selector;
bytes4 claimedSelector = BoostError.IncentiveClaimed.selector;

/// @solidity memory-safe-assembly
assembly {
if gt(incentive, 7) {
Expand All @@ -141,7 +142,7 @@ library IncentiveBits {
// toggle the value that was stored inline on stack with xor
let updatedStorageValue := xor(sload(storageSlot), shl(incentive, 1))
// isolate the toggled bit and see if it's been unset back to zero
let alreadySet := xor(1, shr(incentive, updatedStorageValue))
let alreadySet := xor(1, and(1, shr(incentive, updatedStorageValue)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tfw no NAND

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legend has it you can build a whole computer with those things

if alreadySet {
// revert if the stored value was unset
mstore(0, claimedSelector)
Expand Down
10 changes: 10 additions & 0 deletions packages/evm/test/validators/SignerValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,14 @@ contract IncentiveBitsTest is Test {
vm.expectRevert(abi.encodeWithSelector(BoostError.IncentiveClaimed.selector, 7));
_used.setOrThrow(fakeHash, 7);
}

function testIncentiveWorksOutofOrder() public {
unchecked {
for (uint256 x = 7; x < 8; x--) {
_used.setOrThrow(fakeHash, x);
}
}
uint8 map = _used.map[fakeHash];
assertEq(type(uint8).max, map);
}
}
Loading