Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: faulty meta txn signature that contain bytes data #7

Merged
merged 4 commits into from
Feb 5, 2024
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
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export type TrustedHintRegistryDeployment = {
}

export const deployments: TrustedHintRegistryDeployment[] = [
{ chainId: 11155111, registry: '0xaFec50dd5D3599377C74CEEde4fc54C400D28909', type: "proxy", name: 'sepolia' },
{ chainId: 11155111, registry: '0x8B7D6Dc76c6aF3E42bB9de908Ba7e9a4a46A00ff', type: "logic", name: 'sepolia' },
{ chainId: 11155111, registry: '0x80F5ed34372dBb855f03d9F1D151a9DBc6450b87', type: "proxy", name: 'sepolia' },
{ chainId: 11155111, registry: '0x21B5926c81ea01f4aDd17c08516dcEC75c38cF3f', type: "logic", name: 'sepolia' },
]

export const TRUSTED_HINT_REGISTRY_ABI = [
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spherity/trusted-hint-registry",
"version": "1.0.0",
"version": "1.0.1",
"description": "A registry for trusted hints base on ERC-7506",
"type": "module",

Expand Down
20 changes: 14 additions & 6 deletions src/TrustedHintRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
_list,
_key,
_value,
_metadata,
keccak256(_metadata),
_signer,
nonces[_signer]
)));
Expand Down Expand Up @@ -240,13 +240,17 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
* @param _signature Raw signature created according to EIP-712
*/
function setHintsSigned(address _namespace, bytes32 _list, bytes32[] calldata _keys, bytes32[] calldata _values, bytes[] calldata _metadata, address _signer, bytes calldata _signature) public whenNotPaused {
bytes32[] memory hashedMetadata = new bytes32[](_metadata.length);
for (uint i = 0; i < _metadata.length; i++) {
hashedMetadata[i] = keccak256(_metadata[i]);
}
bytes32 hash = _hashTypedDataV4(keccak256(abi.encode(
keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] _metadata,address signer,uint256 nonce)"),
keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] metadata,address signer,uint256 nonce)"),
_namespace,
_list,
keccak256(abi.encodePacked(_keys)),
keccak256(abi.encodePacked(_values)),
keccak256(abi.encode(_metadata)),
keccak256(abi.encodePacked(hashedMetadata)),
_signer,
nonces[_signer]
)));
Expand Down Expand Up @@ -324,7 +328,7 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
_list,
_key,
_value,
_metadata,
keccak256(_metadata),
_signer,
nonces[_signer]
)));
Expand Down Expand Up @@ -394,13 +398,17 @@ contract TrustedHintRegistry is Initializable, EIP712Upgradeable, PausableUpgrad
* @param _signature Raw signature created according to EIP-712
*/
function setHintsDelegatedSigned(address _namespace, bytes32 _list, bytes32[] calldata _keys, bytes32[] calldata _values, bytes[] calldata _metadata, address _signer, bytes calldata _signature) public whenNotPaused {
bytes32[] memory hashedMetadata = new bytes32[](_metadata.length);
for (uint i = 0; i < _metadata.length; i++) {
hashedMetadata[i] = keccak256(_metadata[i]);
}
bytes32 hash = _hashTypedDataV4(keccak256(abi.encode(
keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] _metadata,address signer,uint256 nonce)"),
keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] metadata,address signer,uint256 nonce)"),
_namespace,
_list,
keccak256(abi.encodePacked(_keys)),
keccak256(abi.encodePacked(_values)),
keccak256(abi.encode(_metadata)),
keccak256(abi.encodePacked(hashedMetadata)),
_signer,
nonces[_signer]
)));
Expand Down
24 changes: 17 additions & 7 deletions test/utils/Sig712Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ contract Sig712Utils {
} else if (_action == MetaAction.SET_HINTS) {
return keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_HINTS_WITH_METADATA) {
return keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] _metadata,address signer,uint256 nonce)");
return keccak256("SetHintsSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,bytes[] metadata,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_HINT_METADATA) {
return keccak256("SetHintMetadataSigned(address namespace,bytes32 list,bytes32 key,bytes32 value,bytes metadata,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_HINT_METADATA_DELEGATED) {
Expand All @@ -123,10 +123,10 @@ contract Sig712Utils {
return keccak256("SetHintDelegatedSigned(address namespace,bytes32 list,bytes32 key,bytes32 value,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_HINT_DELEGATED_WITH_METADATA) {
return keccak256("SetHintDelegatedSigned(address namespace,bytes32 list,bytes32 key,bytes32 value,bytes metadata,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_HINTS_DELEGATED) {
} else if (_action == MetaAction.SET_HINTS_DELEGATED) {
return keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_HINTS_DELEGATED_WITH_METADATA) {
return keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] _metadata,address signer,uint256 nonce)");
return keccak256("SetHintsDelegatedSigned(address namespace,bytes32 list,bytes32[] keys,bytes32[] values, bytes[] metadata,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_LIST_STATUS) {
return keccak256("SetListStatusSigned(address namespace,bytes32 list,bool revoked,address signer,uint256 nonce)");
} else if (_action == MetaAction.SET_LIST_OWNER) {
Expand Down Expand Up @@ -203,7 +203,7 @@ contract Sig712Utils {
_hint.list,
_hint.key,
_hint.value,
_hint.metadata,
keccak256(_hint.metadata),
_signer,
_nonce
));
Expand Down Expand Up @@ -321,7 +321,7 @@ contract Sig712Utils {
_hint.list,
_hint.key,
_hint.value,
_hint.metadata,
keccak256(_hint.metadata),
_signer,
_nonce
));
Expand Down Expand Up @@ -394,13 +394,18 @@ contract Sig712Utils {
* @return Hash of the SetHintDelegatedWithMetadata action
*/
function getSetHintsDelegatedWithMetadataStructHash(HintMetadataEntries calldata _hints, address _signer, uint _nonce) internal pure returns (bytes32) {
bytes32[] memory encodedMetadata = new bytes32[](_hints.metadata.length);
for (uint i = 0; i < _hints.metadata.length; i++) {
// Encode each metadata item
encodedMetadata[i] = keccak256(_hints.metadata[i]);
}
return keccak256(abi.encode(
getTypeHash(MetaAction.SET_HINTS_DELEGATED_WITH_METADATA),
_hints.namespace,
_hints.list,
keccak256(abi.encodePacked(_hints.keys)),
keccak256(abi.encodePacked(_hints.values)),
keccak256(abi.encode(_hints.metadata)),
keccak256(abi.encodePacked(encodedMetadata)),
_signer,
_nonce
));
Expand Down Expand Up @@ -744,13 +749,18 @@ contract Sig712Utils {
* @return Hash of the SetHintsMetadata action
*/
function getSetHintsMetadataStructHash(HintMetadataEntries calldata _hints, address _signer, uint _nonce) internal pure returns (bytes32) {
bytes32[] memory encodedMetadata = new bytes32[](_hints.metadata.length);
for (uint i = 0; i < _hints.metadata.length; i++) {
// Encode each metadata item
encodedMetadata[i] = keccak256(_hints.metadata[i]);
}
return keccak256(abi.encode(
getTypeHash(MetaAction.SET_HINTS_WITH_METADATA),
_hints.namespace,
_hints.list,
keccak256(abi.encodePacked(_hints.keys)),
keccak256(abi.encodePacked(_hints.values)),
keccak256(abi.encode(_hints.metadata)),
keccak256(abi.encodePacked(encodedMetadata)),
_signer,
_nonce
));
Expand Down
Loading