Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/zkevm' into zkevm-2.60
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Sep 17, 2024
2 parents 87fa5ac + af45559 commit d2f950a
Show file tree
Hide file tree
Showing 55 changed files with 2,356 additions and 763 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ COPY --from=builder /app/build/bin/sentry /usr/local/bin/sentry
COPY --from=builder /app/build/bin/state /usr/local/bin/state
COPY --from=builder /app/build/bin/txpool /usr/local/bin/txpool
COPY --from=builder /app/build/bin/verkle /usr/local/bin/verkle

COPY --from=builder /app/build/bin/acl /usr/local/bin/acl

EXPOSE 8545 \
8551 \
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ COPY --from=builder /app/build/bin/state /usr/local/bin/state
COPY --from=builder /app/build/bin/txpool /usr/local/bin/txpool
COPY --from=builder /app/build/bin/verkle /usr/local/bin/verkle
COPY --from=builder /app/build/bin/caplin /usr/local/bin/caplin
COPY --from=builder /app/build/bin/acl /usr/local/bin/acl

COPY --from=builder /go/pkg/mod /go/pkg/mod

Expand Down
135 changes: 135 additions & 0 deletions cmd/rpcdaemon/commands/mocks/l1_syncer_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions core/vm/contracts_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,17 @@ func (c *ripemd160hash_zkevm) Run(input []byte) ([]byte, error) {

// data copy implemented as a native contract.
type dataCopy_zkevm struct {
enabled bool
cc *CounterCollector
enabled bool
cc *CounterCollector
outLength int
}

func (c *dataCopy_zkevm) SetCounterCollector(cc *CounterCollector) {
c.cc = cc
}

func (c *dataCopy_zkevm) SetOutputLength(outLength int) {
c.outLength = outLength
}

// RequiredGas returns the gas required to execute the pre-compiled contract.
Expand All @@ -243,6 +245,11 @@ func (c *dataCopy_zkevm) Run(in []byte) ([]byte, error) {
if !c.enabled {
return []byte{}, ErrUnsupportedPrecompile
}

if c.cc != nil {
c.cc.preIdentity(len(in), c.outLength)
}

return in, nil
}

Expand Down
17 changes: 3 additions & 14 deletions core/vm/zk_batch_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ type BatchCounterCollector struct {
rlpCombinedCounters Counters
executionCombinedCounters Counters
processingCombinedCounters Counters

rlpCombinedCountersCache Counters
executionCombinedCountersCache Counters
processingCombinedCountersCache Counters
}

func NewBatchCounterCollector(smtMaxLevel int, forkId uint16, mcpReduction float64, unlimitedCounters bool, addonCounters *Counters) *BatchCounterCollector {
Expand Down Expand Up @@ -221,7 +217,7 @@ func (bcc *BatchCounterCollector) CombineCollectors(verifyMerkleProof bool) (Cou
}
}

for k, _ := range combined {
for k := range combined {
val := bcc.rlpCombinedCounters[k].used + bcc.executionCombinedCounters[k].used + bcc.processingCombinedCounters[k].used
combined[k].used += val
combined[k].remaining -= val
Expand Down Expand Up @@ -254,15 +250,8 @@ func (bcc *BatchCounterCollector) CombineCollectorsNoChanges() Counters {
}

for _, tx := range bcc.transactions {
for k, v := range tx.rlpCounters.counters {
combined[k].used += v.used
combined[k].remaining -= v.used
}
for k, v := range tx.executionCounters.counters {
combined[k].used += v.used
combined[k].remaining -= v.used
}
for k, v := range tx.processingCounters.counters {
txCounters := tx.CombineCounters()
for k, v := range txCounters {
combined[k].used += v.used
combined[k].remaining -= v.used
}
Expand Down
75 changes: 36 additions & 39 deletions core/vm/zk_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *Counter) AsMap() map[string]int {
type Counters []*Counter

func NewCounters() Counters {
array := make(Counters, counterTypesCount)
array := make(Counters, CounterTypesCount)
return array
}

Expand All @@ -83,14 +83,14 @@ func NewCountersFromUsedArray(used []int) *Counters {
}

func (c Counters) UsedAsString() string {
res := fmt.Sprintf("[%s: %v]", SHAName, c[SHA].used)
res += fmt.Sprintf("[%s: %v]", AName, c[A].used)
res += fmt.Sprintf("[%s: %v]", BName, c[B].used)
res += fmt.Sprintf("[%s: %v]", KName, c[K].used)
res += fmt.Sprintf("[%s: %v]", MName, c[M].used)
res += fmt.Sprintf("[%s: %v]", PName, c[P].used)
res += fmt.Sprintf("[%s: %v]", SName, c[S].used)
res += fmt.Sprintf("[%s: %v]", DName, c[D].used)
res := fmt.Sprintf("[%s: %v]", CounterKeyNames[SHA], c[SHA].used)
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[A], c[A].used)
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[B], c[B].used)
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[K], c[K].used)
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[M], c[M].used)
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[P], c[P].used)
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[S], c[S].used)
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[D], c[D].used)
return res
}

Expand All @@ -106,14 +106,14 @@ func (c Counters) UsedAsArray() []int {

func (c Counters) UsedAsMap() map[string]int {
return map[string]int{
string(SName): c[S].used,
string(AName): c[A].used,
string(BName): c[B].used,
string(MName): c[M].used,
string(KName): c[K].used,
string(DName): c[D].used,
string(PName): c[P].used,
string(SHAName): c[SHA].used,
string(CounterKeyNames[S]): c[S].used,
string(CounterKeyNames[A]): c[A].used,
string(CounterKeyNames[B]): c[B].used,
string(CounterKeyNames[M]): c[M].used,
string(CounterKeyNames[K]): c[K].used,
string(CounterKeyNames[D]): c[D].used,
string(CounterKeyNames[P]): c[P].used,
string(CounterKeyNames[SHA]): c[SHA].used,
}
}

Expand Down Expand Up @@ -162,16 +162,7 @@ func (cc Counters) Clone() Counters {
type CounterKey int
type CounterName string

var (
SName CounterName = "S"
AName CounterName = "A"
BName CounterName = "B"
MName CounterName = "M"
KName CounterName = "K"
DName CounterName = "D"
PName CounterName = "P"
SHAName CounterName = "SHA"

const (
S CounterKey = 0
A CounterKey = 1
B CounterKey = 2
Expand All @@ -181,7 +172,12 @@ var (
P CounterKey = 6
SHA CounterKey = 7

counterTypesCount = 8
CounterTypesCount = 8
)

var (
// important!!! must match the indexes of the keys
CounterKeyNames = []CounterName{"S", "A", "B", "M", "K", "D", "P", "SHA"}
)

type CounterCollector struct {
Expand Down Expand Up @@ -606,7 +602,7 @@ func (cc *CounterCollector) finishBatchProcessing() {
cc.Deduct(S, 200)
cc.Deduct(K, 2)
cc.Deduct(P, cc.smtLevels)
cc.Deduct(B, 1)
cc.Deduct(B, 2)
}

func (cc *CounterCollector) isColdAddress() {
Expand Down Expand Up @@ -736,6 +732,7 @@ func (cc *CounterCollector) setupNewBlockInfoTree() {

func (cc *CounterCollector) verifyMerkleProof() {
cc.Deduct(S, 250)
cc.Deduct(B, 1)
cc.Deduct(K, 33)
}

Expand Down Expand Up @@ -790,9 +787,9 @@ func (cc *CounterCollector) decodeChangeL2BlockTx() {
}

func (cc *CounterCollector) ecAdd() {
cc.Deduct(S, 323)
cc.Deduct(B, 33)
cc.Deduct(A, 40)
cc.Deduct(S, 800)
cc.Deduct(B, 50)
cc.Deduct(A, 50)
}

func (cc *CounterCollector) preECMul() {
Expand All @@ -805,9 +802,9 @@ func (cc *CounterCollector) preECMul() {
}

func (cc *CounterCollector) ecMul() {
cc.Deduct(S, 162890)
cc.Deduct(B, 16395)
cc.Deduct(A, 19161)
cc.Deduct(S, 175000)
cc.Deduct(B, 20000)
cc.Deduct(A, 20000)
}

func (cc *CounterCollector) preECPairing(inputsCount int) {
Expand All @@ -821,9 +818,9 @@ func (cc *CounterCollector) preECPairing(inputsCount int) {
}

func (cc *CounterCollector) ecPairing(inputsCount int) {
cc.Deduct(S, 16+inputsCount*184017+171253)
cc.Deduct(B, inputsCount*3986+650)
cc.Deduct(A, inputsCount*13694+15411)
cc.Deduct(S, 16+inputsCount*200000+175000)
cc.Deduct(B, inputsCount*4100+750)
cc.Deduct(A, inputsCount*15000+17500)
}

func (cc *CounterCollector) preModExp(callDataLength, returnDataLength, bLen, mLen, eLen int, base, exponent, modulus *big.Int) {
Expand Down Expand Up @@ -881,7 +878,7 @@ func (cc *CounterCollector) multiCall(call func(), times int) {
func (cc *CounterCollector) preSha256(callDataLength int) {
cc.Deduct(S, 100)
cc.Deduct(B, 1)
cc.Deduct(SHA, int(math.Ceil(float64(callDataLength+1)/64)))
cc.Deduct(SHA, int(math.Ceil(float64(callDataLength+8)/64)))
cc.multiCall(cc.divArith, 2)
cc.mStore32()
cc.mStoreX()
Expand Down
12 changes: 12 additions & 0 deletions core/vm/zk_transaction_counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ func NewTransactionCounter(transaction types.Transaction, smtMaxLevel int, forkI
return tc
}

func (tc *TransactionCounter) CombineCounters() Counters {
combined := NewCounters()
for k := range tc.rlpCounters.counters {
val := tc.rlpCounters.counters[k].used + tc.executionCounters.counters[k].used + tc.processingCounters.counters[k].used
combined[k] = &Counter{
used: val,
}
}

return combined
}

func (tc *TransactionCounter) Clone() *TransactionCounter {
var l2DataCacheCopy []byte
if tc.l2DataCache != nil {
Expand Down
Loading

0 comments on commit d2f950a

Please sign in to comment.