From e7aa7ef698efe87e762aeecbfb95238d9f628e3d Mon Sep 17 00:00:00 2001 From: ryardley Date: Mon, 30 Sep 2024 21:51:28 +1000 Subject: [PATCH] Decoding events are working --- packages/ciphernode/core/src/evm_enclave.rs | 58 +++++- packages/ciphernode/core/src/lib.rs | 12 +- packages/ciphernode/core/src/logger.rs | 3 + .../src/bin/{bfvgen.rs => pack_e3_params.rs} | 10 +- packages/evm/contracts/test/MockE3Program.sol | 3 +- packages/evm/test/Enclave.spec.ts | 188 +++++++++--------- .../lib/encode_e3_params.mjs | 11 +- .../lib/{bfvgen.sh => pack_e3_params.sh} | 2 +- .../output/encoded_params.hex | 1 + tests/basic_integration/test.sh | 5 +- 10 files changed, 174 insertions(+), 119 deletions(-) rename packages/ciphernode/enclave_node/src/bin/{bfvgen.rs => pack_e3_params.rs} (75%) rename tests/basic_integration/lib/{bfvgen.sh => pack_e3_params.sh} (76%) create mode 100644 tests/basic_integration/output/encoded_params.hex diff --git a/packages/ciphernode/core/src/evm_enclave.rs b/packages/ciphernode/core/src/evm_enclave.rs index bd2026db..ccddfa33 100644 --- a/packages/ciphernode/core/src/evm_enclave.rs +++ b/packages/ciphernode/core/src/evm_enclave.rs @@ -5,15 +5,15 @@ use crate::{ EnclaveEvent, EventBus, }; use actix::Addr; -use alloy::{primitives::Address, sol, sol_types::SolValue}; +use alloy::{ + hex, + primitives::{Address, Bytes}, + sol, + sol_types::SolValue, +}; use anyhow::{Context, Result}; sol! { - struct EncodedE3ProgramParams { - bytes params; - address input_validator; - } - #[derive(Debug)] struct E3 { uint256 seed; @@ -50,9 +50,12 @@ impl TryFrom<&E3Requested> for events::E3Requested { type Error = anyhow::Error; fn try_from(value: &E3Requested) -> Result { let program_params = value.e3.e3ProgramParams.to_vec(); - let decoded = EncodedE3ProgramParams::abi_decode(&program_params, true)?; + println!("received: {}", hex::encode(&program_params)); + + let decoded = + decode_e3_params(&program_params).context("Failed to ABI decode program_params")?; Ok(events::E3Requested { - params: decoded.params.into(), + params: decoded.0.into(), threshold_m: value.e3.threshold[0] as usize, seed: value.e3.seed.into(), e3_id: value.e3Id.to_string().into(), @@ -71,9 +74,7 @@ impl From for events::CiphertextOutputPublished { impl ContractEvent for E3Requested { fn process(&self, bus: Addr) -> Result<()> { - let data: events::E3Requested = self - .try_into() - .context("Could not parse E3Requested event")?; + let data: events::E3Requested = self.try_into()?; bus.do_send(EnclaveEvent::from(data)); Ok(()) @@ -108,3 +109,38 @@ pub async fn connect_evm_enclave(bus: Addr, rpc_url: &str, contract_ad println!("Evm is listening to {}", contract_address); } + +pub fn decode_e3_params(bytes: &[u8]) -> Result<(Vec, String)> { + let decoded: (Bytes, Address) = SolValue::abi_decode_params(bytes, true)?; + Ok((decoded.0.into(), decoded.1.to_string())) +} + +pub fn encode_e3_params(params: &[u8], input_validator: Address) -> Vec { + (params, input_validator).abi_encode_params() +} + +#[cfg(test)] +mod tests { + use crate::encode_bfv_params; + + use super::{decode_e3_params, encode_e3_params}; + use alloy::{hex, primitives::address}; + use anyhow::*; + use fhe::bfv::BfvParameters; + use fhe_traits::Deserialize; + + #[test] + fn test_evm_decode() -> Result<()> { + let params_encoded = encode_bfv_params(vec![0x3FFFFFFF000001], 2048, 1032193); + + let add = address!("8A791620dd6260079BF849Dc5567aDC3F2FdC318"); + let encoded = hex::encode(&encode_e3_params(¶ms_encoded, add)); + assert_eq!(encoded, "00000000000000000000000000000000000000000000000000000000000000400000000000000000000000008a791620dd6260079bf849dc5567adc3f2fdc31800000000000000000000000000000000000000000000000000000000000000130880101208818080f8ffffff1f1881803f200a00000000000000000000000000"); + let input: Vec = hex::decode(&encoded)?; + let (de_params, de_address) = decode_e3_params(&input)?; + let params_assemble = BfvParameters::try_deserialize(&de_params)?; + assert_eq!(params_assemble.degree(), 2048); + assert_eq!(de_address, "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"); + Ok(()) + } +} diff --git a/packages/ciphernode/core/src/lib.rs b/packages/ciphernode/core/src/lib.rs index 678cc561..1b987b6b 100644 --- a/packages/ciphernode/core/src/lib.rs +++ b/packages/ciphernode/core/src/lib.rs @@ -34,6 +34,7 @@ pub use data::*; pub use e3_request::*; pub use eventbus::*; pub use events::*; +pub use evm_enclave::{decode_e3_params, encode_e3_params}; pub use fhe::*; pub use keyshare::*; pub use logger::*; @@ -78,7 +79,12 @@ mod tests { use tokio::{sync::mpsc::channel, time::sleep}; // Simulating a local node - async fn setup_local_ciphernode(bus: Addr, rng:SharedRng, logging: bool, addr: &str) { + async fn setup_local_ciphernode( + bus: Addr, + rng: SharedRng, + logging: bool, + addr: &str, + ) { // create data actor for saving data let data = Data::new(logging).start(); // TODO: Use a sled backed Data Actor @@ -136,7 +142,9 @@ mod tests { &[0x3FFFFFFF000001], 2048, 1032193, - Arc::new(std::sync::Mutex::new(ChaCha20Rng::from_seed(seed.clone().into()))), + Arc::new(std::sync::Mutex::new(ChaCha20Rng::from_seed( + seed.clone().into(), + ))), ); let regevt_1 = EnclaveEvent::from(CiphernodeAdded { diff --git a/packages/ciphernode/core/src/logger.rs b/packages/ciphernode/core/src/logger.rs index 2a6f8bba..540389dd 100644 --- a/packages/ciphernode/core/src/logger.rs +++ b/packages/ciphernode/core/src/logger.rs @@ -44,6 +44,9 @@ impl Handler for SimpleLogger { }, EnclaveEvent::E3Requested { data,.. } => { println!("[{}]: E3Requested(e3_id: {}, threshold_m: {} , seed: {:?})", self.name, data.e3_id, data.threshold_m, data.seed); + }, + EnclaveEvent::EnclaveError { data, .. } => { + println!("[{}]: EnclaveError('{}')", self.name, data.message); } _ => println!("[{}]: {}", self.name, msg), } diff --git a/packages/ciphernode/enclave_node/src/bin/bfvgen.rs b/packages/ciphernode/enclave_node/src/bin/pack_e3_params.rs similarity index 75% rename from packages/ciphernode/enclave_node/src/bin/bfvgen.rs rename to packages/ciphernode/enclave_node/src/bin/pack_e3_params.rs index e23fc091..41974563 100644 --- a/packages/ciphernode/enclave_node/src/bin/bfvgen.rs +++ b/packages/ciphernode/enclave_node/src/bin/pack_e3_params.rs @@ -1,5 +1,6 @@ +use alloy::{hex::FromHex, primitives::{address, Address}}; use clap::{command, Parser}; -use enclave_core::encode_bfv_params; +use enclave_core::{encode_bfv_params, encode_e3_params}; use std::{error::Error, num::ParseIntError, process}; fn parse_hex(arg: &str) -> Result { @@ -21,6 +22,9 @@ struct Args { #[arg(short, long = "no-crp", help = "Skip the CRP generation")] no_crp: bool, + + #[arg(short, long = "input-validator", help = "The input validator address")] + input_validator: String } fn main() -> Result<(), Box> { @@ -32,8 +36,8 @@ fn main() -> Result<(), Box> { } let encoded = encode_bfv_params(args.moduli, args.degree, args.plaintext_modulus); - - for byte in encoded { + let abi_encoded = encode_e3_params(&encoded,Address::from_hex(args.input_validator)?); + for byte in abi_encoded { print!("{:02x}", byte); } diff --git a/packages/evm/contracts/test/MockE3Program.sol b/packages/evm/contracts/test/MockE3Program.sol index dfae54bf..27f7691a 100644 --- a/packages/evm/contracts/test/MockE3Program.sol +++ b/packages/evm/contracts/test/MockE3Program.sol @@ -20,11 +20,12 @@ contract MockE3Program is IE3Program { computeProviderParams.length == 32, invalidParams(e3ProgramParams, computeProviderParams) ); - (,inputValidator) = abi.decode( + (, IInputValidator _inputValidator) = abi.decode( e3ProgramParams, (bytes, IInputValidator) ); + inputValidator = _inputValidator; encryptionSchemeId = 0x0000000000000000000000000000000000000000000000000000000000000001; } diff --git a/packages/evm/test/Enclave.spec.ts b/packages/evm/test/Enclave.spec.ts index a68a9e79..2cf2a2f2 100644 --- a/packages/evm/test/Enclave.spec.ts +++ b/packages/evm/test/Enclave.spec.ts @@ -35,7 +35,7 @@ const proof = "0x1337"; // Hash function used to compute the tree nodes. const hash = (a: bigint, b: bigint) => poseidon2([a, b]); -describe("Enclave", function() { +describe("Enclave", function () { async function setup() { const [owner, notTheOwner] = await ethers.getSigners(); @@ -91,43 +91,43 @@ describe("Enclave", function() { }; } - describe("constructor / initialize()", function() { - it("correctly sets owner", async function() { + describe("constructor / initialize()", function () { + it("correctly sets owner", async function () { const { owner, enclave } = await loadFixture(setup); expect(await enclave.owner()).to.equal(owner.address); }); - it("correctly sets ciphernodeRegistry address", async function() { + it("correctly sets ciphernodeRegistry address", async function () { const { mocks, enclave } = await loadFixture(setup); expect(await enclave.ciphernodeRegistry()).to.equal( await mocks.registry.getAddress(), ); }); - it("correctly sets max duration", async function() { + it("correctly sets max duration", async function () { const { enclave } = await loadFixture(setup); expect(await enclave.maxDuration()).to.equal(60 * 60 * 24 * 30); }); }); - describe("setMaxDuration()", function() { - it("reverts if not called by owner", async function() { + describe("setMaxDuration()", function () { + it("reverts if not called by owner", async function () { const { enclave, notTheOwner } = await loadFixture(setup); await expect(enclave.connect(notTheOwner).setMaxDuration(1)) .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); - it("set max duration correctly", async function() { + it("set max duration correctly", async function () { const { enclave } = await loadFixture(setup); await enclave.setMaxDuration(1); expect(await enclave.maxDuration()).to.equal(1); }); - it("returns true if max duration is set successfully", async function() { + it("returns true if max duration is set successfully", async function () { const { enclave } = await loadFixture(setup); const result = await enclave.setMaxDuration.staticCall(1); expect(result).to.be.true; }); - it("emits MaxDurationSet event", async function() { + it("emits MaxDurationSet event", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.setMaxDuration(1)) .to.emit(enclave, "MaxDurationSet") @@ -135,8 +135,8 @@ describe("Enclave", function() { }); }); - describe("setCiphernodeRegistry()", function() { - it("reverts if not called by owner", async function() { + describe("setCiphernodeRegistry()", function () { + it("reverts if not called by owner", async function () { const { enclave, notTheOwner } = await loadFixture(setup); await expect( @@ -145,13 +145,13 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); - it("reverts if given address(0)", async function() { + it("reverts if given address(0)", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.setCiphernodeRegistry(ethers.ZeroAddress)) .to.be.revertedWithCustomError(enclave, "InvalidCiphernodeRegistry") .withArgs(ethers.ZeroAddress); }); - it("reverts if given address is the same as the current ciphernodeRegistry", async function() { + it("reverts if given address is the same as the current ciphernodeRegistry", async function () { const { enclave, mocks: { registry }, @@ -160,20 +160,20 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "InvalidCiphernodeRegistry") .withArgs(registry); }); - it("sets ciphernodeRegistry correctly", async function() { + it("sets ciphernodeRegistry correctly", async function () { const { enclave } = await loadFixture(setup); expect(await enclave.ciphernodeRegistry()).to.not.equal(AddressTwo); await enclave.setCiphernodeRegistry(AddressTwo); expect(await enclave.ciphernodeRegistry()).to.equal(AddressTwo); }); - it("returns true if ciphernodeRegistry is set successfully", async function() { + it("returns true if ciphernodeRegistry is set successfully", async function () { const { enclave } = await loadFixture(setup); const result = await enclave.setCiphernodeRegistry.staticCall(AddressTwo); expect(result).to.be.true; }); - it("emits CiphernodeRegistrySet event", async function() { + it("emits CiphernodeRegistrySet event", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.setCiphernodeRegistry(AddressTwo)) @@ -182,15 +182,15 @@ describe("Enclave", function() { }); }); - describe("getE3()", function() { - it("reverts if E3 does not exist", async function() { + describe("getE3()", function () { + it("reverts if E3 does not exist", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.getE3(1)) .to.be.revertedWithCustomError(enclave, "E3DoesNotExist") .withArgs(1); }); - it("returns correct E3 details", async function() { + it("returns correct E3 details", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( request.filter, @@ -220,14 +220,14 @@ describe("Enclave", function() { }); }); - describe("getDecryptionVerifier()", function() { - it("returns true if encryption scheme is enabled", async function() { + describe("getDecryptionVerifier()", function () { + it("returns true if encryption scheme is enabled", async function () { const { enclave, mocks } = await loadFixture(setup); expect(await enclave.getDecryptionVerifier(encryptionSchemeId)).to.equal( await mocks.decryptionVerifier.getAddress(), ); }); - it("returns false if encryption scheme is not enabled", async function() { + it("returns false if encryption scheme is not enabled", async function () { const { enclave } = await loadFixture(setup); expect( await enclave.getDecryptionVerifier(newEncryptionSchemeId), @@ -235,8 +235,8 @@ describe("Enclave", function() { }); }); - describe("setDecryptionVerifier()", function() { - it("reverts if caller is not owner", async function() { + describe("setDecryptionVerifier()", function () { + it("reverts if caller is not owner", async function () { const { enclave, notTheOwner, mocks } = await loadFixture(setup); await expect( @@ -250,7 +250,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); - it("reverts if encryption scheme is already enabled", async function() { + it("reverts if encryption scheme is already enabled", async function () { const { enclave, mocks } = await loadFixture(setup); await expect( @@ -262,7 +262,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "InvalidEncryptionScheme") .withArgs(encryptionSchemeId); }); - it("enabled decryption verifier", async function() { + it("enabled decryption verifier", async function () { const { enclave, mocks } = await loadFixture(setup); expect( @@ -275,7 +275,7 @@ describe("Enclave", function() { await enclave.getDecryptionVerifier(newEncryptionSchemeId), ).to.equal(await mocks.decryptionVerifier.getAddress()); }); - it("returns true if decryption verifier is enabled successfully", async function() { + it("returns true if decryption verifier is enabled successfully", async function () { const { enclave, mocks } = await loadFixture(setup); const result = await enclave.setDecryptionVerifier.staticCall( @@ -284,7 +284,7 @@ describe("Enclave", function() { ); expect(result).to.be.true; }); - it("emits EncryptionSchemeEnabled", async function() { + it("emits EncryptionSchemeEnabled", async function () { const { enclave, mocks } = await loadFixture(setup); await expect( @@ -298,8 +298,8 @@ describe("Enclave", function() { }); }); - describe("disableEncryptionScheme()", function() { - it("reverts if caller is not owner", async function() { + describe("disableEncryptionScheme()", function () { + it("reverts if caller is not owner", async function () { const { enclave, notTheOwner } = await loadFixture(setup); await expect( @@ -310,14 +310,14 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); - it("reverts if encryption scheme is not already enabled", async function() { + it("reverts if encryption scheme is not already enabled", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.disableEncryptionScheme(newEncryptionSchemeId)) .to.be.revertedWithCustomError(enclave, "InvalidEncryptionScheme") .withArgs(newEncryptionSchemeId); }); - it("disables encryption scheme", async function() { + it("disables encryption scheme", async function () { const { enclave } = await loadFixture(setup); expect(await enclave.disableEncryptionScheme(encryptionSchemeId)); @@ -325,14 +325,14 @@ describe("Enclave", function() { ethers.ZeroAddress, ); }); - it("returns true if encryption scheme is disabled successfully", async function() { + it("returns true if encryption scheme is disabled successfully", async function () { const { enclave } = await loadFixture(setup); const result = await enclave.disableEncryptionScheme.staticCall(encryptionSchemeId); expect(result).to.be.true; }); - it("emits EncryptionSchemeDisabled", async function() { + it("emits EncryptionSchemeDisabled", async function () { const { enclave } = await loadFixture(setup); await expect(await enclave.disableEncryptionScheme(encryptionSchemeId)) @@ -341,8 +341,8 @@ describe("Enclave", function() { }); }); - describe("enableE3Program()", function() { - it("reverts if not called by owner", async function() { + describe("enableE3Program()", function () { + it("reverts if not called by owner", async function () { const { notTheOwner, enclave, @@ -353,7 +353,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); - it("reverts if E3 Program is already enabled", async function() { + it("reverts if E3 Program is already enabled", async function () { const { enclave, mocks: { e3Program }, @@ -363,7 +363,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "ModuleAlreadyEnabled") .withArgs(e3Program); }); - it("enables E3 Program correctly", async function() { + it("enables E3 Program correctly", async function () { const { enclave, mocks: { e3Program }, @@ -371,12 +371,12 @@ describe("Enclave", function() { const enabled = await enclave.e3Programs(e3Program); expect(enabled).to.be.true; }); - it("returns true if E3 Program is enabled successfully", async function() { + it("returns true if E3 Program is enabled successfully", async function () { const { enclave } = await loadFixture(setup); const result = await enclave.enableE3Program.staticCall(AddressTwo); expect(result).to.be.true; }); - it("emits E3ProgramEnabled event", async function() { + it("emits E3ProgramEnabled event", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.enableE3Program(AddressTwo)) .to.emit(enclave, "E3ProgramEnabled") @@ -384,8 +384,8 @@ describe("Enclave", function() { }); }); - describe("disableE3Program()", function() { - it("reverts if not called by owner", async function() { + describe("disableE3Program()", function () { + it("reverts if not called by owner", async function () { const { notTheOwner, enclave, @@ -395,13 +395,13 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "OwnableUnauthorizedAccount") .withArgs(notTheOwner); }); - it("reverts if E3 Program is not enabled", async function() { + it("reverts if E3 Program is not enabled", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.disableE3Program(AddressTwo)) .to.be.revertedWithCustomError(enclave, "ModuleNotEnabled") .withArgs(AddressTwo); }); - it("disables E3 Program correctly", async function() { + it("disables E3 Program correctly", async function () { const { enclave, mocks: { e3Program }, @@ -411,7 +411,7 @@ describe("Enclave", function() { const enabled = await enclave.e3Programs(e3Program); expect(enabled).to.be.false; }); - it("returns true if E3 Program is disabled successfully", async function() { + it("returns true if E3 Program is disabled successfully", async function () { const { enclave, mocks: { e3Program }, @@ -420,7 +420,7 @@ describe("Enclave", function() { expect(result).to.be.true; }); - it("emits E3ProgramDisabled event", async function() { + it("emits E3ProgramDisabled event", async function () { const { enclave, mocks: { e3Program }, @@ -431,8 +431,8 @@ describe("Enclave", function() { }); }); - describe("request()", function() { - it("reverts if msg.value is 0", async function() { + describe("request()", function () { + it("reverts if msg.value is 0", async function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( @@ -446,7 +446,7 @@ describe("Enclave", function() { ), ).to.be.revertedWithCustomError(enclave, "PaymentRequired"); }); - it("reverts if threshold is 0", async function() { + it("reverts if threshold is 0", async function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( @@ -461,7 +461,7 @@ describe("Enclave", function() { ), ).to.be.revertedWithCustomError(enclave, "InvalidThreshold"); }); - it("reverts if threshold is greater than number", async function() { + it("reverts if threshold is greater than number", async function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( @@ -476,7 +476,7 @@ describe("Enclave", function() { ), ).to.be.revertedWithCustomError(enclave, "InvalidThreshold"); }); - it("reverts if duration is 0", async function() { + it("reverts if duration is 0", async function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( @@ -491,7 +491,7 @@ describe("Enclave", function() { ), ).to.be.revertedWithCustomError(enclave, "InvalidDuration"); }); - it("reverts if duration is greater than maxDuration", async function() { + it("reverts if duration is greater than maxDuration", async function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( @@ -506,7 +506,7 @@ describe("Enclave", function() { ), ).to.be.revertedWithCustomError(enclave, "InvalidDuration"); }); - it("reverts if E3 Program is not enabled", async function() { + it("reverts if E3 Program is not enabled", async function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( @@ -523,7 +523,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "E3ProgramNotAllowed") .withArgs(ethers.ZeroAddress); }); - it("reverts if given encryption scheme is not enabled", async function() { + it("reverts if given encryption scheme is not enabled", async function () { const { enclave, request } = await loadFixture(setup); await enclave.disableEncryptionScheme(encryptionSchemeId); await expect( @@ -541,7 +541,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "InvalidEncryptionScheme") .withArgs(encryptionSchemeId); }); - it("reverts if given E3 Program does not return input validator address", async function() { + it("reverts if given E3 Program does not return input validator address", async function () { const { enclave, request } = await loadFixture(setup); await expect( @@ -557,7 +557,7 @@ describe("Enclave", function() { ), ).to.be.revertedWithCustomError(enclave, "InvalidComputationRequest"); }); - it("reverts if committee selection fails", async function() { + it("reverts if committee selection fails", async function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( @@ -572,7 +572,7 @@ describe("Enclave", function() { ), ).to.be.revertedWithCustomError(enclave, "CommitteeSelectionFailed"); }); - it("instantiates a new E3", async function() { + it("instantiates a new E3", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( request.filter, @@ -590,7 +590,7 @@ describe("Enclave", function() { expect(e3.expiration).to.equal(0n); expect(e3.e3Program).to.equal(request.e3Program); expect(e3.inputValidator).to.equal( - abiCoder.decode(["bytes","address"], request.e3ProgramParams)[1], + abiCoder.decode(["bytes", "address"], request.e3ProgramParams)[1], ); expect(e3.decryptionVerifier).to.equal( abiCoder.decode(["address"], request.computeProviderParams)[0], @@ -599,7 +599,7 @@ describe("Enclave", function() { expect(e3.ciphertextOutput).to.equal(ethers.ZeroHash); expect(e3.plaintextOutput).to.equal(ethers.ZeroHash); }); - it("emits E3Requested event", async function() { + it("emits E3Requested event", async function () { const { enclave, request } = await loadFixture(setup); const tx = await enclave.request( request.filter, @@ -619,15 +619,15 @@ describe("Enclave", function() { }); }); - describe("activate()", function() { - it("reverts if E3 does not exist", async function() { + describe("activate()", function () { + it("reverts if E3 does not exist", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.activate(0)) .to.be.revertedWithCustomError(enclave, "E3DoesNotExist") .withArgs(0); }); - it("reverts if E3 has already been activated", async function() { + it("reverts if E3 has already been activated", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( @@ -647,7 +647,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "E3AlreadyActivated") .withArgs(0); }); - it("reverts if E3 is not yet ready to start", async function() { + it("reverts if E3 is not yet ready to start", async function () { const { enclave, request } = await loadFixture(setup); const startTime = [ (await time.latest()) + 1000, @@ -670,7 +670,7 @@ describe("Enclave", function() { "E3NotReady", ); }); - it("reverts if E3 start has expired", async function() { + it("reverts if E3 start has expired", async function () { const { enclave, request } = await loadFixture(setup); const startTime = [ (await time.latest()) + 1, @@ -695,7 +695,7 @@ describe("Enclave", function() { "E3Expired", ); }); - it("reverts if ciphernodeRegistry does not return a public key", async function() { + it("reverts if ciphernodeRegistry does not return a public key", async function () { const { enclave, request } = await loadFixture(setup); const startTime = [ (await time.latest()) + 1000, @@ -718,7 +718,7 @@ describe("Enclave", function() { "E3NotReady", ); }); - it("reverts if E3 start has expired", async function() { + it("reverts if E3 start has expired", async function () { const { enclave, request } = await loadFixture(setup); const startTime = [await time.latest(), (await time.latest()) + 1] as [ number, @@ -743,7 +743,7 @@ describe("Enclave", function() { "E3Expired", ); }); - it("reverts if ciphernodeRegistry does not return a public key", async function() { + it("reverts if ciphernodeRegistry does not return a public key", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( @@ -841,8 +841,8 @@ describe("Enclave", function() { }); }); - describe("publishInput()", function() { - it("reverts if E3 does not exist", async function() { + describe("publishInput()", function () { + it("reverts if E3 does not exist", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.publishInput(0, "0x")) @@ -850,7 +850,7 @@ describe("Enclave", function() { .withArgs(0); }); - it("reverts if E3 has not been activated", async function() { + it("reverts if E3 has not been activated", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( @@ -874,7 +874,7 @@ describe("Enclave", function() { await enclave.activate(0); }); - it("reverts if input is not valid", async function() { + it("reverts if input is not valid", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( @@ -894,7 +894,7 @@ describe("Enclave", function() { ).to.be.revertedWithCustomError(enclave, "InvalidInput"); }); - it("reverts if outside of input window", async function() { + it("reverts if outside of input window", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( @@ -916,7 +916,7 @@ describe("Enclave", function() { enclave.publishInput(0, ZeroHash), ).to.be.revertedWithCustomError(enclave, "InputDeadlinePassed"); }); - it("returns true if input is published successfully", async function() { + it("returns true if input is published successfully", async function () { const { enclave, request } = await loadFixture(setup); const inputData = "0x12345678"; @@ -938,7 +938,7 @@ describe("Enclave", function() { ); }); - it("adds inputHash to merkle tree", async function() { + it("adds inputHash to merkle tree", async function () { const { enclave, request } = await loadFixture(setup); const inputData = abiCoder.encode(["bytes"], ["0xaabbccddeeff"]); @@ -970,7 +970,7 @@ describe("Enclave", function() { await enclave.publishInput(e3Id, secondInputData); expect(await enclave.getInputRoot(e3Id)).to.equal(tree.root); }); - it("emits InputPublished event", async function() { + it("emits InputPublished event", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( @@ -996,15 +996,15 @@ describe("Enclave", function() { }); }); - describe("publishCiphertextOutput()", function() { - it("reverts if E3 does not exist", async function() { + describe("publishCiphertextOutput()", function () { + it("reverts if E3 does not exist", async function () { const { enclave } = await loadFixture(setup); await expect(enclave.publishCiphertextOutput(0, "0x", "0x")) .to.be.revertedWithCustomError(enclave, "E3DoesNotExist") .withArgs(0); }); - it("reverts if E3 has not been activated", async function() { + it("reverts if E3 has not been activated", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1022,7 +1022,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "E3NotActivated") .withArgs(e3Id); }); - it("reverts if input deadline has not passed", async function() { + it("reverts if input deadline has not passed", async function () { const { enclave, request } = await loadFixture(setup); const tx = await enclave.request( request.filter, @@ -1045,7 +1045,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "InputDeadlineNotPassed") .withArgs(e3Id, expectedExpiration); }); - it("reverts if output has already been published", async function() { + it("reverts if output has already been published", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1069,7 +1069,7 @@ describe("Enclave", function() { ) .withArgs(e3Id); }); - it("reverts if output is not valid", async function() { + it("reverts if output is not valid", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1089,7 +1089,7 @@ describe("Enclave", function() { enclave.publishCiphertextOutput(e3Id, "0x", "0x"), ).to.be.revertedWithCustomError(enclave, "InvalidOutput"); }); - it("sets ciphertextOutput correctly", async function() { + it("sets ciphertextOutput correctly", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1109,7 +1109,7 @@ describe("Enclave", function() { const e3 = await enclave.getE3(e3Id); expect(e3.ciphertextOutput).to.equal(dataHash); }); - it("returns true if output is published successfully", async function() { + it("returns true if output is published successfully", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1129,7 +1129,7 @@ describe("Enclave", function() { await enclave.publishCiphertextOutput.staticCall(e3Id, data, proof), ).to.equal(true); }); - it("emits CiphertextOutputPublished event", async function() { + it("emits CiphertextOutputPublished event", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1151,8 +1151,8 @@ describe("Enclave", function() { }); }); - describe("publishPlaintextOutput()", function() { - it("reverts if E3 does not exist", async function() { + describe("publishPlaintextOutput()", function () { + it("reverts if E3 does not exist", async function () { const { enclave } = await loadFixture(setup); const e3Id = 0; @@ -1160,7 +1160,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "E3DoesNotExist") .withArgs(e3Id); }); - it("reverts if E3 has not been activated", async function() { + it("reverts if E3 has not been activated", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1178,7 +1178,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "E3NotActivated") .withArgs(e3Id); }); - it("reverts if ciphertextOutput has not been published", async function() { + it("reverts if ciphertextOutput has not been published", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1197,7 +1197,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "CiphertextOutputNotPublished") .withArgs(e3Id); }); - it("reverts if plaintextOutput has already been published", async function() { + it("reverts if plaintextOutput has already been published", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1222,7 +1222,7 @@ describe("Enclave", function() { ) .withArgs(e3Id); }); - it("reverts if output is not valid", async function() { + it("reverts if output is not valid", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1243,7 +1243,7 @@ describe("Enclave", function() { .to.be.revertedWithCustomError(enclave, "InvalidOutput") .withArgs(data); }); - it("sets plaintextOutput correctly", async function() { + it("sets plaintextOutput correctly", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1265,7 +1265,7 @@ describe("Enclave", function() { const e3 = await enclave.getE3(e3Id); expect(e3.plaintextOutput).to.equal(dataHash); }); - it("returns true if output is published successfully", async function() { + it("returns true if output is published successfully", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; @@ -1286,7 +1286,7 @@ describe("Enclave", function() { await enclave.publishPlaintextOutput.staticCall(e3Id, data, proof), ).to.equal(true); }); - it("emits PlaintextOutputPublished event", async function() { + it("emits PlaintextOutputPublished event", async function () { const { enclave, request } = await loadFixture(setup); const e3Id = 0; diff --git a/tests/basic_integration/lib/encode_e3_params.mjs b/tests/basic_integration/lib/encode_e3_params.mjs index 5f7d7e90..0dc8adf9 100755 --- a/tests/basic_integration/lib/encode_e3_params.mjs +++ b/tests/basic_integration/lib/encode_e3_params.mjs @@ -1,6 +1,6 @@ #!/usr/bin/env node -import { AbiCoder } from "ethers"; +import { AbiCoder, solidityPacked } from "ethers"; import { Command } from "commander"; const program = new Command(); @@ -13,11 +13,16 @@ program .requiredOption("--bfv-params ", "BFV scheme parameters") .action((options) => { const abiCoder = new AbiCoder(); + const out = abiCoder.encode( ["bytes", "address"], - [options.bfvParams, options.inputValidator], + [ + options.bfvParams, + options.inputValidator, + ], ); + console.log(out); }); -program.parse(process.argv) +program.parse(process.argv); diff --git a/tests/basic_integration/lib/bfvgen.sh b/tests/basic_integration/lib/pack_e3_params.sh similarity index 76% rename from tests/basic_integration/lib/bfvgen.sh rename to tests/basic_integration/lib/pack_e3_params.sh index ff62f9e9..78502e2e 100755 --- a/tests/basic_integration/lib/bfvgen.sh +++ b/tests/basic_integration/lib/pack_e3_params.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -cd packages/ciphernode && RUSTFLAGS="-A warnings" cargo run --bin bfvgen -- "$@" +cd packages/ciphernode && RUSTFLAGS="-A warnings" cargo run --bin pack_e3_params -- "$@" diff --git a/tests/basic_integration/output/encoded_params.hex b/tests/basic_integration/output/encoded_params.hex new file mode 100644 index 00000000..8ff477d7 --- /dev/null +++ b/tests/basic_integration/output/encoded_params.hex @@ -0,0 +1 @@ +0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000008a791620dd6260079bf849dc5567adc3f2fdc31800000000000000000000000000000000000000000000000000000000000000130880101208818080f8ffffff1f1881803f200a00000000000000000000000000 diff --git a/tests/basic_integration/test.sh b/tests/basic_integration/test.sh index bc4811e0..6fde6f5e 100755 --- a/tests/basic_integration/test.sh +++ b/tests/basic_integration/test.sh @@ -122,10 +122,7 @@ yarn ciphernode:add --ciphernode-address $CIPHERNODE_ADDRESS_4 --network localho heading "Request Committee" -PARAMS=0x$($SCRIPT_DIR/lib/bfvgen.sh --moduli 0x3FFFFFFF000001 --degree 2048 --plaintext-modulus 1032193) - - -ENCODED_PARAMS=$($SCRIPT_DIR/lib/encode_e3_params.mjs --input-validator $INPUT_VALIDATOR_CONTRACT --bfv-params $PARAMS) +ENCODED_PARAMS=0x$($SCRIPT_DIR/lib/pack_e3_params.sh --moduli 0x3FFFFFFF000001 --degree 2048 --plaintext-modulus 1032193 --input-validator "$INPUT_VALIDATOR_CONTRACT") yarn committee:new --network localhost --duration 4 --e3-params "$ENCODED_PARAMS"