Skip to content

Commit

Permalink
Merge branch 'main' into sam/refactor-validation-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord authored Oct 1, 2024
2 parents 030cafa + 0dfa048 commit 0d676ec
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"polite-jars-lie",
"popular-books-destroy",
"pretty-carrots-wink",
"red-stingrays-greet",
"shaggy-students-end",
"silent-ants-impress",
"silver-bobcats-switch",
"sixty-turtles-taste",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/red-stingrays-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@boostxyz/signatures": minor
---

pad function selectors to 32 bytes in signatures package
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @boostxyz/cli

## 0.0.0-alpha.12

## 0.0.0-alpha.11

## 0.0.0-alpha.10

## 0.0.0-alpha.9
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boostxyz/cli",
"version": "0.0.0-alpha.10",
"version": "0.0.0-alpha.12",
"description": "A repository of useful scripts to interact with the protocol",
"repository": "https://github.com/rabbitholegg/boost-protocol",
"private": true,
Expand Down
6 changes: 6 additions & 0 deletions packages/evm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @boostxyz/evm

## 0.0.0-alpha.3

### Minor Changes

- a7a3331: refactor base to bases in boost targets, resolve base address from config, and default to sepolia for now

## 0.0.0-alpha.2

### Minor Changes
Expand Down
5 changes: 5 additions & 0 deletions packages/evm/contracts/BoostCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ contract BoostCore is Ownable, ReentrancyGuard {
? boost.action.supportsInterface(type(AValidator).interfaceId) ? address(boost.action) : address(0)
: _makeTarget(type(AValidator).interfaceId, payload_.validator, true)
);

if (address(boost.validator) == address(0)) {
revert BoostError.InvalidInstance(type(AValidator).interfaceId, address(0));
}

emit BoostCreated(
_boosts.length - 1,
boost.owner,
Expand Down
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)))
if alreadySet {
// revert if the stored value was unset
mstore(0, claimedSelector)
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boostxyz/evm",
"version": "0.0.0-alpha.2",
"version": "0.0.0-alpha.3",
"description": "",
"private": true,
"publishConfig": {
Expand Down
51 changes: 45 additions & 6 deletions packages/evm/test/BoostCore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ contract BoostCoreTest is Test {
address[] mockAddresses;

BoostCore boostCore = new BoostCore(new BoostRegistry(), address(1));
BoostLib.Target action = _makeAction(address(mockERC721), MockERC721.mint.selector, mockERC721.mintPrice());
BoostLib.Target action =
_makeERC721MintAction(address(mockERC721), MockERC721.mint.selector, mockERC721.mintPrice());
BoostLib.Target contractAction =
_makeContractAction(address(mockERC721), MockERC721.mint.selector, mockERC721.mintPrice());
BoostLib.Target allowList = _makeAllowList(address(this));

address[] authorized = [address(boostCore)];
Expand Down Expand Up @@ -124,6 +127,30 @@ contract BoostCoreTest is Test {
assertEq(1, boostCore.getBoostCount());
}

function testCreateBoost_NoValidator() public {
bytes memory invalidCreateCalldata = LibZip.cdCompress(
abi.encode(
BoostCore.InitPayload({
budget: budget,
action: contractAction,
validator: BoostLib.Target({isBase: true, instance: address(0), parameters: ""}),
allowList: allowList,
incentives: _makeIncentives(1),
protocolFee: 500, // 5%
referralFee: 1000, // 10%
maxParticipants: 10_000,
owner: address(1)
})
)
);

vm.expectRevert(
abi.encodeWithSelector(BoostError.InvalidInstance.selector, type(AValidator).interfaceId, address(0))
);
boostCore.createBoost(invalidCreateCalldata);
assertEq(0, boostCore.getBoostCount());
}

function testCreateBoost_FullValidation() public {
// Create the Boost
BoostLib.Boost memory boost = boostCore.createBoost(validCreateCalldata);
Expand Down Expand Up @@ -336,14 +363,10 @@ contract BoostCoreTest is Test {
boostCore.createBoost(validCreateCalldata);

// Mint an ERC721 token to the claimant (this contract)
uint256 tokenId = 1;
mockERC721.mint{value: 0.1 ether}(address(this));
mockERC721.mint{value: 0.1 ether}(address(this));
mockERC721.mint{value: 0.1 ether}(address(this));

// Prepare the data payload for validation
bytes memory data = abi.encode(address(this), abi.encode(tokenId));

// Try to claim the incentive with insufficient funds
vm.expectRevert(
abi.encodeWithSelector(
Expand Down Expand Up @@ -483,7 +506,10 @@ contract BoostCoreTest is Test {
// Test Helper Functions //
///////////////////////////

function _makeAction(address target, bytes4 selector, uint256 value) internal returns (BoostLib.Target memory) {
function _makeERC721MintAction(address target, bytes4 selector, uint256 value)
internal
returns (BoostLib.Target memory)
{
return BoostLib.Target({
isBase: true,
instance: address(new ERC721MintAction()),
Expand All @@ -493,6 +519,19 @@ contract BoostCoreTest is Test {
});
}

function _makeContractAction(address target, bytes4 selector, uint256 value)
internal
returns (BoostLib.Target memory)
{
return BoostLib.Target({
isBase: true,
instance: address(new ContractAction()),
parameters: abi.encode(
AContractAction.InitPayload({chainId: block.chainid, target: target, selector: selector, value: value})
)
});
}

function _makeAllowList(address addr) internal returns (BoostLib.Target memory) {
address[] memory list = new address[](1);
list[0] = addr;
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);
}
}
13 changes: 13 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @boostxyz/sdk

## 0.0.0-alpha.14

### Patch Changes

- Updated dependencies [6154f5e]
- @boostxyz/signatures@0.0.0-alpha.3

## 0.0.0-alpha.13

### Minor Changes

- a7a3331: refactor base to bases in boost targets, resolve base address from config, and default to sepolia for now

## 0.0.0-alpha.12

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boostxyz/sdk",
"version": "0.0.0-alpha.12",
"version": "0.0.0-alpha.14",
"license": "GPL-3.0-or-later",
"type": "module",
"files": ["dist", "src"],
Expand Down
Loading

0 comments on commit 0d676ec

Please sign in to comment.