Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
shasper
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
shasper
Commits
171f6175
Unverified
Commit
171f6175
authored
5 years ago
by
Wei Tang
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add logic to push valid deposits to genesis block (#133)
parent
8c37c439
Branches
Branches containing commit
No related merge requests found
Pipeline
#37926
passed with stages
in 4 minutes and 20 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
beacon/src/config.rs
+4
-0
4 additions, 0 deletions
beacon/src/config.rs
blockchain/src/main.rs
+87
-4
87 additions, 4 deletions
blockchain/src/main.rs
with
91 additions
and
4 deletions
beacon/src/config.rs
+
4
−
0
View file @
171f6175
...
...
@@ -180,6 +180,10 @@ pub trait Config {
fn
verify_merkle_branch
(
&
self
,
leaf
:
H256
,
proof
:
&
[
H256
],
depth
:
u64
,
index
:
u64
,
root
:
H256
,
)
->
bool
{
if
proof
.len
()
as
u64
!=
depth
{
return
false
}
let
mut
value
=
leaf
;
for
i
in
0
..
depth
{
if
index
/
2u64
.pow
(
i
as
u32
)
%
2
!=
0
{
...
...
This diff is collapsed.
Click to expand it.
blockchain/src/main.rs
+
87
−
4
View file @
171f6175
use
beacon
::{
genesis
,
NoVerificationConfig
};
use
beacon
::
types
::
Eth1Data
;
use
beacon
::{
genesis
,
Config
,
NoVerificationConfig
};
use
beacon
::
primitives
::
H256
;
use
beacon
::
types
::{
Eth1Data
,
Deposit
,
DepositData
};
use
ssz
::
Digestible
;
use
blockchain
::
backend
::{
SharedBackend
,
MemoryBackend
,
MemoryLikeBackend
};
use
blockchain_network_simple
::
BestDepthStatusProducer
;
use
shasper_blockchain
::{
Block
,
Executor
,
State
};
use
lmd_ghost
::
archive
::{
NoCacheAncestorBackend
,
ArchiveGhostImporter
};
use
clap
::{
App
,
Arg
};
fn
deposit_tree
<
C
:
Config
>
(
deposits
:
&
[
DepositData
],
config
:
&
C
)
->
Vec
<
Vec
<
H256
>>
{
let
mut
zerohashes
=
vec!
[
H256
::
default
()];
for
layer
in
1
..
32
{
zerohashes
.push
(
config
.hash
(
&
[
zerohashes
[
layer
-
1
]
.as_ref
(),
zerohashes
[
layer
-
1
]
.as_ref
(),
]));
}
let
mut
values
=
deposits
.iter
()
.map
(|
d
|
{
H256
::
from_slice
(
Digestible
::
<
C
::
Digest
>
::
hash
(
d
)
.as_slice
()
)
})
.collect
::
<
Vec
<
_
>>
();
let
mut
tree
=
vec!
[
values
.clone
()];
for
h
in
0
..
(
config
.deposit_contract_tree_depth
()
as
usize
)
{
if
values
.len
()
%
2
==
1
{
values
.push
(
zerohashes
[
h
]);
}
let
mut
new_values
=
Vec
::
new
();
for
i
in
0
..
(
values
.len
()
/
2
)
{
new_values
.push
(
config
.hash
(
&
[
values
[
i
]
.as_ref
(),
values
[
i
+
1
]
.as_ref
()
]));
}
values
=
new_values
;
tree
.push
(
values
.clone
());
}
tree
}
fn
deposit_root
(
tree
:
&
Vec
<
Vec
<
H256
>>
)
->
H256
{
tree
.last
()
.expect
(
"Merkle tree cannot be empty; qed"
)[
0
]
}
fn
deposit_proof
<
C
:
Config
>
(
tree
:
&
Vec
<
Vec
<
H256
>>
,
item_index
:
usize
,
config
:
&
C
)
->
Vec
<
H256
>
{
let
mut
zerohashes
=
vec!
[
H256
::
default
()];
for
layer
in
1
..
32
{
zerohashes
.push
(
config
.hash
(
&
[
zerohashes
[
layer
-
1
]
.as_ref
(),
zerohashes
[
layer
-
1
]
.as_ref
(),
]));
}
let
mut
proof
=
Vec
::
new
();
for
i
in
0
..
(
config
.deposit_contract_tree_depth
()
as
usize
)
{
let
subindex
=
(
item_index
/
(
0b1
<<
i
))
^
1
;
if
subindex
<
tree
[
i
]
.len
()
{
proof
.push
(
tree
[
i
][
subindex
]);
}
else
{
proof
.push
(
zerohashes
[
i
]);
}
}
proof
}
fn
main
()
{
let
matches
=
App
::
new
(
"Shasper blockchain client"
)
.arg
(
Arg
::
with_name
(
"port"
)
...
...
@@ -15,9 +76,31 @@ fn main() {
.help
(
"Port to listen on"
))
.get_matches
();
let
config
=
NoVerificationConfig
::
full
();
let
config
=
NoVerificationConfig
::
small
();
let
deposit_datas
=
vec!
[
DepositData
{
pubkey
:
Default
::
default
(),
withdrawal_credentials
:
Default
::
default
(),
amount
:
100000000000000
,
signature
:
Default
::
default
(),
}];
let
deposit_tree
=
deposit_tree
(
&
deposit_datas
,
&
config
);
let
deposits
=
deposit_datas
.clone
()
.into_iter
()
.enumerate
()
.map
(|(
i
,
deposit_data
)|
{
Deposit
{
proof
:
deposit_proof
(
&
deposit_tree
,
i
,
&
config
),
index
:
i
as
u64
,
data
:
deposit_data
,
}
})
.collect
::
<
Vec
<
_
>>
();
let
deposit_root
=
deposit_root
(
&
deposit_tree
);
let
(
genesis_beacon_block
,
genesis_state
)
=
genesis
(
&
[],
0
,
Eth1Data
::
default
(),
&
config
&
deposits
,
0
,
Eth1Data
{
deposit_root
,
deposit_count
:
deposits
.len
()
as
u64
,
block_hash
:
Default
::
default
(),
},
&
config
)
.unwrap
();
let
genesis_block
=
Block
(
genesis_beacon_block
);
let
backend
=
SharedBackend
::
new
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment