Skip to content

Commit

Permalink
add movement contarct (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhiran authored Jan 8, 2025
1 parent 51630d7 commit 5311c0e
Show file tree
Hide file tree
Showing 8 changed files with 1,455 additions and 152 deletions.
1 change: 0 additions & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
lfs: true

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
3 changes: 2 additions & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ func TestE2E(t *testing.T) {
waitSettled(t, taskid, apiNodeUrl)
})
t.Run("gnark-movement", func(t *testing.T) {
t.Skip()
// Register project
projectOwnerKey, err := crypto.GenerateKey()
require.NoError(t, err)
projectOwnerAddr := crypto.PubkeyToAddress(projectOwnerKey.PublicKey)
sendETH(t, chainEndpoint, payerHex, projectOwnerAddr, 20)
projectID := big.NewInt(3)
registerIoID(t, chainEndpoint, contracts, deviceKey, projectID)
registerProject(t, chainEndpoint, contracts, projectOwnerKey, projectID, common.HexToAddress(contracts.MockDapp))
registerProject(t, chainEndpoint, contracts, projectOwnerKey, projectID, common.HexToAddress(contracts.MockDappMovement))

gnarkCodePath := "./testdata/geodnet.circuit"
gnarkMetadataPath := "./testdata/geodnet.pk"
Expand Down
5 changes: 5 additions & 0 deletions e2e/services/contractdeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
routerRe = regexp.MustCompile(`W3bstreamRouter deployed to (\S+)`)
mockDappRe = regexp.MustCompile(`MockDapp deployed to (\S+)`)
mockDappLivenessRe = regexp.MustCompile(`MockDappLiveness deployed to (\S+)`)
mockDappMovementRe = regexp.MustCompile(`MockDappMovement deployed to (\S+)`)
projectRewardRe = regexp.MustCompile(`W3bstreamProjectReward deployed to (\S+)`)
debitsRe = regexp.MustCompile(`W3bstreamDebits deployed to (\S+)`)
ioIDRe = regexp.MustCompile(`MockIoID deployed to (\S+)`)
Expand All @@ -38,6 +39,7 @@ type ContractsDeployments struct {
Router string
MockDapp string
MockDappLiveness string
MockDappMovement string
ProjectReward string
Debits string
IoID string
Expand Down Expand Up @@ -108,6 +110,9 @@ func DeployContract(endpoint string, payerHex string) (*ContractsDeployments, er
if match := mockDappLivenessRe.FindStringSubmatch(output); len(match) > 1 {
deployments.MockDappLiveness = match[1]
}
if match := mockDappMovementRe.FindStringSubmatch(output); len(match) > 1 {
deployments.MockDappMovement = match[1]
}
if match := routerRe.FindStringSubmatch(output); len(match) > 1 {
deployments.Router = match[1]
}
Expand Down
3 changes: 0 additions & 3 deletions e2e/testdata/geodnet.pk

This file was deleted.

Large diffs are not rendered by default.

1,263 changes: 1,263 additions & 0 deletions smartcontracts/contracts/MovementVerifier.sol

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions smartcontracts/contracts/test/MockDappMovement.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract MockDappMovement {
error CustomError();

uint8 public errorType;
address public verifier;

constructor(address _verifier) {
verifier = _verifier;
}

function setErrorType(uint8 _errorType) external {
errorType = _errorType;
}

function process(
uint256 _projectId,
bytes32 _taskId,
address _prover,
address _deviceId,
bytes calldata _data
) external view {
if (errorType == 1) {
require(false, "Normal Error");
} else if (errorType == 2) {
revert CustomError();
}

// Validate data length (79 uint256 values = 79 * 32 bytes)
require(_data.length == 79 * 32, "Invalid data length");

// Prepare function selector
bytes4 selector = bytes4(keccak256("verifyProof(uint256[8],uint256[2],uint256[2],uint256[67])"));

// Call verifier contract
(bool success, ) = verifier.staticcall(abi.encodePacked(selector, _data));
require(success, "Verifier call failed");

// TODO: cross-validate the public inputs which are the last 66 uint256 values in the _data
}
}
21 changes: 15 additions & 6 deletions smartcontracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ async function main() {

projectAddr = MockProject.target.toString()
}

const LivenessVerifier = await ethers.deployContract('LivenessVerifier', []);
await LivenessVerifier.waitForDeployment();

const MovementVerifier = await ethers.deployContract('MovementVerifier', []);
await MovementVerifier.waitForDeployment();

if (process.env.DAPP_PROCESSOR) {
} else {
const gnarkVerifier = await ethers.deployContract('Verifier', []);
await gnarkVerifier.waitForDeployment();
const MockDappLiveness = await ethers.deployContract('MockDappLiveness', [gnarkVerifier.target]);
await MockDappLiveness.waitForDeployment();
console.log(`MockDappLiveness deployed to ${MockDappLiveness.target}`);

const MockDapp = await ethers.deployContract('MockDapp', []);
await MockDapp.waitForDeployment();
console.log(`MockDapp deployed to ${MockDapp.target}`);

const MockDappLiveness = await ethers.deployContract('MockDappLiveness', [LivenessVerifier.target]);
await MockDappLiveness.waitForDeployment();
console.log(`MockDappLiveness deployed to ${MockDappLiveness.target}`);

const MockDappMovement = await ethers.deployContract('MockDappMovement', [MovementVerifier.target]);
await MockDappMovement.waitForDeployment();
console.log(`MockDappMovement deployed to ${MockDappMovement.target}`);
}
if (process.env.PROJECT_REGISTRATION_FEE) {
projectRegistrationFee = process.env.PROJECT_REGISTRATION_FEE
Expand Down

0 comments on commit 5311c0e

Please sign in to comment.