diff --git a/AllTests-mainnet.md b/AllTests-mainnet.md index 98d5abaa4..7be6a5536 100644 --- a/AllTests-mainnet.md +++ b/AllTests-mainnet.md @@ -237,7 +237,7 @@ OK: 5/5 Fail: 0/5 Skip: 0/5 OK: 8/8 Fail: 0/8 Skip: 0/8 ## chain DAG finalization tests [Preset: mainnet] ```diff -+ prune heads on finalization [Preset: mainnet] OK ++ init with gaps [Preset: mainnet] OK ``` OK: 1/1 Fail: 0/1 Skip: 0/1 ## hash diff --git a/beacon_chain.nimble b/beacon_chain.nimble index 7415856b4..c1c93fd9a 100644 --- a/beacon_chain.nimble +++ b/beacon_chain.nimble @@ -72,7 +72,6 @@ task test, "Run all tests": # Consensus object SSZ tests buildAndRunBinary "test_fixture_ssz_consensus_objects", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=mainnet" - # 0.12.1 buildAndRunBinary "all_fixtures_require_ssz", "tests/official/", "-d:chronicles_log_level=TRACE -d:const_preset=mainnet" # State and block sims; getting to 4th epoch triggers consensus checks diff --git a/beacon_chain/merkle_minimal.nim b/beacon_chain/merkle_minimal.nim index 819010ca7..d3b92ed0a 100644 --- a/beacon_chain/merkle_minimal.nim +++ b/beacon_chain/merkle_minimal.nim @@ -18,21 +18,15 @@ import ../../beacon_chain/spec/[beaconstate, datatypes, digest, helpers], ../../beacon_chain/ssz/merkleization -# TODO -# -# This module currently represents a direct translation of the Python -# code, appearing in the spec. We need to review it to ensure that it -# doesn't duplicate any code defined in ssz.nim already. -# -# All tests need to be moved to the test suite. +# TODO All tests need to be moved to the test suite. -func round_step_down*(x: Natural, step: static Natural): int {.inline.} = +func round_step_down(x: Natural, step: static Natural): int {.inline.} = ## Round the input to the previous multiple of "step" when (step and (step - 1)) == 0: # Step is a power of 2. (If compiler cannot prove that x>0 it does not make the optim) - result = x and not(step - 1) + x and not(step - 1) else: - result = x - x mod step + x - x mod step type SparseMerkleTree*[Depth: static int] = object ## Sparse Merkle tree @@ -41,7 +35,7 @@ type SparseMerkleTree*[Depth: static int] = object # and the root hash at the last depth nnznodes: array[Depth+1, seq[Eth2Digest]] # nodes that leads to non-zero leaves -proc merkleTreeFromLeaves*( +func merkleTreeFromLeaves( values: openarray[Eth2Digest], Depth: static[int] = DEPOSIT_CONTRACT_TREE_DEPTH ): SparseMerkleTree[Depth] = @@ -68,21 +62,28 @@ proc merkleTreeFromLeaves*( h.update zeroHashes[depth-1] result.nnznodes[depth].add nodeHash -proc getMerkleProof*[Depth: static int](tree: SparseMerkleTree[Depth], - index: int): array[Depth, Eth2Digest] = - +func getMerkleProof[Depth: static int](tree: SparseMerkleTree[Depth], + index: int, + depositMode = false): array[Depth, Eth2Digest] = # Descend down the tree according to the bit representation # of the index: # - 0 --> go left # - 1 --> go right let path = uint32(index) + var depthLen = index + 1 for depth in 0 ..< Depth: let nodeIdx = int((path shr depth) xor 1) - if nodeIdx < tree.nnznodes[depth].len: + + # depositMode simulates only having constructed SparseMerkleTree[Depth] + # through exactly deposit specified. + if nodeIdx < tree.nnznodes[depth].len and + (nodeIdx < depthLen or not depositMode): result[depth] = tree.nnznodes[depth][nodeIdx] else: result[depth] = zeroHashes[depth] + depthLen = (depthLen + 1) div 2 + func attachMerkleProofs*(deposits: var openarray[Deposit]) = let deposit_data_roots = mapIt(deposits, it.data.hash_tree_root) var @@ -91,9 +92,9 @@ func attachMerkleProofs*(deposits: var openarray[Deposit]) = deposit_data_roots, 1'i64 shl DEPOSIT_CONTRACT_TREE_DEPTH): deposit_data_sums.add prefix_root + let merkle_tree = merkleTreeFromLeaves(deposit_data_roots) for val_idx in 0 ..< deposits.len: - let merkle_tree = merkleTreeFromLeaves(deposit_data_roots[0..val_idx]) - deposits[val_idx].proof[0..31] = merkle_tree.getMerkleProof(val_idx) + deposits[val_idx].proof[0..31] = merkle_tree.getMerkleProof(val_idx, true) deposits[val_idx].proof[32].data[0..7] = uint_to_bytes8((val_idx + 1).uint64) doAssert is_valid_merkle_branch( diff --git a/research/block_sim.nim b/research/block_sim.nim index 767bab70c..3f8a5c962 100644 --- a/research/block_sim.nim +++ b/research/block_sim.nim @@ -40,7 +40,7 @@ type Timers = enum # TODO confutils is an impenetrable black box. how can a help text be added here? cli do(slots = SLOTS_PER_EPOCH * 6, - validators = SLOTS_PER_EPOCH * 130, # One per shard is minimum + validators = SLOTS_PER_EPOCH * 200, # One per shard is minimum attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.73, blockRatio {.desc: "ratio of slots with blocks"} = 1.0, replay = true): diff --git a/research/state_sim.nim b/research/state_sim.nim index ee0c4caeb..7ef8a0a9d 100644 --- a/research/state_sim.nim +++ b/research/state_sim.nim @@ -34,7 +34,7 @@ proc writeJson*(fn, v: auto) = Json.saveFile(fn, v, pretty = true) cli do(slots = SLOTS_PER_EPOCH * 6, - validators = SLOTS_PER_EPOCH * 100, # One per shard is minimum + validators = SLOTS_PER_EPOCH * 200, # One per shard is minimum json_interval = SLOTS_PER_EPOCH, write_last_json = false, prefix: int = 0,