diff --git a/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/state/BeaconState.java b/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/state/BeaconState.java index ba124d857e4..fff8b2fc1aa 100644 --- a/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/state/BeaconState.java +++ b/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/state/BeaconState.java @@ -65,6 +65,8 @@ public class BeaconState { private Eth1Data latest_eth1_data; private List eth1_data_votes; + private UnsignedLong deposit_index; + public static BeaconState deepCopy(BeaconState state) { Gson gson = new GsonBuilder() @@ -111,7 +113,8 @@ public BeaconState( // Ethereum 1.0 chain data Eth1Data latest_eth1_data, - List eth1_data_votes) { + List eth1_data_votes, + UnsignedLong deposit_index) { this.slot = slot; this.genesis_time = genesis_time; this.fork = fork; @@ -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) { @@ -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() { @@ -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()); }); } @@ -280,7 +287,8 @@ public int hashCode() { latest_attestations, batched_block_roots, latest_eth1_data, - eth1_data_votes); + eth1_data_votes, + deposit_index); } @Override @@ -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 * * ******************* */ @@ -529,6 +538,14 @@ public void setEth1_data_votes(List 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); } diff --git a/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/util/BeaconStateUtil.java b/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/util/BeaconStateUtil.java index a006d6e6b64..642b84d4e6c 100644 --- a/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/util/BeaconStateUtil.java +++ b/ethereum/datastructures/src/main/java/tech/pegasys/artemis/datastructures/util/BeaconStateUtil.java @@ -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) { @@ -850,8 +851,9 @@ public static void process_deposit( List 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 validator_pubkeys = diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/artemis/statetransition/util/BlockProcessorUtil.java b/ethereum/statetransition/src/main/java/tech/pegasys/artemis/statetransition/util/BlockProcessorUtil.java index 6cb5388663a..1b7e6c3e94b 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/artemis/statetransition/util/BlockProcessorUtil.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/artemis/statetransition/util/BlockProcessorUtil.java @@ -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( @@ -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)); } }