Skip to content

Commit cec1a8a

Browse files
committed
feat(coprocessor): add copro context ID for input proofs
Add support for a separate uin256 context ID in the event listened to by the gw-listener and using it to sign a `CiphertextVerification` in transaction-sender. Related to #211
1 parent aa8ec89 commit cec1a8a

File tree

23 files changed

+136
-263
lines changed

23 files changed

+136
-263
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE verify_proofs
2+
ADD COLUMN IF NOT EXISTS coprocessor_context_id BYTEA NOT NULL DEFAULT ''::BYTEA;

coprocessor/fhevm-engine/gw-listener/.sqlx/query-774d0833f523257d42044019619094083caf37a564283a97822f0efb309f2ea8.json renamed to coprocessor/fhevm-engine/gw-listener/.sqlx/query-989cdc420a832541b7df7be83086f6b78eb1966540df01871b27fe8383c0d52e.json

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/gw-listener/.sqlx/query-d1a294c48d897dc9685c95c8a59be64262d55e5d5b1dcbf40ae6d829fbc02970.json renamed to coprocessor/fhevm-engine/gw-listener/.sqlx/query-a06d342308b9f63791f9fdfc1568b351137d9561c952cceb0eb1fdf66c33c59d.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/gw-listener/contracts/InputVerification.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pragma solidity ^0.8.28;
66
contract InputVerification {
77
event VerifyProofRequest(
88
uint256 indexed zkProofId,
9+
uint256 indexed coprocessorContextId,
910
uint256 indexed contractChainId,
1011
address contractAddress,
1112
address userAddress,
@@ -14,6 +15,7 @@ contract InputVerification {
1415
);
1516

1617
uint256 zkProofIdCounter = 0;
18+
uint256 public coprocessorContextId = 7;
1719

1820
function verifyProofRequest(
1921
uint256 contractChainId,
@@ -26,6 +28,7 @@ contract InputVerification {
2628
zkProofIdCounter += 1;
2729
emit VerifyProofRequest(
2830
zkProofId,
31+
coprocessorContextId,
2932
contractChainId,
3033
contractAddress,
3134
userAddress,

coprocessor/fhevm-engine/gw-listener/src/gw_listener.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,13 @@ impl<P: Provider<Ethereum> + Clone + 'static> GatewayListener<P> {
136136
// TODO: check if we can avoid the cast from u256 to i64
137137
sqlx::query!(
138138
"WITH ins AS (
139-
INSERT INTO verify_proofs (zk_proof_id, chain_id, contract_address, user_address, input, extra_data)
140-
VALUES ($1, $2, $3, $4, $5, $6)
139+
INSERT INTO verify_proofs (zk_proof_id, coprocessor_context_id, chain_id, contract_address, user_address, input, extra_data)
140+
VALUES ($1, $2, $3, $4, $5, $6, $7)
141141
ON CONFLICT(zk_proof_id) DO NOTHING
142142
)
143-
SELECT pg_notify($7, '')",
143+
SELECT pg_notify($8, '')",
144144
request.zkProofId.to::<i64>(),
145+
&request.coprocessorContextId.to_le_bytes::<32>(),
145146
request.contractChainId.to::<i64>(),
146147
request.contractAddress.to_string(),
147148
request.userAddress.to_string(),

coprocessor/fhevm-engine/gw-listener/tests/gw_listener_tests.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,22 @@ async fn verify_proof_request_inserted_into_db() -> anyhow::Result<()> {
101101
let receipt = pending_txn.get_receipt().await?;
102102
assert!(receipt.status());
103103

104+
let coprocessor_context_id = input_verification
105+
.coprocessorContextId()
106+
.call()
107+
.await?
108+
.to_le_bytes::<32>();
109+
104110
loop {
105111
let rows = sqlx::query!(
106-
"SELECT zk_proof_id, chain_id, contract_address, user_address, input, extra_data
112+
"SELECT zk_proof_id, coprocessor_context_id, chain_id, contract_address, user_address, input, extra_data
107113
FROM verify_proofs",
108114
)
109115
.fetch_all(&env.db_pool)
110116
.await?;
111117
if !rows.is_empty() {
112118
let row = &rows[0];
119+
assert_eq!(row.coprocessor_context_id, coprocessor_context_id);
113120
assert_eq!(row.chain_id, 42);
114121
assert_eq!(row.contract_address, contract_address.to_string());
115122
assert_eq!(row.user_address, user_address.to_string());

coprocessor/fhevm-engine/transaction-sender/.sqlx/query-048212909e0bbe46633e404235d2c5cffb5284903adb757b4fda59b7fbe81d57.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/transaction-sender/.sqlx/query-09f4bb2ed7df17aa0305c7fb88e87473e5be704202eb8f2fa571d47a4f98b7af.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

coprocessor/fhevm-engine/transaction-sender/.sqlx/query-7e4f6abc7e18549f31548130efa4bed4d267da6e28697ceb780a58d787e739f1.json renamed to coprocessor/fhevm-engine/transaction-sender/.sqlx/query-1fcea613de0ee1b05fdc6dbbe1f33974012524688114b5d313f9ce2da2ef1282.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/transaction-sender/.sqlx/query-556dbda2415973bd6d94b8455eeae8cb8e4e177cd72376a7acad880eef60e419.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)