Skip to content
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
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ out = 'out'
libs = ['lib']
solc = "0.8.27"
solc-version = "0.8.27"
evm_version = "paris"
via_ir = true
use_literal_content = true

Expand Down
22 changes: 10 additions & 12 deletions src/tokens/ERC1155/presets/pack/ERC1155Pack.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ERC1155Items } from "../items/ERC1155Items.sol";
import { IERC1155ItemsFunctions } from "../items/IERC1155Items.sol";
import { IERC1155Pack } from "./IERC1155Pack.sol";

import { MerkleProof } from "openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol";
import { MerkleProofLib } from "solady/utils/MerkleProofLib.sol";

contract ERC1155Pack is ERC1155Items, IERC1155Pack {

Expand Down Expand Up @@ -59,9 +59,6 @@ contract ERC1155Pack is ERC1155Items, IERC1155Pack {
if (_commitments[packId][msg.sender] != 0) {
revert PendingReveal();
}
if (balanceOf(msg.sender, packId) == 0) {
revert NoBalance();
}
_burn(msg.sender, packId, 1);
uint256 revealAfterBlock = block.number + 1;
_commitments[packId][msg.sender] = revealAfterBlock;
Expand All @@ -79,7 +76,7 @@ contract ERC1155Pack is ERC1155Items, IERC1155Pack {
(uint256 randomIndex, uint256 revealIdx) = _getRevealIdx(user, packId);

bytes32 leaf = keccak256(abi.encode(revealIdx, packContent));
if (!MerkleProof.verify(proof, merkleRoot[packId], leaf)) {
if (!MerkleProofLib.verify(proof, merkleRoot[packId], leaf)) {
revert InvalidProof();
}

Expand All @@ -106,10 +103,11 @@ contract ERC1155Pack is ERC1155Items, IERC1155Pack {

/// @inheritdoc IERC1155Pack
function refundPack(address user, uint256 packId) external {
if (_commitments[packId][user] == 0) {
uint256 commitment = _commitments[packId][user];
if (commitment == 0) {
revert NoCommit();
}
if (uint256(blockhash(_commitments[packId][user])) != 0 || block.number <= _commitments[packId][user]) {
if (uint256(blockhash(commitment)) != 0 || block.number <= commitment) {
revert PendingReveal();
}
delete _commitments[packId][user];
Expand All @@ -127,15 +125,15 @@ contract ERC1155Pack is ERC1155Items, IERC1155Pack {
revert AllPacksOpened();
}

bytes32 blockHash = blockhash(_commitments[packId][user]);
uint256 commitment = _commitments[packId][user];
if (commitment == 0) {
revert NoCommit();
}
bytes32 blockHash = blockhash(commitment);
if (uint256(blockHash) == 0) {
revert InvalidCommit();
}

if (_commitments[packId][user] == 0) {
revert NoCommit();
}

randomIdx = uint256(keccak256(abi.encode(blockHash, user))) % remainingSupply[packId];
revealIdx = _getIndexOrDefault(randomIdx, packId);
return (randomIdx, revealIdx);
Expand Down
5 changes: 0 additions & 5 deletions src/tokens/ERC1155/presets/pack/IERC1155Pack.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ interface IERC1155Pack {
*/
error NoCommit();

/**
* No balance.
*/
error NoBalance();

/**
* Invalid proof.
*/
Expand Down
4 changes: 3 additions & 1 deletion test/tokens/ERC1155/presets/ERC1155Pack.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { IERC165 } from "openzeppelin-contracts/contracts/utils/introspection/IE

import { ISignalsImplicitMode } from "signals-implicit-mode/src/helper/SignalsImplicitMode.sol";

import { ERC1155 } from "solady/tokens/ERC1155.sol";

contract ERC1155PackHack is ERC1155Pack {

function setAllExceptOneClaimed(
Expand Down Expand Up @@ -218,7 +220,7 @@ contract ERC1155PackTest is TestHelper, IERC1155ItemsSignals {
) public {
assumeSafeAddress(user);
vm.prank(user);
vm.expectRevert(IERC1155Pack.NoBalance.selector);
vm.expectRevert(ERC1155.InsufficientBalance.selector);
pack.commit(0);
}

Expand Down
Loading