Skip to content

Commit

Permalink
Feat: Fixed the multi-chain reporting and Bridge exploit issues #144
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-eshghie committed Jun 24, 2024
1 parent 617c3f6 commit 89c55c0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 251 deletions.
16 changes: 4 additions & 12 deletions CI/setup-cross-chain-unified.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,15 @@ const exploitsList = [
async function setupAndRunTests() {
for (const exploitPath of exploitsList) {
try {
const exploitModule = require(path.resolve(__dirname, exploitPath));
if (typeof exploitModule.startUp === 'function') {
await exploitModule.startUp();
console.log(`Successfully ran startUp for ${exploitPath}`);
} else {
console.error(`No startUp function found in ${exploitPath}`);
}
const exploitSetup = require(path.resolve(__dirname, exploitPath));
await exploitSetup();
bridgeTestLogger.info(`Successfully completed setup for ${exploitPath}`);
} catch (error) {
console.error(`Failed to run startUp for ${exploitPath}:`, error);
console.error(`Failed to run setup for ${exploitPath}:`, error);
}
}
}

setupAndRunTests()
.then(() => console.log('All tests have been set up and run.'))
.catch(err => console.error('Error setting up and running tests:', err));

// proper command to run this would be:
// pkill anvil; clear; node CI/run.js -t cross-chain -e unified
module.exports = setupAndRunTests;
29 changes: 26 additions & 3 deletions CI/tests/Bridge.exploit1.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,33 @@ async function callSmartContract(method, sender, value = 0){
}

async function startUp() {

console.log(chalk.cyan(`exploit 1`));
bridgeTestLogger.debug("Starting Anvil...");
let envAnvil = await setupAnvilEnv();
bridgeTestLogger.debug("Finished running Anvil...");
//let envAnvil = await setupAnvilEnv();

const maxRetries = 10;
let attempts = 0;
let envAnvil;

while (attempts < maxRetries) {
try {
await sleep(1000);
envAnvil = await setupAnvilEnv();
bridgeTestLogger.debug('Environment setup successful:', envAnvil);
break;
} catch (error) {
bridgeTestLogger.debug(`Attempt ${attempts + 1}: Failed to set up environment - ${error}`);
console.error(`Attempt ${attempts + 1}: Failed to set up environment - ${error}`);
attempts++;
if (attempts === maxRetries) {
console.error('Max retries reached, failing with error');
bridgeTestLogger.error('Max retries reached, failing with error');
throw error; // Optionally re-throw the last error after max retries
}
}
}

//bridgeTestLogger.debug("Finished running Anvil...");

bridgeTestLogger.debug("Starting Avalanche...");
let envAvalanche = await setupAvalancheEnv();
Expand Down
26 changes: 25 additions & 1 deletion CI/tests/Bridge.exploit2.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,33 @@ async function callSmartContract(method, sender, value = 0){
}

async function startUp() {

console.log(chalk.cyan(`exploit 2`));

bridgeTestLogger.debug("Starting Anvil...");
let envAnvil = await setupAnvilEnv();

const maxRetries = 10;
let attempts = 0;
let envAnvil;

while (attempts < maxRetries) {
try {
await sleep(1000);
envAnvil = await setupAnvilEnv();
bridgeTestLogger.debug('Environment setup successful:', envAnvil);
break;
} catch (error) {
bridgeTestLogger.debug(`Attempt ${attempts + 1}: Failed to set up environment - ${error}`);
console.error(`Attempt ${attempts + 1}: Failed to set up environment - ${error}`);
attempts++;
if (attempts === maxRetries) {
console.error('Max retries reached, failing with error');
bridgeTestLogger.error('Max retries reached, failing with error');
throw error; // Optionally re-throw the last error after max retries
}
}
}

bridgeTestLogger.debug("Finished running Anvil...");

bridgeTestLogger.debug("Starting Avalanche...");
Expand Down
4 changes: 2 additions & 2 deletions lib/logging/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ exports.getLogger = (moduleName) => {
),
transports: [
new winston.transports.Console({
//level: 'debug', // Ensure all levels are logged to the console
level: 'info', // Suppress all other types of logs in the console for now;
level: 'debug', // Ensure all levels are logged to the console
//level: 'info', // Suppress all other types of logs in the console for now;
format: winston.format.combine(
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
winston.format.printf(info => `${info.timestamp} [${info.level}]: ${colorize(info.level, info.message)}`)
Expand Down
232 changes: 0 additions & 232 deletions monitor/multi-chain-monitor-backup.js

This file was deleted.

3 changes: 2 additions & 1 deletion monitor/multi-chain-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Monitor extends EventEmitter {
// activities: await getActivities(1823056),
// modelId: 1823056,
// hasResponseRelation: true,
// modelName: "something",
// };


Expand Down Expand Up @@ -182,7 +183,7 @@ class Monitor extends EventEmitter {

const markdownContent = `${headerLine}\n${separatorLine}\n${tableRows}`;

const fileName = `${this.configs.contractFileName}.md`;
const fileName = `${this.configs.modelName}.md`;
const filePath = path.join('results', fileName);

fs.writeFileSync(filePath, markdownContent, 'utf8');
Expand Down

0 comments on commit 89c55c0

Please sign in to comment.