Skip to content

Commit

Permalink
feat: use the verify_proofs table for gw-listener
Browse files Browse the repository at this point in the history
Add two new fields:
 * verified - boolean, whether the proof was verified, used by txn
   sender to send responses only for verified proofs
 * input - used by gw-listener and zkproof-worker to store the
   input data for the proof

Also, complete the verify_proof_response() integration test.

Update to sqlx 0.8.3.

Fix deprecated compile() protobuf calls in build.rs files.
  • Loading branch information
dartdart26 committed Feb 14, 2025
1 parent 930cbba commit aae9cb0
Show file tree
Hide file tree
Showing 20 changed files with 720 additions and 316 deletions.
389 changes: 190 additions & 199 deletions fhevm-engine/Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion fhevm-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ daggy = "0.8.0"
futures-util = "0.3.31"
prometheus = "0.13.4"
prost = "0.13"
rand = "0.9.0"
rayon = "1.10.0"
serde = "1.0.210"
sha3 = "0.10.8"
sqlx = { version = "0.7", features = ["runtime-tokio", "tls-rustls", "time", "postgres", "uuid"] }
sqlx = { version = "0.8.3", features = ["runtime-tokio", "tls-rustls", "time", "postgres", "uuid"] }
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "zk-pok", "experimental-force_fft_algo_dif4"] }
tokio = { version = "1.38.0", features = ["full"] }
tokio-util = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion fhevm-engine/coprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bincode = { workspace = true }
clap = { workspace = true }
prometheus = { workspace = true }
prost = { workspace = true }
rand = { workspace = true }
rayon = { workspace = true }
sha3 = { workspace = true }
sqlx = { workspace = true }
Expand All @@ -39,7 +40,6 @@ strum = { version = "0.26", features = ["derive"] }
tonic-health = "0.12"
tonic-types = "0.12"
tonic-web = "0.12"
rand = "0.8.5"

# local dependencies
fhevm-engine-common = { path = "../fhevm-engine-common" }
Expand Down
2 changes: 1 addition & 1 deletion fhevm-engine/coprocessor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ fn main() {
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("coprocessor_descriptor.bin"))
.protoc_arg("--experimental_allow_proto3_optional")
.compile(&["../../proto/coprocessor.proto"], &["../../proto"])
.compile_protos(&["../../proto/coprocessor.proto"], &["../../proto"])
.unwrap();
}
2 changes: 1 addition & 1 deletion fhevm-engine/executor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("executor_descriptor.bin"))
.compile(&["../../proto/executor.proto"], &["../../proto"])
.compile_protos(&["../../proto/executor.proto"], &["../../proto"])
.unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ CREATE TABLE IF NOT EXISTS verify_proofs (
chain_id INTEGER NOT NULL CHECK(chain_id >= 0),
contract_address TEXT NOT NULL,
user_address TEXT NOT NULL,
input BYTEA,
handles BYTEA NOT NULL,
retry_count INTEGER NOT NULL DEFAULT 0
retry_count INTEGER NOT NULL DEFAULT 0,
verified BOOLEAN NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS idx_verify_proofs_retry_count ON verify_proofs(retry_count);
CREATE INDEX IF NOT EXISTS idx_verify_proofs_verified_retry ON verify_proofs(verified, retry_count, zk_proof_id);
2 changes: 1 addition & 1 deletion fhevm-engine/fhevm-engine-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license.workspace = true
# workspace dependencies
anyhow = { workspace = true }
bincode = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
sha3 = { workspace = true }
tfhe = { workspace = true }
Expand All @@ -18,7 +19,6 @@ tonic = { workspace = true }
# crates.io dependencies
bigdecimal = "0.4.5"
hex = "0.4"
rand = "0.8.5"
paste = "1.0.15"
rand_chacha = "0.3.1"
strum = { version = "0.26", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion fhevm-engine/fhevm-engine-common/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("common_descriptor.bin"))
.compile(&["../../proto/common.proto"], &["../../proto"])
.compile_protos(&["../../proto/common.proto"], &["../../proto"])
.unwrap();
}

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

5 changes: 5 additions & 0 deletions fhevm-engine/transaction-sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ alloy = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true }
futures-util = { workspace = true }
rand = { workspace = true }
sqlx = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
Expand All @@ -23,3 +24,7 @@ async-trait = "0.1.86"
[build-dependencies]
# crates.io dependencies
foundry-compilers = { version = "0.13.0", features = ["svm-solc"] }

[dev-dependencies]
# crates.io dependencies
serial_test = "3.2.0"
16 changes: 16 additions & 0 deletions fhevm-engine/transaction-sender/contracts/ZKPoKManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@ contract ZKPoKManager {

error CoprocessorHasAlreadySigned(uint256 zkProofId, address signer);

bool alreadySignedRevert;
bool generalRevert;

constructor(bool _alreadySignedRevert, bool _generalRevert) {
alreadySignedRevert = _alreadySignedRevert;
generalRevert = _generalRevert;
}

function verifyProofResponse(
uint256 zkProofId,
bytes32[] calldata handles,
bytes calldata signature
) public {
if (generalRevert) {
revert("General revert");
}

if (alreadySignedRevert) {
revert CoprocessorHasAlreadySigned(zkProofId, msg.sender);
}

emit VerifyProofResponseCalled(zkProofId, handles, signature);
}
}
2 changes: 2 additions & 0 deletions fhevm-engine/transaction-sender/src/bin/transaction_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fn install_signal_handlers(cancel_token: CancellationToken) -> anyhow::Result<()

#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt().json().with_level(true).init();
let conf = Conf::parse();
let signer = PrivateKeySigner::from_str(conf.private_key.trim())?;
let wallet = EthereumWallet::new(signer.clone());
Expand Down Expand Up @@ -101,6 +102,7 @@ async fn main() -> anyhow::Result<()> {
error_sleep_initial_secs: conf.error_sleep_initial_secs,
error_sleep_max_secs: conf.error_sleep_max_secs,
},
None,
);
install_signal_handlers(cancel_token)?;
sender.run().await
Expand Down
2 changes: 1 addition & 1 deletion fhevm-engine/transaction-sender/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod ops;
mod transaction_sender;

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ConfigSettings {
pub db_url: String,
pub db_pool_size: u32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ sol!(
);

#[derive(Clone)]
pub struct AddCiphertextsOperation<P: Provider<Ethereum> + Clone + 'static> {
pub struct AddCiphertextOperation<P: Provider<Ethereum> + Clone + 'static> {
ciphertext_storage_address: Address,
provider: Arc<P>,
}

impl<P: Provider<Ethereum> + Clone + 'static> AddCiphertextsOperation<P> {
impl<P: Provider<Ethereum> + Clone + 'static> AddCiphertextOperation<P> {
pub fn new(ciphertext_storage_address: Address, provider: Arc<P>) -> Self {
Self {
ciphertext_storage_address,
Expand All @@ -26,7 +26,7 @@ impl<P: Provider<Ethereum> + Clone + 'static> AddCiphertextsOperation<P> {
}

#[async_trait]
impl<P> TransactionOperation<P> for AddCiphertextsOperation<P>
impl<P> TransactionOperation<P> for AddCiphertextOperation<P>
where
P: alloy::providers::Provider<Ethereum> + Clone + 'static,
{
Expand Down
4 changes: 2 additions & 2 deletions fhevm-engine/transaction-sender/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ where
async fn execute(&self, db_pool: &Pool<Postgres>) -> anyhow::Result<bool>;
}

pub(crate) mod add_ciphertexts;
pub(crate) mod verify_proofs;
pub(crate) mod add_ciphertext;
pub(crate) mod verify_proof;
Loading

0 comments on commit aae9cb0

Please sign in to comment.