Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SortedOracles sourced from Mento core for CR10 #10946

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/protocol/lib/compatibility/ignored-contracts-v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ export const ignoredContractsV9 = [
'StableTokenRegistry',
'Reserve',
'ReserveSpenderMultiSig',
]

'SortedOracles'
// Note: Sorted Oracles is a Celo Core Contract
// but as it has also been modified and deployed but the Mento team.
// We currently need work to be able to upgrade it again:
// https://github.com/celo-org/celo-monorepo/issues/10435
export const ignoredContractsV9Only = [
'SortedOracles'
// In CR9 the SortedOracles contract was deployed by Mento team, in CR10 we redeployed it ourselves
pahor167 marked this conversation as resolved.
Show resolved Hide resolved
]

export function getReleaseVersion(tag: string) {
const regexp = /core-contracts.v(?<version>.*[0-9])/gm
const matches = regexp.exec(tag)
const version = parseInt(matches?.groups?.version ?? '0', 10)
if ((version) == 0){
if ((version) == 0) {
throw `Tag doesn't have the correct format ${tag}`
}
return version
Expand Down
25 changes: 13 additions & 12 deletions packages/protocol/lib/compatibility/verify-bytecode.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable no-console: 0 */
import { ensureLeading0x } from '@celo/base/lib/address'
import {
LibraryAddresses,
LibraryPositions,
linkLibraries,
stripMetadata,
verifyAndStripLibraryPrefix,
LibraryAddresses,
LibraryPositions,
linkLibraries,
stripMetadata,
verifyAndStripLibraryPrefix,
} from '@celo/protocol/lib/bytecode'
import { verifyProxyStorageProof } from '@celo/protocol/lib/proxy-utils'
import { ProposalTx } from '@celo/protocol/scripts/truffle/make-release'
import { BuildArtifacts } from '@openzeppelin/upgrades'
import { ProxyInstance, RegistryInstance } from 'types'
import Web3 from 'web3'
import { ignoredContractsV9 } from './ignored-contracts-v9'
import { ignoredContractsV9, ignoredContractsV9Only } from './ignored-contracts-v9'

let ignoredContracts = [
// This contract is not proxied
Expand Down Expand Up @@ -143,8 +143,7 @@ const dfsStep = async (queue: string[], visited: Set<string>, context: Verificat
throw new Error(`${contract}'s onchain and compiled bytecodes do not match`)
} else {
console.log(
`${
isLibrary(contract, context) ? 'Library' : 'Contract'
`${isLibrary(contract, context) ? 'Library' : 'Contract'
} deployed at ${implementationAddress} matches ${contract}`
)
}
Expand Down Expand Up @@ -231,15 +230,17 @@ export const verifyBytecodes = async (

const compiledContracts = artifacts.listArtifacts().map((a) => a.contractName)

if (version >= 9) {
if (version > 9) {
ignoredContracts = [...ignoredContracts, ...ignoredContractsV9]
} else if (version == 9) {
ignoredContracts = [...ignoredContracts, ...ignoredContractsV9, ...ignoredContractsV9Only]
}

const queue = contracts.filter(
(contract) => !ignoredContracts.includes(contract)
).filter(
(contract) => compiledContracts.includes(contract)
)
).filter(
(contract) => compiledContracts.includes(contract)
)

const visited: Set<string> = new Set(queue)

Expand Down
6 changes: 2 additions & 4 deletions packages/protocol/scripts/bash/contract-exclusion-regex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ if [ $VERSION_NUMBER -gt 8 ]
CONTRACT_EXCLUSION_REGEX="$CONTRACT_EXCLUSION_REGEX|^Ownable|Initializable|BLS12_377Passthrough|BLS12_381Passthrough]UniswapV2ERC20"
fi

# https://github.com/celo-org/celo-monorepo/issues/10435
# SortedOracles is currently not deployable
# after fixing that this should be modified to VERSION_NUMBER==10
pahor167 marked this conversation as resolved.
Show resolved Hide resolved
if [ $VERSION_NUMBER -gt 9 ]
# In CR9 the SortedOracles contract was deployed by Mento team, in CR10 we redeployed it ourselves
if [ $VERSION_NUMBER -eq 9 ]
then
CONTRACT_EXCLUSION_REGEX="$CONTRACT_EXCLUSION_REGEX|SortedOracles"
fi
27 changes: 27 additions & 0 deletions packages/protocol/scripts/bash/verify-deployed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,31 @@ done
source scripts/bash/release-lib.sh
build_tag $BRANCH $LOG_FILE

if [ "$BRANCH" = "core-contracts.v10" ]; then
if [ ! -d "build/mento" ]; then
mkdir -p build/mento
cd build/mento
git clone --depth 1 --branch v2.2.1 https://github.com/mento-protocol/mento-core.git
cd mento-core
yarn
forge install
forge build
pahor167 marked this conversation as resolved.
Show resolved Hide resolved
else
cd build/mento/mento-core
fi

# Replace the bytecode of the SortedOracles contracts with the bytecode from Mento core v2.2.1
pahor167 marked this conversation as resolved.
Show resolved Hide resolved
orig_value_SortedOracles=$(jq -r '.deployedBytecode.object' out/SortedOracles.sol/SortedOracles.json)
substring_to_replace='__$e9f4a9f9de32ce6d7070252f1b707ecbd2$__'
pahor167 marked this conversation as resolved.
Show resolved Hide resolved
replacement='__AddressSortedLinkedListWithMedian_____'
value_SortedOracles="${orig_value_SortedOracles//$substring_to_replace/$replacement}"
jq --arg value "$value_SortedOracles" '.deployedBytecode = $value' ../../../$BUILD_DIR/contracts/SortedOracles.json > "temp.json" && mv "temp.json" ../../../$BUILD_DIR/contracts/SortedOracles.json

# Replace the bytecode of the AddressSortedLinkedListWithMedian contract with the bytecode from Mento core v2.2.1
value_AddressSortedLinkedListWithMedian=$(jq -r '.deployedBytecode.object' out/AddressSortedLinkedListWithMedian.sol/AddressSortedLinkedListWithMedian.json)
jq --arg value "$value_AddressSortedLinkedListWithMedian" '.deployedBytecode = $value' ../../../$BUILD_DIR/contracts/AddressSortedLinkedListWithMedian.json > temp.json && mv temp.json ../../../$BUILD_DIR/contracts/AddressSortedLinkedListWithMedian.json

cd ../../../
fi

yarn run truffle exec ./scripts/truffle/verify-bytecode.js --network $NETWORK --build_artifacts $BUILD_DIR/contracts --branch $BRANCH --librariesFile "libraries.json" $FORNO
Loading