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

Remove Gundb and generate MACI key from wallet signature #615

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
72d2b50
refactor maci utility functions and bump ethers.js version
yuetloo Oct 19, 2022
3480d9a
fix hardhat error by bumping node version
yuetloo Oct 20, 2022
fbd3599
update Poseidon contract location
yuetloo Oct 20, 2022
8f85cdf
generate contributor encryption key using contributor signature hash
yuetloo Oct 26, 2022
f480934
fix linting warning
yuetloo Oct 26, 2022
1826c8a
subgraph schema change
yuetloo Oct 26, 2022
0ea2d5b
fix contract test case failures
yuetloo Oct 28, 2022
c8daaca
fix build error with contract
yuetloo Oct 28, 2022
ae00295
deploy Poseidon contracts with the correct bytecode
yuetloo Nov 3, 2022
465ad3b
remove unused variables
yuetloo Nov 3, 2022
63e6ec3
revert voice credit factor changes
yuetloo Nov 3, 2022
b223da9
Merge remote-tracking branch 'origin/develop' into deterministic-key
yuetloo Jan 13, 2023
7d2221f
merged with the develop branch
yuetloo Jan 13, 2023
90788b9
remove gundb
yuetloo Jan 16, 2023
9ef2caf
fix incorrect contribution amount when there are more than 1 round
yuetloo Jan 17, 2023
842bab4
add missing project index
yuetloo Jan 17, 2023
652ceff
filter messages by funding round and contributor address
yuetloo Jan 18, 2023
78e0bf7
simplify code
yuetloo Jan 18, 2023
ccc6037
upgrade subgraph
yuetloo Jan 18, 2023
3f03747
remove warning
yuetloo Jan 18, 2023
219e269
change login message to use round address
yuetloo Jan 18, 2023
32b741b
remove unused import
yuetloo Jan 18, 2023
bbd02ae
fix missing key for reallocation and code cleanup
yuetloo Jan 18, 2023
b94cef5
upgrade vue-app to typescript 4
yuetloo Jan 19, 2023
73f5a67
update github script for better testing
yuetloo Jan 19, 2023
9323c2b
fix trigger
yuetloo Jan 19, 2023
789cb8f
handle lost key scenario
yuetloo Jan 19, 2023
3a0d726
code cleanup and change new key generation logic
yuetloo Jan 23, 2023
8f08260
remove unused library
yuetloo Jan 23, 2023
01f5703
upgrade to typescript 4.1.2
yuetloo Jan 23, 2023
e676dfe
disable eslint error on BigInt
yuetloo Jan 23, 2023
67545b8
update specVersion
yuetloo Jan 23, 2023
0fb0a5c
update version to 0.0.4
yuetloo Jan 23, 2023
5a03c8f
Merge remote-tracking branch 'origin/develop' into deterministic-key
yuetloo Jan 23, 2023
bad351b
rework the logic to find key changes and use ethers.js sha256 for con…
yuetloo Jan 24, 2023
a999e78
missing await
yuetloo Jan 24, 2023
b05b846
upload the tally file before finalize so we have it if finalize fails
yuetloo Jan 24, 2023
1dee70d
refactor key lookup logic
yuetloo Jan 24, 2023
cd9bcc6
add set-duration task
yuetloo Feb 27, 2023
eeacb62
use passkey to generate MACI key
yuetloo Mar 1, 2023
d178065
add missing component
yuetloo Mar 1, 2023
2c601b6
remove console log debug statements
yuetloo Mar 1, 2023
7013a9f
fix unused variables warnings
yuetloo Mar 1, 2023
16cf838
merge with maci-0.10.2 branch
yuetloo Mar 11, 2023
9e31696
Merge remote-tracking branch 'origin/develop' into deterministic-key
yuetloo Mar 13, 2023
4bcd660
Merge remote-tracking branch 'origin/develop' into deterministic-key
yuetloo Mar 13, 2023
1d9f4b9
remove unused import
yuetloo Mar 13, 2023
f00d227
Merge remote-tracking branch 'origin/develop' into deterministic-key
yuetloo Mar 13, 2023
99fac9c
missing comma
yuetloo Mar 15, 2023
9f20846
find the valid public key from subgraph when creating from existing key
yuetloo Mar 15, 2023
c9aad4c
add usage to passkey modal
yuetloo Mar 15, 2023
4b85159
show passkey modal with description
yuetloo Mar 15, 2023
f4c54c0
fix missing locale key
yuetloo Mar 15, 2023
3e43692
show empty cart instead of spinning
yuetloo Mar 15, 2023
ffcc7df
guide for testing the clrfund app
yuetloo Mar 15, 2023
dffb4e0
rename variables
yuetloo Mar 15, 2023
0e355af
fix up documentation
yuetloo Mar 15, 2023
70641f2
merged with develop branch
yuetloo Mar 21, 2023
b7b2400
add sequence diagram for passkey creation and retrieval flow
yuetloo Mar 29, 2023
ac4fd16
add line breaks and reformatting
yuetloo Mar 29, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/finalize-round.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:
NETWORK: "arbitrum-goerli"
COORDINATOR_ETH_PK: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_WALLET_PRIVATE_KEY }}
COORDINATOR_PK: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_MACI_PRIVATE_KEY }}
JSONRPC_HTTP_URL: ${{ secrets.JSONRPC_HTTP_URL }}

jobs:
finalize:
Expand Down Expand Up @@ -46,7 +47,7 @@ jobs:
# tally and finalize
cd contracts
yarn hardhat run --network "${NETWORK}" scripts/tally.ts
yarn hardhat run --network "${NETWORK}" scripts/finalize.ts
curl --location --request POST 'https://api.pinata.cloud/pinning/pinFileToIPFS' \
--header "Authorization: Bearer ${{ secrets.PINATA_JWT }}" \
--form 'file=@"tally.json"'
JSONRPC_HTTP_URL=${{env.JSONRPC_HTTP_URL}} yarn hardhat run --network "${NETWORK}" scripts/finalize.ts
1 change: 1 addition & 0 deletions .github/workflows/test-scripts.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Hardhat script tests

on:
workflow_dispatch:
push:
paths:
- 'contracts/scripts/**'
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ to run `yarn test` or `yarn test:contracts`.
- [Vuelidate](https://vuelidate-next.netlify.app/)
- [Vue js modal](http://vue-js-modal.yev.io/)
- [Ethers](https://docs.ethers.io/v5/)
- [Gun](https://gun.eco/docs/)

### Visual Studio Code

Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/FundingRound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract FundingRound is Ownable, MACISharedObjs, SignUpGatekeeper, InitialVoice
using SafeERC20 for ERC20;

// Constants
uint256 private constant MAX_VOICE_CREDITS = 10 ** 9; // MACI allows 2 ** 32 voice credits max
uint256 private constant MAX_VOICE_CREDITS = 10 ** 9; // MACI allows 2 ** 32 voice credits max
uint256 private constant MAX_CONTRIBUTION_AMOUNT = 10 ** 4; // In tokens
uint256 private constant ALPHA_PRECISION = 10 ** 18; // to account for loss of precision in division
uint8 private constant LEAVES_PER_NODE = 5; // leaves per node of the tally result tree
Expand Down
94 changes: 77 additions & 17 deletions contracts/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import { use, expect } from 'chai'
import { solidity } from 'ethereum-waffle'
import { BigNumber, Contract, Signer, Wallet } from 'ethers'
import { genProofs, proveOnChain } from 'maci-cli'
import { Keypair } from 'maci-domainobjs'
import { Keypair, createMessage, Message, PubKey } from '@clrfund/maci-utils'

import { UNIT } from '../utils/constants'
import { getEventArg } from '../utils/contracts'
import {
deployContract,
deployMaciFactory,
deployPoseidon,
CIRCUITS,
} from '../utils/deployment'
import { getIpfsHash } from '../utils/ipfs'
import {
MaciParameters,
createMessage,
addTallyResultsBatch,
getRecipientClaimData,
} from '../utils/maci'
import { CIRCUITS } from '../utils/deployment'
import { sha256 } from 'ethers/lib/utils'

use(solidity)

Expand Down Expand Up @@ -296,8 +296,8 @@ describe('End-to-end Tests', function () {
// Submit messages
for (const contribution of contributions) {
const contributor = contribution.signer
const messages = []
const encPubKeys = []
const messages: Message[] = []
const encPubKeys: PubKey[] = []
let nonce = 1

// Change key
Expand Down Expand Up @@ -346,6 +346,66 @@ describe('End-to-end Tests', function () {
expect(claims[2]).to.equal(UNIT.mul(58).div(10))
})

it('should allocate funds correctly when users change keys using signature hash', async () => {
const contributions = await makeContributions([
UNIT.mul(8).div(10),
UNIT.mul(8).div(10),
])
// Submit messages
for (const contribution of contributions) {
const contributor = contribution.signer
const messages: Message[] = []
const encPubKeys: PubKey[] = []
let nonce = 1

// Change key
const signature = await contributor.signMessage('hello world')
const hash = sha256(signature)
const newContributorKeypair = Keypair.createFromSignatureHash(hash, 1)
const [message, encPubKey] = createMessage(
contribution.stateIndex,
contribution.keypair,
newContributorKeypair,
coordinatorKeypair.pubKey,
null,
null,
nonce
)
messages.push(message)
encPubKeys.push(encPubKey)
nonce += 1

// Spend voice credits on both recipients
for (const recipientIndex of [1, 2]) {
const voiceCredits = contribution.voiceCredits.div(2)
const [message, encPubKey] = createMessage(
contribution.stateIndex,
newContributorKeypair,
null,
coordinatorKeypair.pubKey,
recipientIndex,
voiceCredits,
nonce
)
messages.push(message)
encPubKeys.push(encPubKey)
nonce += 1
}

await fundingRound.connect(contributor).submitMessageBatch(
messages.reverse().map((msg) => msg.asContractParam()),
encPubKeys.reverse().map((key) => key.asContractParam())
)
}

await provider.send('evm_increaseTime', [maciParameters.signUpDuration])
await provider.send('evm_increaseTime', [maciParameters.votingDuration])
const { tally, claims } = await finalizeRound()
expect(tally.totalVoiceCredits.spent).to.equal('160000')
expect(claims[1]).to.equal(UNIT.mul(58).div(10))
expect(claims[2]).to.equal(UNIT.mul(58).div(10))
})

it('should allocate funds correctly if not all voice credits are spent', async () => {
const contributions = await makeContributions([
UNIT.mul(8).div(10),
Expand All @@ -357,8 +417,8 @@ describe('End-to-end Tests', function () {
const contributor = contribution.signer
const voiceCredits = contribution.voiceCredits.div(4)
let nonce = 1
const messages = []
const encPubKeys = []
const messages: Message[] = []
const encPubKeys: PubKey[] = []

for (const recipientIndex of [1, 2]) {
const [message, encPubKey] = createMessage(
Expand Down Expand Up @@ -399,8 +459,8 @@ describe('End-to-end Tests', function () {
[2, contribution.voiceCredits.div(2)],
[1, contribution.voiceCredits.div(2)],
]
const messages = []
const encPubKeys = []
const messages: Message[] = []
const encPubKeys: PubKey[] = []
let nonce = 1
for (const [recipientIndex, voiceCredits] of votes) {
const [message, encPubKey] = createMessage(
Expand Down Expand Up @@ -458,8 +518,8 @@ describe('End-to-end Tests', function () {
[1, ZERO],
[2, contribution.voiceCredits],
]
const messages = []
const encPubKeys = []
const messages: Message[] = []
const encPubKeys: PubKey[] = []
let nonce = 1
for (const [recipientIndex, voiceCredits] of votes) {
const [message, encPubKey] = createMessage(
Expand Down Expand Up @@ -526,8 +586,8 @@ describe('End-to-end Tests', function () {
],
]
for (const batch of votes) {
const messages = []
const encPubKeys = []
const messages: Message[] = []
const encPubKeys: PubKey[] = []
let nonce = 1
for (const [recipientIndex, voiceCredits] of batch) {
const [message, encPubKey] = createMessage(
Expand Down Expand Up @@ -587,8 +647,8 @@ describe('End-to-end Tests', function () {
let encPubKey

// Vote for recipient 1 for a bribe immediately after signup
const messageBatch1 = []
const encPubKeyBatch1 = []
const messageBatch1: Message[] = []
const encPubKeyBatch1: PubKey[] = []
;[message, encPubKey] = createMessage(
contribution.stateIndex,
contribution.keypair,
Expand Down Expand Up @@ -619,8 +679,8 @@ describe('End-to-end Tests', function () {

// Wait for signup period to end to override votes
await provider.send('evm_increaseTime', [maciParameters.signUpDuration])
const messageBatch2 = []
const encPubKeyBatch2 = []
const messageBatch2: Message[] = []
const encPubKeyBatch2: PubKey[] = []
// Change key
const newContributorKeypair = new Keypair()
;[message, encPubKey] = createMessage(
Expand Down
5 changes: 5 additions & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dotenv.config()
const GAS_LIMIT = 20000000
const WALLET_MNEMONIC = process.env.WALLET_MNEMONIC
const WALLET_PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY
const WALLET_PRIVATE_KEY_2 = process.env.WALLET_PRIVATE_KEY_2

let accounts
if (WALLET_MNEMONIC) {
Expand All @@ -23,6 +24,10 @@ if (WALLET_PRIVATE_KEY) {
accounts = [WALLET_PRIVATE_KEY]
}

if (WALLET_PRIVATE_KEY_2) {
accounts = [...accounts, WALLET_PRIVATE_KEY_2]
}

const config: HardhatUserConfig = {
networks: {
hardhat: {
Expand Down
11 changes: 6 additions & 5 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"solidity-rlp": "2.0.3"
},
"devDependencies": {
"@clrfund/maci-utils": "^0.0.1",
"@ethereum-waffle/mock-contract": "^3.4.4",
"@kleros/gtcr-encoder": "^1.4.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.4",
Expand All @@ -36,10 +38,10 @@
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/node": "^13.9.2",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@typescript-eslint/eslint-plugin": "5.48.2",
"@typescript-eslint/parser": "5.48.2",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.3.0",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.7.2",
Expand All @@ -48,10 +50,9 @@
"ipfs-only-hash": "^2.0.1",
"maci-cli": "0.9.4",
"maci-crypto": "~0.9.1",
"maci-domainobjs": "~0.9.1",
"solhint": "^3.3.2",
"ts-generator": "^0.0.8",
"ts-node": "^8.8.1",
"typescript": "^3.8.3"
"typescript": "4.1.2"
}
}
2 changes: 1 addition & 1 deletion contracts/scripts/contribute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import { ethers } from 'hardhat'
import { Keypair } from 'maci-domainobjs'
import { Keypair } from '@clrfund/maci-utils'

import { UNIT } from '../utils/constants'
import { getEventArg } from '../utils/contracts'
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/deployRound.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'hardhat'
import { Contract, utils } from 'ethers'
import { Keypair } from 'maci-domainobjs'
import { Keypair } from '@clrfund/maci-utils'

import { deployMaciFactory } from '../utils/deployment'
import { getEventArg } from '../utils/contracts'
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/deployTestRound.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import { ethers } from 'hardhat'
import { Keypair } from 'maci-domainobjs'
import { Keypair } from '@clrfund/maci-utils'

import { UNIT } from '../utils/constants'
import { getEventArg } from '../utils/contracts'
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/generate-key.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Keypair } from 'maci-domainobjs'
import { Keypair } from '@clrfund/maci-utils'

async function main() {
const keypair = new Keypair()
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/vote.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import { ethers } from 'hardhat'
import { BigNumber } from 'ethers'
import { PrivKey, Keypair } from 'maci-domainobjs'
import { PrivKey, Keypair } from '@clrfund/maci-utils'

import { createMessage } from '../utils/maci'

Expand Down
2 changes: 1 addition & 1 deletion contracts/tasks/cancelRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { task } from 'hardhat/config'

task('cancel-round', 'Cancel the current round')
.addParam('factory', 'The funding round factory contract address')
.setAction(async ({ factory }, { network, ethers }) => {
.setAction(async ({ factory }, { ethers }) => {
const [deployer] = await ethers.getSigners()
console.log('deployer', deployer.address)
const fundingRoundFactory = await ethers.getContractAt(
Expand Down
Loading