Skip to content

Commit fe4b803

Browse files
authored
fix: faulty meta txn signatures that contain bytes data (#7)
* fix: faulty meta txn signature that contain bytes data * fix: metadata was not hashed for signed hint setting as a delegate * chore: update deployment address * chore: bump version
1 parent 95ef165 commit fe4b803

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export type TrustedHintRegistryDeployment = {
88
}
99

1010
export const deployments: TrustedHintRegistryDeployment[] = [
11-
{ chainId: 11155111, registry: '0xaFec50dd5D3599377C74CEEde4fc54C400D28909', type: "proxy", name: 'sepolia' },
12-
{ chainId: 11155111, registry: '0x8B7D6Dc76c6aF3E42bB9de908Ba7e9a4a46A00ff', type: "logic", name: 'sepolia' },
11+
{ chainId: 11155111, registry: '0x80F5ed34372dBb855f03d9F1D151a9DBc6450b87', type: "proxy", name: 'sepolia' },
12+
{ chainId: 11155111, registry: '0x21B5926c81ea01f4aDd17c08516dcEC75c38cF3f', type: "logic", name: 'sepolia' },
1313
]
1414

1515
export const TRUSTED_HINT_REGISTRY_ABI = [

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@spherity/trusted-hint-registry",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A registry for trusted hints base on ERC-7506",
55
"type": "module",
66

src/TrustedHintRegistry.sol

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
142142
_list,
143143
_key,
144144
_value,
145-
_metadata,
145+
keccak256(_metadata),
146146
_signer,
147147
nonces[_signer]
148148
)));
@@ -240,13 +240,17 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
240240
* @param _signature Raw signature created according to EIP-712
241241
*/
242242
function setHintsSigned(address _namespace, bytes32 _list, bytes32[] calldata _keys, bytes32[] calldata _values, bytes[] calldata _metadata, address _signer, bytes calldata _signature) public whenNotPaused {
243+
bytes32[] memory hashedMetadata = new bytes32[](_metadata.length);
244+
for (uint i = 0; i < _metadata.length; i++) {
245+
hashedMetadata[i] = keccak256(_metadata[i]);
246+
}
243247
bytes32 hash = _hashTypedDataV4(keccak256(abi.encode(
244-
keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] _metadata,address signer,uint256 nonce)"),
248+
keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] metadata,address signer,uint256 nonce)"),
245249
_namespace,
246250
_list,
247251
keccak256(abi.encodePacked(_keys)),
248252
keccak256(abi.encodePacked(_values)),
249-
keccak256(abi.encode(_metadata)),
253+
keccak256(abi.encodePacked(hashedMetadata)),
250254
_signer,
251255
nonces[_signer]
252256
)));
@@ -324,7 +328,7 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
324328
_list,
325329
_key,
326330
_value,
327-
_metadata,
331+
keccak256(_metadata),
328332
_signer,
329333
nonces[_signer]
330334
)));
@@ -394,13 +398,17 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
394398
* @param _signature Raw signature created according to EIP-712
395399
*/
396400
function setHintsDelegatedSigned(address _namespace, bytes32 _list, bytes32[] calldata _keys, bytes32[] calldata _values, bytes[] calldata _metadata, address _signer, bytes calldata _signature) public whenNotPaused {
401+
bytes32[] memory hashedMetadata = new bytes32[](_metadata.length);
402+
for (uint i = 0; i < _metadata.length; i++) {
403+
hashedMetadata[i] = keccak256(_metadata[i]);
404+
}
397405
bytes32 hash = _hashTypedDataV4(keccak256(abi.encode(
398-
keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] _metadata,address signer,uint256 nonce)"),
406+
keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] metadata,address signer,uint256 nonce)"),
399407
_namespace,
400408
_list,
401409
keccak256(abi.encodePacked(_keys)),
402410
keccak256(abi.encodePacked(_values)),
403-
keccak256(abi.encode(_metadata)),
411+
keccak256(abi.encodePacked(hashedMetadata)),
404412
_signer,
405413
nonces[_signer]
406414
)));

test/utils/Sig712Utils.sol

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ contract Sig712Utils {
114114
} else if (_action == MetaAction.SET_HINTS) {
115115
return keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,address signer,uint256 nonce)");
116116
} else if (_action == MetaAction.SET_HINTS_WITH_METADATA) {
117-
return keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] _metadata,address signer,uint256 nonce)");
117+
return keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] metadata,address signer,uint256 nonce)");
118118
} else if (_action == MetaAction.SET_HINT_METADATA) {
119119
return keccak256("SetHintMetadataSigned(address namespace,bytes32 list,bytes32 key,bytes32 value,bytes metadata,address signer,uint256 nonce)");
120120
} else if (_action == MetaAction.SET_HINT_METADATA_DELEGATED) {
@@ -123,10 +123,10 @@ contract Sig712Utils {
123123
return keccak256("SetHintDelegatedSigned(address namespace,bytes32 list,bytes32 key,bytes32 value,address signer,uint256 nonce)");
124124
} else if (_action == MetaAction.SET_HINT_DELEGATED_WITH_METADATA) {
125125
return keccak256("SetHintDelegatedSigned(address namespace,bytes32 list,bytes32 key,bytes32 value,bytes metadata,address signer,uint256 nonce)");
126-
} else if (_action == MetaAction.SET_HINTS_DELEGATED) {
126+
} else if (_action == MetaAction.SET_HINTS_DELEGATED) {
127127
return keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,address signer,uint256 nonce)");
128128
} else if (_action == MetaAction.SET_HINTS_DELEGATED_WITH_METADATA) {
129-
return keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] _metadata,address signer,uint256 nonce)");
129+
return keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] metadata,address signer,uint256 nonce)");
130130
} else if (_action == MetaAction.SET_LIST_STATUS) {
131131
return keccak256("SetListStatusSigned(address namespace,bytes32 list,bool revoked,address signer,uint256 nonce)");
132132
} else if (_action == MetaAction.SET_LIST_OWNER) {
@@ -203,7 +203,7 @@ contract Sig712Utils {
203203
_hint.list,
204204
_hint.key,
205205
_hint.value,
206-
_hint.metadata,
206+
keccak256(_hint.metadata),
207207
_signer,
208208
_nonce
209209
));
@@ -321,7 +321,7 @@ contract Sig712Utils {
321321
_hint.list,
322322
_hint.key,
323323
_hint.value,
324-
_hint.metadata,
324+
keccak256(_hint.metadata),
325325
_signer,
326326
_nonce
327327
));
@@ -394,13 +394,18 @@ contract Sig712Utils {
394394
* @return Hash of the SetHintDelegatedWithMetadata action
395395
*/
396396
function getSetHintsDelegatedWithMetadataStructHash(HintMetadataEntries calldata _hints, address _signer, uint _nonce) internal pure returns (bytes32) {
397+
bytes32[] memory encodedMetadata = new bytes32[](_hints.metadata.length);
398+
for (uint i = 0; i < _hints.metadata.length; i++) {
399+
// Encode each metadata item
400+
encodedMetadata[i] = keccak256(_hints.metadata[i]);
401+
}
397402
return keccak256(abi.encode(
398403
getTypeHash(MetaAction.SET_HINTS_DELEGATED_WITH_METADATA),
399404
_hints.namespace,
400405
_hints.list,
401406
keccak256(abi.encodePacked(_hints.keys)),
402407
keccak256(abi.encodePacked(_hints.values)),
403-
keccak256(abi.encode(_hints.metadata)),
408+
keccak256(abi.encodePacked(encodedMetadata)),
404409
_signer,
405410
_nonce
406411
));
@@ -744,13 +749,18 @@ contract Sig712Utils {
744749
* @return Hash of the SetHintsMetadata action
745750
*/
746751
function getSetHintsMetadataStructHash(HintMetadataEntries calldata _hints, address _signer, uint _nonce) internal pure returns (bytes32) {
752+
bytes32[] memory encodedMetadata = new bytes32[](_hints.metadata.length);
753+
for (uint i = 0; i < _hints.metadata.length; i++) {
754+
// Encode each metadata item
755+
encodedMetadata[i] = keccak256(_hints.metadata[i]);
756+
}
747757
return keccak256(abi.encode(
748758
getTypeHash(MetaAction.SET_HINTS_WITH_METADATA),
749759
_hints.namespace,
750760
_hints.list,
751761
keccak256(abi.encodePacked(_hints.keys)),
752762
keccak256(abi.encodePacked(_hints.values)),
753-
keccak256(abi.encode(_hints.metadata)),
763+
keccak256(abi.encodePacked(encodedMetadata)),
754764
_signer,
755765
_nonce
756766
));

0 commit comments

Comments
 (0)