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

add e2e test #789

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ contract-test:
.PHONY: e2e_test
e2e_test:
@cd smartcontracts && yarn install
@TEST_E2E=true go test ./e2e -v
@TEST_E2E=true go test -count=1 ./e2e -v
33 changes: 33 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func TestE2E(t *testing.T) {
registerIoID(t, chainEndpoint, contracts, deviceKey, projectID)

t.Run("RISC0", func(t *testing.T) {
t.Skip()
t.Cleanup(func() {
if err := risc0VMContainer.Terminate(context.Background()); err != nil {
t.Logf("failed to terminate vm container: %v", err)
Expand Down Expand Up @@ -172,6 +173,7 @@ func TestE2E(t *testing.T) {
})

t.Run("GNARK", func(t *testing.T) {
t.Skip()
t.Cleanup(func() {
if err := gnarkVMContainer.Terminate(context.Background()); err != nil {
t.Logf("failed to terminate vm container: %v", err)
Expand All @@ -195,6 +197,37 @@ func TestE2E(t *testing.T) {
taskid := sendMessage(t, data, projectID, nil, deviceKey, apiNodeUrl)
waitSettled(t, taskid, apiNodeUrl)
})

t.Run("GNARK2", func(t *testing.T) {
t.Cleanup(func() {
if err := gnarkVMContainer.Terminate(context.Background()); err != nil {
t.Logf("failed to terminate vm container: %v", err)
}
})
gnarkCodePath := "./testdata/pebble.circuit"
gnarkMetadataPath := "./testdata/pebble.pk"
project := &project.Project{Configs: []*project.Config{{
Version: "v1",
VMTypeID: 5,
SignedKeys: []project.SignedKey{{Name: "timestamp", Type: "uint64"}},
}}}

// Upload project
uploadProject(t, chainEndpoint, ipfsEndpoint, project, &gnarkCodePath, &gnarkMetadataPath, contracts, projectOwnerKey, projectID, false)
require.NoError(t, err)

// Wait a few seconds for the device info synced on api node
time.Sleep(2 * time.Second)

data, err := json.Marshal(struct {
Timestamp uint64 `json:"timestamp"`
}{
Timestamp: uint64(time.Now().Unix()),
})
require.NoError(t, err)
taskid := sendMessage(t, data, projectID, project.Configs[0], deviceKey, apiNodeUrl)
waitSettled(t, taskid, apiNodeUrl)
})
}

func sendMessage(t *testing.T, dataJson []byte, projectID *big.Int,
Expand Down
Binary file added e2e/testdata/pebble.circuit
Binary file not shown.
Binary file added e2e/testdata/pebble.pk
Binary file not shown.
17 changes: 17 additions & 0 deletions smartcontracts/contracts/test/MockProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ contract MockProcessor {
error CustomError();

uint8 public errorType;
address public verifier;

constructor(address _verifier) {
verifier = _verifier;
}

function setErrorType(uint8 _errorType) external {
errorType = _errorType;
Expand All @@ -22,5 +27,17 @@ contract MockProcessor {
} else if (errorType == 2) {
revert CustomError();
}

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

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

// 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
}
}
1,268 changes: 1,268 additions & 0 deletions smartcontracts/contracts/test/Verifier.sol

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion smartcontracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ async function main() {
}
if (process.env.DAPP_PROCESSOR) {
} else {
const MockProcessor = await ethers.deployContract('MockProcessor', []);
const gnarkVerifier = await ethers.deployContract('Verifier', []);
await gnarkVerifier.waitForDeployment();
const MockProcessor = await ethers.deployContract('MockProcessor', [gnarkVerifier.target]);
await MockProcessor.waitForDeployment();
console.log(`MockProcessor deployed to ${MockProcessor.target}`);
}
Expand Down
16 changes: 8 additions & 8 deletions vm/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ var (
)

func LoadPayload(task *task.Task, projectConfig *project.Config) ([]byte, error) {
switch task.ProjectID.String() {
case _pebbleProjectID.String():
return encodePebblePayload(task, projectConfig)
case _geoProjectID.String():
return encodeGeodnetPayload(task, projectConfig)
default:
return task.Payload, nil
}
// switch task.ProjectID.String() {
// case _pebbleProjectID.String():
return encodePebblePayload(task, projectConfig)
// case _geoProjectID.String():
// return encodeGeodnetPayload(task, projectConfig)
// default:
// return task.Payload, nil
// }
}

type ProofofLivenessCircuit struct {
Expand Down
Loading