Truncate the index into the Merkle tree to bytes[8]
The beacon chain expects a `uint64` in part to avoid big-int computation. This commit updates the `Deposit` log so that it broadcasts data of the appropriate size.
This commit is contained in:
parent
d62834654f
commit
4cf06d908a
|
@ -653,7 +653,7 @@ DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32
|
||||||
TWO_TO_POWER_OF_TREE_DEPTH: constant(uint256) = 4294967296 # 2**32
|
TWO_TO_POWER_OF_TREE_DEPTH: constant(uint256) = 4294967296 # 2**32
|
||||||
SECONDS_PER_DAY: constant(uint256) = 86400
|
SECONDS_PER_DAY: constant(uint256) = 86400
|
||||||
|
|
||||||
Deposit: event({previous_deposit_root: bytes32, data: bytes[2064], merkle_tree_index: uint256})
|
Deposit: event({previous_deposit_root: bytes32, data: bytes[2064], merkle_tree_index: bytes[8]})
|
||||||
ChainStart: event({deposit_root: bytes32, time: bytes[8]})
|
ChainStart: event({deposit_root: bytes32, time: bytes[8]})
|
||||||
|
|
||||||
deposit_tree: map(uint256, bytes32)
|
deposit_tree: map(uint256, bytes32)
|
||||||
|
@ -666,18 +666,19 @@ def deposit(deposit_input: bytes[2048]):
|
||||||
assert msg.value >= as_wei_value(MIN_DEPOSIT, "ether")
|
assert msg.value >= as_wei_value(MIN_DEPOSIT, "ether")
|
||||||
assert msg.value <= as_wei_value(MAX_DEPOSIT, "ether")
|
assert msg.value <= as_wei_value(MAX_DEPOSIT, "ether")
|
||||||
|
|
||||||
merkle_tree_index: uint256 = self.deposit_count + TWO_TO_POWER_OF_TREE_DEPTH
|
index: uint256 = self.deposit_count + TWO_TO_POWER_OF_TREE_DEPTH
|
||||||
msg_gwei_bytes8: bytes[8] = slice(concat("", convert(msg.value / GWEI_PER_ETH, bytes32)), start=24, len=8)
|
msg_gwei_bytes8: bytes[8] = slice(concat("", convert(msg.value / GWEI_PER_ETH, bytes32)), start=24, len=8)
|
||||||
timestamp_bytes8: bytes[8] = slice(concat("", convert(block.timestamp, bytes32)), start=24, len=8)
|
timestamp_bytes8: bytes[8] = slice(concat("", convert(block.timestamp, bytes32)), start=24, len=8)
|
||||||
deposit_data: bytes[2064] = concat(msg_gwei_bytes8, timestamp_bytes8, deposit_input)
|
deposit_data: bytes[2064] = concat(msg_gwei_bytes8, timestamp_bytes8, deposit_input)
|
||||||
|
merkle_tree_index: bytes[8] = slice(concat("", convert(index, bytes32)), start=24, len=8)
|
||||||
|
|
||||||
log.Deposit(self.deposit_tree[1], deposit_data, merkle_tree_index)
|
log.Deposit(self.deposit_tree[1], deposit_data, merkle_tree_index)
|
||||||
|
|
||||||
# add deposit to merkle tree
|
# add deposit to merkle tree
|
||||||
self.deposit_tree[merkle_tree_index] = sha3(deposit_data)
|
self.deposit_tree[index] = sha3(deposit_data)
|
||||||
for i in range(DEPOSIT_CONTRACT_TREE_DEPTH):
|
for i in range(DEPOSIT_CONTRACT_TREE_DEPTH):
|
||||||
merkle_tree_index /= 2
|
index /= 2
|
||||||
self.deposit_tree[merkle_tree_index] = sha3(concat(self.deposit_tree[merkle_tree_index * 2], self.deposit_tree[merkle_tree_index * 2 + 1]))
|
self.deposit_tree[index] = sha3(concat(self.deposit_tree[index * 2], self.deposit_tree[index * 2 + 1]))
|
||||||
|
|
||||||
self.deposit_count += 1
|
self.deposit_count += 1
|
||||||
if msg.value == as_wei_value(MAX_DEPOSIT, "ether"):
|
if msg.value == as_wei_value(MAX_DEPOSIT, "ether"):
|
||||||
|
|
Loading…
Reference in New Issue