Null账号技术文档

in #cn-devlast month

Null账号技术文档

概述

null账号是Steem区块链中的一个特殊系统账号,用于表示一个无法被任何人访问或控制的账号。发送到null账号的资金将被永久锁定,无法被提取。

账号定义

账号名称

  • 账号名: null
  • 定义位置: libraries/protocol/include/steem/protocol/config.hpp
/// Represents the canonical account with NO authority (nobody can access funds in null account)
#define STEEM_NULL_ACCOUNT                    "null"

系统账号分类

Steem区块链中定义了多个保留账号:

  • miners - 代表当前见证人
  • null - 无权限账号(无人能访问其中的资金)
  • temp - 通配符权限账号(任何人都能访问其中的资金)
  • steem.dao - 无权限账号,用于提案系统的资源支付

初始化

null账号在创世块(genesis)初始化时创建:

// 位置: libraries/chain/database.cpp::init_genesis()

create< account_object >( [&]( account_object& a )
{
   a.name = STEEM_NULL_ACCOUNT;
} );
create< account_authority_object >( [&]( account_authority_object& auth )
{
   auth.account = STEEM_NULL_ACCOUNT;
   auth.owner.weight_threshold = 1;
   auth.active.weight_threshold = 1;
});

权限结构(Authority)

Authority配置

null账号的权限配置如下:

  • Owner权限:

    • weight_threshold = 1
    • key_auths = {} (空)
    • account_auths = {} (空)
  • Active权限:

    • weight_threshold = 1
    • key_auths = {} (空)
    • account_auths = {} (空)

无法满足的权限(Impossible Authority)

由于null账号的authority没有任何密钥或账号授权,但weight_threshold设置为1,这导致权限无法满足:

bool authority::is_impossible()const
{
   uint64_t auth_weights = 0;
   for( const auto& item : account_auths ) auth_weights += item.second;
   for( const auto& item : key_auths ) auth_weights += item.second;
   return auth_weights < weight_threshold;
}
  • 总权重 = 0(没有任何授权)
  • 阈值 = 1
  • 结果:is_impossible() = true

这意味着:

  • 没有任何私钥可以控制null账号
  • 无法使用null账号签名任何交易
  • 发送到null账号的资金将永久锁定

私钥

结论:没有可用私钥

null账号没有可用的私钥,原因如下:

  1. Authority结构: null账号的authority中没有配置任何公钥(key_auths为空)
  2. 无法满足: 即使存在私钥,由于authority无法满足,也无法用于签名交易
  3. 设计目的: null账号的设计目的就是创建一个无法被任何人控制的账号

代码验证

在代码中,null账号的authority被明确标记为"impossible to satisfy":

// 位置: libraries/protocol/include/steem/protocol/steem_operations.hpp
a.push_back( authority( 1, STEEM_NULL_ACCOUNT, 1 ) ); 
// The null account auth is impossible to satisfy

用途

1. 资金销毁

null账号的主要用途是作为资金销毁地址。当需要永久销毁代币时,可以将其发送到null账号:

  • 发送到null账号的STEEM、SBD、VESTS等资产将永久锁定
  • 这些资产无法被任何人提取或使用

2. 费用处理

在某些操作中,费用可能被发送到null账号:

// 位置: libraries/chain/steem_evaluator.cpp
_db.adjust_balance( _db.get< account_object, by_name >( STEEM_NULL_ACCOUNT ), o.fee );

3. 余额清理机制

系统实现了自动清理null账号余额的机制(在硬分叉0.14之后):

// 位置: libraries/chain/database.cpp::clear_null_account_balance()
void database::clear_null_account_balance()
{
   if( !has_hardfork( STEEM_HARDFORK_0_14__327 ) ) return;
   
   // 检查并清理null账号的所有余额类型:
   // - balance (STEEM)
   // - savings_balance (STEEM)
   // - sbd_balance (SBD)
   // - savings_sbd_balance (SBD)
   // - vesting_shares (VESTS)
   // - reward_steem_balance
   // - reward_sbd_balance
   // - reward_vesting_balance
}

清理操作会:

  1. 统计null账号的所有余额
  2. 生成clear_null_account_balance_operation虚拟操作
  3. 将所有余额清零
  4. 从全局供应中扣除相应数量

4. 默认重置账号

在账号恢复机制中,null账号被用作默认的reset_account

// 位置: libraries/chain/include/steem/chain/account_object.hpp
account_name_type reset_account = STEEM_NULL_ACCOUNT;

相关操作

clear_null_account_balance_operation

这是一个虚拟操作(virtual operation),用于记录null账号余额的清理:

// 位置: libraries/protocol/include/steem/protocol/steem_virtual_operations.hpp
struct clear_null_account_balance_operation : public virtual_operation
{
   vector< asset > total_cleared;
};

测试用例

代码库中包含针对null账号的测试:

  • 位置: tests/tests/operation_time_tests.cpp
  • 测试函数: clear_null_account
  • 测试内容: 验证向null账号转账后,余额清理机制是否正常工作

安全考虑

  1. 不可逆性: 发送到null账号的资金无法恢复,操作前需谨慎
  2. 无权限访问: 即使知道账号名,也无法通过任何方式访问其中的资金
  3. 系统保护: null账号的authority结构确保其永远不会被控制

总结

属性说明
账号类型系统保留账号
账号名null
是否有私钥否,没有可用私钥
Authority状态Impossible(无法满足)
资金可访问性否,资金永久锁定
主要用途资金销毁、费用处理
余额清理支持(硬分叉0.14后)

参考代码位置

  • 定义: libraries/protocol/include/steem/protocol/config.hpp:332
  • 初始化: libraries/chain/database.cpp:3019-3028
  • Authority检查: libraries/protocol/authority.cpp:25-31
  • 余额清理: libraries/chain/database.cpp:1458-1590
  • 测试用例: tests/tests/operation_time_tests.cpp:2852