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

V0.7.1 integration #1

Merged
merged 34 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
94ecad3
Constants update (v0.7.1) (#725)
cemozerr Jun 17, 2019
f90309d
Update data structures (#727)
cemozerr Jun 18, 2019
47576b5
add bls_domain
dangerousfood Jun 18, 2019
47f7efb
get_churn_limit added
dangerousfood Jun 18, 2019
281a678
is_slashable_attestation_data added
dangerousfood Jun 18, 2019
e84f943
validate_indexed_attestation added
dangerousfood Jun 18, 2019
cb8c4d6
get_domain modified
dangerousfood Jun 18, 2019
420fed3
convert_to_indexed
dangerousfood Jun 18, 2019
0ed57d9
get_attesting_indices modified
dangerousfood Jun 18, 2019
cf59933
get_shuffled_index added
dangerousfood Jun 18, 2019
3143900
compute_committee added
dangerousfood Jun 18, 2019
84f90f6
get_crosslink_committee added
dangerousfood Jun 18, 2019
676bc6b
get_epoch_start_shard added
dangerousfood Jun 18, 2019
f555095
get_shard_delta added
dangerousfood Jun 18, 2019
44b9e35
get_epoch_committee_count added
dangerousfood Jun 18, 2019
56e1e46
get_block_root_at_slot added
dangerousfood Jun 18, 2019
669156e
get_attestation_data_slot added
dangerousfood Jun 18, 2019
7a57eb7
decrease_balance added
dangerousfood Jun 18, 2019
06844c5
increase_balance added
dangerousfood Jun 18, 2019
1fcd600
is_slashable_validator added
dangerousfood Jun 18, 2019
13c20d5
get_previous_epoch modified
dangerousfood Jun 18, 2019
50ed5f6
get_active_validator_indices modified
dangerousfood Jun 18, 2019
67a7e9a
get_randao_mix modified
dangerousfood Jun 18, 2019
1324246
get_active_index_root modified
dangerousfood Jun 18, 2019
4c70f06
generate_seed modified
dangerousfood Jun 18, 2019
4a452a3
get_beacon_proposer_index modified
dangerousfood Jun 19, 2019
1a5d55e
removed methods
dangerousfood Jun 19, 2019
a10a42d
replacce assert
dangerousfood Jun 19, 2019
35d6fbb
bug fixes
dangerousfood Jun 19, 2019
effd86d
bug fixes
dangerousfood Jun 20, 2019
431c606
couture
dangerousfood Jun 21, 2019
e88ec71
bug fixes
dangerousfood Jun 21, 2019
3eb0422
best dev evar
dangerousfood Jun 21, 2019
a7f8cc5
bug fixes
dangerousfood Jun 21, 2019
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
122 changes: 103 additions & 19 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,129 @@ DepositSimulation = ["secp", "bls", "deposit_data", "events"]

# Modify constants in Constants.java
[constants]
# Minimal preset


# Misc
# ---------------------------------------------------------------

# [customized] Just 8 shards for testing purposes
SHARD_COUNT = 8
# [customized] unsecure, but fast
TARGET_COMMITTEE_SIZE = 4
MAX_BALANCE_CHURN_QUOTIENT = 32
MAX_INDICES_PER_SLASHABLE_VOTE = 4096
MAX_EXIT_DEQUEUES_PER_EPOCH = 4
SHUFFLE_ROUND_COUNT = 90
# 2**12 (= 4,096)
MAX_INDICES_PER_ATTESTATION = 4096
# 2**2 (= 4)
MIN_PER_EPOCH_CHURN_LIMIT = 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT = 65536
# Normalizes base rewards
BASE_REWARDS_PER_EPOCH = 5
# [customized] Faster, but unsecure.
SHUFFLE_ROUND_COUNT = 10


# Deposit contract
# ---------------------------------------------------------------
# **TBD**
DEPOSIT_CONTRACT_ADDRESS = '0x1234567890123456789012345678901234567890'
# 2**5 (= 32)
DEPOSIT_CONTRACT_TREE_DEPTH = 32


# Gwei values
# ---------------------------------------------------------------
# 2**0 * 10**9 (= 1,000,000,000) Gwei
MIN_DEPOSIT_AMOUNT = 1000000000
MAX_DEPOSIT_AMOUNT = 32000000000
FORK_CHOICE_BALANCE_INCREMENT = 1000000000
# 2**5 * 10**9 (= 32,000,000,000) Gwei
MAX_EFFECTIVE_BALANCE = 32000000000
# 2**4 * 10**9 (= 16,000,000,000) Gwei
EJECTION_BALANCE = 16000000000
GENESIS_FORK_VERSION = 0
GENESIS_SLOT = 4294967296
GENESIS_EPOCH = 536870912
GENESIS_START_SHARD = 0
# 2**0 * 10**9 (= 1,000,000,000) Gwei
EFFECTIVE_BALANCE_INCREMENT = 1000000000


# Initial values
# ---------------------------------------------------------------
GENESIS_FORK_VERSION = '0x00000000'
# 0, GENESIS_EPOCH is derived from this constant
GENESIS_SLOT = 0
# 2**64 - 1
FAR_FUTURE_EPOCH = 18446744073709551615
BLS_WITHDRAWAL_PREFIX = 0


# Time parameters
# ---------------------------------------------------------------
# 6 seconds 6 seconds
SECONDS_PER_SLOT = 6
MIN_ATTESTATION_INCLUSION_DELAY = 1
# [customized] 2 slots
MIN_ATTESTATION_INCLUSION_DELAY = 2
# [customized] fast epochs
SLOTS_PER_EPOCH = 8
# 2**0 (= 1) epochs
MIN_SEED_LOOKAHEAD = 1
# 2**2 (= 4) epochs
ACTIVATION_EXIT_DELAY = 4
EPOCHS_PER_ETH1_VOTING_PERIOD = 16
# [customized] higher frequency new deposits from eth1 for testing
SLOTS_PER_ETH1_VOTING_PERIOD = 16
# [customized] smaller state
SLOTS_PER_HISTORICAL_ROOT = 64
# 2**8 (= 256) epochs
MIN_VALIDATOR_WITHDRAWABILITY_DELAY = 256
# 2**11 (= 2,048) epochs
PERSISTENT_COMMITTEE_PERIOD = 2048
# 2**6 (= 64) epochs
MAX_EPOCHS_PER_CROSSLINK = 64
# 2**2 (= 4) epochs
MIN_EPOCHS_TO_INACTIVITY_PENALTY = 4
# [customized] 2**12 (= 4,096) epochs
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS = 4096


# State list lengths
# ---------------------------------------------------------------
# [customized] smaller state
LATEST_RANDAO_MIXES_LENGTH = 64
# [customized] smaller state
LATEST_ACTIVE_INDEX_ROOTS_LENGTH = 64
# [customized] smaller state
LATEST_SLASHED_EXIT_LENGTH = 64
BASE_REWARD_QUOTIENT = 32
WHISTLEBLOWER_REWARD_QUOTIENT = 512
ATTESTATION_INCLUSION_REWARD_QUOTIENT = 8
INACTIVITY_PENALTY_QUOTIENT = 16777216
MIN_PENALTY_QUOTIENT = 32


# Reward and penalty quotients
# ---------------------------------------------------------------
# 2**5 (= 32)
BASE_REWARD_FACTOR = 32
# 2**9 (= 512)
WHISTLEBLOWING_REWARD_QUOTIENT = 512
# 2**3 (= 8)
PROPOSER_REWARD_QUOTIENT = 8
# 2**25 (= 33,554,432)
INACTIVITY_PENALTY_QUOTIENT = 33554432
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT = 32


# Max operations per block
# ---------------------------------------------------------------
# 2**4 (= 16)
MAX_PROPOSER_SLASHINGS = 16
# 2**0 (= 1)
MAX_ATTESTER_SLASHINGS = 1
# 2**7 (= 128)
MAX_ATTESTATIONS = 128
# 2**4 (= 16)
MAX_DEPOSITS = 16
# 2**4 (= 16)
MAX_VOLUNTARY_EXITS = 16
MAX_TRANSFERS = 16
DOMAIN_BEACON_BLOCK = 0
# Originally 2**4 (= 16), disabled for now.
MAX_TRANSFERS = 0


# Signature domains
# ---------------------------------------------------------------
DOMAIN_BEACON_PROPOSER = 0
DOMAIN_RANDAO = 1
DOMAIN_ATTESTATION = 2
DOMAIN_DEPOSIT = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,54 @@ public class Constants {
// Misc
public static int SHARD_COUNT = 1024; // 2^10 shards
public static int TARGET_COMMITTEE_SIZE = 128; // 2^7 validators
public static int MAX_BALANCE_CHURN_QUOTIENT = 32; // 2^5
public static int MAX_INDICES_PER_SLASHABLE_VOTE = 4096; // 2^12 votes
public static int MAX_EXIT_DEQUEUES_PER_EPOCH = 4; // 2^2 withdrawals
public static int MAX_INDICES_PER_ATTESTATION = 4096; // 2^5
public static int MIN_PER_EPOCH_CHURN_LIMIT = 4; // 2^2 withdrawals
public static int CHURN_LIMIT_QUOTIENT = 65536; // 2^2 withdrawals
public static int BASE_REWARD_PER_EPOCH = 5; // 2^2 withdrawals
public static int SHUFFLE_ROUND_COUNT = 90;

// Deposit contract
public static String DEPOSIT_CONTRACT_ADDRESS = "0x0"; // This is TBD in the spec.
public static int DEPOSIT_CONTRACT_TREE_DEPTH = 32; // 2^5

// Gwei values
public static long MIN_DEPOSIT_AMOUNT = 1000000000L; // 2^0 * 1E9 Gwei
public static long MAX_DEPOSIT_AMOUNT = 32000000000L; // 2^5 * 1E9 Gwei
public static long FORK_CHOICE_BALANCE_INCREMENT = 1000000000L; // 2^0 * 1E9 Gwei
public static long MAX_EFFECTIVE_BALANCE = 32000000000L; // 2^5 * 1E9 Gwei
public static long EJECTION_BALANCE = 16000000000L; // 2^4 * 1E9 Gwei
public static long EFFECTIVE_BALANCE_INCREMENT = 1000000000L; // 2^0 * 1E9 Gwei

// Initial values
public static long GENESIS_SLOT = 0; // 2^32
public static long GENESIS_EPOCH = 0;
public static long GENESIS_FORK_VERSION = 0;
public static UnsignedLong FAR_FUTURE_EPOCH = UnsignedLong.MAX_VALUE;
public static Bytes32 ZERO_HASH = Bytes32.ZERO; // TODO confirm if equals to b'\x00' * 32
public static int BLS_WITHDRAWAL_PREFIX_BYTE = 0;

// Time parameters
public static int SECONDS_PER_SLOT = 6; // 6 seconds
public static int MIN_ATTESTATION_INCLUSION_DELAY = 4; // 2^2 slots
public static int SLOTS_PER_EPOCH = 64; // 2^6 slots
public static int MIN_SEED_LOOKAHEAD = 1; // 2^0 epochs (6.4 minutes)
public static int ACTIVATION_EXIT_DELAY = 4; // 2^2 epochs (25.6 minutes)
public static int EPOCHS_PER_ETH1_VOTING_PERIOD = 16; // 2^4 epochs (~1.7 hours)
public static int SLOTS_PER_ETH1_VOTING_PERIOD = 1024; // 2^4 epochs (~1.7 hours)
public static int SLOTS_PER_HISTORICAL_ROOT = 8192; // 2^13 slots (~13 hours)
public static int MIN_VALIDATOR_WITHDRAWABILITY_DELAY = 256; // 2^8 epochs (~27 hours)
public static int PERSISTENT_COMMITTEE_PERIOD = 2048; // 2^11 epochs (~9 days)
public static int MAX_EPOCHS_PER_CROSSLINK = 64; // 2^11 epochs (~9 days)
public static int MIN_EPOCHS_TO_INACTIVITY_PENALTY = 4; // 2^11 epochs (~9 days)

// Initial values
public static int GENESIS_FORK_VERSION = 0;
public static long GENESIS_SLOT = 4294967296L; // 2^32
public static long GENESIS_EPOCH = slot_to_epoch(GENESIS_SLOT);
public static long GENESIS_START_SHARD = 0;
public static UnsignedLong FAR_FUTURE_EPOCH = UnsignedLong.MAX_VALUE;
public static Bytes32 ZERO_HASH = Bytes32.ZERO;
public static BLSSignature EMPTY_SIGNATURE = BLSSignature.empty();
public static Bytes BLS_WITHDRAWAL_PREFIX_BYTE = Bytes.EMPTY;
public static int SECONDS_PER_SLOT = 6; // removed in 7.1 main spec for some reason but keep for now

// State list lengths
public static int LATEST_RANDAO_MIXES_LENGTH = 8192; // 2^13 epochs (~36 days)
public static int LATEST_ACTIVE_INDEX_ROOTS_LENGTH = 8192; // 2^13 epochs (~36 days)
public static int LATEST_SLASHED_EXIT_LENGTH = 8192; // 2^13 epochs (~36 days)

// Reward and penalty quotients
public static int BASE_REWARD_QUOTIENT = 32; // 2^5
public static int WHISTLEBLOWER_REWARD_QUOTIENT = 512; // 2^9
public static int ATTESTATION_INCLUSION_REWARD_QUOTIENT = 8; // 2^3
public static int INACTIVITY_PENALTY_QUOTIENT = 16777216; // 2^24
public static int MIN_PENALTY_QUOTIENT = 32; // 2^5
public static int BASE_REWARD_FACTOR = 32; // 2^5
public static int WHISTLEBLOWING_REWARD_QUOTIENT = 512; // 2^9
public static int PROPOSER_REWARD_QUOTIENT = 8; // 2^3
public static int INACTIVITY_PENALTY_QUOTIENT = 33554432; // 2^25
public static int MIN_SLASHING_PENALTY_QUOTIENT = 32; // 2^5

// Max transactions per block
public static int MAX_PROPOSER_SLASHINGS = 16; // 2^4
Expand All @@ -84,7 +85,7 @@ public class Constants {
public static int MAX_TRANSFERS = 16; // 2^4

// Signature domains
public static int DOMAIN_BEACON_BLOCK = 0;
public static int DOMAIN_BEACON_PROPOSER = 0;
public static int DOMAIN_RANDAO = 1;
public static int DOMAIN_ATTESTATION = 2;
public static int DOMAIN_DEPOSIT = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class BeaconBlock {

// Header
private long slot;
private Bytes32 previous_block_root;
private Bytes32 parent_root;
private Bytes32 state_root;

// Body
Expand All @@ -37,12 +37,12 @@ public final class BeaconBlock {

public BeaconBlock(
long slot,
Bytes32 previous_block_root,
Bytes32 parent_root,
Bytes32 state_root,
BeaconBlockBody body,
BLSSignature signature) {
this.slot = slot;
this.previous_block_root = previous_block_root;
this.parent_root = parent_root;
this.state_root = state_root;
this.body = body;
this.signature = signature;
Expand All @@ -64,7 +64,7 @@ public Bytes toBytes() {
return SSZ.encode(
writer -> {
writer.writeUInt64(slot);
writer.writeFixedBytes(32, previous_block_root);
writer.writeFixedBytes(32, parent_root);
writer.writeFixedBytes(32, state_root);
writer.writeBytes(body.toBytes());
writer.writeBytes(signature.toBytes());
Expand All @@ -73,7 +73,7 @@ public Bytes toBytes() {

@Override
public int hashCode() {
return Objects.hash(slot, previous_block_root, state_root, body, signature);
return Objects.hash(slot, parent_root, state_root, body, signature);
}

@Override
Expand All @@ -92,7 +92,7 @@ public boolean equals(Object obj) {

BeaconBlock other = (BeaconBlock) obj;
return slot == other.getSlot()
&& Objects.equals(this.getPrevious_block_root(), other.getPrevious_block_root())
&& Objects.equals(this.getParent_root(), other.getParent_root())
&& Objects.equals(this.getState_root(), other.getState_root())
&& Objects.equals(this.getBody(), other.getBody())
&& Objects.equals(this.getSignature(), other.getSignature());
Expand Down Expand Up @@ -123,12 +123,12 @@ public void setState_root(Bytes32 state_root) {
this.state_root = state_root;
}

public Bytes32 getPrevious_block_root() {
return previous_block_root;
public Bytes32 getParent_root() {
return parent_root;
}

public void setPrevious_block_root(Bytes32 previous_block_root) {
this.previous_block_root = previous_block_root;
public void setParent_root(Bytes32 parent_root) {
this.parent_root = parent_root;
}

public long getSlot() {
Expand All @@ -149,7 +149,7 @@ public Bytes32 signed_root(String truncation_param) {
HashTreeUtil.merkleize(
Arrays.asList(
HashTreeUtil.hash_tree_root(SSZTypes.BASIC, SSZ.encodeUInt64(slot)),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, previous_block_root),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, parent_root),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, state_root),
body.hash_tree_root())));
}
Expand All @@ -158,7 +158,7 @@ public Bytes32 hash_tree_root() {
return HashTreeUtil.merkleize(
Arrays.asList(
HashTreeUtil.hash_tree_root(SSZTypes.BASIC, SSZ.encodeUInt64(slot)),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, previous_block_root),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, parent_root),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, state_root),
body.hash_tree_root(),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, signature.toBytes())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class BeaconBlockBody {
private BLSSignature randao_reveal;
private Eth1Data eth1_data;
private Bytes32 graffiti;
private List<ProposerSlashing> proposer_slashings;
private List<AttesterSlashing> attester_slashings;
private List<Attestation> attestations;
Expand All @@ -44,6 +45,7 @@ public class BeaconBlockBody {
public BeaconBlockBody(
BLSSignature randao_reveal,
Eth1Data eth1_data,
Bytes32 graffiti,
List<ProposerSlashing> proposer_slashings,
List<AttesterSlashing> attester_slashings,
List<Attestation> attestations,
Expand All @@ -52,6 +54,7 @@ public BeaconBlockBody(
List<Transfer> transfers) {
this.randao_reveal = randao_reveal;
this.eth1_data = eth1_data;
this.graffiti = graffiti;
this.proposer_slashings = proposer_slashings;
this.attester_slashings = attester_slashings;
this.attestations = attestations;
Expand All @@ -67,6 +70,7 @@ public static BeaconBlockBody fromBytes(Bytes bytes) {
new BeaconBlockBody(
BLSSignature.fromBytes(reader.readBytes()),
Eth1Data.fromBytes(reader.readBytes()),
Bytes32.wrap(reader.readFixedBytes(32)),
reader.readBytesList().stream()
.map(ProposerSlashing::fromBytes)
.collect(Collectors.toList()),
Expand Down Expand Up @@ -105,6 +109,7 @@ public Bytes toBytes() {
writer -> {
writer.writeBytes(randao_reveal.toBytes());
writer.writeBytes(eth1_data.toBytes());
writer.writeFixedBytes(32, graffiti);
writer.writeBytesList(proposerSlashingsBytes);
writer.writeBytesList(attesterSlashingsBytes);
writer.writeBytesList(attestationsBytes);
Expand All @@ -119,6 +124,7 @@ public int hashCode() {
return Objects.hash(
randao_reveal,
eth1_data,
graffiti,
proposer_slashings,
attester_slashings,
attestations,
Expand All @@ -144,6 +150,7 @@ public boolean equals(Object obj) {
BeaconBlockBody other = (BeaconBlockBody) obj;
return Objects.equals(this.getRandao_reveal(), other.getRandao_reveal())
&& Objects.equals(this.getEth1_data(), other.getEth1_data())
&& Objects.equals(this.getGraffiti(), other.getGraffiti())
&& Objects.equals(this.getProposer_slashings(), other.getProposer_slashings())
&& Objects.equals(this.getAttester_slashings(), other.getAttester_slashings())
&& Objects.equals(this.getAttestations(), other.getAttestations())
Expand All @@ -169,6 +176,14 @@ public void setEth1_data(Eth1Data eth1_data) {
this.eth1_data = eth1_data;
}

public Bytes32 getGraffiti() {
return graffiti;
}

public void setGraffiti(Bytes32 graffiti) {
this.graffiti = graffiti;
}

public List<Attestation> getAttestations() {
return attestations;
}
Expand Down Expand Up @@ -222,6 +237,7 @@ public Bytes32 hash_tree_root() {
Arrays.asList(
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, randao_reveal.toBytes()),
eth1_data.hash_tree_root(),
HashTreeUtil.hash_tree_root(SSZTypes.TUPLE_OF_BASIC, graffiti),
HashTreeUtil.hash_tree_root(SSZTypes.LIST_OF_COMPOSITE, proposer_slashings),
HashTreeUtil.hash_tree_root(SSZTypes.LIST_OF_COMPOSITE, attester_slashings),
HashTreeUtil.hash_tree_root(SSZTypes.LIST_OF_COMPOSITE, attestations),
Expand Down
Loading