Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ad5b5a48
Commit
ad5b5a48
authored
Jun 09, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pad precompiled EC recover input and add validations
parent
d8e55a5c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
8 deletions
+14
-8
contracts.go
core/vm/contracts.go
+14
-8
No files found.
core/vm/contracts.go
View file @
ad5b5a48
...
...
@@ -67,21 +67,27 @@ func ripemd160Func(in []byte) []byte {
const
ecRecoverInputLength
=
128
func
ecrecoverFunc
(
in
[]
byte
)
[]
byte
{
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
if
len
(
in
)
<
ecRecoverInputLength
{
return
nil
in
=
common
.
RightPadBytes
(
in
,
128
)
}
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
r
:=
common
.
BytesToBig
(
in
[
64
:
96
])
s
:=
common
.
BytesToBig
(
in
[
96
:
128
])
// Treat V as a 256bit integer
v
:=
new
(
big
.
Int
)
.
Sub
(
common
.
Bytes2Big
(
in
[
32
:
64
]),
big
.
NewInt
(
27
))
// Ethereum requires V to be either 0 or 1 => (27 || 28)
if
!
(
v
.
Cmp
(
Zero
)
==
0
||
v
.
Cmp
(
One
)
==
0
)
{
vbig
:=
common
.
Bytes2Big
(
in
[
32
:
64
])
v
:=
byte
(
vbig
.
Uint64
())
if
!
crypto
.
ValidateSignatureValues
(
v
,
r
,
s
)
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"EC RECOVER FAIL: v, r or s value invalid"
)
return
nil
}
// v needs to be moved to the end
rsv
:=
append
(
in
[
64
:
128
],
byte
(
v
.
Uint64
()))
// v needs to be at the end and normalized for libsecp256k1
vbignormal
:=
new
(
big
.
Int
)
.
Sub
(
vbig
,
big
.
NewInt
(
27
))
vnormal
:=
byte
(
vbignormal
.
Uint64
())
rsv
:=
append
(
in
[
64
:
128
],
vnormal
)
pubKey
,
err
:=
crypto
.
Ecrecover
(
in
[
:
32
],
rsv
)
// make sure the public key is a valid one
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment