Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,29 @@ var PrecompiledContractsIsthmus = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x01, 0x00}): &p256VerifyFjord{},
}

var PrecompiledContractsJovian = 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}): &bn256PairingJovian{},
common.BytesToAddress([]byte{9}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
common.BytesToAddress([]byte{0x0c}): &bls12381G1MultiExpJovian{},
common.BytesToAddress([]byte{0x0d}): &bls12381G2Add{},
common.BytesToAddress([]byte{0x0e}): &bls12381G2MultiExpJovian{},
common.BytesToAddress([]byte{0x0f}): &bls12381PairingJovian{},
common.BytesToAddress([]byte{0x10}): &bls12381MapG1{},
common.BytesToAddress([]byte{0x11}): &bls12381MapG2{},
common.BytesToAddress([]byte{0x01, 0x00}): &p256VerifyFjord{},
}

var (
PrecompiledAddressesJovian []common.Address
PrecompiledAddressesIsthmus []common.Address
PrecompiledAddressesGranite []common.Address
PrecompiledAddressesFjord []common.Address
Expand Down Expand Up @@ -271,11 +293,16 @@ func init() {
for k := range PrecompiledContractsIsthmus {
PrecompiledAddressesIsthmus = append(PrecompiledAddressesIsthmus, k)
}
for k := range PrecompiledContractsJovian {
PrecompiledAddressesJovian = append(PrecompiledAddressesJovian, k)
}
}

func activePrecompiledContracts(rules params.Rules) PrecompiledContracts {
// note: the order of these switch cases is important
switch {
case rules.IsOptimismJovian:
return PrecompiledContractsJovian
case rules.IsOptimismIsthmus:
return PrecompiledContractsIsthmus
case rules.IsOptimismGranite:
Expand Down Expand Up @@ -309,6 +336,8 @@ func ActivePrecompiledContracts(rules params.Rules) PrecompiledContracts {
// ActivePrecompiles returns the precompile addresses enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsOptimismJovian:
return PrecompiledAddressesJovian
case rules.IsOptimismIsthmus:
return PrecompiledAddressesIsthmus
case rules.IsOptimismGranite:
Expand Down Expand Up @@ -823,6 +852,23 @@ func (c *bn256PairingGranite) Name() string {
return "BN254_PAIRING"
}

type bn256PairingJovian struct{}

func (c *bn256PairingJovian) RequiredGas(input []byte) uint64 {
return new(bn256PairingIstanbul).RequiredGas(input)
}

func (c *bn256PairingJovian) Run(input []byte) ([]byte, error) {
if len(input) > int(params.Bn256PairingMaxInputSizeJovian) {
return nil, errBadPairingInputSize
}
return runBn256Pairing(input)
}

func (c *bn256PairingJovian) Name() string {
return "BN254_PAIRING"
}

// bn256PairingIstanbul implements a pairing pre-compile for the bn256 curve
// conforming to Istanbul consensus rules.
type bn256PairingIstanbul struct{}
Expand Down Expand Up @@ -986,6 +1032,25 @@ func (c *bls12381G1MultiExpIsthmus) Name() string {
return "BLS12_G1MSM"
}

type bls12381G1MultiExpJovian struct {
}

func (c *bls12381G1MultiExpJovian) RequiredGas(input []byte) uint64 {
return new(bls12381G1MultiExp).RequiredGas(input)
}

func (c *bls12381G1MultiExpJovian) Run(input []byte) ([]byte, error) {
if len(input) > int(params.Bls12381G1MulMaxInputSizeJovian) {
return nil, errBLS12381MaxG1Size
}

return new(bls12381G1MultiExp).Run(input)
}

func (c *bls12381G1MultiExpJovian) Name() string {
return "BLS12_G1MSM"
}

// bls12381G1MultiExp implements EIP-2537 G1MultiExp precompile for Prague (no size limits).
func (c *bls12381G1Add) Name() string {
return "BLS12_G1ADD"
Expand Down Expand Up @@ -1115,6 +1180,25 @@ func (c *bls12381G2MultiExpIsthmus) Name() string {
return "BLS12_G2MSM"
}

type bls12381G2MultiExpJovian struct {
}

func (c *bls12381G2MultiExpJovian) RequiredGas(input []byte) uint64 {
return new(bls12381G2MultiExp).RequiredGas(input)
}

func (c *bls12381G2MultiExpJovian) Run(input []byte) ([]byte, error) {
if len(input) > int(params.Bls12381G2MulMaxInputSizeJovian) {
return nil, errBLS12381MaxG2Size
}

return new(bls12381G2MultiExp).Run(input)
}

func (c *bls12381G2MultiExpJovian) Name() string {
return "BLS12_G2MSM"
}

// bls12381G2MultiExp implements EIP-2537 G2MultiExp precompile.
type bls12381G2MultiExp struct{}

Expand Down Expand Up @@ -1198,6 +1282,25 @@ func (c *bls12381PairingIsthmus) Name() string {
return "BLS12_PAIRING_CHECK"
}

type bls12381PairingJovian struct {
}

func (c *bls12381PairingJovian) RequiredGas(input []byte) uint64 {
return new(bls12381Pairing).RequiredGas(input)
}

func (c *bls12381PairingJovian) Run(input []byte) ([]byte, error) {
if len(input) > int(params.Bls12381PairingMaxInputSizeJovian) {
return nil, errBLS12381MaxPairingSize
}

return new(bls12381Pairing).Run(input)
}

func (c *bls12381PairingJovian) Name() string {
return "BLS12_PAIRING_CHECK"
}

// bls12381Pairing implements EIP-2537 Pairing precompile.
type bls12381Pairing struct{}

Expand Down
5 changes: 5 additions & 0 deletions core/vm/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ var allPrecompiles = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x0b}): &p256Verify{},

common.BytesToAddress([]byte{0x01, 0x00}): &p256VerifyFjord{},

common.BytesToAddress([]byte{0x2f, 0x08}): &bn256PairingJovian{},
common.BytesToAddress([]byte{0x2f, 0x0e}): &bls12381PairingJovian{},
common.BytesToAddress([]byte{0x2f, 0x0b}): &bls12381G1MultiExpJovian{},
common.BytesToAddress([]byte{0x2f, 0x0d}): &bls12381G2MultiExpJovian{},
}

// EIP-152 test vectors
Expand Down
5 changes: 5 additions & 0 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ const (
Bls12381G2MulMaxInputSizeIsthmus uint64 = 488448 // Maximum input size for BLS12-381 G2 multiple-scalar-multiply operation
Bls12381PairingMaxInputSizeIsthmus uint64 = 235008 // Maximum input size for BLS12-381 pairing check

Bn256PairingMaxInputSizeJovian uint64 = 81984 // bn256Pairing limit (427 pairs)
Bls12381G1MulMaxInputSizeJovian uint64 = 288960 // BLS12-381 G1 MSM limit (1,806 pairs)
Bls12381G2MulMaxInputSizeJovian uint64 = 278784 // BLS12-381 G2 MSM limit (968 pairs)
Bls12381PairingMaxInputSizeJovian uint64 = 156672 // BLS12-381 pairing limit (408 pairs)

// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529
RefundQuotient uint64 = 2
Expand Down