Skip to content

Commit 8649338

Browse files
[hebaov2] wallet nonce refine (#2380)
* [hebaov2] wallet nonce refine * update
1 parent 82374c0 commit 8649338

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

packages/hebao_v2/contracts/base/SmartWallet.sol

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ contract SmartWallet is ERC1271
223223
return wallet.isGuardian(addr, includePendingAddition);
224224
}
225225

226-
function guardians(bool includePendingAddition)
226+
function getGuardians(bool includePendingAddition)
227227
public
228228
view
229229
returns (Guardian[] memory )
@@ -340,14 +340,6 @@ contract SmartWallet is ERC1271
340340
wallet.batchCall(to, data);
341341
}
342342

343-
function getNonce(address relayer)
344-
public
345-
view
346-
returns (uint)
347-
{
348-
return wallet.nonce[relayer];
349-
}
350-
351343
//
352344
// Recover
353345
//

packages/hebao_v2/contracts/base/libwallet/MetaTxLib.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ library MetaTxLib
9393
require(gasLeft >= (metaTx.gasLimit.mul(64) / 63), "OPERATOR_INSUFFICIENT_GAS");
9494

9595
// Update the nonce before the call to protect against reentrancy
96-
require(isNonceValid(wallet, msg.sender, metaTx.nonce, metaTx.data.toBytes4(0)), "INVALID_NONCE");
96+
require(isNonceValid(wallet, metaTx.nonce, metaTx.data.toBytes4(0)), "INVALID_NONCE");
9797
if (metaTx.nonce != 0) {
98-
wallet.nonce[msg.sender] = metaTx.nonce;
98+
wallet.nonce = metaTx.nonce;
9999
} else {
100100
require(metaTx.requiresSuccess, "META_TX_WITHOUT_NONCE_REQUIRES_SUCCESS");
101101
}
@@ -153,7 +153,6 @@ library MetaTxLib
153153

154154
function isNonceValid(
155155
Wallet storage wallet,
156-
address relayer,
157156
uint nonce,
158157
bytes4 methodId
159158
)
@@ -174,7 +173,7 @@ library MetaTxLib
174173
methodId == SmartWallet.approveThenCallContractWA.selector ) {
175174
return nonce == 0;
176175
} else {
177-
return nonce > wallet.nonce[relayer] && (nonce >> 128) <= block.number;
176+
return nonce > wallet.nonce && (nonce >> 128) <= block.number;
178177
}
179178
}
180179
}

packages/hebao_v2/contracts/base/libwallet/WalletData.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Wallet
4949
address owner;
5050

5151
// relayer => nonce
52-
mapping(address => uint) nonce;
52+
uint nonce;
5353
// hash => consumed
5454
mapping(bytes32 => bool) hashes;
5555

packages/hebao_v2/test/read.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ describe("wallet", () => {
3434
describe.only("read methods", () => {
3535
it("quota", async () => {
3636
const walletData = await wallet.wallet();
37-
console.log("quota:", walletData["quota"]);
37+
console.log("walletData:", walletData);
38+
const quotaInfo = walletData["quota"];
39+
console.log("quota:", quotaInfo);
3840
});
3941

4042
it("guardians", async () => {
41-
const guardians = await wallet.guardians(true);
43+
const guardians = await wallet.getGuardians(true);
4244
console.log("guardians:", guardians);
4345
});
4446

@@ -48,7 +50,8 @@ describe("wallet", () => {
4850
});
4951

5052
it("getNonce", async () => {
51-
const nonce = await wallet.getNonce("0x" + "11".repeat(20));
53+
const walletData = await wallet.wallet();
54+
const nonce = walletData["nonce"];
5255
console.log("nonce:", nonce);
5356
});
5457
});

0 commit comments

Comments
 (0)