mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
micro-opt
This commit is contained in:
parent
92adee104b
commit
00d800d221
2 changed files with 21 additions and 11 deletions
|
|
@ -53,6 +53,10 @@ func calcMemSize64WithUint(off *uint256.Int, length64 uint64) (uint64, bool) {
|
||||||
// getData returns a slice from the data based on the start and size and pads
|
// getData returns a slice from the data based on the start and size and pads
|
||||||
// up to size with zero's. This function is overflow safe.
|
// up to size with zero's. This function is overflow safe.
|
||||||
func getData(data []byte, start uint64, size uint64) []byte {
|
func getData(data []byte, start uint64, size uint64) []byte {
|
||||||
|
unpaddedData := getDataNoPadding(data, start, size)
|
||||||
|
return common.RightPadBytes(unpaddedData, int(size))
|
||||||
|
}
|
||||||
|
func getDataNoPadding(data []byte, start uint64, size uint64) []byte {
|
||||||
length := uint64(len(data))
|
length := uint64(len(data))
|
||||||
if start > length {
|
if start > length {
|
||||||
start = length
|
start = length
|
||||||
|
|
@ -61,7 +65,7 @@ func getData(data []byte, start uint64, size uint64) []byte {
|
||||||
if end > length {
|
if end > length {
|
||||||
end = length
|
end = length
|
||||||
}
|
}
|
||||||
return common.RightPadBytes(data[start:end], int(size))
|
return data[start:end]
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDataAndAdjustedBounds(data []byte, start uint64, size uint64) (codeCopyPadded []byte, actualStart uint64, sizeNonPadded uint64) {
|
func getDataAndAdjustedBounds(data []byte, start uint64, size uint64) (codeCopyPadded []byte, actualStart uint64, sizeNonPadded uint64) {
|
||||||
|
|
|
||||||
|
|
@ -498,13 +498,19 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *bigModExp) Run(input []byte) ([]byte, error) {
|
func (c *bigModExp) Run(input []byte) ([]byte, error) {
|
||||||
|
// Extract lengths - they're 32-byte big-endian integers
|
||||||
// Note: This can be done more efficiently
|
// with the actual uint64 value in the last 8 bytes
|
||||||
var (
|
var baseLen, expLen, modLen uint64
|
||||||
baseLen = new(big.Int).SetBytes(getData(input, 0, 32)).Uint64()
|
if len(input) >= 32 {
|
||||||
expLen = new(big.Int).SetBytes(getData(input, 32, 32)).Uint64()
|
baseLen = binary.BigEndian.Uint64(input[24:32])
|
||||||
modLen = new(big.Int).SetBytes(getData(input, 64, 32)).Uint64()
|
}
|
||||||
)
|
if len(input) >= 64 {
|
||||||
|
expLen = binary.BigEndian.Uint64(input[56:64])
|
||||||
|
}
|
||||||
|
if len(input) >= 96 {
|
||||||
|
modLen = binary.BigEndian.Uint64(input[88:96])
|
||||||
|
}
|
||||||
|
// TODO: We could combine this if second if statement with the one above
|
||||||
if len(input) > 96 {
|
if len(input) > 96 {
|
||||||
input = input[96:]
|
input = input[96:]
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -520,9 +526,9 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
// Retrieve the operands and execute the exponentiation
|
// Retrieve the operands and execute the exponentiation
|
||||||
var (
|
var (
|
||||||
base = getData(input, 0, baseLen)
|
base = getDataNoPadding(input, 0, baseLen)
|
||||||
exp = getData(input, baseLen, expLen)
|
exp = getDataNoPadding(input, baseLen, expLen)
|
||||||
mod = getData(input, baseLen+expLen, modLen)
|
mod = getDataNoPadding(input, baseLen+expLen, modLen)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Use the modexp implementation
|
// Use the modexp implementation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue