From ace4af29ef18bd5208346a8969ddc604f061bfdd Mon Sep 17 00:00:00 2001
From: Martin <martin@celo.org>
Date: Fri, 16 Oct 2020 18:42:56 +0200
Subject: [PATCH] Add positive output to the verify-bytecodes script (#5398)

### Description

Previously the script would just exit with code 0 and no stdout output about success. Added logs reporting which contracts have been checked and at which address on the network.

Added a `--quiet` flag to optionally suppress this new output (`-q` in the bash wrapper).

### Other changes

`getImplementationAddress` was previously returning pre-release 1 library addresses without a "0x" prefix, fixed this for consistency in logs.

Improved the documentation comment in `verify-bytecodes.ts`.

### Tested

`yarn verify-bytecodes -b rc1 -n rc1 -r -f` succeeds outputs the new logs. Adding `-q` still succeeds and suppresses output.

### Related issues

- Part of #4812

### Backwards compatibility

Only cosmetic script change.
---
 .../lib/compatibility/verify-bytecode.ts      |  8 ++++++--
 .../scripts/truffle/verify-bytecode.ts        | 20 +++++++++++--------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/packages/protocol/lib/compatibility/verify-bytecode.ts b/packages/protocol/lib/compatibility/verify-bytecode.ts
index 4aaa23044c4..dd6de4436c2 100644
--- a/packages/protocol/lib/compatibility/verify-bytecode.ts
+++ b/packages/protocol/lib/compatibility/verify-bytecode.ts
@@ -81,7 +81,7 @@ const getImplementationAddress = async (contract: string, context: VerificationC
     proxyAddress = context.libraryAddresses.addresses[contract]
     // Before the first contracts upgrade libraries are not proxied.
     if (context.isBeforeRelease1) {
-      return proxyAddress
+      return `0x${proxyAddress}`
     }
   } else {
     // contract is registered but we need to check if the proxy is affected by the proposal
@@ -124,6 +124,10 @@ const dfsStep = async (queue: string[], visited: Set<string>, context: Verificat
 
   if (onchainBytecode !== linkedSourceBytecode) {
     throw new Error(`${contract}'s onchain and compiled bytecodes do not match`)
+  } else {
+    // tslint:disable-next-line: no-console
+    console.log(
+      `${isLibrary(contract, context) ? 'Library' : 'Contract'} deployed at ${implementationAddress} matches ${contract}`)
   }
 
   // push unvisited libraries to DFS queue
@@ -144,7 +148,7 @@ export const verifyBytecodes = async (
   proposal: ProposalTx[],
   Proxy: Truffle.Contract<ProxyInstance>,
   web3: Web3,
-  isBeforeRelease1: boolean = false
+  isBeforeRelease1: boolean = false,
 ) => {
   const queue = contracts.filter((contract) => !ignoredContracts.includes(contract))
   const visited: Set<string> = new Set(queue)
diff --git a/packages/protocol/scripts/truffle/verify-bytecode.ts b/packages/protocol/scripts/truffle/verify-bytecode.ts
index 29153dfb6e8..6f832cbf37d 100644
--- a/packages/protocol/scripts/truffle/verify-bytecode.ts
+++ b/packages/protocol/scripts/truffle/verify-bytecode.ts
@@ -12,16 +12,17 @@ import fs = require('fs')
  * proposal description.
  *
  * Expects the following flags:
- *   build_artifacts: The directory in which smart contract build artifacts can
- *   be found.
- *   proposal (optional): The JSON file containing a Governance proposal that
+ *   --build_artifacts: The directory in which smart contract build artifacts
+ *   can be found (defaults to ./build/contracts/)
+ *   --proposal: The JSON file containing a Governance proposal that
  *   repoints the Registry to newly deployed Proxies and/or repoints existing
  *   Proxies to new implementation addresses.
- *   before_release_1 (optional): a temporary feature flag needed before the
- *   first contracts upgrades establishes new conventions around how smart
- *   contracts are handled on chain. Specifically, after the first release,
- *   linked libraries will be proxied, so libraries before this release have to
- *   be handled differently by this script.
+ *   --before_release_1: a temporary feature flag needed before the first
+ *   contracts upgrade establishes new conventions around how smart contracts
+ *   are handled on chain. Specifically, after the first release, linked
+ *   libraries will be proxied, so libraries before this release have to be
+ *   handled differently by this script.
+ *   TODO: remove --before_release_1 after the first release
  *
  * Run using truffle exec, e.g.:
  * truffle exec scripts/truffle/verify-bytecode \
@@ -54,6 +55,9 @@ module.exports = async (callback: (error?: any) => number) => {
       web3,
       beforeRelease1
     )
+
+    // tslint:disable-next-line: no-console
+    console.log('Success, no bytecode mismatches found!')
   } catch (error) {
     callback(error)
   }