mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Return error for disabled precompile calls (#337)
return error for disabled precompile calls
This commit is contained in:
parent
fb570dc8c7
commit
334892ae07
2 changed files with 36 additions and 2 deletions
|
|
@ -34,6 +34,10 @@ import (
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errPrecompileDisabled = errors.New("sha256, ripemd160, blake2f precompiles temporarily disabled")
|
||||||
|
)
|
||||||
|
|
||||||
// PrecompiledContract is the basic interface for native Go contracts. The implementation
|
// PrecompiledContract is the basic interface for native Go contracts. The implementation
|
||||||
// requires a deterministic gas count based on the input size of the Run method of the
|
// requires a deterministic gas count based on the input size of the Run method of the
|
||||||
// contract.
|
// contract.
|
||||||
|
|
@ -96,11 +100,14 @@ var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{
|
||||||
// contracts used in the Archimedes release. Same as Berlin but without sha2, blake2f, ripemd160
|
// contracts used in the Archimedes release. Same as Berlin but without sha2, blake2f, ripemd160
|
||||||
var PrecompiledContractsArchimedes = map[common.Address]PrecompiledContract{
|
var PrecompiledContractsArchimedes = map[common.Address]PrecompiledContract{
|
||||||
common.BytesToAddress([]byte{1}): &ecrecover{},
|
common.BytesToAddress([]byte{1}): &ecrecover{},
|
||||||
|
common.BytesToAddress([]byte{2}): &sha256hashDisabled{},
|
||||||
|
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
|
||||||
common.BytesToAddress([]byte{4}): &dataCopy{},
|
common.BytesToAddress([]byte{4}): &dataCopy{},
|
||||||
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
|
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
|
||||||
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
|
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
|
||||||
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
|
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
|
||||||
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
|
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
|
||||||
|
common.BytesToAddress([]byte{9}): &blake2FDisabled{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
|
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
|
||||||
|
|
@ -227,6 +234,15 @@ func (c *sha256hash) Run(input []byte) ([]byte, error) {
|
||||||
return h[:], nil
|
return h[:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type sha256hashDisabled struct{}
|
||||||
|
|
||||||
|
func (c *sha256hashDisabled) RequiredGas(input []byte) uint64 {
|
||||||
|
return (&sha256hash{}).RequiredGas(input)
|
||||||
|
}
|
||||||
|
func (c *sha256hashDisabled) Run(input []byte) ([]byte, error) {
|
||||||
|
return nil, errPrecompileDisabled
|
||||||
|
}
|
||||||
|
|
||||||
// RIPEMD160 implemented as a native contract.
|
// RIPEMD160 implemented as a native contract.
|
||||||
type ripemd160hash struct{}
|
type ripemd160hash struct{}
|
||||||
|
|
||||||
|
|
@ -243,6 +259,15 @@ func (c *ripemd160hash) Run(input []byte) ([]byte, error) {
|
||||||
return common.LeftPadBytes(ripemd.Sum(nil), 32), nil
|
return common.LeftPadBytes(ripemd.Sum(nil), 32), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ripemd160hashDisabled struct{}
|
||||||
|
|
||||||
|
func (c *ripemd160hashDisabled) RequiredGas(input []byte) uint64 {
|
||||||
|
return (&ripemd160hash{}).RequiredGas(input)
|
||||||
|
}
|
||||||
|
func (c *ripemd160hashDisabled) Run(input []byte) ([]byte, error) {
|
||||||
|
return nil, errPrecompileDisabled
|
||||||
|
}
|
||||||
|
|
||||||
// data copy implemented as a native contract.
|
// data copy implemented as a native contract.
|
||||||
type dataCopy struct{}
|
type dataCopy struct{}
|
||||||
|
|
||||||
|
|
@ -636,6 +661,15 @@ func (c *blake2F) Run(input []byte) ([]byte, error) {
|
||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type blake2FDisabled struct{}
|
||||||
|
|
||||||
|
func (c *blake2FDisabled) RequiredGas(input []byte) uint64 {
|
||||||
|
return (&blake2F{}).RequiredGas(input)
|
||||||
|
}
|
||||||
|
func (c *blake2FDisabled) Run(input []byte) ([]byte, error) {
|
||||||
|
return nil, errPrecompileDisabled
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errBLS12381InvalidInputLength = errors.New("invalid input length")
|
errBLS12381InvalidInputLength = errors.New("invalid input length")
|
||||||
errBLS12381InvalidFieldElementTopBytes = errors.New("invalid field element top bytes")
|
errBLS12381InvalidFieldElementTopBytes = errors.New("invalid field element top bytes")
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionMajor = 3 // Major version component of the current release
|
VersionMajor = 3 // Major version component of the current release
|
||||||
VersionMinor = 2 // Minor version component of the current release
|
VersionMinor = 3 // Minor version component of the current release
|
||||||
VersionPatch = 4 // Patch version component of the current release
|
VersionPatch = 0 // Patch version component of the current release
|
||||||
VersionMeta = "alpha" // Version metadata to append to the version string
|
VersionMeta = "alpha" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue