Skip to content

Commit 5311c0e

Browse files
authored
add movement contarct (#803)
1 parent 51630d7 commit 5311c0e

File tree

8 files changed

+1455
-152
lines changed

8 files changed

+1455
-152
lines changed

.github/workflows/e2e-test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
with:
2323
ref: ${{ github.event.pull_request.head.sha }}
2424
fetch-depth: 0
25-
lfs: true
2625

2726
- name: Setup Node.js
2827
uses: actions/setup-node@v4

e2e/e2e_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,15 @@ func TestE2E(t *testing.T) {
188188
waitSettled(t, taskid, apiNodeUrl)
189189
})
190190
t.Run("gnark-movement", func(t *testing.T) {
191+
t.Skip()
191192
// Register project
192193
projectOwnerKey, err := crypto.GenerateKey()
193194
require.NoError(t, err)
194195
projectOwnerAddr := crypto.PubkeyToAddress(projectOwnerKey.PublicKey)
195196
sendETH(t, chainEndpoint, payerHex, projectOwnerAddr, 20)
196197
projectID := big.NewInt(3)
197198
registerIoID(t, chainEndpoint, contracts, deviceKey, projectID)
198-
registerProject(t, chainEndpoint, contracts, projectOwnerKey, projectID, common.HexToAddress(contracts.MockDapp))
199+
registerProject(t, chainEndpoint, contracts, projectOwnerKey, projectID, common.HexToAddress(contracts.MockDappMovement))
199200

200201
gnarkCodePath := "./testdata/geodnet.circuit"
201202
gnarkMetadataPath := "./testdata/geodnet.pk"

e2e/services/contractdeploy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
routerRe = regexp.MustCompile(`W3bstreamRouter deployed to (\S+)`)
2424
mockDappRe = regexp.MustCompile(`MockDapp deployed to (\S+)`)
2525
mockDappLivenessRe = regexp.MustCompile(`MockDappLiveness deployed to (\S+)`)
26+
mockDappMovementRe = regexp.MustCompile(`MockDappMovement deployed to (\S+)`)
2627
projectRewardRe = regexp.MustCompile(`W3bstreamProjectReward deployed to (\S+)`)
2728
debitsRe = regexp.MustCompile(`W3bstreamDebits deployed to (\S+)`)
2829
ioIDRe = regexp.MustCompile(`MockIoID deployed to (\S+)`)
@@ -38,6 +39,7 @@ type ContractsDeployments struct {
3839
Router string
3940
MockDapp string
4041
MockDappLiveness string
42+
MockDappMovement string
4143
ProjectReward string
4244
Debits string
4345
IoID string
@@ -108,6 +110,9 @@ func DeployContract(endpoint string, payerHex string) (*ContractsDeployments, er
108110
if match := mockDappLivenessRe.FindStringSubmatch(output); len(match) > 1 {
109111
deployments.MockDappLiveness = match[1]
110112
}
113+
if match := mockDappMovementRe.FindStringSubmatch(output); len(match) > 1 {
114+
deployments.MockDappMovement = match[1]
115+
}
111116
if match := routerRe.FindStringSubmatch(output); len(match) > 1 {
112117
deployments.Router = match[1]
113118
}

e2e/testdata/geodnet.pk

Lines changed: 0 additions & 3 deletions
This file was deleted.

smartcontracts/contracts/test/Verifier.sol renamed to smartcontracts/contracts/LivenessVerifier.sol

Lines changed: 127 additions & 141 deletions
Large diffs are not rendered by default.

smartcontracts/contracts/MovementVerifier.sol

Lines changed: 1263 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
contract MockDappMovement {
5+
error CustomError();
6+
7+
uint8 public errorType;
8+
address public verifier;
9+
10+
constructor(address _verifier) {
11+
verifier = _verifier;
12+
}
13+
14+
function setErrorType(uint8 _errorType) external {
15+
errorType = _errorType;
16+
}
17+
18+
function process(
19+
uint256 _projectId,
20+
bytes32 _taskId,
21+
address _prover,
22+
address _deviceId,
23+
bytes calldata _data
24+
) external view {
25+
if (errorType == 1) {
26+
require(false, "Normal Error");
27+
} else if (errorType == 2) {
28+
revert CustomError();
29+
}
30+
31+
// Validate data length (79 uint256 values = 79 * 32 bytes)
32+
require(_data.length == 79 * 32, "Invalid data length");
33+
34+
// Prepare function selector
35+
bytes4 selector = bytes4(keccak256("verifyProof(uint256[8],uint256[2],uint256[2],uint256[67])"));
36+
37+
// Call verifier contract
38+
(bool success, ) = verifier.staticcall(abi.encodePacked(selector, _data));
39+
require(success, "Verifier call failed");
40+
41+
// TODO: cross-validate the public inputs which are the last 66 uint256 values in the _data
42+
}
43+
}

smartcontracts/scripts/deploy.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,26 @@ async function main() {
1313

1414
projectAddr = MockProject.target.toString()
1515
}
16+
17+
const LivenessVerifier = await ethers.deployContract('LivenessVerifier', []);
18+
await LivenessVerifier.waitForDeployment();
19+
20+
const MovementVerifier = await ethers.deployContract('MovementVerifier', []);
21+
await MovementVerifier.waitForDeployment();
22+
1623
if (process.env.DAPP_PROCESSOR) {
1724
} else {
18-
const gnarkVerifier = await ethers.deployContract('Verifier', []);
19-
await gnarkVerifier.waitForDeployment();
20-
const MockDappLiveness = await ethers.deployContract('MockDappLiveness', [gnarkVerifier.target]);
21-
await MockDappLiveness.waitForDeployment();
22-
console.log(`MockDappLiveness deployed to ${MockDappLiveness.target}`);
23-
2425
const MockDapp = await ethers.deployContract('MockDapp', []);
2526
await MockDapp.waitForDeployment();
2627
console.log(`MockDapp deployed to ${MockDapp.target}`);
28+
29+
const MockDappLiveness = await ethers.deployContract('MockDappLiveness', [LivenessVerifier.target]);
30+
await MockDappLiveness.waitForDeployment();
31+
console.log(`MockDappLiveness deployed to ${MockDappLiveness.target}`);
32+
33+
const MockDappMovement = await ethers.deployContract('MockDappMovement', [MovementVerifier.target]);
34+
await MockDappMovement.waitForDeployment();
35+
console.log(`MockDappMovement deployed to ${MockDappMovement.target}`);
2736
}
2837
if (process.env.PROJECT_REGISTRATION_FEE) {
2938
projectRegistrationFee = process.env.PROJECT_REGISTRATION_FEE

0 commit comments

Comments
 (0)