mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +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
|
||||
// up to size with zero's. This function is overflow safe.
|
||||
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))
|
||||
if start > length {
|
||||
start = length
|
||||
|
|
@ -61,7 +65,7 @@ func getData(data []byte, start uint64, size uint64) []byte {
|
|||
if 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) {
|
||||
|
|
|
|||
|
|
@ -498,13 +498,19 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
|
|||
}
|
||||
|
||||
func (c *bigModExp) Run(input []byte) ([]byte, error) {
|
||||
|
||||
// Note: This can be done more efficiently
|
||||
var (
|
||||
baseLen = new(big.Int).SetBytes(getData(input, 0, 32)).Uint64()
|
||||
expLen = new(big.Int).SetBytes(getData(input, 32, 32)).Uint64()
|
||||
modLen = new(big.Int).SetBytes(getData(input, 64, 32)).Uint64()
|
||||
)
|
||||
// Extract lengths - they're 32-byte big-endian integers
|
||||
// with the actual uint64 value in the last 8 bytes
|
||||
var baseLen, expLen, modLen uint64
|
||||
if len(input) >= 32 {
|
||||
baseLen = binary.BigEndian.Uint64(input[24:32])
|
||||
}
|
||||
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 {
|
||||
input = input[96:]
|
||||
} else {
|
||||
|
|
@ -520,9 +526,9 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
|
|||
}
|
||||
// Retrieve the operands and execute the exponentiation
|
||||
var (
|
||||
base = getData(input, 0, baseLen)
|
||||
exp = getData(input, baseLen, expLen)
|
||||
mod = getData(input, baseLen+expLen, modLen)
|
||||
base = getDataNoPadding(input, 0, baseLen)
|
||||
exp = getDataNoPadding(input, baseLen, expLen)
|
||||
mod = getDataNoPadding(input, baseLen+expLen, modLen)
|
||||
)
|
||||
|
||||
// Use the modexp implementation
|
||||
|
|
|
|||
Loading…
Reference in a new issue