Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev() Add hardhat framework to compile and test contracts #63

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Main

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run test
- run: npm run build
17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm ci
- run: npm run build
- uses: JS-DevTools/npm-publish@0f451a94170d1699fd50710966d48fb26194d939
with:
token: ${{ secrets.NPM_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: PR test

on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run test
- run: npm run build
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ res/
node_modules/
.venv
.vscode

node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

19 changes: 17 additions & 2 deletions examples/BlindAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ contract BlindAuction is EIP712WithModifier {
onlySignedPublicKey(publicKey, signature)
returns (bytes memory)
{
return TFHE.reencrypt(bids[msg.sender], publicKey);
if (TFHE.isInitialized(bids[msg.sender])) {
return TFHE.reencrypt(bids[msg.sender], publicKey);
} else {
return TFHE.reencrypt(TFHE.asEuint32(0), publicKey);
}
}

// Returns the user bid
Expand All @@ -119,7 +123,18 @@ contract BlindAuction is EIP712WithModifier {
onlySignedPublicKey(publicKey, signature)
returns (bytes memory)
{
return TFHE.reencrypt(TFHE.le(highestBid, bids[msg.sender]), publicKey);
if (
TFHE.isInitialized(highestBid) &&
TFHE.isInitialized(bids[msg.sender])
) {
return
TFHE.reencrypt(
TFHE.le(highestBid, bids[msg.sender]),
publicKey
);
} else {
return TFHE.reencrypt(TFHE.asEuint32(0), publicKey);
}
}

// Claim the object. Succeeds only if the caller has the highest bid.
Expand Down
21 changes: 16 additions & 5 deletions examples/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract EncryptedERC20 is EIP712WithModifier {
// Sets the balance of the owner to the given encrypted balance.
function mint(bytes calldata encryptedAmount) public onlyContractOwner {
euint32 amount = TFHE.asEuint32(encryptedAmount);
balances[contractOwner] = amount;
balances[contractOwner] = TFHE.add(balances[contractOwner], amount);
totalSupply = TFHE.add(totalSupply, amount);
}

Expand All @@ -51,11 +51,14 @@ contract EncryptedERC20 is EIP712WithModifier {
)
public
view
onlyContractOwner
onlySignedPublicKey(publicKey, signature)
returns (bytes memory)
{
return TFHE.reencrypt(totalSupply, publicKey);
if (TFHE.isInitialized(totalSupply)) {
return TFHE.reencrypt(totalSupply, publicKey);
} else {
return TFHE.reencrypt(TFHE.asEuint32(0), publicKey);
}
}

// Returns the balance of the caller encrypted under the provided public key.
Expand All @@ -68,7 +71,11 @@ contract EncryptedERC20 is EIP712WithModifier {
onlySignedPublicKey(publicKey, signature)
returns (bytes memory)
{
return TFHE.reencrypt(balances[msg.sender], publicKey);
if (TFHE.isInitialized(balances[msg.sender])) {
return TFHE.reencrypt(balances[msg.sender], publicKey);
} else {
return TFHE.reencrypt(TFHE.asEuint32(0), publicKey);
}
}

// Sets the `encryptedAmount` as the allowance of `spender` over the caller's tokens.
Expand Down Expand Up @@ -118,7 +125,11 @@ contract EncryptedERC20 is EIP712WithModifier {
address owner,
address spender
) internal view returns (euint32) {
return allowances[owner][spender];
if (TFHE.isInitialized(allowances[owner][spender])) {
return allowances[owner][spender];
} else {
return TFHE.asEuint32(0);
}
}

function _updateAllowance(
Expand Down
11 changes: 11 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
solidity: "0.8.18",
paths: {
sources: "./examples",
},
};

export default config;
Loading