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
1335a6cc
Unverified
Commit
1335a6cc
authored
Aug 17, 2017
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/vm, crypto/bn256: fix bn256 use and pairing corner case
parent
0b978f91
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
16 deletions
+81
-16
contracts.go
core/vm/contracts.go
+7
-6
contracts_test.go
core/vm/contracts_test.go
+62
-3
bn256.go
crypto/bn256/bn256.go
+12
-6
optate.go
crypto/bn256/optate.go
+0
-1
No files found.
core/vm/contracts.go
View file @
1335a6cc
...
...
@@ -307,8 +307,9 @@ func (c *bn256Add) Run(input []byte) ([]byte, error) {
if
err
!=
nil
{
return
nil
,
err
}
x
.
Add
(
x
,
y
)
return
x
.
Marshal
(),
nil
res
:=
new
(
bn256
.
G1
)
res
.
Add
(
x
,
y
)
return
res
.
Marshal
(),
nil
}
// bn256ScalarMul implements a native elliptic curve scalar multiplication.
...
...
@@ -324,8 +325,9 @@ func (c *bn256ScalarMul) Run(input []byte) ([]byte, error) {
if
err
!=
nil
{
return
nil
,
err
}
p
.
ScalarMult
(
p
,
new
(
big
.
Int
)
.
SetBytes
(
getData
(
input
,
64
,
32
)))
return
p
.
Marshal
(),
nil
res
:=
new
(
bn256
.
G1
)
res
.
ScalarMult
(
p
,
new
(
big
.
Int
)
.
SetBytes
(
getData
(
input
,
64
,
32
)))
return
res
.
Marshal
(),
nil
}
var
(
...
...
@@ -370,8 +372,7 @@ func (c *bn256Pairing) Run(input []byte) ([]byte, error) {
ts
=
append
(
ts
,
t
)
}
// Execute the pairing checks and return the results
ok
:=
bn256
.
PairingCheck
(
cs
,
ts
)
if
ok
{
if
bn256
.
PairingCheck
(
cs
,
ts
)
{
return
true32Byte
,
nil
}
return
false32Byte
,
nil
...
...
core/vm/contracts_test.go
View file @
1335a6cc
This diff is collapsed.
Click to expand it.
crypto/bn256/bn256.go
View file @
1335a6cc
...
...
@@ -379,16 +379,22 @@ func Pair(g1 *G1, g2 *G2) *GT {
return
&
GT
{
optimalAte
(
g2
.
p
,
g1
.
p
,
new
(
bnPool
))}
}
// PairingCheck calculates the Optimal Ate pairing for a set of points.
func
PairingCheck
(
a
[]
*
G1
,
b
[]
*
G2
)
bool
{
pool
:=
new
(
bnPool
)
e
:=
newGFp12
(
pool
)
e
.
SetOne
()
acc
:=
newGFp12
(
pool
)
acc
.
SetOne
()
for
i
:=
0
;
i
<
len
(
a
);
i
++
{
new_e
:=
miller
(
b
[
i
]
.
p
,
a
[
i
]
.
p
,
pool
)
e
.
Mul
(
e
,
new_e
,
pool
)
if
a
[
i
]
.
p
.
IsInfinity
()
||
b
[
i
]
.
p
.
IsInfinity
()
{
continue
}
acc
.
Mul
(
acc
,
miller
(
b
[
i
]
.
p
,
a
[
i
]
.
p
,
pool
),
pool
)
}
ret
:=
finalExponentiation
(
e
,
pool
)
e
.
Put
(
pool
)
ret
:=
finalExponentiation
(
acc
,
pool
)
acc
.
Put
(
pool
)
return
ret
.
IsOne
()
}
...
...
crypto/bn256/optate.go
View file @
1335a6cc
...
...
@@ -393,6 +393,5 @@ func optimalAte(a *twistPoint, b *curvePoint, pool *bnPool) *gfP12 {
if
a
.
IsInfinity
()
||
b
.
IsInfinity
()
{
ret
.
SetOne
()
}
return
ret
}
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