Skip to content

Commit

Permalink
feat(satp-hermes): fabric and besu bridges, wrapper contracts with on…
Browse files Browse the repository at this point in the history
…tology (#3382)

feat(satp-hermes): added forge to compile solidity contracts

Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>
  • Loading branch information
LordKubaya authored and rafaelbelchiorbd committed Nov 13, 2024
1 parent aadfbbc commit f2edd47
Show file tree
Hide file tree
Showing 76 changed files with 14,970 additions and 2,873 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"PrivacyPolicyOpts": {
"description": "identifier of the policy used to process a view",
"type": "string",
"enum": ["pruneState"],
"x-enum-varnames": ["PruneState"]
"enum": ["pruneState", "singleTransaction"],
"x-enum-varnames": ["PruneState", "SingleTransaction"]
},
"MergePolicyOpts": {
"description": "identifier of the policy used to merge views (can be none)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export interface MergeViewsResponse {
*/

export const PrivacyPolicyOpts = {
PruneState: 'pruneState'
PruneState: 'pruneState',
SingleTransaction: 'singleTransaction'
} as const;

export type PrivacyPolicyOpts = typeof PrivacyPolicyOpts[keyof typeof PrivacyPolicyOpts];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ export class PrivacyPolicies {
return view;
}

public singleTransaction(
view: View,
stateId: string,
transactionId: string,
): View {
const snapshot = view.getSnapshot();
snapshot.filterTransaction(stateId, transactionId);
return view;
}

public getPrivacyPolicy(opts: PrivacyPolicyOpts): IPrivacyPolicy | undefined {
switch (opts) {
case PrivacyPolicyOpts.PruneState:
return this.pruneState;
break;
case PrivacyPolicyOpts.SingleTransaction:
return this.singleTransaction;
break;
default:
return undefined;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ export class Snapshot {
this.stateBins = stateBins;
}

public selectStates(states: string[]): void {
const stateBins: State[] = [];
for (const state of this.stateBins) {
if (states.includes(state.getId())) {
stateBins.push(state);
}
}
this.stateBins = stateBins;
}

public filterTransaction(stateId: string, transaction: string): void {
this.selectStates([stateId]);
const state = this.stateBins[0];
state.selectTransactions([transaction]);
}

public getSnapshotJson(): string {
const snapshotJson = {
id: this.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export class State {
return this.transactions;
}

public selectTransactions(txs: string[]): void {
const transactions: Transaction[] = [];
for (const tx of this.transactions) {
if (txs.includes(tx.getId())) {
transactions.push(tx);
}
}
this.transactions = transactions;
}

public getInitialTime(): string {
if (this.transactions.length >= 1) {
return this.transactions[0].getTimeStamp();
Expand Down
1 change: 1 addition & 0 deletions packages/cactus-plugin-satp-hermes/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/main/typescript/generated/gateway-client/typescript-axios/.openapi-generator
src/main/typescript/generated/gateway-client/typescript-axios/api.ts
src/main/typescript/generated/gateway-client/typescript-axios/git_push.sh
src/main/typescript/generated/gateway-client/typescript-axios/.openapi-generator/FILES
src/main/typescript/fabric-contracts/satp/chaincode-typescript/.yarn/
3 changes: 3 additions & 0 deletions packages/cactus-plugin-satp-hermes/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[profile.default]
solc-version = "0.8.20"
evm-version = "paris"
15 changes: 14 additions & 1 deletion packages/cactus-plugin-satp-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
{
"name": "Rafael Belchior",
"url": "https://github.com/RafaelAPB"
},
{
"name": "Carlos Amaro",
"url": "https://github.com/LordKubaya"
}
],
"main": "dist/lib/main/typescript/index.js",
Expand All @@ -46,8 +50,12 @@
"bundle-openapi-json": "swagger-cli bundle ./src/main/yml/bol/openapi-blo.yml -o ./src/main/json/openapi-blo-bundled.json -r -t json",
"bundle-openapi-yaml": "swagger-cli bundle ./src/main/yml/bol/openapi-blo.yml -o ./src/main/yml/bol/openapi-blo-bundled.yml -r -t yaml",
"codegen": "run-p 'codegen:*'",
"codegen:abi": "yarn forge:all && abi-types-generator './src/solidity/generated/satp-wrapper.sol/SATPWrapperContract.json' --output='./src/main/typescript/generated'",
"codegen:openapi": "npm run generate-sdk",
"codegen:proto": "npm run generate-proto",
"forge": "forge build ./src/solidity/*.sol --out ./src/solidity/generated",
"forge:all": "run-p 'forge' 'forge:test'",
"forge:test": "forge build ./src/test/solidity/contracts/*.sol --out ./src/test/solidity/generated",
"generate-proto": "cd src/main/proto && buf generate --template buf.gen.yaml --config buf.yaml --verbose",
"generate-sdk": "run-p 'generate-sdk:*'",
"generate-sdk:go": "openapi-generator-cli generate -i ./src/main/yml/bol/openapi-blo-bundled.yml -g go -o ./src/main/go/generated/gateway-client --additional-properties=packageName=generated,generateInterfaces=true,packageVersion=v0.0.1,moduleName=github.com/hyperledger/cacti/packages/cactus-plugin-satp-hermes/src/main/go/generated --git-user-id hyperledger --git-repo-id cacti/packages/cactus-plugin-satp-hermes/src/main/go/generated",
Expand Down Expand Up @@ -81,17 +89,20 @@
"@connectrpc/protoc-gen-connect-es": "1.3.0",
"@bufbuild/protobuf": "1.10.0",
"@hyperledger/cactus-plugin-bungee-hermes": "2.0.0",

"axios": "1.7.7",
"body-parser": "1.20.2",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"crypto-js": "4.2.0",
"ethers": "^6.13.1",
"express": "4.17.2",
"fabric-network": "2.2.19",
"fs-extra": "11.2.0",
"hardhat": "2.22.5",
"knex": "2.4.0",
"kubo-rpc-client": "3.0.1",
"npm-run-all": "4.1.5",
"openzeppelin-solidity": "3.4.2",
"secp256k1": "4.0.3",
"socket.io": "4.6.2",
"sqlite3": "5.1.5",
Expand All @@ -104,6 +115,7 @@
"devDependencies": {
"@apidevtools/swagger-cli": "4.0.4",
"@bufbuild/buf": "1.29.0",
"@bufbuild/protobuf": "1.7.2",
"@bufbuild/protoc-gen-es": "1.8.0",
"@quobix/vacuum": "^0.9.10",
"@types/body-parser": "1.19.4",
Expand All @@ -115,6 +127,7 @@
"@types/tape": "4.13.4",
"@types/uuid": "10.0.0",
"body-parser": "1.20.3",
"ethereum-abi-types-generator": "1.3.4",
"express": "4.21.0",
"fabric-network": "2.2.20",
"kubo-rpc-client": "3.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ message CommitReadyResponseMessage {

message CommitFinalAssertionRequestMessage {
cacti.satp.v02.common.CommonSatp common = 1;
cacti.satp.v02.common.BurnAssertionClaim burn_assertion_claim = 2;
string burn_assertion_claim = 2;
cacti.satp.v02.common.BurnAssertionClaimFormat burn_assertion_claim_format = 3;
string client_transfer_number = 4;
string client_signature = 5;
Expand All @@ -30,7 +30,7 @@ message CommitFinalAssertionRequestMessage {

message CommitFinalAcknowledgementReceiptResponseMessage {
cacti.satp.v02.common.CommonSatp common = 1;
cacti.satp.v02.common.AssignmentAssertionClaim assignment_assertion_claim = 2;
string assignment_assertion_claim = 2;
cacti.satp.v02.common.AssignmentAssertionClaimFormat assignment_assertion_claim_format = 3;
string server_transfer_number = 4;
string server_signature = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
StatusRequest,
StatusResponse,
Transact200ResponseStatusResponseOriginChain,
} from "../../generated/gateway-client/typescript-axios";
} from "../../generated/gateway-client/typescript-axios/api";
import { Logger } from "@hyperledger/cactus-common";

export async function ExecuteGetStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
ISATPClientServiceOptions,
ISATPServiceOptions,
} from "../satp-service";
import { ACCEPTANCE } from "../../../generated/proto/cacti/satp/v02/common/session_pb";

export class Stage1ClientService extends SATPService {
public static readonly SATP_STAGE = "1";
Expand Down Expand Up @@ -211,7 +212,7 @@ export class Stage1ClientService extends SATPService {
const fnTag = `${this.getServiceIdentifier()}#${stepTag}`;
this.Log.debug(`${fnTag}, transferCommenceRequest...`);

if (!response || !response.common) {
if (response.common == undefined) {
throw new Error("Response or response.common is undefined");
}

Expand All @@ -226,11 +227,17 @@ export class Stage1ClientService extends SATPService {
commonBody.messageType = MessageType.TRANSFER_COMMENCE_REQUEST;
commonBody.sequenceNumber = response.common.sequenceNumber + BigInt(1);

//todo check when reject
commonBody.hashPreviousMessage = getMessageHash(
sessionData,
MessageType.INIT_RECEIPT,
);
if (sessionData.acceptance == ACCEPTANCE.ACCEPTANCE_ACCEPTED) {
commonBody.hashPreviousMessage = getMessageHash(
sessionData,
MessageType.INIT_RECEIPT,
);
} else if (sessionData.acceptance == ACCEPTANCE.ACCEPTANCE_CONDITIONAL) {
commonBody.hashPreviousMessage = getMessageHash(
sessionData,
MessageType.INIT_REJECT,
);
}

commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey;
commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey;
Expand All @@ -243,7 +250,15 @@ export class Stage1ClientService extends SATPService {
transferCommenceRequestMessage.hashTransferInitClaims =
sessionData.hashTransferInitClaims;

// transferCommenceRequestMessage.clientTransferNumber = sessionData.clientTransferNumber;
if (sessionData.transferContextId != undefined) {
transferCommenceRequestMessage.common.transferContextId =
sessionData.transferContextId;
}

if (sessionData.clientTransferNumber != undefined) {
transferCommenceRequestMessage.clientTransferNumber =
sessionData.clientTransferNumber;
}

const messageSignature = bufArray2HexStr(
sign(this.Signer, JSON.stringify(transferCommenceRequestMessage)),
Expand Down Expand Up @@ -296,8 +311,6 @@ export class Stage1ClientService extends SATPService {
throw new Error(`${fnTag}, satp common body is missing required fields`);
}

// const sessionId = response.common.sessionId;

const sessionData = session.getSessionData();

if (sessionData == undefined) {
Expand Down Expand Up @@ -369,6 +382,15 @@ export class Stage1ClientService extends SATPService {
);
}

if (
sessionData.transferContextId != undefined &&
response.common.transferContextId != sessionData.transferContextId
) {
throw new Error(
`${fnTag}, TransferProposalReceipt transferContextId mismatch or not received`,
);
}

if (
response.common.messageType == MessageType.INIT_REJECT &&
response.transferCounterClaims == undefined
Expand Down
Loading

0 comments on commit f2edd47

Please sign in to comment.