Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip Invalid Deposits, Add Deposit Index Ordering - (Spec PR #589, #594) #454

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class BeaconState {
private Eth1Data latest_eth1_data;
private List<Eth1DataVote> eth1_data_votes;

private UnsignedLong deposit_index;

public static BeaconState deepCopy(BeaconState state) {
Gson gson =
new GsonBuilder()
Expand Down Expand Up @@ -111,7 +113,8 @@ public BeaconState(

// Ethereum 1.0 chain data
Eth1Data latest_eth1_data,
List<Eth1DataVote> eth1_data_votes) {
List<Eth1DataVote> eth1_data_votes,
UnsignedLong deposit_index) {
this.slot = slot;
this.genesis_time = genesis_time;
this.fork = fork;
Expand Down Expand Up @@ -142,6 +145,8 @@ public BeaconState(

this.latest_eth1_data = latest_eth1_data;
this.eth1_data_votes = eth1_data_votes;

this.deposit_index = deposit_index;
}

public static BeaconState fromBytes(Bytes bytes) {
Expand Down Expand Up @@ -196,7 +201,8 @@ public static BeaconState fromBytes(Bytes bytes) {
Eth1Data.fromBytes(reader.readBytes()),
reader.readBytesList().stream()
.map(Eth1DataVote::fromBytes)
.collect(Collectors.toList())));
.collect(Collectors.toList()),
UnsignedLong.fromLongBits(reader.readUInt64())));
}

public Bytes toBytes() {
Expand Down Expand Up @@ -250,6 +256,7 @@ public Bytes toBytes() {
// Ethereum 1.0 chain data
writer.writeBytes(latest_eth1_data.toBytes());
writer.writeBytesList(eth1_data_votesBytes);
writer.writeUInt64(deposit_index.longValue());
});
}

Expand Down Expand Up @@ -280,7 +287,8 @@ public int hashCode() {
latest_attestations,
batched_block_roots,
latest_eth1_data,
eth1_data_votes);
eth1_data_votes,
deposit_index);
}

@Override
Expand Down Expand Up @@ -325,7 +333,8 @@ public boolean equals(Object obj) {
&& Objects.equals(this.getLatest_attestations(), other.getLatest_attestations())
&& Objects.equals(this.getBatched_block_roots(), other.getBatched_block_roots())
&& Objects.equals(this.getLatest_eth1_data(), other.getLatest_eth1_data())
&& Objects.equals(this.getEth1_data_votes(), other.getEth1_data_votes());
&& Objects.equals(this.getEth1_data_votes(), other.getEth1_data_votes())
&& Objects.equals(this.getDeposit_index(), other.getDeposit_index());
}

/** ******************* * GETTERS & SETTERS * * ******************* */
Expand Down Expand Up @@ -529,6 +538,14 @@ public void setEth1_data_votes(List<Eth1DataVote> eth1_data_votes) {
this.eth1_data_votes = eth1_data_votes;
}

public UnsignedLong getDeposit_index() {
return deposit_index;
}

public void setDeposit_index(UnsignedLong deposit_index) {
this.deposit_index = deposit_index;
}

public void incrementSlot() {
this.slot = slot.plus(UnsignedLong.ONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public static BeaconState get_initial_beacon_state(

// Ethereum 1.0 chain data
latest_eth1_data,
new ArrayList<>());
new ArrayList<>(),
UnsignedLong.valueOf(initial_validator_deposits.size()));

// Process initial deposits
for (Deposit validator_deposit : initial_validator_deposits) {
Expand Down Expand Up @@ -850,8 +851,9 @@ public static void process_deposit(
List<UnsignedLong> validatorBalances = state.getValidator_balances();

// Verify that the proof of posession is valid before processing the deposit.
checkArgument(
validate_proof_of_possession(state, pubkey, proof_of_possession, withdrawal_credentials));
if (!validate_proof_of_possession(state, pubkey, proof_of_possession, withdrawal_credentials)) {
return;
}

// Retrieve the list of validator's public keys from the current state.
List<BLSPublicKey> validator_pubkeys =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ public static void processDeposits(BeaconState state, BeaconBlock block)
// the hash was placed into the Merkle tree.
Bytes serialized_deposit_data = deposit.getDeposit_data().toBytes();

checkArgument(Objects.equals(state.getDeposit_index(), deposit.getIndex()));

// - Vadliate verify_merkle_branch(hash(serialized_deposit_data), deposit.branch,
// DEPOSIT_CONTRACT_TREE_DEPTH, deposit.index, state.latest_eth1_data.deposit_root)
checkArgument(
Expand All @@ -550,6 +552,8 @@ public static void processDeposits(BeaconState state, BeaconBlock block)
deposit.getDeposit_data().getAmount(),
deposit.getDeposit_data().getDeposit_input().getProof_of_possession(),
deposit.getDeposit_data().getDeposit_input().getWithdrawal_credentials());

state.setDeposit_index(state.getDeposit_index().plus(UnsignedLong.ONE));
}
}

Expand Down