(向左滑动,查看完整代码) 对于上述第 3 部分数据完整性的校验与构造交易数据一致,校验的逻辑关系参考下图: 可以看到,由于合约接收的参数是固定的格式和语义的,所以直接将各部分 pack 成 32 bytes,然后做 merkleize 求值,最后与接收到的 deposit_data_root 进行比较,如果相同则说明数据没有被篡改。 信标链的处理当存款交易成功被以太坊 1.0 链上执行后,以太坊 2.0 的信标链接下来如何处理? 信标链会一直监听存款合约的 DepositEvent 事件,如果存在新的存款合约,那么会启动相应的处理程序。以下为规范上对 deposit 的处理: def process_deposit(state: BeaconState, deposit: Deposit) -> None: ##################### 必要检验 ################### # Verify the Merkle branch assert is_valid_merkle_branch( leaf=hash_tree_root(deposit.data), branch=deposit.proof, depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the List length mix-in index=state.eth1_deposit_index, root=state.eth1_data.deposit_root, ) # Deposits must be processed in order state.eth1_deposit_index += 1 pubkey = deposit.data.pubkey amount = deposit.data.amount validator_pubkeys = [v.pubkey for v in state.validators] if pubkey not in validator_pubkeys: # Verify the deposit signature (proof of possession) which is not checked by the deposit contract deposit_message = DepositMessage( pubkey=deposit.data.pubkey, withdrawal_credentials=deposit.data.withdrawal_credentials, amount=deposit.data.amount, ) domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks signing_root = compute_signing_root(deposit_message, domain) if not bls.Verify(pubkey, signing_root, deposit.data.signature): return ################################################# ##################### 添加新验证人 ################### # Add validator and balance entries state.validators.append(get_validator_from_deposit(state, deposit)) state.balances.append(amount) ################################################# else: ################ 同一个验证人多次存入 ############### # Increase balance by deposit amount index = ValidatorIndex(validator_pubkeys.index(pubkey)) increase_balance(state, index, amount) ################################################# (向左滑动,查看完整代码) 可以看到,如果存入的已经是一个验证者,只需增加其余额便可。如果存入的是新的验证者,会在进行必要的校验后,在全局状态注册一个新的验证者。 (责任编辑:admin) |