Skip to content
Merged
74 changes: 52 additions & 22 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"

Check failure on line 23 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / build-mock-ccc-geth

"fmt" imported and not used

Check failure on line 23 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / check

"fmt" imported and not used

Check failure on line 23 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / check

"fmt" imported and not used

Check failure on line 23 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / check

"fmt" imported and not used

Check failure on line 23 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / test

"fmt" imported and not used
"math/big"

"github.com/scroll-tech/go-ethereum/common"
Expand Down Expand Up @@ -64,7 +65,7 @@
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{5}): &bigModExp{eip2565: false, eip7823: false},
common.BytesToAddress([]byte{6}): &bn256AddByzantium{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulByzantium{},
common.BytesToAddress([]byte{8}): &bn256PairingByzantium{},
Expand All @@ -77,7 +78,7 @@
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{5}): &bigModExp{eip2565: false, eip7823: false},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{limitInputLength: false},
Expand All @@ -91,7 +92,7 @@
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{5}): &bigModExp{eip2565: true, eip7823: false},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{limitInputLength: false},
Expand All @@ -105,7 +106,7 @@
common.BytesToAddress([]byte{2}): &sha256hashDisabled{},
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true, eip7823: false},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{limitInputLength: true},
Expand All @@ -119,7 +120,7 @@
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true, eip7823: false},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{limitInputLength: true},
Expand All @@ -133,7 +134,7 @@
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true, eip7823: false},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{limitInputLength: true},
Expand All @@ -148,7 +149,22 @@
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true, eip7823: false},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{limitInputLength: false},
common.BytesToAddress([]byte{9}): &blake2FDisabled{},
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
}

// PrecompiledContractsGalileo contains the default set of pre-compiled Ethereum
// contracts used in the Galileo release.
var PrecompiledContractsGalileo = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hashDisabled{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true, eip7823: true},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{limitInputLength: false},
Expand All @@ -171,6 +187,7 @@
}

var (
PrecompiledAddressesGalileo []common.Address
PrecompiledAddressesFeynman []common.Address
PrecompiledAddressesEuclidV2 []common.Address
PrecompiledAddressesBernoulli []common.Address
Expand Down Expand Up @@ -206,11 +223,16 @@
for k := range PrecompiledContractsFeynman {
PrecompiledAddressesFeynman = append(PrecompiledAddressesFeynman, k)
}
for k := range PrecompiledContractsGalileo {
PrecompiledAddressesGalileo = append(PrecompiledAddressesGalileo, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsGalileo:

Check failure on line 234 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / build-mock-ccc-geth

rules.IsGalileo undefined (type params.Rules has no field or method IsGalileo)

Check failure on line 234 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / check

rules.IsGalileo undefined (type params.Rules has no field or method IsGalileo)) (typecheck)

Check failure on line 234 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / check

rules.IsGalileo undefined (type params.Rules has no field or method IsGalileo)) (typecheck)

Check failure on line 234 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / check

rules.IsGalileo undefined (type params.Rules has no field or method IsGalileo)) (typecheck)

Check failure on line 234 in core/vm/contracts.go

View workflow job for this annotation

GitHub Actions / test

rules.IsGalileo undefined (type params.Rules has no field or method IsGalileo)
return PrecompiledAddressesGalileo
case rules.IsFeynman:
return PrecompiledAddressesFeynman
case rules.IsEuclidV2:
Expand Down Expand Up @@ -349,6 +371,7 @@
// bigModExp implements a native big integer exponential modular operation.
type bigModExp struct {
eip2565 bool
eip7823 bool
}

var (
Expand Down Expand Up @@ -471,40 +494,47 @@

func (c *bigModExp) Run(input []byte) ([]byte, error) {
var (
baseLenBigInt = new(big.Int).SetBytes(getData(input, 0, 32))
expLenBigInt = new(big.Int).SetBytes(getData(input, 32, 32))
modLenBigInt = new(big.Int).SetBytes(getData(input, 64, 32))
baseLenBig = new(big.Int).SetBytes(getData(input, 0, 32))
expLenBig = new(big.Int).SetBytes(getData(input, 32, 32))
modLenBig = new(big.Int).SetBytes(getData(input, 64, 32))
baseLen = baseLenBig.Uint64()
expLen = expLenBig.Uint64()
modLen = modLenBig.Uint64()
inputLenOverflow = max(baseLenBig.BitLen(), expLenBig.BitLen(), modLenBig.BitLen()) > 64
)
var (
baseLen = baseLenBigInt.Uint64()
expLen = expLenBigInt.Uint64()
modLen = modLenBigInt.Uint64()
)
// Check that all inputs are `u256` (32 - bytes) or less, revert otherwise
var lenLimit = new(big.Int).SetInt64(32)
if baseLenBigInt.Cmp(lenLimit) > 0 || expLenBigInt.Cmp(lenLimit) > 0 || modLenBigInt.Cmp(lenLimit) > 0 {
return nil, errModexpUnsupportedInput
}
if len(input) > 96 {
input = input[96:]
} else {
input = input[:0]
}

// enforce size cap for inputs
if c.eip7823 && (inputLenOverflow || max(baseLen, expLen, modLen) > 1024) {
return nil, errors.New("one or more of base/exponent/modulus length exceeded 1024 bytes")
}
// Handle a special case when both the base and mod length is zero
if baseLen == 0 && modLen == 0 {
return []byte{}, nil
}

// Retrieve the operands and execute the exponentiation
var (
base = new(big.Int).SetBytes(getData(input, 0, baseLen))
exp = new(big.Int).SetBytes(getData(input, baseLen, expLen))
mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
v []byte
)
if mod.BitLen() == 0 {
switch {
case mod.BitLen() == 0:
// Modulo 0 is undefined, return zero
return common.LeftPadBytes([]byte{}, int(modLen)), nil
case base.BitLen() == 1: // a bit length of 1 means it's 1 (or -1).
//If base == 1, then we can just return base % mod (if mod >= 1, which it is)
v = base.Mod(base, mod).Bytes()
default:
v = base.Exp(base, exp, mod).Bytes()
}
return common.LeftPadBytes(base.Exp(base, exp, mod).Bytes(), int(modLen)), nil
return common.LeftPadBytes(v, int(modLen)), nil
}

// newCurvePoint unmarshals a binary blob into a bn256 elliptic curve point,
Expand Down
2 changes: 1 addition & 1 deletion rollup/missing_header_fields/export-headers-toolkit/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
replace github.com/scroll-tech/go-ethereum => ../../..

require (
github.com/scroll-tech/da-codec v0.1.3-0.20250626091118-58b899494da6
github.com/scroll-tech/da-codec v0.1.3-0.20250825071838-cddc263e5ef6
github.com/scroll-tech/go-ethereum v1.10.14-0.20250625112225-a67863c65587
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
Expand Down
1 change: 1 addition & 0 deletions rollup/missing_header_fields/export-headers-toolkit/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/scroll-tech/da-codec v0.1.3-0.20250313120912-344f2d5e33e1 h1:Dhd58LE1D+dnoxpgLVeQBMF9uweL/fhQfZHWtWSiOlE=
github.com/scroll-tech/da-codec v0.1.3-0.20250313120912-344f2d5e33e1/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY=
github.com/scroll-tech/da-codec v0.1.3-0.20250626091118-58b899494da6/go.mod h1:Z6kN5u2khPhiqHyk172kGB7o38bH/nj7Ilrb/46wZGg=
github.com/scroll-tech/da-codec v0.1.3-0.20250825071838-cddc263e5ef6/go.mod h1:Z6kN5u2khPhiqHyk172kGB7o38bH/nj7Ilrb/46wZGg=
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=
github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
Expand Down
Loading