Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dunixir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
teaching
dunixir
Commits
eae9bbbb
Commit
eae9bbbb
authored
4 years ago
by
x18zhan2
Browse files
Options
Downloads
Patches
Plain Diff
index on dev:
f6440af4
Delete README.md
parent
f6440af4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/block/validation/local/block_signature.ex
+85
-0
85 additions, 0 deletions
lib/block/validation/local/block_signature.ex
with
85 additions
and
0 deletions
lib/block/validation/local/block_signature.ex
0 → 100644
+
85
−
0
View file @
eae9bbbb
defmodule
Block
.
Validation
.
Local
.
BlockSignature
do
require
Logger
def
invalid_g1_block
()
do
[
15144
,
31202
,
85448
,
87566
,
90830
,
109_327
,
189_835
,
199_172
,
221_274
,
253_582
]
end
def
invalid_gt_blocks
()
do
[
24316
,
62067
,
62551
,
93288
,
173_118
,
183_706
,
196_196
,
246_027
,
247_211
,
263_207
,
307_038
,
328_741
,
335_914
,
377_316
,
395_714
,
396_024
,
407_913
,
422_366
,
496_751
]
end
@doc
"""
check if block signature is valid
"""
def
valid
(
block
)
do
# Historically, Duniter used a buggy version of TweetNaCl (see duniter #1390)
# Starting with the v12 blocks, Duniter uses a fixed version of TweetNaCl.
signed_part
=
get_signed_part
(
block
[
"inner_hash"
],
to_string
(
block
[
"nonce"
]))
cond
do
Crypto
.
verify_digital_signature
(
block
[
"signature"
],
signed_part
,
block
[
"issuer"
])
->
true
(
block
[
"version"
]
<
12
and
block
[
"currency"
]
===
"G1"
and
Enum
.
member?
(
invalid_g1_block
(),
block
[
"number"
]))
or
(
block
[
"version"
]
<
12
and
block
[
"currency"
]
===
"GT"
and
Enum
.
member?
(
invalid_gt_blocks
(),
block
[
"number"
]))
->
true
true
->
Logger
.
error
(
"Block's signature must match"
)
false
end
# if Crypto.verify_digital_signature(block["signature"], signed_part, block["issuer"]) do
# true
# else
# # If DUBP < v12, block may have invalid signature
# if (block["version"] < 12 and block["currency"] === "G1" and
# Enum.member?(invalid_g1_block(), block["number"])) or
# (block["version"] < 12 and block["currency"] === "GT" and
# Enum.member?(invalid_gt_blocks(), block["number"])) do
# true
# else
# Logger.error("Block's signature must match")
# false
# end
# end
end
defp
get_signed_part
(
inner_hash
,
nonce
)
do
"InnerHash: "
<>
inner_hash
<>
"
\n
"
<>
"Nonce: "
<>
nonce
<>
"
\n
"
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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