Skip to content

Commit 67b51ef

Browse files
committed
feat: P256Verify precompile glue (#1739)
commit 7b78570 Author: Ivo Kubjas <[email protected]> Date: Mon Nov 24 12:50:12 2025 +0000 chore: gnark update to master commit 9c19167 Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 03:19:28 2025 +0000 fix: ensure assignment is called commit 03437cf Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 02:53:20 2025 +0000 feat: define p256 input instance count commit 1cf0482 Merge: 81d6377 c5117f9 Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 02:50:51 2025 +0000 Merge branch 'feat/bls-glue' into feat/secp256r1 commit c5117f9 Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 02:48:12 2025 +0000 feat: add default circuit sizes commit 81d6377 Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 02:47:29 2025 +0000 feat: loat p256 module commit abedf2e Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 02:45:28 2025 +0000 fix: correct instance number calculation commit 0aab08d Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 02:44:58 2025 +0000 docs: circuit size commit bdfa261 Author: Ivo Kubjas <[email protected]> Date: Wed Nov 19 02:44:24 2025 +0000 chore: gnark update commit 1ae0acc Author: Ivo Kubjas <[email protected]> Date: Tue Nov 18 12:06:59 2025 +0000 docs: refer to test vector location commit 2aa908b Author: Ivo Kubjas <[email protected]> Date: Tue Nov 18 12:05:31 2025 +0000 test: include generated tests commit d4094d3 Author: Ivo Kubjas <[email protected]> Date: Tue Nov 18 12:05:18 2025 +0000 test: implement unit tests commit dae2651 Author: Ivo Kubjas <[email protected]> Date: Tue Nov 18 12:05:05 2025 +0000 test: do not write noop test cases commit 119bd71 Author: Ivo Kubjas <[email protected]> Date: Tue Nov 18 12:04:38 2025 +0000 feat: implement inputfiller commit 7620614 Author: Ivo Kubjas <[email protected]> Date: Tue Nov 18 11:27:39 2025 +0000 test: add testdata generator commit 332f497 Author: Ivo Kubjas <[email protected]> Date: Tue Nov 18 11:27:07 2025 +0000 fix: enforce public vars commit cb05285 Author: Ivo Kubjas <[email protected]> Date: Mon Nov 17 11:45:14 2025 +0000 chore: implement p256verify glue commit e19129c Author: Ivo Kubjas <[email protected]> Date: Mon Nov 17 11:44:58 2025 +0000 chore: gnark update commit 439b911 Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 21:08:48 2025 +0000 fix: more unique constraint names commit be09cf7 Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 20:52:05 2025 +0000 fix: incorrect limb count for scalar commit 206ee01 Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 20:48:05 2025 +0000 fix: ensure unique constraints commit afbfaee Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 20:43:31 2025 +0000 fix: store new rangechecker commit dd4e1eb Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 20:20:59 2025 +0000 chore: clarify error message commit f76c7c4 Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 20:18:36 2025 +0000 chore: remove excessive logging commit b83d78c Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 20:14:15 2025 +0000 fix: compilation errors commit 6f60e01 Merge: 5fdb039 cbf344e Author: Ivo Kubjas <[email protected]> Date: Sun Nov 16 20:12:33 2025 +0000 Merge branch 'main' into feat/bls-glue commit 5fdb039 Author: Ivo Kubjas <[email protected]> Date: Fri Sep 26 08:14:18 2025 +0000 test: make source local commit 4d526ed Author: Ivo Kubjas <[email protected]> Date: Mon Sep 29 22:18:09 2025 +0000 feat: integrate BLS precompile with zkevm commit 81a8876 Author: Ivo Kubjas <[email protected]> Date: Mon Sep 29 22:17:48 2025 +0000 docs: limits documentation commit a102526 Author: Ivo Kubjas <[email protected]> Date: Mon Sep 29 22:17:26 2025 +0000 feat: precise bls source getters commit d312c3d Author: Ivo Kubjas <[email protected]> Date: Mon Sep 29 13:14:35 2025 +0000 test: regenerate testdata commit b392c30 Author: Ivo Kubjas <[email protected]> Date: Mon Sep 29 11:36:29 2025 +0000 fix: align G2 tower order with gnark commit e823165 Author: Ivo Kubjas <[email protected]> Date: Fri Sep 26 13:09:09 2025 +0000 feat: remove circuit number limits commit 152d2a0 Author: Ivo Kubjas <[email protected]> Date: Wed Sep 24 11:28:54 2025 +0000 test: update included test files commit 3bf1ff6 Author: Ivo Kubjas <[email protected]> Date: Wed Sep 24 10:49:29 2025 +0000 fix: change ordering of serialized values commit c1bb5b6 Author: Ivo Kubjas <[email protected]> Date: Thu Sep 18 09:36:56 2025 +0000 chore: go mod tidy commit 9b138df Author: Ivo Kubjas <[email protected]> Date: Fri Sep 5 11:37:24 2025 +0000 test: add BLS testdata generator commit 44d9251 Author: Ivo Kubjas <[email protected]> Date: Tue Sep 2 11:05:12 2025 +0000 test: include minimal number of test files commit 81d4abf Author: Ivo Kubjas <[email protected]> Date: Fri Aug 29 15:09:24 2025 +0000 feat: add BLS precompile glue commit 6902d28 Author: Ivo Kubjas <[email protected]> Date: Fri Aug 29 15:09:01 2025 +0000 feat: csvtraces fill up to column size commit ae6bc69 Author: Ivo Kubjas <[email protected]> Date: Fri Aug 29 15:07:38 2025 +0000 fix: gnark schema walker field commit 896ba98 Author: Ivo Kubjas <[email protected]> Date: Fri Aug 29 15:07:17 2025 +0000 fix: typed builder commit af228c7 Author: Ivo Kubjas <[email protected]> Date: Fri Aug 29 15:06:50 2025 +0000 fix: remove unused test engine option commit 8bbd5ba Author: Ivo Kubjas <[email protected]> Date: Fri Aug 29 15:06:38 2025 +0000 fix: gnark logderiv interface change commit 2d1d55e Author: Ivo Kubjas <[email protected]> Date: Fri Aug 29 15:05:50 2025 +0000 chore: cherry pick gkr changes from smallfield commit b6a374a Author: Ivo Kubjas <[email protected]> Date: Thu Sep 18 09:35:46 2025 +0000 chore: gnark dependency update
1 parent 65da196 commit 67b51ef

File tree

12 files changed

+8137
-18
lines changed

12 files changed

+8137
-18
lines changed

prover/go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.6
55
require (
66
github.com/bits-and-blooms/bitset v1.24.0
77
github.com/consensys/compress v0.2.5
8-
github.com/consensys/gnark v0.14.1-0.20251115181224-9c9cf0deb462
8+
github.com/consensys/gnark v0.14.1-0.20251124124756-6a0918db4556
99
github.com/consensys/gnark-crypto v0.19.3-0.20251115174214-022ec58e8c19
1010
github.com/consensys/go-corset v1.1.28
1111
github.com/crate-crypto/go-kzg-4844 v1.1.0
@@ -28,9 +28,9 @@ require (
2828
github.com/spf13/cobra v1.10.1
2929
github.com/spf13/viper v1.19.0
3030
github.com/stretchr/testify v1.11.1
31-
golang.org/x/crypto v0.42.0
32-
golang.org/x/net v0.43.0
33-
golang.org/x/sync v0.17.0
31+
golang.org/x/crypto v0.45.0
32+
golang.org/x/net v0.47.0
33+
golang.org/x/sync v0.18.0
3434
golang.org/x/time v0.9.0
3535
)
3636

@@ -83,7 +83,7 @@ require (
8383
github.com/x448/float16 v0.8.4 // indirect
8484
github.com/yusufpapurcu/wmi v1.2.4 // indirect
8585
go.uber.org/multierr v1.11.0 // indirect
86-
golang.org/x/text v0.29.0 // indirect
86+
golang.org/x/text v0.31.0 // indirect
8787
google.golang.org/protobuf v1.34.2 // indirect
8888
gopkg.in/ini.v1 v1.67.0 // indirect
8989
)
@@ -94,6 +94,6 @@ require (
9494
github.com/pkg/profile v1.7.0
9595
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
9696
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b
97-
golang.org/x/sys v0.36.0 // indirect
97+
golang.org/x/sys v0.38.0 // indirect
9898
gopkg.in/yaml.v3 v3.0.1 // indirect
9999
)

prover/go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
7474
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
7575
github.com/consensys/compress v0.2.5 h1:gJr1hKzbOD36JFsF1AN8lfXz1yevnJi1YolffY19Ntk=
7676
github.com/consensys/compress v0.2.5/go.mod h1:pyM+ZXiNUh7/0+AUjUf9RKUM6vSH7T/fsn5LLS0j1Tk=
77-
github.com/consensys/gnark v0.14.1-0.20251115181224-9c9cf0deb462 h1:X2GtytWZIH0PT0g4RfFWu/56Fhus9Uf08cEacDmbN+E=
78-
github.com/consensys/gnark v0.14.1-0.20251115181224-9c9cf0deb462/go.mod h1:y3yL/y4fe6pg5Hakknn5r8ukr19T6l8OZq90+PHVM1o=
77+
github.com/consensys/gnark v0.14.1-0.20251124124756-6a0918db4556 h1:DLtPn4esNLrqdP0FIZJhPu4yxIzvjSPxEkz68c7R/ew=
78+
github.com/consensys/gnark v0.14.1-0.20251124124756-6a0918db4556/go.mod h1:XBV7LkFSZq5AyQhdEN1Y6ntm/QNdu7lnKNvZnh25O7I=
7979
github.com/consensys/gnark-crypto v0.19.3-0.20251115174214-022ec58e8c19 h1:uUbFaofcFwkv5T/zbR/Gyfm06v84Rua9a1xv9VZrPAA=
8080
github.com/consensys/gnark-crypto v0.19.3-0.20251115174214-022ec58e8c19/go.mod h1:OgCH7cSoJ46c+nOzvQuwOrIE9fawpXMYOQFzj22Vy3E=
8181
github.com/consensys/go-corset v1.1.28 h1:4vaaIFAWCzEgGTz6YGm8rt7+0F6mHDT8DS2u+WWslFw=
@@ -459,8 +459,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
459459
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
460460
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
461461
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
462-
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
463-
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
462+
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
463+
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
464464
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
465465
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
466466
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -540,8 +540,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
540540
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
541541
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
542542
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
543-
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
544-
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
543+
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
544+
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
545545
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
546546
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
547547
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -567,8 +567,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
567567
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
568568
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
569569
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
570-
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
571-
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
570+
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
571+
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
572572
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
573573
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
574574
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -625,8 +625,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
625625
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
626626
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
627627
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
628-
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
629-
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
628+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
629+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
630630
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
631631
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
632632
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@@ -641,8 +641,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
641641
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
642642
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
643643
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
644-
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
645-
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
644+
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
645+
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
646646
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
647647
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
648648
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

prover/zkevm/full.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/consensys/linea-monorepo/prover/zkevm/prover/hash/keccak"
2424
"github.com/consensys/linea-monorepo/prover/zkevm/prover/hash/sha2"
2525
"github.com/consensys/linea-monorepo/prover/zkevm/prover/modexp"
26+
"github.com/consensys/linea-monorepo/prover/zkevm/prover/p256verify"
2627
"github.com/consensys/linea-monorepo/prover/zkevm/prover/statemanager"
2728
"github.com/consensys/linea-monorepo/prover/zkevm/prover/statemanager/accumulator"
2829
)
@@ -250,6 +251,9 @@ func FullZKEVMWithSuite(tl *config.TracesLimits, suite CompilationSuite, cfg *co
250251
NbPointEvalInputInstances: NbInputPerInstanceBLSPointEval,
251252
NbPointEvalFailureInputInstances: NbInputPerInstanceBLSPointEvalFailure,
252253
},
254+
P256Verify: p256verify.Limits{
255+
NbInputInstances: NbInputPerInstanceP256Verify,
256+
},
253257
}
254258

255259
// Initialize the Full zkEVM arithmetization
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package p256verify
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/consensys/gnark/frontend"
7+
"github.com/consensys/gnark/std/evmprecompiles"
8+
"github.com/consensys/gnark/std/math/bitslice"
9+
"github.com/consensys/gnark/std/math/emulated"
10+
"github.com/consensys/gnark/std/math/emulated/emparams"
11+
)
12+
13+
const (
14+
nbBits = 128 // for large-field we use 128-bit limbs both for base and scalar fields
15+
nbBytes = nbBits / 8
16+
17+
nbFrLimbs = 2 // P-256 scalar field represented with 2 limbs of 128 bits
18+
nbFpLimbs = 2 // P-256 base field represented with 2 limbs of 128 bits
19+
nbResLimbs = 2
20+
21+
nbG1Limbs = 2 * nbFpLimbs // (Ax, Ay)
22+
23+
nbRows = 3*nbFrLimbs + nbG1Limbs + nbResLimbs // msg
24+
)
25+
26+
type scalarfield = emparams.P256Fr
27+
type basefield = emparams.P256Fp
28+
29+
var fpParams basefield
30+
var frParams scalarfield
31+
32+
type scalarElementWizard struct {
33+
S [nbFrLimbs]frontend.Variable
34+
}
35+
36+
func (c scalarElementWizard) ToElement(api frontend.API, fr *emulated.Field[scalarfield]) *emulated.Element[scalarfield] {
37+
Slimbs := make([]frontend.Variable, frParams.NbLimbs())
38+
Slimbs[2], Slimbs[3] = bitslice.Partition(api, c.S[0], 64, bitslice.WithNbDigits(128))
39+
Slimbs[0], Slimbs[1] = bitslice.Partition(api, c.S[1], 64, bitslice.WithNbDigits(128))
40+
return fr.NewElement(Slimbs)
41+
}
42+
43+
type baseElementWizard struct {
44+
P [nbFpLimbs]frontend.Variable
45+
}
46+
47+
func (c baseElementWizard) ToElement(api frontend.API, fp *emulated.Field[basefield]) *emulated.Element[basefield] {
48+
Plimbs := make([]frontend.Variable, fpParams.NbLimbs())
49+
Plimbs[2], Plimbs[3] = bitslice.Partition(api, c.P[0], 64, bitslice.WithNbDigits(128))
50+
Plimbs[0], Plimbs[1] = bitslice.Partition(api, c.P[1], 64, bitslice.WithNbDigits(128))
51+
return fp.NewElement(Plimbs)
52+
}
53+
54+
type p256VerifyInstance struct {
55+
H scalarElementWizard `gnark:",public"`
56+
R scalarElementWizard `gnark:",public"`
57+
S scalarElementWizard `gnark:",public"`
58+
Qx baseElementWizard `gnark:",public"`
59+
Qy baseElementWizard `gnark:",public"`
60+
Expected [nbResLimbs]frontend.Variable `gnark:",public"`
61+
}
62+
63+
type multiP256VerifyInstanceCircuit struct {
64+
Instances []p256VerifyInstance
65+
}
66+
67+
func (c *multiP256VerifyInstanceCircuit) Define(api frontend.API) error {
68+
scalarApi, err := emulated.NewField[scalarfield](api)
69+
if err != nil {
70+
return fmt.Errorf("new scalar field: %w", err)
71+
}
72+
baseApi, err := emulated.NewField[basefield](api)
73+
if err != nil {
74+
return fmt.Errorf("new base field: %w", err)
75+
}
76+
77+
nbInstances := len(c.Instances)
78+
for i := 0; i < nbInstances; i++ {
79+
h := c.Instances[i].H.ToElement(api, scalarApi)
80+
r := c.Instances[i].R.ToElement(api, scalarApi)
81+
s := c.Instances[i].S.ToElement(api, scalarApi)
82+
qx := c.Instances[i].Qx.ToElement(api, baseApi)
83+
qy := c.Instances[i].Qy.ToElement(api, baseApi)
84+
// the high limb of the result is always zero
85+
api.AssertIsEqual(c.Instances[i].Expected[0], 0)
86+
// the expected result should be boolean
87+
expected := c.Instances[i].Expected[1]
88+
api.AssertIsBoolean(expected)
89+
res := evmprecompiles.P256Verify(api, h, r, s, qx, qy)
90+
api.AssertIsEqual(res, expected)
91+
}
92+
return nil
93+
}
94+
95+
func newP256VerifyCircuit(limits *Limits) frontend.Circuit {
96+
return &multiP256VerifyInstanceCircuit{
97+
Instances: make([]p256VerifyInstance, limits.NbInputInstances),
98+
}
99+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package p256verify
2+
3+
import (
4+
"github.com/consensys/linea-monorepo/prover/maths/field"
5+
"github.com/consensys/linea-monorepo/prover/protocol/dedicated/plonk"
6+
)
7+
8+
const (
9+
input_filler_key = "p256-verify-input-filler"
10+
)
11+
12+
func init() {
13+
plonk.RegisterInputFiller(input_filler_key, inputFiller)
14+
}
15+
16+
func inputFiller(circuitInstance, inputIndex int) field.Element {
17+
datas := []string{
18+
// h
19+
"0", "0",
20+
// r
21+
"0", "1",
22+
// s
23+
"0", "1",
24+
// qx
25+
"0x77037d812deb33a0f4a13945d898c296",
26+
"0x6b17d1f2e12c4247f8bce6e563a440f2",
27+
// qy
28+
"0x2bce33576b315ececbb6406837bf51f5",
29+
"0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e16",
30+
// expected result
31+
"0", "0",
32+
}
33+
return field.NewFromString(datas[inputIndex%nbRows])
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package p256verify
2+
3+
// Limits defines limits for P256Verify module.
4+
type Limits struct {
5+
// NbInputInstances is the number of P256 input instances per a single
6+
// verification circuit. gnark circuit size approximately 709k constraints
7+
// and in Plonk-in-Wizard (with externalized range checks) approximately
8+
// 183k rows per instance.
9+
NbInputInstances int
10+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package p256verify
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/consensys/linea-monorepo/prover/protocol/dedicated/plonk"
7+
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
8+
"github.com/consensys/linea-monorepo/prover/protocol/query"
9+
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
10+
)
11+
12+
const (
13+
NAME_P256_VERIFY = "P256_VERIFY"
14+
moduleName = "ECDATA"
15+
ROUND_NR = 0
16+
)
17+
18+
func colNameFn(colName string) ifaces.ColID {
19+
return ifaces.ColID(fmt.Sprintf("%s.%s", moduleName, colName))
20+
}
21+
22+
type p256VerifyDataSource struct {
23+
ID ifaces.Column
24+
CS ifaces.Column
25+
Limb ifaces.Column
26+
Index ifaces.Column
27+
IsData ifaces.Column
28+
IsResult ifaces.Column
29+
}
30+
31+
func newP256VerifyDataSource(comp *wizard.CompiledIOP) *p256VerifyDataSource {
32+
return &p256VerifyDataSource{
33+
ID: comp.Columns.GetHandle(colNameFn("ID")),
34+
CS: comp.Columns.GetHandle(colNameFn("CIRCUIT_SELECTOR_P256_VERIFY")),
35+
Limb: comp.Columns.GetHandle(colNameFn("LIMB")),
36+
Index: comp.Columns.GetHandle(colNameFn("INDEX")),
37+
IsData: comp.Columns.GetHandle(colNameFn("DATA_P256_VERIFY_FLAG")),
38+
IsResult: comp.Columns.GetHandle(colNameFn("RSLT_P256_VERIFY_FLAG")),
39+
}
40+
}
41+
42+
type P256Verify struct {
43+
*p256VerifyDataSource
44+
p256VerifyGnarkData *plonk.Alignment
45+
*Limits
46+
}
47+
48+
func newP256Verify(_ *wizard.CompiledIOP, limits *Limits, src *p256VerifyDataSource) *P256Verify {
49+
res := &P256Verify{
50+
p256VerifyDataSource: src,
51+
Limits: limits,
52+
}
53+
54+
return res
55+
}
56+
57+
func (pv *P256Verify) WithCircuit(comp *wizard.CompiledIOP, options ...query.PlonkOption) *P256Verify {
58+
nbRowsPerCircuit := nbRows * pv.Limits.NbInputInstances
59+
maxNbCircuits := (pv.p256VerifyDataSource.CS.Size() + nbRowsPerCircuit - 1) / nbRowsPerCircuit
60+
61+
toAlign := &plonk.CircuitAlignmentInput{
62+
Name: fmt.Sprintf("%s_ALIGNMENT", NAME_P256_VERIFY),
63+
Round: ROUND_NR,
64+
DataToCircuitMask: pv.p256VerifyDataSource.CS,
65+
DataToCircuit: pv.p256VerifyDataSource.Limb,
66+
Circuit: newP256VerifyCircuit(pv.Limits),
67+
NbCircuitInstances: maxNbCircuits,
68+
PlonkOptions: options,
69+
InputFillerKey: input_filler_key,
70+
}
71+
pv.p256VerifyGnarkData = plonk.DefineAlignment(comp, toAlign)
72+
return pv
73+
}
74+
75+
func (pv *P256Verify) Assign(run *wizard.ProverRuntime) {
76+
if pv.p256VerifyGnarkData != nil {
77+
pv.p256VerifyGnarkData.Assign(run)
78+
}
79+
}
80+
81+
func NewP256VerifyZkEvm(comp *wizard.CompiledIOP, limits *Limits) *P256Verify {
82+
return newP256Verify(comp, limits, newP256VerifyDataSource(comp))
83+
}

0 commit comments

Comments
 (0)