mirror of
https://github.com/social-tw/social-tw-website.git
synced 2026-01-09 15:38:09 -05:00
build: remove epoch key lite proof in edit comment
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -3,15 +3,11 @@ pragma solidity ^0.8.0;
|
||||
|
||||
import {Unirep} from "@unirep/contracts/Unirep.sol";
|
||||
import {ReputationVerifierHelper} from "@unirep/contracts/verifierHelpers/ReputationVerifierHelper.sol";
|
||||
import {EpochKeyLiteVerifierHelper} from "@unirep/contracts/verifierHelpers/EpochKeyLiteVerifierHelper.sol";
|
||||
import {BaseVerifierHelper} from "@unirep/contracts/verifierHelpers/BaseVerifierHelper.sol";
|
||||
import {VerifierHelperManager} from "./verifierHelpers/VerifierHelperManager.sol";
|
||||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import {DailyClaimVHelper} from "./verifierHelpers/DailyClaimVHelper.sol";
|
||||
|
||||
// Uncomment this line to use console.log
|
||||
// import "hardhat/console.sol";
|
||||
|
||||
interface IVerifier {
|
||||
function verifyProof(uint256[] calldata publicSignals, uint256[8] calldata proof) external view returns (bool);
|
||||
}
|
||||
@@ -31,7 +27,6 @@ contract UnirepApp is Ownable {
|
||||
Unirep public unirep;
|
||||
IVerifier internal dataVerifier;
|
||||
ReputationVerifierHelper internal repHelper;
|
||||
EpochKeyLiteVerifierHelper internal epkLiteHelper;
|
||||
VerifierHelperManager internal verifierHelperManager;
|
||||
|
||||
// a global variable to store the latest postId
|
||||
@@ -83,7 +78,6 @@ contract UnirepApp is Ownable {
|
||||
constructor(
|
||||
Unirep _unirep,
|
||||
ReputationVerifierHelper _repHelper,
|
||||
EpochKeyLiteVerifierHelper _epkLiteHelper,
|
||||
IVerifier _dataVerifier,
|
||||
VerifierHelperManager _verifierHelperManager,
|
||||
uint48 _epochLength
|
||||
@@ -94,9 +88,6 @@ contract UnirepApp is Ownable {
|
||||
// set epoch key verifier helper address
|
||||
repHelper = _repHelper;
|
||||
|
||||
// set epoch key lite verifier helper address
|
||||
epkLiteHelper = _epkLiteHelper;
|
||||
|
||||
// set verifier address
|
||||
dataVerifier = _dataVerifier;
|
||||
|
||||
@@ -215,8 +206,8 @@ contract UnirepApp is Ownable {
|
||||
* @param newContent: new content of the comment. if this == "", means removing
|
||||
*/
|
||||
function editComment(
|
||||
uint256[] memory publicSignals,
|
||||
uint256[8] memory proof,
|
||||
uint256[] calldata publicSignals,
|
||||
uint256[8] calldata proof,
|
||||
uint256 postId,
|
||||
uint256 commentId,
|
||||
string memory newContent
|
||||
@@ -229,8 +220,7 @@ contract UnirepApp is Ownable {
|
||||
|
||||
proofNullifier[nullifier] = true;
|
||||
|
||||
EpochKeyLiteVerifierHelper.EpochKeySignals memory signals =
|
||||
epkLiteHelper.decodeEpochKeyLiteSignals(publicSignals);
|
||||
ReputationVerifierHelper.ReputationSignals memory signals = decodeAndVerify(publicSignals, proof);
|
||||
|
||||
// check the epoch != current epoch (ppl can only post in current aepoch)
|
||||
uint48 epoch = unirep.attesterCurrentEpoch(signals.attesterId);
|
||||
@@ -247,8 +237,6 @@ contract UnirepApp is Ownable {
|
||||
revert InvalidCommentEpochKey(signals.epochKey);
|
||||
}
|
||||
|
||||
epkLiteHelper.verifyAndCheckCaller(publicSignals, proof);
|
||||
|
||||
emit UpdatedComment(signals.epochKey, postId, commentId, signals.epoch, newContent);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,6 @@ export async function deployApp(deployer: ethers.Signer, epochLength: number) {
|
||||
deployer,
|
||||
Circuit.reputation
|
||||
)
|
||||
const epkLiteHelper = await deployVerifierHelper(
|
||||
unirep.address,
|
||||
deployer,
|
||||
Circuit.epochKeyLite
|
||||
)
|
||||
|
||||
// deploy verifiers
|
||||
console.log('Deploying Verifiers')
|
||||
@@ -112,7 +107,6 @@ export async function deployApp(deployer: ethers.Signer, epochLength: number) {
|
||||
const app = await AppF.deploy(
|
||||
unirep.address,
|
||||
repHelper.address,
|
||||
epkLiteHelper.address,
|
||||
dataProofVerifier.address,
|
||||
vHelperManager.address,
|
||||
epochLength
|
||||
|
||||
@@ -6,9 +6,9 @@ import { deployApp } from '../scripts/utils/deployUnirepSocialTw'
|
||||
import { Unirep, UnirepApp } from '../typechain-types'
|
||||
import {
|
||||
createMultipleUserIdentity,
|
||||
genEpochKeyLiteProof,
|
||||
genReputationProof,
|
||||
genUserState,
|
||||
userStateTransition
|
||||
} from './utils'
|
||||
|
||||
describe('Comment Test', function () {
|
||||
@@ -168,23 +168,34 @@ describe('Comment Test', function () {
|
||||
it('should revert editing comment with invalid epoch', async function () {
|
||||
const userState = await genUserState(users[1].id, app)
|
||||
const id = users[1].id
|
||||
const epoch = 0
|
||||
// generating a proof with wrong epoch
|
||||
const wrongEpoch = 44444
|
||||
const attesterId = userState.sync.attesterId
|
||||
const postId = 0
|
||||
const commentId = 0
|
||||
const content = 'Invalid Epoch'
|
||||
const { publicSignals, proof } = await genEpochKeyLiteProof({
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId
|
||||
)
|
||||
const data = await userState.getProvableData()
|
||||
const repProof = await genReputationProof({
|
||||
id,
|
||||
tree,
|
||||
leafIndex,
|
||||
epoch: wrongEpoch,
|
||||
nonce: 0,
|
||||
attesterId,
|
||||
chainId,
|
||||
attesterId,
|
||||
data,
|
||||
})
|
||||
|
||||
await expect(
|
||||
app.editComment(
|
||||
publicSignals,
|
||||
proof,
|
||||
repProof.publicSignals,
|
||||
repProof.proof,
|
||||
postId,
|
||||
commentId,
|
||||
content
|
||||
@@ -195,18 +206,32 @@ describe('Comment Test', function () {
|
||||
|
||||
it('should revert with invalid comment id', async function () {
|
||||
const userState = await genUserState(users[1].id, app)
|
||||
const { publicSignals, proof } =
|
||||
await userState.genEpochKeyLiteProof({
|
||||
epoch: 0,
|
||||
nonce: 0,
|
||||
})
|
||||
const id = users[1].id
|
||||
const epoch = 0
|
||||
const attesterId = userState.sync.attesterId
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId
|
||||
)
|
||||
const data = await userState.getProvableData()
|
||||
const repProof = await genReputationProof({
|
||||
id,
|
||||
tree,
|
||||
leafIndex,
|
||||
epoch,
|
||||
nonce: 0,
|
||||
chainId,
|
||||
attesterId,
|
||||
data,
|
||||
})
|
||||
const postId = 0
|
||||
const commentId = 1
|
||||
const newContent = 'Invalid Comment Id'
|
||||
await expect(
|
||||
app.editComment(
|
||||
publicSignals,
|
||||
proof,
|
||||
repProof.publicSignals,
|
||||
repProof.proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent
|
||||
@@ -217,19 +242,32 @@ describe('Comment Test', function () {
|
||||
|
||||
it('should revert with invalid epochKey', async function () {
|
||||
const userState = await genUserState(users[1].id, app)
|
||||
const { publicSignals, proof } =
|
||||
await userState.genEpochKeyLiteProof({
|
||||
epoch: 0,
|
||||
nonce: 0,
|
||||
})
|
||||
publicSignals[1] = BigInt(0)
|
||||
const id = users[1].id
|
||||
const epoch = 0
|
||||
const attesterId = userState.sync.attesterId
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId
|
||||
)
|
||||
const data = await userState.getProvableData()
|
||||
const repProof = await genReputationProof({
|
||||
id,
|
||||
tree,
|
||||
leafIndex,
|
||||
epoch,
|
||||
nonce: 2,
|
||||
chainId,
|
||||
attesterId,
|
||||
data,
|
||||
})
|
||||
const postId = 0
|
||||
const commentId = 0
|
||||
const newContent = 'Invalid Comment Epoch Key'
|
||||
await expect(
|
||||
app.editComment(
|
||||
publicSignals,
|
||||
proof,
|
||||
repProof.publicSignals,
|
||||
repProof.proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent
|
||||
@@ -238,21 +276,35 @@ describe('Comment Test', function () {
|
||||
userState.stop()
|
||||
})
|
||||
|
||||
it('should revert editing comment with invalid epoch key lite proof', async function () {
|
||||
it('should revert editing comment with invalid reputation proof', async function () {
|
||||
const userState = await genUserState(users[1].id, app)
|
||||
const { publicSignals, proof } =
|
||||
await userState.genEpochKeyLiteProof({
|
||||
epoch: 0,
|
||||
nonce: 0,
|
||||
})
|
||||
proof[0] = BigInt(0)
|
||||
const id = users[1].id
|
||||
const epoch = 0
|
||||
const attesterId = userState.sync.attesterId
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId
|
||||
)
|
||||
const data = await userState.getProvableData()
|
||||
const repProof = await genReputationProof({
|
||||
id,
|
||||
tree,
|
||||
leafIndex,
|
||||
epoch,
|
||||
nonce: 0,
|
||||
chainId,
|
||||
attesterId,
|
||||
data,
|
||||
})
|
||||
repProof.proof[0] = BigInt(0)
|
||||
const postId = 0
|
||||
const commentId = 0
|
||||
const newContent = 'Invalid Proof'
|
||||
await expect(
|
||||
app.editComment(
|
||||
publicSignals,
|
||||
proof,
|
||||
repProof.publicSignals,
|
||||
repProof.proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent
|
||||
@@ -263,19 +315,36 @@ describe('Comment Test', function () {
|
||||
|
||||
it('should update comment with same epoch and nonce', async function () {
|
||||
const userState = await genUserState(users[1].id, app)
|
||||
const { publicSignals, proof } =
|
||||
await userState.genEpochKeyLiteProof()
|
||||
const id = users[1].id
|
||||
const epoch = 0
|
||||
const attesterId = userState.sync.attesterId
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId
|
||||
)
|
||||
const data = await userState.getProvableData()
|
||||
const repProof = await genReputationProof({
|
||||
id,
|
||||
tree,
|
||||
leafIndex,
|
||||
epoch,
|
||||
nonce: 0,
|
||||
chainId,
|
||||
attesterId,
|
||||
data,
|
||||
})
|
||||
const postId = 0
|
||||
const commentId = 0
|
||||
const newContent = 'Nice content, bruh!'
|
||||
|
||||
inputPublicSig = publicSignals
|
||||
inputProof = proof
|
||||
inputPublicSig = repProof.publicSignals
|
||||
inputProof = repProof.proof
|
||||
|
||||
await expect(
|
||||
app.editComment(
|
||||
publicSignals,
|
||||
proof,
|
||||
repProof.publicSignals,
|
||||
repProof.proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent
|
||||
@@ -283,7 +352,7 @@ describe('Comment Test', function () {
|
||||
)
|
||||
.to.emit(app, 'UpdatedComment')
|
||||
.withArgs(
|
||||
publicSignals[1], // epochKey
|
||||
repProof.publicSignals[0], // epochKey
|
||||
postId,
|
||||
commentId,
|
||||
0, // epoch
|
||||
@@ -308,41 +377,42 @@ describe('Comment Test', function () {
|
||||
})
|
||||
|
||||
it('should update comment in another epoch', async function () {
|
||||
const userState = await genUserState(users[1].id, app)
|
||||
const attesterId = userState.sync.attesterId
|
||||
const epoch = await userState.sync.loadCurrentEpoch()
|
||||
const tree = await userState.sync.genStateTree(epoch, attesterId)
|
||||
const leafIndex = await userState.latestStateTreeLeafIndex(
|
||||
epoch,
|
||||
attesterId
|
||||
)
|
||||
|
||||
// epoch transition
|
||||
await ethers.provider.send('evm_increaseTime', [epochLength])
|
||||
await ethers.provider.send('evm_mine', [])
|
||||
|
||||
// user state transition
|
||||
const userState2 = await genUserState(users[1].id, app)
|
||||
const attesterId = userState2.sync.attesterId
|
||||
const toEpoch = await unirep.attesterCurrentEpoch(attesterId)
|
||||
await userStateTransition(userState, unirep, app)
|
||||
|
||||
await userState2.waitForSync()
|
||||
const {
|
||||
publicSignals: userTransitionSignals,
|
||||
proof: userTransitiionProof,
|
||||
} = await userState2.genUserStateTransitionProof({ toEpoch })
|
||||
await unirep
|
||||
.userStateTransition(
|
||||
userTransitionSignals,
|
||||
userTransitiionProof
|
||||
)
|
||||
.then((tx) => tx.wait())
|
||||
|
||||
userState2.stop()
|
||||
|
||||
const userState = await genUserState(users[1].id, app)
|
||||
userState.waitForSync()
|
||||
const { publicSignals, proof } =
|
||||
await userState.genEpochKeyLiteProof({ epoch: 0 })
|
||||
const id = users[1].id
|
||||
const data = await userState.getProvableData()
|
||||
const repProof = await genReputationProof({
|
||||
id,
|
||||
tree,
|
||||
leafIndex,
|
||||
epoch,
|
||||
nonce: 0,
|
||||
chainId,
|
||||
attesterId,
|
||||
data,
|
||||
})
|
||||
const postId = 0
|
||||
const commentId = 0
|
||||
const newContent = 'Nice content, bruh!'
|
||||
|
||||
await expect(
|
||||
app.editComment(
|
||||
publicSignals,
|
||||
proof,
|
||||
repProof.publicSignals,
|
||||
repProof.proof,
|
||||
postId,
|
||||
commentId,
|
||||
newContent
|
||||
@@ -350,7 +420,7 @@ describe('Comment Test', function () {
|
||||
)
|
||||
.to.emit(app, 'UpdatedComment')
|
||||
.withArgs(
|
||||
publicSignals[1], // epochKey
|
||||
repProof.publicSignals[0], // epochKey
|
||||
postId,
|
||||
commentId,
|
||||
0, // epoch
|
||||
|
||||
Reference in New Issue
Block a user