Skip to content

Commit

Permalink
feat(plugin-htlc-eth-besu): add private HTLCs and forge build & test
Browse files Browse the repository at this point in the history
Adds privacy-preserving HTLCs to the htlc-eth-besu package.

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: improve hash time lock base

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: add privacy helper offchain relayer

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: add private HTLC draft (wip)

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

chore: add configuration files

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

chore: recompile contracts

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

test(wip): private htlc

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: private htlc verifications

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

docs: update documentation and configs

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

test: private HTLC (wip)

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

chore: config files and artefacts

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: private htlc

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: fix bug in proof verification

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

chore: lint contracts

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

chore: use hardcoded variable for contract name

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: privacy enhancements

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat: update offchain relayer

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

feat(plugin-htlc-eth-besu): add private HTLCs and forge build & test

Adds privacy-preserving HTLCs to the htlc-eth-besu package.

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

docs(htlc): update README

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

ci(htlc): add foundry setup and tests

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

fix(htlc): remove magic strings

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

fix(htlc): remove gitmodules from root

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

fix(htlc): re-order ci

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

fix(htlc): fix magic strings

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

chore(htlc): update nohoist configuration

Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>

build(package.json): removed global nohoist, add localized remappings

1. Applied the remappings in the foundry.toml file which is local to the
package that's being changed. I figured out the parameters by reverse
engineering the output of `foundry config`
2. Also removed the remappings.txt file because it is deprecated according
to the foundry issue tracker on GitHub.

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
RafaelAPB committed Jun 28, 2023
1 parent da99672 commit 268dcc3
Show file tree
Hide file tree
Showing 31 changed files with 6,036 additions and 17,621 deletions.
8 changes: 3 additions & 5 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"JORDI",
"jsrsa",
"jsrsasign",
"keccak",
"Keychain",
"Keycloak",
"KEYUTIL",
Expand Down Expand Up @@ -103,6 +104,7 @@
"openethereum",
"organisation",
"Orgs",
"ossp",
"parameterizable",
"Postgres",
"proto",
Expand Down Expand Up @@ -139,11 +141,7 @@
"uuidv",
"vscc",
"wasm",
"Xdai",
"goquorum",
"hada",
"undici",
"ossp"
"Xdai"
],
"dictionaries": [
"typescript,node,npm,go,rust"
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,13 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- run: ./tools/ci.sh

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run solidity tests
run: cd packages/cactus-plugin-htlc-eth-besu && forge test -vvvvv

cactus-test-plugin-htlc-eth-besu-erc20:
continue-on-error: false
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const web3SigningCredential: Web3SigningCredential = {
type: Web3SigningCredentialType.PrivateKeyHex,
} as Web3SigningCredential;
const contractAddress = "0xCfEB869F69431e42cdB54A4F4f105C19C080A601";

const contractName = HashTimeLockJSON.contractName;
const testCase = "Test own htlc endpoint";

test("BEFORE " + testCase, async (t: Test) => {
Expand Down Expand Up @@ -95,10 +95,7 @@ test(testCase, async (t: Test) => {
DemoHelperJSON.contractName,
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
JSON.stringify(HashTimeLockJSON),
);
keychainPlugin.set(contractName, JSON.stringify(HashTimeLockJSON));

const factory = new PluginFactoryLedgerConnector({
pluginImportType: PluginImportType.Local,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const web3SigningCredential: Web3SigningCredential = {
type: Web3SigningCredentialType.PrivateKeyHex,
} as Web3SigningCredential;
const contractAddress = "0xCfEB869F69431e42cdB54A4F4f105C19C080A601";

const contractName = HashTimeLockJSON.contractName;
const testCase = "Test own htlc endpoint";

test("BEFORE " + testCase, async (t: Test) => {
Expand Down Expand Up @@ -94,10 +94,7 @@ test(testCase, async (t: Test) => {
DemoHelperJSON.contractName,
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
JSON.stringify(HashTimeLockJSON),
);
keychainPlugin.set(contractName, JSON.stringify(HashTimeLockJSON));

const factory = new PluginFactoryLedgerConnector({
pluginImportType: PluginImportType.Local,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const web3SigningCredential: Web3SigningCredential = {
type: Web3SigningCredentialType.PrivateKeyHex,
} as Web3SigningCredential;
const contractAddress = "0xCfEB869F69431e42cdB54A4F4f105C19C080A601";

const contractName = HashTimeLockJSON.contractName;
const testCase = "Test own htlc endpoint";

test("BEFORE " + testCase, async (t: Test) => {
Expand Down Expand Up @@ -99,10 +99,7 @@ test(testCase, async (t: Test) => {
DemoHelperJSON.contractName,
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
JSON.stringify(HashTimeLockJSON),
);
keychainPlugin.set(contractName, JSON.stringify(HashTimeLockJSON));

const factory = new PluginFactoryLedgerConnector({
pluginImportType: PluginImportType.Local,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const web3SigningCredential: Web3SigningCredential = {
type: Web3SigningCredentialType.PrivateKeyHex,
} as Web3SigningCredential;
const contractAddress = "0xCfEB869F69431e42cdB54A4F4f105C19C080A601";

const contractName = HashTimeLockJSON.contractName;
const testCase = "Test own htlc endpoint";

test("BEFORE " + testCase, async (t: Test) => {
Expand Down Expand Up @@ -99,10 +99,7 @@ test(testCase, async (t: Test) => {
DemoHelperJSON.contractName,
JSON.stringify(DemoHelperJSON),
);
keychainPlugin.set(
HashTimeLockJSON.contractName,
JSON.stringify(HashTimeLockJSON),
);
keychainPlugin.set(contractName, JSON.stringify(HashTimeLockJSON));

const factory = new PluginFactoryLedgerConnector({
pluginImportType: PluginImportType.Local,
Expand Down
5 changes: 5 additions & 0 deletions packages/cactus-plugin-htlc-eth-besu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
cache
lib
vendor
.gas-snapshot
41 changes: 32 additions & 9 deletions packages/cactus-plugin-htlc-eth-besu/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
# @hyperledger/cactus-plugin-htlc-eth-besu

Allows `Cactus` to interact with HTLC contract
Allows `Cacti` to interact with HTLC contract manager.


## Summary

- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installing](#installing)
- [Runing the tests](#running-the-tests)
- [Contributing](#contributing)
- [License](#license)


## Getting Started
The smart contracts and rationalle ane explained in detail in <a href=https://medium.com/@rafaelbelchior/dlt-interoperability-and-more-%EF%B8%8F-24-privacy-preserving-cross-chain-atomic-swaps-bonus-lets-ff99a90714de> this Medium article </a>.

These instructions will get you a copy of the project up and running on
your local machine for development and testing purposes.

### Prerequisites

### Installing

Steps to compile the project:
Install Foundry: https://book.getfoundry.sh/getting-started/installation

Steps to compile the project: `forge build`.



In a `Cactus` root directory execute:
```sh
npm run configure
```
## Running the tests

The tests can be found in @hyperledger/cactus-test-htlc-eth-besu. To run this, in the root project execute:
Expand All @@ -35,11 +34,35 @@ The tests can be found in @hyperledger/cactus-test-htlc-eth-besu. To run this, i
npm run test:plugin-htlc-besu
```

To run the solidity tests (within the root directory of this package):
`forge test --match-contract PrivateHashTimeLockTest`

To run a specific function:
`forge test --match-contract PrivateHashTimeLockTest --match-test testDeployment`

Run ALL the solidity tests: `forge test -vvvv`


## Contributing

We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do!

Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started.

## Nohoist configuration
Foundry uses ``forge-std``and ``ds-test``modules for testing purposes. Given that Foundry cannot access files outside of the project, we use nohoist to force lerna to download the packages within the Forge project directory:

``
"nohoist": [
"**/iroha-helpers",
"**/forge-std",
"**/forge-std/**"
]
},
``

If in the future Forge supports importing Solidity files from outside the project, the imports/re-mappings can be updated and the nohoist configuration removed.

## License

This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file.
45 changes: 45 additions & 0 deletions packages/cactus-plugin-htlc-eth-besu/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Foundry Configuration File
# Default definitions: https://github.com/gakonst/foundry/blob/b7917fa8491aedda4dd6db53fbb206ea233cd531/config/src/lib.rs#L782

[profile.default]
# The source directory
src = './src/main/solidity/contracts'
# The test directory
test = 'src/test/solidity/integration'
# The script directory
script = './src/main/solidity/contracts/scripts'
# The artifact directory
out = 'build'
solc_version = '0.8.19'
auto_detect_solc = false
optimizer_runs = 1_000
sender = '0x00a329c0648769a73afac7f9381e08fb43dbea72' # the address of `msg.sender` in tests
tx_origin = '0x00a329c0648769a73afac7f9381e08fb43dbea72' # the address of `tx.origin` in tests
block_number = 0 # the block number we are at in tests
chain_id = 99 # the chain id we are on in tests
gas_limit = 9223372036854775807 # the gas limit in tests
gas_reports = ['*']
gas_price = 0 # the gas price (in wei) in tests
block_base_fee_per_gas = 0 # the base fee (in wei) in tests
block_coinbase = '0x0000000000000000000000000000000000000000' # the address of `block.coinbase` in tests
block_timestamp = 0 # the value of `block.timestamp` in tests
block_difficulty = 0
fuzz = { runs = 256 } # the number of fuzz runs for tests
libs = ["../../node_modules"]
remappings = [
"ds-test/=../../node_modules/ds-test/src/",
"forge-std/=../../node_modules/forge-std/src/",
]

# Fuzzing CI
[profile.ci]
fuzz_runs = 100_00
verbosity = 4

[rpc_endpoints]
goerli = "${RPC_URL_GOERLI}"
mainnet = "${RPC_URL_MAINNET}"

[etherscan]
goerli = {key = "${ETHERSCAN_KEY}", url = "https://api-goerli.etherscan.io/api"}
mainnet = {key = "${ETHERSCAN_KEY}"}
17 changes: 14 additions & 3 deletions packages/cactus-plugin-htlc-eth-besu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
"name": "Azahara Castaño",
"email": "a.castano.benito@accenture.com",
"url": "https://accenture.com"
},
{
"name": "Rafael Belchior",
"email": "rafael.belchior@tecnico.ulisboa.pt",
"url": "https://rafaelapb.github.io/"
}
],
"main": "dist/lib/main/typescript/index.js",
Expand All @@ -52,11 +57,13 @@
"codegen:openapi": "npm run generate-sdk",
"generate-sdk": "run-p generate-sdk:*",
"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",
"lint": "solhint --fix",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev",
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web",
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js",
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js"
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js",
"compile-contracts": "forge build"
},
"dependencies": {
"@hyperledger/cactus-common": "2.0.0-alpha.1",
Expand All @@ -66,17 +73,21 @@
"@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-alpha.1",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.1",
"axios": "0.21.4",
"bn.js": "5.2.1",
"dotenv": "16.0.3",
"ethers": "6.3.0",
"express": "4.17.1",
"joi": "17.9.1",
"openapi-types": "9.1.0",
"typescript-optional": "2.0.1",
"web3": "1.5.2",
"web3js-quorum": "21.7.0-rc1"
},
"devDependencies": {
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-alpha.1",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.1",
"@types/express": "4.17.13"
"@types/express": "4.17.13",
"forge-std": "https://github.com/foundry-rs/forge-std.git#66bf4e2c92cf507531599845e8d5a08cc2e3b5bb",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0"
},
"engines": {
"node": ">=10",
Expand Down
Loading

0 comments on commit 268dcc3

Please sign in to comment.