Skip to content

Commit 334892a

Browse files
authored
Return error for disabled precompile calls (#337)
return error for disabled precompile calls
1 parent fb570dc commit 334892a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

core/vm/contracts.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import (
3434
"golang.org/x/crypto/ripemd160"
3535
)
3636

37+
var (
38+
errPrecompileDisabled = errors.New("sha256, ripemd160, blake2f precompiles temporarily disabled")
39+
)
40+
3741
// PrecompiledContract is the basic interface for native Go contracts. The implementation
3842
// requires a deterministic gas count based on the input size of the Run method of the
3943
// contract.
@@ -96,11 +100,14 @@ var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{
96100
// contracts used in the Archimedes release. Same as Berlin but without sha2, blake2f, ripemd160
97101
var PrecompiledContractsArchimedes = map[common.Address]PrecompiledContract{
98102
common.BytesToAddress([]byte{1}): &ecrecover{},
103+
common.BytesToAddress([]byte{2}): &sha256hashDisabled{},
104+
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
99105
common.BytesToAddress([]byte{4}): &dataCopy{},
100106
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
101107
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
102108
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
103109
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
110+
common.BytesToAddress([]byte{9}): &blake2FDisabled{},
104111
}
105112

106113
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
@@ -227,6 +234,15 @@ func (c *sha256hash) Run(input []byte) ([]byte, error) {
227234
return h[:], nil
228235
}
229236

237+
type sha256hashDisabled struct{}
238+
239+
func (c *sha256hashDisabled) RequiredGas(input []byte) uint64 {
240+
return (&sha256hash{}).RequiredGas(input)
241+
}
242+
func (c *sha256hashDisabled) Run(input []byte) ([]byte, error) {
243+
return nil, errPrecompileDisabled
244+
}
245+
230246
// RIPEMD160 implemented as a native contract.
231247
type ripemd160hash struct{}
232248

@@ -243,6 +259,15 @@ func (c *ripemd160hash) Run(input []byte) ([]byte, error) {
243259
return common.LeftPadBytes(ripemd.Sum(nil), 32), nil
244260
}
245261

262+
type ripemd160hashDisabled struct{}
263+
264+
func (c *ripemd160hashDisabled) RequiredGas(input []byte) uint64 {
265+
return (&ripemd160hash{}).RequiredGas(input)
266+
}
267+
func (c *ripemd160hashDisabled) Run(input []byte) ([]byte, error) {
268+
return nil, errPrecompileDisabled
269+
}
270+
246271
// data copy implemented as a native contract.
247272
type dataCopy struct{}
248273

@@ -636,6 +661,15 @@ func (c *blake2F) Run(input []byte) ([]byte, error) {
636661
return output, nil
637662
}
638663

664+
type blake2FDisabled struct{}
665+
666+
func (c *blake2FDisabled) RequiredGas(input []byte) uint64 {
667+
return (&blake2F{}).RequiredGas(input)
668+
}
669+
func (c *blake2FDisabled) Run(input []byte) ([]byte, error) {
670+
return nil, errPrecompileDisabled
671+
}
672+
639673
var (
640674
errBLS12381InvalidInputLength = errors.New("invalid input length")
641675
errBLS12381InvalidFieldElementTopBytes = errors.New("invalid field element top bytes")

params/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323

2424
const (
2525
VersionMajor = 3 // Major version component of the current release
26-
VersionMinor = 2 // Minor version component of the current release
27-
VersionPatch = 4 // Patch version component of the current release
26+
VersionMinor = 3 // Minor version component of the current release
27+
VersionPatch = 0 // Patch version component of the current release
2828
VersionMeta = "alpha" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)