Skip to content

Commit

Permalink
minimal bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Feb 7, 2024
1 parent 6d99ff2 commit b11f7f7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 152 deletions.
16 changes: 16 additions & 0 deletions contracts/A.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.20;

import "fhevm/lib/TFHE.sol";

Check warning on line 5 in contracts/A.sol

View workflow job for this annotation

GitHub Actions / ci

global import of path fhevm/lib/TFHE.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

contract A {

Check failure on line 8 in contracts/A.sol

View workflow job for this annotation

GitHub Actions / ci

Delete ⏎
constructor() {}

Check warning on line 9 in contracts/A.sol

View workflow job for this annotation

GitHub Actions / ci

Code contains empty blocks

function requestDecryption(euint32 ct) external {
require(TFHE.isInitialized(ct), "Ciphertext is not initialized");

Check warning on line 12 in contracts/A.sol

View workflow job for this annotation

GitHub Actions / ci

Use Custom Errors instead of require statements
euint32 ct_r = TFHE.shl(ct, 0);

Check warning on line 13 in contracts/A.sol

View workflow job for this annotation

GitHub Actions / ci

Variable name must be in mixedCase

Check warning on line 13 in contracts/A.sol

View workflow job for this annotation

GitHub Actions / ci

Variable "ct_r" is unused
}

Check failure on line 14 in contracts/A.sol

View workflow job for this annotation

GitHub Actions / ci

Delete ⏎

}
21 changes: 21 additions & 0 deletions contracts/B.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.20;

import "fhevm/lib/TFHE.sol";

Check warning on line 5 in contracts/B.sol

View workflow job for this annotation

GitHub Actions / ci

global import of path fhevm/lib/TFHE.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import "./A.sol";

Check warning on line 6 in contracts/B.sol

View workflow job for this annotation

GitHub Actions / ci

global import of path ./A.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

contract B {
euint32 x;

Check warning on line 9 in contracts/B.sol

View workflow job for this annotation

GitHub Actions / ci

Explicitly mark visibility of state
A a;

Check warning on line 10 in contracts/B.sol

View workflow job for this annotation

GitHub Actions / ci

Explicitly mark visibility of state

constructor(address _a) {
a = A(_a);
x = TFHE.asEuint32(32);
}

function request() public {
a.requestDecryption(x);
}

Check failure on line 20 in contracts/B.sol

View workflow job for this annotation

GitHub Actions / ci

Delete ⏎
}
93 changes: 0 additions & 93 deletions contracts/Oracle.sol

This file was deleted.

35 changes: 0 additions & 35 deletions contracts/TestAsyncDecrypt.sol

This file was deleted.

35 changes: 11 additions & 24 deletions test/testAsyncDecrypt/testAsyncDecrypt.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
import { expect } from "chai";
import { ethers } from "hardhat";

import { createInstances } from "../instance";
import { getSigners, initSigners } from "../signers";

describe("TestAsyncDecrypt", function () {
describe("Test", function () {
before(async function () {
await initSigners();
this.signers = await getSigners();
});

beforeEach(async function () {
const oracleFactory = await ethers.getContractFactory("Oracle");
this.oracle = await oracleFactory.connect(this.signers.alice).deploy(); // Alice is the Oracle Admin
await this.oracle.waitForDeployment();

const tx1 = await this.oracle.addRelayer(this.signers.bob); // Bob is an Oracle Relayer
await tx1.wait();
const aFactory = await ethers.getContractFactory("A");
this.a = await aFactory.connect(this.signers.alice).deploy(); // Alice is the Oracle Admin
await this.a.waitForDeployment();

const oracleAddress = await this.oracle.getAddress();
const contractFactory = await ethers.getContractFactory("TestAsyncDecrypt");
this.contract = await contractFactory.connect(this.signers.alice).deploy(oracleAddress);
const aAddress = await this.a.getAddress();
const bFactory = await ethers.getContractFactory("B");
this.b = await bFactory.connect(this.signers.alice).deploy(aAddress);
});

it("test async decrypt", async function () {
const tx2 = await this.contract.connect(this.signers.carol).request(5, 15);
await tx2.wait();

const filter = this.oracle.filters.EventDecryption;
const events = await this.oracle.queryFilter(filter, -1);
const event = events[0];

const args = event.args;
console.log(args);
it("test b", async function () {
const tx = await this.b.connect(this.signers.carol).request();
await tx.wait();
});
});
});

0 comments on commit b11f7f7

Please sign in to comment.