Chain drama: fee tiers, congestion, mempool drops, address poisoning, clipboard hijack, phishing; selected-button style

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZHU MINCHAOandClaude Opus 5.5 committed 2026-11-03 23:29:54 +08:00
1 parent 2b781acd82
commit dbba8b4376
15 files changed
+357 -20

No files matched your search

+26
View File
@@ -41,5 +41,31 @@ namespace Decentralized.Domain
}
public static bool Same(string a, string b) => Normalize(a) == Normalize(b);
/// <summary>缩写(钱包列表里的样子):0x + 主体前 3 位 + … + 校验位,例如 0x4b9…17。</summary>
public static string Short(string a)
{
a = Normalize(a);
return WellFormed(a) ? a.Substring(0, 5) + "…" + a.Substring(2 + BodyLength) : a;
}
/// <summary>
/// 相似地址(地址投毒、剪贴板木马用):主体前 3 位和校验位都和原地址一样,缩写看起来完全相同,中间几位不同;本身是合法地址,
/// 币转过去就进了骗子手里。找不到校验位相同的就只保留前 3 位。
/// </summary>
public static string Lookalike(string a, Rng rng)
{
a = Normalize(a);
if (!Valid(a)) return Make(rng.NextUInt());
string prefix = a.Substring(2, 3), check = a.Substring(2 + BodyLength), body0 = a.Substring(2, BodyLength);
for (int i = 0; i < 20000; i++)
{
string body = prefix + (rng.NextUInt() & 0xFFF).ToString("x3");
if (body != body0 && Check(body) == check) return "0x" + body + check;
}
string fallback;
do fallback = prefix + (rng.NextUInt() & 0xFFF).ToString("x3"); while (fallback == body0);
return "0x" + fallback + Check(fallback);
}
}
}
+12
View File
@@ -142,6 +142,18 @@ namespace Decentralized.Domain
/// <summary>被投毒的钱包:币的总价值达到 DrainMin 起,每晚有概率被转空;价值越高越快:期望天数从门槛处的 SlowDays(7 天)按价值线性降到 DrainFull 处的 1 天,每晚概率 = 1 / 期望天数。</summary>
public const double WalletDrainMin = 3000, WalletDrainFull = 20000, WalletDrainSlowDays = 7;
/// <summary>转账手续费(信用点等值,按转出的币扣):慢 / 普通 / 快;拥堵时乘以倍数。</summary>
public const double TxFeeSlow = 0.5, TxFeeNormal = 1.5, TxFeeFast = 4, TxCongestedFeeMult = 4;
/// <summary>网络拥堵:每晚开始拥堵的概率、持续天数上限;拥堵时普通档、慢档的确认间隔倍数,慢档被挤出内存池的概率。</summary>
public const double TxCongestionChance = 0.12, TxCongestedNormalSlow = 2, TxCongestedSlowSlow = 3.5, TxSlowDrop = 0.3;
public const int TxCongestionDaysMax = 2;
/// <summary>确认数:默认 3;金额(信用点)≥ MidValue 时 6,≥ BigValue 时 12。</summary>
public const int TxConfirmBase = 3, TxConfirmMid = 6, TxConfirmBig = 12;
public const double TxConfirmMidValue = 2000, TxConfirmBigValue = 10000;
/// <summary>地址投毒:每笔转出后被盯上的概率,0 币转入在 1–2 天后出现。剪贴板木马(被投毒的钱包):粘贴时换成相似地址的概率。钓鱼公告:每晚出现的概率。</summary>
public const double TxPoisonChance = 0.35, TxHijackChance = 0.3, TxPhishChance = 0.05;
public const int TxPoisonDelayMax = 2;
/// <summary>主交易对(信用点一侧)的深度随天数增长。</summary>
public static double PoolDepth(int day) => PoolDepth0 * (1 + day / 60.0);
}
+43
View File
@@ -0,0 +1,43 @@
using System.Collections.Generic;
namespace Decentralized.Domain
{
/// <summary>钱包里的一条转账记录:对方地址、币种、数量、哪天、转入还是转出。地址投毒的 0 币转入也记在这里。</summary>
public sealed class TxRecord
{
public string Addr, Asset;
public double Amount;
public int Day;
public bool In;
}
/// <summary>手续费档位:慢最便宜,网络拥堵时可能被挤出内存池;快最贵,拥堵时也照常确认。</summary>
public enum FeeTier { Slow, Normal, Fast }
/// <summary>链上转账的规则:手续费、需要的确认数、拥堵时慢档被丢弃的概率。</summary>
public static class TxRules
{
/// <summary>手续费(信用点等值,按转出的币扣):档位基础价 × 拥堵倍数。</summary>
public static double FeeCredits(FeeTier t, bool congested) =>
(t == FeeTier.Slow ? Tuning.TxFeeSlow : t == FeeTier.Normal ? Tuning.TxFeeNormal : Tuning.TxFeeFast) * (congested ? Tuning.TxCongestedFeeMult : 1);
/// <summary>需要的确认数:金额越大越多。</summary>
public static int Confirmations(double valueCredits) =>
valueCredits >= Tuning.TxConfirmBigValue ? Tuning.TxConfirmBig : valueCredits >= Tuning.TxConfirmMidValue ? Tuning.TxConfirmMid : Tuning.TxConfirmBase;
/// <summary>每次确认的间隔倍数:拥堵时慢档、普通档变慢。</summary>
public static double Slowdown(FeeTier t, bool congested) => !congested ? 1 : t == FeeTier.Fast ? 1 : t == FeeTier.Normal ? Tuning.TxCongestedNormalSlow : Tuning.TxCongestedSlowSlow;
/// <summary>拥堵时慢档交易被挤出内存池的概率(交易作废,手续费照扣)。</summary>
public static double DropChance(FeeTier t, bool congested) => congested && t == FeeTier.Slow ? Tuning.TxSlowDrop : 0;
/// <summary>转账记录最多保留几条。</summary>
public const int HistoryMax = 20;
public static void Record(List<TxRecord> history, TxRecord r)
{
history.Insert(0, r);
if (history.Count > HistoryMax) history.RemoveRange(HistoryMax, history.Count - HistoryMax);
}
}
}
+3
View File
@@ -22,6 +22,9 @@ namespace Decentralized.Domain
public string Name;
/// <summary>玩家起的名字;空时用默认名。</summary>
public string Label;
/// <summary>转账记录(最新的在前),PLEDGER 发送页的"最近"列表从这里取。</summary>
public List<TxRecord> History = new List<TxRecord>();
/// <summary>硬件钱包被动过手脚(供应链投毒):别人手里有助记词。玩家看不到。</summary>
public bool Poisoned;