From 0f8e7fe5339bf923fed4a9de25c7d3d8a0d7090e Mon Sep 17 00:00:00 2001 From: Tang Bo Hao Date: Sat, 26 Aug 2023 16:23:14 +0800 Subject: [PATCH] fix: rotateAuthAccount failed When `giveOwnership` and `addOwnedAccount` are executed in the same transaction `rotateAuthAccount` will be called twice. However, during the second call, since authAcctPath is the same, it will cause `acct.linkAccount` to return `nil` as a result. --- contracts/HybridCustody.cdc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/HybridCustody.cdc b/contracts/HybridCustody.cdc index 3d4f960..a363f53 100644 --- a/contracts/HybridCustody.cdc +++ b/contracts/HybridCustody.cdc @@ -1023,7 +1023,10 @@ pub contract HybridCustody { // NOTE: This path cannot be sufficiently randomly generated, an app calling this function could build a // capability to this path before it is made, thus maintaining ownership despite making it look like they // gave it away. Until capability controllers, this method should not be fully trusted. - let authAcctPath = "HybridCustodyRelinquished".concat(HybridCustody.account.address.toString()).concat(getCurrentBlock().height.toString()) + let authAcctPath = "HybridCustodyRelinquished" + .concat(HybridCustody.account.address.toString()) + .concat(getCurrentBlock().height.toString()) + .concat((pathsToUnlink.length + 1).toString()) // ensure that the path is different from the previous one let acctCap = acct.linkAccount(PrivatePath(identifier: authAcctPath)!)! self.acct = acctCap