Skip to content

Commit

Permalink
feat(bungee-hermes): viewProof & ethereum strategy
Browse files Browse the repository at this point in the history
* Views have new attribute viewProof
* This attribute has the roots of all state proofs and transaction
proofs in the view
* Added new endpoint to verify integrity of view proofs
* Created strategy for bungee-hermes to support the ethereum-connector
* Created new test for the strategy-ethereum, and altered the API test
to test the new viewProof endpoint
* Updated documentation to reflect new changes.
* Fixes in Fabric Strategy, stateProofs and error handling

Co-authored-by: André Augusto <andre.augusto@tecnico.ulisboa.pt>
Co-authored-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

Signed-off-by: eduv09 <eduardovasques10@tecnico.ulisboa.pt>
  • Loading branch information
eduv09 authored and RafaelAPB committed May 7, 2024
1 parent 7e55ac4 commit 22f389f
Show file tree
Hide file tree
Showing 46 changed files with 1,523 additions and 1,527 deletions.
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
"lmify",
"LOCALMSPID",
"mailru",
"Merkle",
"merkletreejs",
"miekg",
"mitchellh",
"MSPCONFIGPATH",
Expand Down
33 changes: 32 additions & 1 deletion packages/cactus-plugin-bungee-hermes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ Know how to use the following plugins of the project:

- [cactus-plugin-ledger-connector-fabric](https://github.com/hyperledger/cactus/tree/main/packages/cactus-plugin-ledger-connector-fabric)
- [cactus-plugin-ledger-connector-besu](https://github.com/hyperledger/cactus/tree/main/packages/cactus-plugin-ledger-connector-besu)
- [cactus-plugin-ledger-connector-ethereum](https://github.com/hyperledger/cactus/tree/main/packages/cactus-plugin-ledger-connector-ethereum)


## Architecture

The plugin interacts with a cactus ledger connector, using strategies with custom logic for each different network.

Note that, so far, only strategies for Fabric and Besu networks were implemented. Smart-contracts in Fabric and Besu must implement the interface provided in the files ITraceableContract.ts and ITraceableContract.sol, in the test directory
Note that, so far, only strategies for Fabric, Besu and Ethereum networks were implemented. Smart-contracts for Fabric and EVM based chains must implement the interface provided in the files ITraceableContract.ts and ITraceableContract.sol, in the test directory

The plugin stands _behind_ a cacti-ledger-connector, which is used to fetch information from the ledger to create the snapshot.
```typescript
Expand Down Expand Up @@ -70,10 +71,12 @@ Endpoints exposed:
- CreateViewV1
- GetPublicKey
- GetAvailableStrategies
- VerifyMerkleRoot


## Running the tests
- **besu-test-basic.test.ts**: A test using strategy-besu and a besu connector, testing creating views for different timeframes and states.
- **ethereum-test-basic.test.ts**: A test using strategy-ethereum and a ethereum connector, testing creating views for different timeframes and states.
- **fabric-test-basic.test.ts**: A test using strategy-fabric and a fabric connector, testing creating views for different timeframes and states.
- **besu-test-pruning.test.ts**: A test using strategy-besu and a besu connector, testing creating views for specific timeframes.
- **fabric-test-pruning.test.ts**: A test using strategy-fabric and a fabric connector, testing creating views for specific timeframes.
Expand Down Expand Up @@ -149,6 +152,34 @@ Note that each strategy can be used to query different ledgers (ledgers of the s
Each strategy implements the logic to query information from each different ledger (i.e. capture set of asset states), while bungee-hermes plugin handles the snapshot and view creation.


'View' object contains a 'viewProof'. viewProof is composed by two merkle trees, one for stateProofs and another for transactionProofs.
One can check if the content of a view has no inconsistencies, by querying the VerifyMerkleRoot endpoint with the appropriate input:

```typescript
//using a previously created View object

const stateProofs = view?.getSnapshot()
.getStateBins()
.map((x) => JSON.stringify(x.getStateProof()));
const transactionProofs: string[] = [];
view?
.getAllTransactions()
.forEach((t) => transactionProofs.push(JSON.stringify(t.getProof())));

const verifyStateRoot = await bungeeApi.verifyMerkleRoot({
input: stateProofs?.reverse(), //check integrity, order should not matter
root: proof?.statesMerkleRoot,
});
expect(verifyStateRoot.data.result).toBeTrue();

const verifyTransactionsRoot = await bungeeApi.verifyMerkleRoot({
input: transactionProofs?.reverse(), //check integrity, order should not matter
root: proof?.transactionsMerkleRoot,
});
expect(verifyTransactionsRoot.data.result).toBeTrue();
```
## Contributing
We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do!
Expand Down
7 changes: 4 additions & 3 deletions packages/cactus-plugin-bungee-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"codegen": "run-p 'codegen:*'",
"codegen:openapi": "npm run generate-sdk",
"generate-sdk": "run-p 'generate-sdk:*'",
"generate-sdk:kotlin": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g kotlin -o ./src/main/kotlin/generated/openapi/kotlin-client/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore",
"generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore",
"pretsc": "npm run generate-sdk",
"tsc": "tsc --project ./tsconfig.json",
Expand All @@ -60,19 +59,21 @@
"@hyperledger/cactus-core-api": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-ledger-connector-ethereum": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-object-store-ipfs": "2.0.0-alpha.2",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.2",
"axios": "1.6.0",
"body-parser": "1.20.2",
"fs-extra": "10.1.0",
"key-encoder": "2.0.3",
"merkletreejs": "0.3.11",
"typescript-optional": "2.0.1",
"uuid": "9.0.1",
"web3": "1.6.1",
"web3-core": "1.6.1"
},
"devDependencies": {
"@hyperledger/cactus-test-geth-ledger": "2.0.0-alpha.2",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.2",
"@types/body-parser": "1.19.4",
"@types/crypto-js": "4.0.1",
"@types/express": "4.17.19",
Expand Down
70 changes: 70 additions & 0 deletions packages/cactus-plugin-bungee-hermes/src/main/json/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@
"type": "string",
"example": "strategy-fabric"
}
},
"VerifyMerkleRootRequest":{
"type": "object",
"description": "Set of transaction or state proofs and merkle tree root for verification",
"properties": {
"input":{
"nullable": false,
"type": "array",
"items":{
"type": "string",
"example": "transactionProof stringified"
}
},
"root":{
"nullable": false,
"type": "string"
}
}
},
"VerifyMerkleRootResponse": {
"type": "object",
"description": "true or false, wether input matched provided root",
"properties": {
"result":{
"type": "boolean",
"example": "true"
}
}
}
}
},
Expand Down Expand Up @@ -216,6 +244,48 @@
}
}
}
},

"/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/verify-merkle-root": {
"get": {
"x-hyperledger-cacti": {
"http": {
"verbLowerCase": "get",
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/verify-merkle-root"
}
},
"operationId": "verifyMerkleRoot",
"summary": "Checks validity of merkle tree root given an input",
"description": "",
"parameters": [],
"requestBody": {
"required": true,
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VerifyMerkleRootRequest"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/VerifyMerkleRootResponse"
},
"example": {"result": true}
}
}
},
"404": {
"description": "Could not complete request."
}
}
}
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 22f389f

Please sign in to comment.