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
1496b3af
Commit
1496b3af
authored
Jun 06, 2017
by
Martin Holst Swende
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common/math, core/vm: Un-expose bigEndianByteAt, use correct terms for endianness
parent
3285a0fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
18 deletions
+19
-18
big.go
common/math/big.go
+11
-11
big_test.go
common/math/big_test.go
+6
-5
instructions.go
core/vm/instructions.go
+2
-2
No files found.
common/math/big.go
View file @
1496b3af
...
...
@@ -130,10 +130,10 @@ func PaddedBigBytes(bigint *big.Int, n int) []byte {
return
ret
}
//
Little
EndianByteAt returns the byte at position n,
// if bigint is considered
little
-endian.
// So n==0
give
s the least significant byte
func
Little
EndianByteAt
(
bigint
*
big
.
Int
,
n
int
)
byte
{
//
big
EndianByteAt returns the byte at position n,
// if bigint is considered
big
-endian.
// So n==0
return
s the least significant byte
func
big
EndianByteAt
(
bigint
*
big
.
Int
,
n
int
)
byte
{
words
:=
bigint
.
Bits
()
// Check word-bucket the byte will reside in
i
:=
n
/
wordBytes
...
...
@@ -147,15 +147,15 @@ func LittleEndianByteAt(bigint *big.Int, n int) byte {
return
byte
(
word
>>
shift
)
}
// B
igEndian32ByteAt
returns the byte at position n,
// if bigint is considered
big-endian
.
//
So n==0 give
s the most significant byte
//
WARNING: Only works for bigints in 32-byte range
func
B
igEndian32ByteAt
(
bigint
*
big
.
Int
,
n
int
)
byte
{
if
n
>
31
{
// B
yte
returns the byte at position n,
// if bigint is considered
little-endian with the supplied padlength
.
//
n==0 return
s the most significant byte
//
bigint '5', padlength 32, n=31 => 5
func
B
yte
(
bigint
*
big
.
Int
,
padlength
,
n
int
)
byte
{
if
n
>
=
padlength
{
return
byte
(
0
)
}
return
LittleEndianByteAt
(
bigint
,
3
1
-
n
)
return
bigEndianByteAt
(
bigint
,
padlength
-
1
-
n
)
}
// ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure
...
...
common/math/big_test.go
View file @
1496b3af
...
...
@@ -157,13 +157,13 @@ func BenchmarkPaddedBigBytesSmallOnePadding(b *testing.B) {
func
BenchmarkByteAtBrandNew
(
b
*
testing
.
B
)
{
bigint
:=
MustParseBig256
(
"0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC"
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
BigEndian32
ByteAt
(
bigint
,
15
)
bigEndian
ByteAt
(
bigint
,
15
)
}
}
func
BenchmarkByteAt
(
b
*
testing
.
B
)
{
bigint
:=
MustParseBig256
(
"0x18F8F8F1000111000110011100222004330052300000000000000000FEFCF3CC"
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
BigEndian32
ByteAt
(
bigint
,
15
)
bigEndian
ByteAt
(
bigint
,
15
)
}
}
func
BenchmarkByteAtOld
(
b
*
testing
.
B
)
{
...
...
@@ -225,7 +225,7 @@ func TestLittleEndianByteAt(t *testing.T) {
}
for
_
,
test
:=
range
tests
{
v
:=
new
(
big
.
Int
)
.
SetBytes
(
common
.
Hex2Bytes
(
test
.
x
))
actual
:=
Little
EndianByteAt
(
v
,
test
.
y
)
actual
:=
big
EndianByteAt
(
v
,
test
.
y
)
if
actual
!=
test
.
exp
{
t
.
Fatalf
(
"Expected [%v] %v:th byte to be %v, was %v."
,
test
.
x
,
test
.
y
,
test
.
exp
,
actual
)
}
...
...
@@ -254,11 +254,12 @@ func TestBigEndianByteAt(t *testing.T) {
{
"0000000000000000000000000000000000000000000000000000000000102030"
,
31
,
0x30
},
{
"0000000000000000000000000000000000000000000000000000000000102030"
,
30
,
0x20
},
{
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
32
,
0x0
},
{
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
0xFFFFFFFF
,
0x0
},
{
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
31
,
0xFF
},
{
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
0xFFFF
,
0x0
},
}
for
_
,
test
:=
range
tests
{
v
:=
new
(
big
.
Int
)
.
SetBytes
(
common
.
Hex2Bytes
(
test
.
x
))
actual
:=
B
igEndian32ByteAt
(
v
,
test
.
y
)
actual
:=
B
yte
(
v
,
32
,
test
.
y
)
if
actual
!=
test
.
exp
{
t
.
Fatalf
(
"Expected [%v] %v:th byte to be %v, was %v."
,
test
.
x
,
test
.
y
,
test
.
exp
,
actual
)
}
...
...
core/vm/instructions.go
View file @
1496b3af
...
...
@@ -258,8 +258,8 @@ func opXor(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stac
func
opByte
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
th
,
val
:=
stack
.
pop
(),
stack
.
peek
()
if
th
.
Cmp
(
common
.
Big32
)
<
0
{
b
:=
math
.
B
igEndian32ByteAt
(
val
,
int
(
th
.
Int64
()))
val
.
Set
Int64
(
int64
(
b
))
b
:=
math
.
B
yte
(
val
,
32
,
int
(
th
.
Int64
()))
val
.
Set
Uint64
(
u
int64
(
b
))
}
else
{
val
.
SetUint64
(
0
)
}
...
...
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