Skip to content

Commit

Permalink
fix: hash string array
Browse files Browse the repository at this point in the history
  • Loading branch information
rndquu committed Dec 6, 2023
1 parent a1714d4 commit 2a5c4fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/NftReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ contract NftReward is ERC721, Ownable, Pausable, EIP712 {
* @return Mint request digest which should be signed by `minter`
*/
function getMintRequestDigest(MintRequest calldata _mintRequest) public view returns (bytes32) {
// for `string[]` array type we need to hash all the array values first
bytes32[] memory valuesHashed = new bytes32[](_mintRequest.values.length);
for (uint256 i = 0; i < _mintRequest.values.length; i++) {
valuesHashed[i] = keccak256(bytes(_mintRequest.values[i]));
}
// return final hash
return _hashTypedDataV4(keccak256(abi.encode(
keccak256("MintRequest(address beneficiary,uint256 deadline,bytes32[] keys,uint256 nonce,string[] values"),
keccak256("MintRequest(address beneficiary,uint256 deadline,bytes32[] keys,uint256 nonce,string[] values)"),
_mintRequest.beneficiary,
_mintRequest.deadline,
_mintRequest.keys,
keccak256(abi.encodePacked(_mintRequest.keys)),
_mintRequest.nonce,
_mintRequest.values
keccak256(abi.encodePacked(valuesHashed))
)));
}

Expand Down
2 changes: 1 addition & 1 deletion test/NftReward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract NftRewardTest is Test {
// get mint request digest which should be signed
bytes32 digest = nftReward.getMintRequestDigest(mintRequest);

assertEq(digest, 0xddc32c7e599cc39e82377aa8b3feaf2b2c178e5a1883bed3b11bb3b563698fc7);
assertEq(digest, 0x2c680706f2350ed5622f229af6736cd20626f7b9b4569b2fd5abb7e086886dc3);
}

function testGetTokenDataKeys_ReturnAllTokenDataKeys() public {
Expand Down

0 comments on commit 2a5c4fd

Please sign in to comment.