From 6ce46331211199dfc92c86e2c527d910e3ae4bb5 Mon Sep 17 00:00:00 2001 From: nan01ab Date: Sun, 13 Oct 2024 17:47:23 +0800 Subject: [PATCH 1/2] fix: concurrency conflict because of Memory Order in Nep6Wallt and SQLiteWallt creation --- src/Neo/Wallets/NEP6/NEP6Wallet.cs | 2 ++ src/Plugins/SQLiteWallet/SQLiteWallet.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/Neo/Wallets/NEP6/NEP6Wallet.cs b/src/Neo/Wallets/NEP6/NEP6Wallet.cs index 3edb41c5aa..9cbcb9a7e3 100644 --- a/src/Neo/Wallets/NEP6/NEP6Wallet.cs +++ b/src/Neo/Wallets/NEP6/NEP6Wallet.cs @@ -20,6 +20,7 @@ using System.Security; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; +using System.Threading; using System.Threading.Tasks; namespace Neo.Wallets.NEP6 @@ -93,6 +94,7 @@ private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dicti scrypt = ScryptParameters.FromJson((JObject)wallet["scrypt"]); accounts = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson((JObject)p, this)).ToDictionary(p => p.ScriptHash); extra = wallet["extra"]; + Thread.MemoryBarrier(); if (!VerifyPasswordInternal(password.GetClearText())) throw new InvalidOperationException("Wrong password."); } diff --git a/src/Plugins/SQLiteWallet/SQLiteWallet.cs b/src/Plugins/SQLiteWallet/SQLiteWallet.cs index a4004dcff0..1b36231f91 100644 --- a/src/Plugins/SQLiteWallet/SQLiteWallet.cs +++ b/src/Plugins/SQLiteWallet/SQLiteWallet.cs @@ -318,6 +318,7 @@ private Dictionary LoadAccounts() account.Contract = contract; account.Key = new KeyPair(GetPrivateKeyFromNEP2(db_contract.Account.Nep2key, masterKey, ProtocolSettings.AddressVersion, scrypt.N, scrypt.R, scrypt.P)); } + Thread.MemoryBarrier(); return accounts; } From 6098d88df43ad83623654f9d18409282a25fe077 Mon Sep 17 00:00:00 2001 From: nan01ab Date: Sun, 13 Oct 2024 19:56:49 +0800 Subject: [PATCH 2/2] fix: concurrency conflict because of Memory Order in Nep6Wallet and SQLiteWallet creation --- src/Neo/Wallets/NEP6/NEP6Wallet.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Neo/Wallets/NEP6/NEP6Wallet.cs b/src/Neo/Wallets/NEP6/NEP6Wallet.cs index 9cbcb9a7e3..71a5c73a33 100644 --- a/src/Neo/Wallets/NEP6/NEP6Wallet.cs +++ b/src/Neo/Wallets/NEP6/NEP6Wallet.cs @@ -72,6 +72,7 @@ public NEP6Wallet(string path, string password, ProtocolSettings settings, strin accounts = new Dictionary(); extra = JToken.Null; } + Thread.MemoryBarrier(); } /// @@ -85,6 +86,7 @@ public NEP6Wallet(string path, string password, ProtocolSettings settings, JObje { this.password = password.ToSecureString(); LoadFromJson(json, out Scrypt, out accounts, out extra); + Thread.MemoryBarrier(); } private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dictionary accounts, out JToken extra) @@ -94,7 +96,6 @@ private void LoadFromJson(JObject wallet, out ScryptParameters scrypt, out Dicti scrypt = ScryptParameters.FromJson((JObject)wallet["scrypt"]); accounts = ((JArray)wallet["accounts"]).Select(p => NEP6Account.FromJson((JObject)p, this)).ToDictionary(p => p.ScriptHash); extra = wallet["extra"]; - Thread.MemoryBarrier(); if (!VerifyPasswordInternal(password.GetClearText())) throw new InvalidOperationException("Wrong password."); }