Skip to content

Commit 7218492

Browse files
authored
Merge pull request #45 from datachainlab/enhance-accountKey
feat: enhance _accountKey function to handle AUTH_MODE_EXTENSION case
2 parents 8f9934f + 987bd8f commit 7218492

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/core/TxAuthManager.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ contract TxAuthManager is Initializable, TxAuthManagerBase, CrossStore, ITxAuthM
149149
}
150150

151151
function _accountKey(Account.Data memory a) internal pure returns (bytes32) {
152+
if (a.auth_type.mode == AuthType.AuthMode.AUTH_MODE_EXTENSION) {
153+
return keccak256(abi.encode(
154+
a.id,
155+
a.auth_type.mode,
156+
a.auth_type.option.type_url
157+
));
158+
}
152159
return keccak256(abi.encode(a.id, a.auth_type));
153160
}
154161
}

test/TxAuthManager.t.sol

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,27 @@ contract TxAuthManagerTest is Test, ICrossError {
389389
assertEq(keyA, keyACopy, "Identical accounts should produce the same key");
390390
}
391391

392+
function test_accountKey_ExtensionModeIgnoresOptionValue() public {
393+
bytes memory id = bytes("user1");
394+
string memory typeUrl = URL_VALID;
395+
396+
GoogleProtobufAny.Data memory optionA = GoogleProtobufAny.Data({type_url: typeUrl, value: hex"aaaa"});
397+
GoogleProtobufAny.Data memory optionB = GoogleProtobufAny.Data({type_url: typeUrl, value: hex"bbbb"});
398+
399+
AuthAccount.Data memory accA = AuthAccount.Data({
400+
id: id, auth_type: AuthType.Data({mode: AuthType.AuthMode.AUTH_MODE_EXTENSION, option: optionA})
401+
});
402+
403+
AuthAccount.Data memory accB = AuthAccount.Data({
404+
id: id, auth_type: AuthType.Data({mode: AuthType.AuthMode.AUTH_MODE_EXTENSION, option: optionB})
405+
});
406+
407+
bytes32 keyA = harness.exposed_accountKey(accA);
408+
bytes32 keyB = harness.exposed_accountKey(accB);
409+
410+
assertEq(keyA, keyB, "Extension mode should ignore option.value in accountKey generation");
411+
}
412+
392413
function test_setStateFromRemainingList_HandlesDuplicatesAndReturnsRemains() public {
393414
AuthAccount.Data[] memory signers = new AuthAccount.Data[](3);
394415
signers[0] = signerA;

0 commit comments

Comments
 (0)