mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
add trigger for disable XDCx precompiles (#509)
This commit is contained in:
parent
ef4b8ef91b
commit
fb91c1e802
4 changed files with 37 additions and 7 deletions
|
|
@ -87,6 +87,18 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{
|
||||||
common.BytesToAddress([]byte{42}): &XDCxEpochPrice{},
|
common.BytesToAddress([]byte{42}): &XDCxEpochPrice{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var PrecompiledContractsXDCv2 = map[common.Address]PrecompiledContract{
|
||||||
|
common.BytesToAddress([]byte{1}): &ecrecover{},
|
||||||
|
common.BytesToAddress([]byte{2}): &sha256hash{},
|
||||||
|
common.BytesToAddress([]byte{3}): &ripemd160hash{},
|
||||||
|
common.BytesToAddress([]byte{4}): &dataCopy{},
|
||||||
|
common.BytesToAddress([]byte{5}): &bigModExp{},
|
||||||
|
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
|
||||||
|
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
|
||||||
|
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
|
||||||
|
common.BytesToAddress([]byte{9}): &blake2F{},
|
||||||
|
}
|
||||||
|
|
||||||
// RunPrecompiledContract runs and evaluates the output of a precompiled contract.
|
// RunPrecompiledContract runs and evaluates the output of a precompiled contract.
|
||||||
func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contract) (ret []byte, err error) {
|
func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contract) (ret []byte, err error) {
|
||||||
gas := p.RequiredGas(input)
|
gas := p.RequiredGas(input)
|
||||||
|
|
|
||||||
|
|
@ -357,9 +357,15 @@ var bn256PairingTests = []precompiledTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
var XDCxLastPriceTests = []precompiledTest{
|
var XDCxLastPriceTests = []precompiledTest{
|
||||||
|
// {
|
||||||
|
// input: common.Bytes2Hex(append(common.Hex2BytesFixed(BTCAddress, 32), common.Hex2BytesFixed(USDTAddress, 32)...)),
|
||||||
|
// expected: common.Bytes2Hex(common.LeftPadBytes(BTCUSDTLastPrice.Bytes(), XDCXPriceNumberOfBytesReturn)),
|
||||||
|
// name: "BTCUSDT",
|
||||||
|
// },
|
||||||
|
// since we diable XDCx precompiles, the test now returns 0
|
||||||
{
|
{
|
||||||
input: common.Bytes2Hex(append(common.Hex2BytesFixed(BTCAddress, 32), common.Hex2BytesFixed(USDTAddress, 32)...)),
|
input: common.Bytes2Hex(append(common.Hex2BytesFixed(BTCAddress, 32), common.Hex2BytesFixed(USDTAddress, 32)...)),
|
||||||
expected: common.Bytes2Hex(common.LeftPadBytes(BTCUSDTLastPrice.Bytes(), XDCXPriceNumberOfBytesReturn)),
|
expected: common.Bytes2Hex(common.LeftPadBytes(common.Big0.Bytes(), XDCXPriceNumberOfBytesReturn)),
|
||||||
name: "BTCUSDT",
|
name: "BTCUSDT",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -375,9 +381,15 @@ var XDCxLastPriceTests = []precompiledTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
var XDCxEpochPriceTests = []precompiledTest{
|
var XDCxEpochPriceTests = []precompiledTest{
|
||||||
|
// {
|
||||||
|
// input: common.Bytes2Hex(append(common.Hex2BytesFixed(BTCAddress, 32), common.Hex2BytesFixed(USDTAddress, 32)...)),
|
||||||
|
// expected: common.Bytes2Hex(common.LeftPadBytes(BTCUSDTEpochPrice.Bytes(), XDCXPriceNumberOfBytesReturn)),
|
||||||
|
// name: "BTCUSDT",
|
||||||
|
// },
|
||||||
|
// since we diable XDCx precompiles, the test now returns 0
|
||||||
{
|
{
|
||||||
input: common.Bytes2Hex(append(common.Hex2BytesFixed(BTCAddress, 32), common.Hex2BytesFixed(USDTAddress, 32)...)),
|
input: common.Bytes2Hex(append(common.Hex2BytesFixed(BTCAddress, 32), common.Hex2BytesFixed(USDTAddress, 32)...)),
|
||||||
expected: common.Bytes2Hex(common.LeftPadBytes(BTCUSDTEpochPrice.Bytes(), XDCXPriceNumberOfBytesReturn)),
|
expected: common.Bytes2Hex(common.LeftPadBytes(common.Big0.Bytes(), XDCXPriceNumberOfBytesReturn)),
|
||||||
name: "BTCUSDT",
|
name: "BTCUSDT",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
|
||||||
if contract.CodeAddr != nil {
|
if contract.CodeAddr != nil {
|
||||||
var precompiles map[common.Address]PrecompiledContract
|
var precompiles map[common.Address]PrecompiledContract
|
||||||
switch {
|
switch {
|
||||||
|
case evm.chainRules.IsXDCxDisable:
|
||||||
|
precompiles = PrecompiledContractsXDCv2
|
||||||
case evm.chainRules.IsIstanbul:
|
case evm.chainRules.IsIstanbul:
|
||||||
precompiles = PrecompiledContractsIstanbul
|
precompiles = PrecompiledContractsIstanbul
|
||||||
case evm.chainRules.IsByzantium:
|
case evm.chainRules.IsByzantium:
|
||||||
|
|
@ -56,11 +58,13 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
|
||||||
precompiles = PrecompiledContractsHomestead
|
precompiles = PrecompiledContractsHomestead
|
||||||
}
|
}
|
||||||
if p := precompiles[*contract.CodeAddr]; p != nil {
|
if p := precompiles[*contract.CodeAddr]; p != nil {
|
||||||
switch p.(type) {
|
if evm.chainConfig.IsTIPXDCXReceiver(evm.BlockNumber) {
|
||||||
case *XDCxEpochPrice:
|
switch p := p.(type) {
|
||||||
p.(*XDCxEpochPrice).SetTradingState(evm.tradingStateDB)
|
case *XDCxEpochPrice:
|
||||||
case *XDCxLastPrice:
|
p.SetTradingState(evm.tradingStateDB)
|
||||||
p.(*XDCxLastPrice).SetTradingState(evm.tradingStateDB)
|
case *XDCxLastPrice:
|
||||||
|
p.SetTradingState(evm.tradingStateDB)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return RunPrecompiledContract(p, input, contract)
|
return RunPrecompiledContract(p, input, contract)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -753,6 +753,7 @@ type Rules struct {
|
||||||
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
|
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
|
||||||
IsBerlin, IsLondon bool
|
IsBerlin, IsLondon bool
|
||||||
IsMerge, IsShanghai bool
|
IsMerge, IsShanghai bool
|
||||||
|
IsXDCxDisable bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChainConfig) Rules(num *big.Int) Rules {
|
func (c *ChainConfig) Rules(num *big.Int) Rules {
|
||||||
|
|
@ -774,5 +775,6 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
|
||||||
IsLondon: c.IsLondon(num),
|
IsLondon: c.IsLondon(num),
|
||||||
IsMerge: c.IsMerge(num),
|
IsMerge: c.IsMerge(num),
|
||||||
IsShanghai: c.IsShanghai(num),
|
IsShanghai: c.IsShanghai(num),
|
||||||
|
IsXDCxDisable: c.IsTIPXDCXReceiver(num),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue