|
|
|
@ -49,83 +49,86 @@ type PrecompiledContract interface { |
|
|
|
|
// PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
|
|
|
|
|
// contracts used in the Frontier and Homestead releases.
|
|
|
|
|
var PrecompiledContractsHomestead = 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{0x1}): &ecrecover{}, |
|
|
|
|
common.BytesToAddress([]byte{0x2}): &sha256hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x4}): &dataCopy{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
|
|
|
|
|
// contracts used in the Byzantium release.
|
|
|
|
|
var PrecompiledContractsByzantium = 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{eip2565: false}, |
|
|
|
|
common.BytesToAddress([]byte{6}): &bn256AddByzantium{}, |
|
|
|
|
common.BytesToAddress([]byte{7}): &bn256ScalarMulByzantium{}, |
|
|
|
|
common.BytesToAddress([]byte{8}): &bn256PairingByzantium{}, |
|
|
|
|
common.BytesToAddress([]byte{0x1}): &ecrecover{}, |
|
|
|
|
common.BytesToAddress([]byte{0x2}): &sha256hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x4}): &dataCopy{}, |
|
|
|
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false}, |
|
|
|
|
common.BytesToAddress([]byte{0x6}): &bn256AddByzantium{}, |
|
|
|
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulByzantium{}, |
|
|
|
|
common.BytesToAddress([]byte{0x8}): &bn256PairingByzantium{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum
|
|
|
|
|
// contracts used in the Istanbul release.
|
|
|
|
|
var PrecompiledContractsIstanbul = 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{eip2565: false}, |
|
|
|
|
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{9}): &blake2F{}, |
|
|
|
|
common.BytesToAddress([]byte{0x1}): &ecrecover{}, |
|
|
|
|
common.BytesToAddress([]byte{0x2}): &sha256hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x4}): &dataCopy{}, |
|
|
|
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: false}, |
|
|
|
|
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x9}): &blake2F{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
|
|
|
|
|
// contracts used in the Berlin release.
|
|
|
|
|
var PrecompiledContractsBerlin = 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{eip2565: true}, |
|
|
|
|
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{9}): &blake2F{}, |
|
|
|
|
common.BytesToAddress([]byte{0x1}): &ecrecover{}, |
|
|
|
|
common.BytesToAddress([]byte{0x2}): &sha256hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x4}): &dataCopy{}, |
|
|
|
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true}, |
|
|
|
|
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x9}): &blake2F{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrecompiledContractsCancun contains the default set of pre-compiled Ethereum
|
|
|
|
|
// contracts used in the Cancun release.
|
|
|
|
|
var PrecompiledContractsCancun = 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{eip2565: true}, |
|
|
|
|
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{9}): &blake2F{}, |
|
|
|
|
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
|
|
|
|
|
// contracts specified in EIP-2537. These are exported for testing purposes.
|
|
|
|
|
var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ |
|
|
|
|
common.BytesToAddress([]byte{11}): &bls12381G1Add{}, |
|
|
|
|
common.BytesToAddress([]byte{12}): &bls12381G1Mul{}, |
|
|
|
|
common.BytesToAddress([]byte{13}): &bls12381G1MultiExp{}, |
|
|
|
|
common.BytesToAddress([]byte{14}): &bls12381G2Add{}, |
|
|
|
|
common.BytesToAddress([]byte{15}): &bls12381G2Mul{}, |
|
|
|
|
common.BytesToAddress([]byte{16}): &bls12381G2MultiExp{}, |
|
|
|
|
common.BytesToAddress([]byte{17}): &bls12381Pairing{}, |
|
|
|
|
common.BytesToAddress([]byte{18}): &bls12381MapG1{}, |
|
|
|
|
common.BytesToAddress([]byte{19}): &bls12381MapG2{}, |
|
|
|
|
} |
|
|
|
|
common.BytesToAddress([]byte{0x1}): &ecrecover{}, |
|
|
|
|
common.BytesToAddress([]byte{0x2}): &sha256hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, |
|
|
|
|
common.BytesToAddress([]byte{0x4}): &dataCopy{}, |
|
|
|
|
common.BytesToAddress([]byte{0x5}): &bigModExp{eip2565: true}, |
|
|
|
|
common.BytesToAddress([]byte{0x6}): &bn256AddIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x9}): &blake2F{}, |
|
|
|
|
common.BytesToAddress([]byte{0xa}): &kzgPointEvaluation{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PrecompiledContractsPrague contains the set of pre-compiled Ethereum
|
|
|
|
|
// contracts used in the Prague release.
|
|
|
|
|
var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{ |
|
|
|
|
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{}, |
|
|
|
|
common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{}, |
|
|
|
|
common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{}, |
|
|
|
|
common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{}, |
|
|
|
|
common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{}, |
|
|
|
|
common.BytesToAddress([]byte{0x11}): &bls12381Pairing{}, |
|
|
|
|
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{}, |
|
|
|
|
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var PrecompiledContractsBLS = PrecompiledContractsPrague |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
PrecompiledAddressesPrague []common.Address |
|
|
|
|
PrecompiledAddressesCancun []common.Address |
|
|
|
|
PrecompiledAddressesBerlin []common.Address |
|
|
|
|
PrecompiledAddressesIstanbul []common.Address |
|
|
|
@ -149,11 +152,16 @@ func init() { |
|
|
|
|
for k := range PrecompiledContractsCancun { |
|
|
|
|
PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k) |
|
|
|
|
} |
|
|
|
|
for k := range PrecompiledContractsPrague { |
|
|
|
|
PrecompiledAddressesPrague = append(PrecompiledAddressesPrague, k) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ActivePrecompiles returns the precompiles enabled with the current configuration.
|
|
|
|
|
func ActivePrecompiles(rules params.Rules) []common.Address { |
|
|
|
|
switch { |
|
|
|
|
case rules.IsPrague: |
|
|
|
|
return PrecompiledAddressesPrague |
|
|
|
|
case rules.IsCancun: |
|
|
|
|
return PrecompiledAddressesCancun |
|
|
|
|
case rules.IsBerlin: |
|
|
|
|