Bump to latest deposit contract dev branch (fad5c32)
This commit is contained in:
parent
05dc4b576f
commit
30bb8986c4
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,10 @@ CHAIN_START_FULL_DEPOSIT_THRESHOLD: constant(uint256) = 65536 # 2**16
|
||||||
DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32
|
DEPOSIT_CONTRACT_TREE_DEPTH: constant(uint256) = 32
|
||||||
SECONDS_PER_DAY: constant(uint256) = 86400
|
SECONDS_PER_DAY: constant(uint256) = 86400
|
||||||
MAX_64_BIT_VALUE: constant(uint256) = 18446744073709551615 # 2**64 - 1
|
MAX_64_BIT_VALUE: constant(uint256) = 18446744073709551615 # 2**64 - 1
|
||||||
|
PUBKEY_LENGTH: constant(uint256) = 48 # bytes
|
||||||
|
WITHDRAWAL_CREDENTIALS_LENGTH: constant(uint256) = 32 # bytes
|
||||||
|
SIGNATURE_LENGTH: constant(uint256) = 96 # bytes
|
||||||
|
MAX_DEPOSIT_COUNT: constant(uint256) = 4294967295 # 2**DEPOSIT_CONTRACT_TREE_DEPTH - 1
|
||||||
|
|
||||||
Deposit: event({
|
Deposit: event({
|
||||||
pubkey: bytes[48],
|
pubkey: bytes[48],
|
||||||
|
@ -25,7 +29,6 @@ chainStarted: public(bool)
|
||||||
def __init__():
|
def __init__():
|
||||||
for i in range(DEPOSIT_CONTRACT_TREE_DEPTH - 1):
|
for i in range(DEPOSIT_CONTRACT_TREE_DEPTH - 1):
|
||||||
self.zerohashes[i+1] = sha256(concat(self.zerohashes[i], self.zerohashes[i]))
|
self.zerohashes[i+1] = sha256(concat(self.zerohashes[i], self.zerohashes[i]))
|
||||||
self.branch[i+1] = self.zerohashes[i + 1]
|
|
||||||
|
|
||||||
|
|
||||||
@public
|
@public
|
||||||
|
@ -45,18 +48,6 @@ def to_little_endian_64(value: uint256) -> bytes[8]:
|
||||||
return slice(convert(y, bytes32), start=24, len=8)
|
return slice(convert(y, bytes32), start=24, len=8)
|
||||||
|
|
||||||
|
|
||||||
@public
|
|
||||||
@constant
|
|
||||||
def from_little_endian_64(value: bytes[8]) -> uint256:
|
|
||||||
y: uint256 = 0
|
|
||||||
x: uint256 = convert(value, uint256)
|
|
||||||
for i in range(8):
|
|
||||||
y = y + shift(bitwise_and(x, 255), 8 * (7-i))
|
|
||||||
x = shift(x, -8)
|
|
||||||
|
|
||||||
return y
|
|
||||||
|
|
||||||
|
|
||||||
@public
|
@public
|
||||||
@constant
|
@constant
|
||||||
def get_deposit_root() -> bytes32:
|
def get_deposit_root() -> bytes32:
|
||||||
|
@ -77,7 +68,18 @@ def get_deposit_count() -> bytes[8]:
|
||||||
|
|
||||||
@payable
|
@payable
|
||||||
@public
|
@public
|
||||||
def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96]):
|
def deposit(pubkey: bytes[PUBKEY_LENGTH],
|
||||||
|
withdrawal_credentials: bytes[WITHDRAWAL_CREDENTIALS_LENGTH],
|
||||||
|
signature: bytes[SIGNATURE_LENGTH]):
|
||||||
|
# Prevent edge case in computing `self.branch` when `self.deposit_count == MAX_DEPOSIT_COUNT`
|
||||||
|
# NOTE: reaching this point with the constants as currently defined is impossible due to the
|
||||||
|
# uni-directional nature of transfers from eth1 to eth2 and the total ether supply (< 130M).
|
||||||
|
assert self.deposit_count < MAX_DEPOSIT_COUNT
|
||||||
|
|
||||||
|
assert len(pubkey) == PUBKEY_LENGTH
|
||||||
|
assert len(withdrawal_credentials) == WITHDRAWAL_CREDENTIALS_LENGTH
|
||||||
|
assert len(signature) == SIGNATURE_LENGTH
|
||||||
|
|
||||||
deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei")
|
deposit_amount: uint256 = msg.value / as_wei_value(1, "gwei")
|
||||||
assert deposit_amount >= MIN_DEPOSIT_AMOUNT
|
assert deposit_amount >= MIN_DEPOSIT_AMOUNT
|
||||||
amount: bytes[8] = self.to_little_endian_64(deposit_amount)
|
amount: bytes[8] = self.to_little_endian_64(deposit_amount)
|
||||||
|
@ -115,7 +117,6 @@ def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: byt
|
||||||
self.branch[i] = value
|
self.branch[i] = value
|
||||||
|
|
||||||
self.deposit_count += 1
|
self.deposit_count += 1
|
||||||
new_deposit_root: bytes32 = self.get_deposit_root()
|
|
||||||
log.Deposit(
|
log.Deposit(
|
||||||
pubkey,
|
pubkey,
|
||||||
withdrawal_credentials,
|
withdrawal_credentials,
|
||||||
|
@ -132,6 +133,7 @@ def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: byt
|
||||||
as_unitless_number(block.timestamp) % SECONDS_PER_DAY +
|
as_unitless_number(block.timestamp) % SECONDS_PER_DAY +
|
||||||
2 * SECONDS_PER_DAY
|
2 * SECONDS_PER_DAY
|
||||||
)
|
)
|
||||||
|
new_deposit_root: bytes32 = self.get_deposit_root()
|
||||||
log.Eth2Genesis(new_deposit_root,
|
log.Eth2Genesis(new_deposit_root,
|
||||||
self.to_little_endian_64(self.deposit_count),
|
self.to_little_endian_64(self.deposit_count),
|
||||||
self.to_little_endian_64(timestamp_day_boundary))
|
self.to_little_endian_64(timestamp_day_boundary))
|
||||||
|
|
|
@ -77,13 +77,6 @@ def test_to_little_endian_64(registration_contract, value, success, assert_tx_fa
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_from_little_endian_64(registration_contract, assert_tx_failed):
|
|
||||||
values = [0, 2**64 - 1] + [randint(1, 2**64 - 2) for _ in range(10)]
|
|
||||||
for value in values:
|
|
||||||
call = registration_contract.functions.from_little_endian_64((value).to_bytes(8, 'little'))
|
|
||||||
assert call.call() == value
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'success,deposit_amount',
|
'success,deposit_amount',
|
||||||
[
|
[
|
||||||
|
@ -108,6 +101,43 @@ def test_deposit_amount(registration_contract,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'invalid_pubkey,invalid_withdrawal_credentials,invalid_signature,success',
|
||||||
|
[
|
||||||
|
(False, False, False, True),
|
||||||
|
(True, False, False, False),
|
||||||
|
(False, True, False, False),
|
||||||
|
(False, False, True, False),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_deposit_inputs(registration_contract,
|
||||||
|
w3,
|
||||||
|
assert_tx_failed,
|
||||||
|
deposit_input,
|
||||||
|
invalid_pubkey,
|
||||||
|
invalid_withdrawal_credentials,
|
||||||
|
invalid_signature,
|
||||||
|
success):
|
||||||
|
pubkey = deposit_input[0][2:] if invalid_pubkey else deposit_input[0]
|
||||||
|
if invalid_withdrawal_credentials: # this one is different to satisfy linter
|
||||||
|
withdrawal_credentials = deposit_input[1][2:]
|
||||||
|
else:
|
||||||
|
withdrawal_credentials = deposit_input[1]
|
||||||
|
signature = deposit_input[2][2:] if invalid_signature else deposit_input[2]
|
||||||
|
|
||||||
|
call = registration_contract.functions.deposit(
|
||||||
|
pubkey,
|
||||||
|
withdrawal_credentials,
|
||||||
|
signature,
|
||||||
|
)
|
||||||
|
if success:
|
||||||
|
assert call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei})
|
||||||
|
else:
|
||||||
|
assert_tx_failed(
|
||||||
|
lambda: call.transact({"value": FULL_DEPOSIT_AMOUNT * eth_utils.denoms.gwei})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_deposit_log(registration_contract, a0, w3, deposit_input):
|
def test_deposit_log(registration_contract, a0, w3, deposit_input):
|
||||||
log_filter = registration_contract.events.Deposit.createFilter(
|
log_filter = registration_contract.events.Deposit.createFilter(
|
||||||
fromBlock='latest',
|
fromBlock='latest',
|
||||||
|
@ -151,7 +181,7 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input
|
||||||
assert log["merkle_tree_index"] == i.to_bytes(8, 'little')
|
assert log["merkle_tree_index"] == i.to_bytes(8, 'little')
|
||||||
|
|
||||||
deposit_data = DepositData(
|
deposit_data = DepositData(
|
||||||
pubkey=deposit_input[0][:20],
|
pubkey=deposit_input[0],
|
||||||
withdrawal_credentials=deposit_input[1],
|
withdrawal_credentials=deposit_input[1],
|
||||||
amount=deposit_amount_list[i],
|
amount=deposit_amount_list[i],
|
||||||
signature=deposit_input[2],
|
signature=deposit_input[2],
|
||||||
|
|
Loading…
Reference in New Issue