Start by cloning the repository to your local machine:
git clone https://github.com/aditipolkam/contract-monitoring.git
cd contract-monitoring
npm install
Create and configure environment variable files for the Notification Service. You may need to create a .env
file in the notification-service
or configure your environment variables as needed.
Ensure the following variables are set:
./notification-service/.env
GOOGLE_CLIENT_ID=<your-google-client-id>
GOOGLE_CLIENT_SECRET=<your-google-client-secret>
ACCESS_TOKEN=<your-access-token>
REFRESH_TOKEN=<your-refresh-token>
FROM_EMAIL=<your-from-email-address>
You can get client id and client secret from a Google Oauth app, and an access token and refresh token by using this app to create an Oauth flow - check this.
Ensure that the privateKey
to deploy contract from and ownerEmail
to notify are correctly set in global-config.json
or any other configuration files used for deployment.
Navigate to the root directory of the repository and install the required dependencies for all services. This will install the necessary packages for the Bank Contract
, Trigger Pause Service
, and Notification Service
.
npm run setup
Start a hardhat node in another terminal
npm run node
Comeback to the 1st terminal and deploy the initial version of the Bank_V1
smart contract:
cd bank-contract
npx hardhat run --network localhost dist/scripts/deploy.js
This starts the notification service on http://localhost:3000
and starts listening to contract.
npm start
Deposit some eth to the contract:
npx hardhat run --network localhost dist/scripts/deposit.js
Check balance of the contract and the depositors:
npx hardhat run --network localhost dist/scripts/check_balance.js
Deploy the attacker contract:
npx hardhat run --network localhost dist/scripts/deploy_attacker.js
Execute the attack:
npx hardhat run --network localhost dist/scripts/attack.js
Deploy the upgraded Bank_V2
contract if needed:
npx hardhat run --network localhost dist/scripts/upgrade.js
Contract will be paused by the event processor when the attack is detected, you can use the following to unpause it
npx hardhat run --network localhost dist/scripts/unpause.js