Skip to content

Commit

Permalink
updated hash method
Browse files Browse the repository at this point in the history
  • Loading branch information
bearni95 committed Oct 1, 2024
1 parent 161dbc0 commit e6a0f9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ contract TrailblazersBadgesS2 is
}

/// @notice End a migration
/// @param _hash The hash to sign
/// @param v signature V field
/// @param r signature R field
/// @param s signature S field
/// @dev Can be called only during an active migration, after the cooldown is over
/// @dev The final color is determined randomly, and affected by the tamper amounts
function endMigration(bytes32 _hash, uint8 v, bytes32 r, bytes32 s) external isMigrating {
Expand Down Expand Up @@ -398,12 +402,22 @@ contract TrailblazersBadgesS2 is

/// @notice Generate a unique hash for each migration uniquely
/// @param _user The user address
/// @param _exp The users experience points
/// @param _blockNumber The block number
/// @return _hash The unique hash
function generateClaimHash(address _user) external view returns (bytes32) {
function generateClaimHash(
address _user,
uint256 _exp,
uint256 _blockNumber
)
external
view
returns (bytes32)
{
if (claimCooldowns[_user] == 0) {
revert MIGRATION_NOT_STARTED();
}
return keccak256(abi.encodePacked(_user, claimCooldowns[_user]));
return keccak256(abi.encodePacked(_user, claimCooldowns[_user], _exp, _blockNumber));
}

/// @notice Generates a random number from a signature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ contract TrailblazersBadgesS2Test is Test {
wait(s2Badges.COOLDOWN_MIGRATION());

// generate the claim hash for the current migration
bytes32 claimHash = s2Badges.generateClaimHash(minters[0]);
bytes32 claimHash = s2Badges.generateClaimHash(
minters[0],
0, // experience points
0 // block number
);

// simulate the backend signing the hash
(uint8 v, bytes32 r, bytes32 s) = vm.sign(mintSignerPk, claimHash);
Expand Down Expand Up @@ -433,7 +437,7 @@ contract TrailblazersBadgesS2Test is Test {

function test_generateClaimHash_revert() public {
vm.expectRevert();
s2Badges.generateClaimHash(minters[0]);
s2Badges.generateClaimHash(minters[0], 0, 0);
}

function test_migrateSameBadgeId_revert() public {
Expand Down

0 comments on commit e6a0f9a

Please sign in to comment.