Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any docs for zk counter pricing? #1583

Closed
doutv opened this issue Dec 19, 2024 · 4 comments
Closed

Any docs for zk counter pricing? #1583

doutv opened this issue Dec 19, 2024 · 4 comments
Labels
Polygon Work done by Polygon team question Further information is requested

Comments

@doutv
Copy link
Collaborator

doutv commented Dec 19, 2024

I have several questions about zk counter and I can't find relevent documents.

How you determine zk counter limits?

preForkId10TotalSteps = 1 << 23
forkId10TotalSteps = 1 << 24
forkId11TotalSteps = 1 << 25

How you set price for EVM operations?

take p256Verify precompile for example

cc.Deduct some magic numbers, how you get these numbers?

I think there is some pricing mechanism, which map EVM operations to zkevm-prover cost.

func (cc *CounterCollector) p256verify(r, s, x, y *big.Int) {
if r.Cmp(big.NewInt(0)) == 0 {
cc.Deduct(S, 13)
cc.Deduct(B, 1)
} else if SECP256R1_N_MINUS_ONE.Cmp(r) == -1 {
cc.Deduct(S, 15)
cc.Deduct(B, 2)
} else if s.Cmp(big.NewInt(0)) == 0 {
cc.Deduct(S, 17)
cc.Deduct(B, 3)
} else if SECP256R1_N_MINUS_ONE.Cmp(s) == -1 {
cc.Deduct(S, 19)
cc.Deduct(B, 4)
} else if SECP256R1_P_MINUS_ONE.Cmp(x) == -1 {
cc.Deduct(S, 22)
cc.Deduct(B, 5)
} else if SECP256R1_P_MINUS_ONE.Cmp(y) == -1 {
cc.Deduct(S, 24)
cc.Deduct(B, 6)
} else if x.Cmp(big.NewInt(0)) == 0 && y.Cmp(big.NewInt(0)) == 0 {
cc.Deduct(S, 29)
cc.Deduct(B, 8)
} else {
aux_x3 := new(big.Int).Exp(x, big.NewInt(3), SECP256R1_P)
aux_ax_b := new(big.Int).Mul(x, SECP256R1_A).Add(x, SECP256R1_B)
aux_x3_ax_b := aux_x3.Add(aux_x3, aux_ax_b).Mod(aux_x3, SECP256R1_P)
aux_y2 := new(big.Int).Exp(y, big.NewInt(2), SECP256R1_P)
if aux_y2.Cmp(aux_x3_ax_b) != 0 {
cc.Deduct(S, 104)
cc.Deduct(B, 15)
cc.Deduct(A, 12)
return
}
cc.Deduct(S, 7718)
cc.Deduct(B, 22)
cc.Deduct(A, 531)
}
}

@obynonwane
Copy link

@doutv we have a this in the doc

@doutv
Copy link
Collaborator Author

doutv commented Dec 23, 2024

I see. However, after read through all docs and code from repo zkevm-prover, zkevm-rom, I still confused.

Why fork11+ can have larger zkCounter?

@revitteth revitteth added the question Further information is requested label Jan 7, 2025
@revitteth revitteth added the Polygon Work done by Polygon team label Jan 14, 2025
@revitteth
Copy link
Collaborator

@doutv fork11+ counters changes are due to changes in the prover. It may be worth raising the issue here: https://github.com/0xPolygonHermez/zkevm-prover. For now I will close.

@doutv
Copy link
Collaborator Author

doutv commented Jan 27, 2025

sadly no one reply my issue in zkevm-prover. Are they focusing on the new prover?
0xPolygonHermez/zkevm-prover#880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Polygon Work done by Polygon team question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants