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

adding transaction for June 13th HCU #295

Merged
merged 9 commits into from
Jun 13, 2024
5 changes: 5 additions & 0 deletions templates/deploy_contract_dependency_audit.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
transaction(code: String, addresses: [Address]) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janezpodhostnik - will be using this to deploy the DependencyAudit contract

vishalchangrani marked this conversation as resolved.
Show resolved Hide resolved
prepare(serviceAccount: AuthAccount) {
serviceAccount.contracts.add(name: name, code: code.decodeHex(), excludedAddresses: addresses)
}
}
130 changes: 130 additions & 0 deletions transactions/deploy-contract/2024/jun-13/DependencyAudit.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import MigrationContractStaging from 0x56100d46aa9b0212

// This contract is is used by the FVM calling the `checkDependencies` function from a function of the same name and singnature in the FlowServiceAccount contract,
// at the end of every transaction.
// The `dependenciesAddresses` and `dependenciesNames` will be all the dependencies needded to run that transaction.
//
// The `checkDependencies` function will check if any of the dependencies are not staged in the MigrationContractStaging contract.
// If any of the dependencies are not staged, the function will emit an event with the unstaged dependencies, or panic if `panicOnUnstaged` is set to true.
access(all) contract DependencyAudit {

access(all) let AdministratorStoragePath: StoragePath

// The system addresses have contracts that will not be stages via the migration contract so we exclude them from the dependency chekcs
access(self) var excludedAddresses: {Address: Bool}

access(all) var panicOnUnstaged: Bool

access(all) event UnstagedDependencies(dependencies: [Dependency])

access(all) event PanicOnUnstagedDependenciesChanged(shouldPanic: Bool)

// checkDependencies is called from the FlowServiceAccount contract
access(account) fun checkDependencies(_ dependenciesAddresses: [Address], _ dependenciesNames: [String], _ authorizers: [Address]) {
var unstagedDependencies: [Dependency] = []

var numDependencies = dependenciesAddresses.length
var i = 0
while i < numDependencies {
let isExcluded = DependencyAudit.excludedAddresses[dependenciesAddresses[i]] ?? false
if isExcluded {
i = i + 1
continue
}

let staged = MigrationContractStaging.isStaged(address: dependenciesAddresses[i], name: dependenciesNames[i])
if !staged {
unstagedDependencies.append(Dependency(address: dependenciesAddresses[i], name: dependenciesNames[i]))
}

i = i + 1
}

if unstagedDependencies.length > 0 {
if DependencyAudit.panicOnUnstaged {
// If `panicOnUnstaged` is set to true, the transaction will panic if there are any unstaged dependencies
// the panic message will include the unstaged dependencies
var unstagedDependenciesString = ""
var numUnstagedDependencies = unstagedDependencies.length
var j = 0
while j < numUnstagedDependencies {
if j > 0 {
unstagedDependenciesString = unstagedDependenciesString.concat(", ")
}
unstagedDependenciesString = unstagedDependenciesString.concat(unstagedDependencies[j].toString())

j = j + 1
}

// the transactions will fail with a message that looks like this: `error: panic: Found unstaged dependencies: A.2ceae959ed1a7e7a.MigrationContractStaging, A.2ceae959ed1a7e7a.DependencyAudit`
panic("This transaction is using dependencies not staged for Crescendo upgrade coming soon! Learn more: https://bit.ly/FLOWCRESCENDO. Dependencies not staged: ".concat(unstagedDependenciesString))
} else {
emit UnstagedDependencies(dependencies: unstagedDependencies)
}
}
}

// The Administrator resorce can be used to add or remove addresses from the excludedAddresses dictionary
//
access(all) resource Administrator {
// addExcludedAddresses add the addresses to the excludedAddresses dictionary
access(all) fun addExcludedAddresses(addresses: [Address]) {
for address in addresses {
DependencyAudit.excludedAddresses[address] = true
}
}

// removeExcludedAddresses remove the addresses from the excludedAddresses dictionary
access(all) fun removeExcludedAddresses(addresses: [Address]) {
for address in addresses {
DependencyAudit.excludedAddresses.remove(key: address)
}
}

// setPanicOnUnstagedDependencies sets the `panicOnUnstaged` variable to the value of `shouldPanic`
access(all) fun setPanicOnUnstagedDependencies(shouldPanic: Bool) {
DependencyAudit.panicOnUnstaged = shouldPanic
emit PanicOnUnstagedDependenciesChanged(shouldPanic: shouldPanic)
}

// testCheckDependencies is used for testing purposes
// It will call the `checkDependencies` function with the provided dependencies
// `checkDependencies` is otherwise not callable from the outside
access(all) fun testCheckDependencies(_ dependenciesAddresses: [Address], _ dependenciesNames: [String], _ authorizers: [Address]) {
return DependencyAudit.checkDependencies(dependenciesAddresses, dependenciesNames, authorizers)
}
}

access(all) struct Dependency {
access(all) let address: Address
access(all) let name: String

init(address: Address, name: String) {
self.address = address
self.name = name
}

access(all) fun toString(): String {
var addressString = self.address.toString()
// remove 0x prefix
addressString = addressString.slice(from: 2, upTo: addressString.length)
return "A.".concat(addressString).concat(".").concat(self.name)
}
}

// The admin resource is saved to the storage so that the admin can be accessed by the service account
// The `excludedAddresses` will be the addresses with the system contracts.
init(excludedAddresses: [Address]) {
self.excludedAddresses = {}
self.panicOnUnstaged = false

self.AdministratorStoragePath = /storage/flowDependencyAuditAdmin

for address in excludedAddresses {
self.excludedAddresses[address] = true
}

let admin <- create Administrator()
self.account.save(<-admin, to: self.AdministratorStoragePath)
}
}
41 changes: 41 additions & 0 deletions transactions/deploy-contract/2024/jun-13/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Deploy [DependencyAudit.cdc](https://github.com/onflow/contract-updater/blob/main/contracts/DependencyAudit.cdc)

> June 13th, 2024

## Contract to be deployed

https://github.com/onflow/contract-updater/blob/main/contracts/DependencyAudit.cdc

See [issue](https://github.com/onflow/service-account/issues/294)

## Transaction template

../../../../templates/deploy_contract_dependency_audit.cdc

##

Arguments generated using:
```
cd transactions/deploy-contract/2024/jun-13

wget https://raw.githubusercontent.com/onflow/contract-updater/main/contracts/DependencyAudit.cdc

To generates hex encoded contract cdc

cat "./DependencyAudit.cdc" | xxd -p | tr -d '\n'
```

Arguments verified using:
```
$ cat arguments.json | jq '.[1] | .value' | xxd -r -p > /tmp/temp.txt
$ diff /tmp/temp.txt ./DependencyAudit.cdc
(Should produce no difference)
```


[Multi-sign setup](https://flow-multisig-git-service-account-onflow.vercel.app/mainnet)


## Results

https://www.flowdiver.io/tx/
1 change: 1 addition & 0 deletions transactions/deploy-contract/2024/jun-13/arguments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"type":"String","value":"DependencyAudit"},{"type":"String","value":"696d706f7274204d6967726174696f6e436f6e747261637453746167696e672066726f6d203078353631303064343661613962303231320a0a2f2f205468697320636f6e74726163742069732069732075736564206279207468652046564d2063616c6c696e67207468652060636865636b446570656e64656e63696573602066756e6374696f6e2066726f6d20612066756e6374696f6e206f66207468652073616d65206e616d6520616e642073696e676e617475726520696e2074686520466c6f77536572766963654163636f756e7420636f6e74726163742c0a2f2f2061742074686520656e64206f66206576657279207472616e73616374696f6e2e0a2f2f205468652060646570656e64656e636965734164647265737365736020616e642060646570656e64656e636965734e616d6573602077696c6c20626520616c6c2074686520646570656e64656e63696573206e65656464656420746f2072756e2074686174207472616e73616374696f6e2e0a2f2f0a2f2f205468652060636865636b446570656e64656e63696573602066756e6374696f6e2077696c6c20636865636b20696620616e79206f662074686520646570656e64656e6369657320617265206e6f742073746167656420696e20746865204d6967726174696f6e436f6e747261637453746167696e6720636f6e74726163742e0a2f2f20496620616e79206f662074686520646570656e64656e6369657320617265206e6f74207374616765642c207468652066756e6374696f6e2077696c6c20656d697420616e206576656e7420776974682074686520756e73746167656420646570656e64656e636965732c206f722070616e6963206966206070616e69634f6e556e737461676564602069732073657420746f20747275652e0a61636365737328616c6c2920636f6e747261637420446570656e64656e63794175646974207b0a0a2020202061636365737328616c6c29206c65742041646d696e6973747261746f7253746f72616765506174683a2053746f72616765506174680a0a202020202f2f205468652073797374656d20616464726573736573206861766520636f6e74726163747320746861742077696c6c206e6f74206265207374616765732076696120746865206d6967726174696f6e20636f6e747261637420736f207765206578636c756465207468656d2066726f6d2074686520646570656e64656e6379206368656b63730a202020206163636573732873656c662920766172206578636c756465644164647265737365733a207b416464726573733a20426f6f6c7d0a0a2020202061636365737328616c6c29207661722070616e69634f6e556e7374616765643a20426f6f6c0a0a2020202061636365737328616c6c29206576656e7420556e737461676564446570656e64656e6369657328646570656e64656e636965733a205b446570656e64656e63795d290a0a2020202061636365737328616c6c29206576656e742050616e69634f6e556e737461676564446570656e64656e636965734368616e6765642873686f756c6450616e69633a20426f6f6c290a0a202020202f2f20636865636b446570656e64656e636965732069732063616c6c65642066726f6d2074686520466c6f77536572766963654163636f756e7420636f6e74726163740a20202020616363657373286163636f756e74292066756e20636865636b446570656e64656e63696573285f20646570656e64656e636965734164647265737365733a205b416464726573735d2c205f20646570656e64656e636965734e616d65733a205b537472696e675d2c205f20617574686f72697a6572733a205b416464726573735d29207b0a202020202020202076617220756e737461676564446570656e64656e636965733a205b446570656e64656e63795d203d205b5d0a0a2020202020202020766172206e756d446570656e64656e63696573203d20646570656e64656e636965734164647265737365732e6c656e6774680a20202020202020207661722069203d20300a20202020202020207768696c652069203c206e756d446570656e64656e63696573207b0a2020202020202020202020206c65742069734578636c75646564203d20446570656e64656e637941756469742e6578636c756465644164647265737365735b646570656e64656e636965734164647265737365735b695d5d203f3f2066616c73650a20202020202020202020202069662069734578636c75646564207b0a2020202020202020202020202020202069203d2069202b20310a20202020202020202020202020202020636f6e74696e75650a2020202020202020202020207d0a0a2020202020202020202020206c657420737461676564203d204d6967726174696f6e436f6e747261637453746167696e672e697353746167656428616464726573733a20646570656e64656e636965734164647265737365735b695d2c206e616d653a20646570656e64656e636965734e616d65735b695d290a20202020202020202020202069662021737461676564207b0a20202020202020202020202020202020756e737461676564446570656e64656e636965732e617070656e6428446570656e64656e637928616464726573733a20646570656e64656e636965734164647265737365735b695d2c206e616d653a20646570656e64656e636965734e616d65735b695d29290a2020202020202020202020207d0a0a20202020202020202020202069203d2069202b20310a20202020202020207d0a0a2020202020202020696620756e737461676564446570656e64656e636965732e6c656e677468203e2030207b0a202020202020202020202020696620446570656e64656e637941756469742e70616e69634f6e556e737461676564207b0a202020202020202020202020202020202f2f204966206070616e69634f6e556e737461676564602069732073657420746f20747275652c20746865207472616e73616374696f6e2077696c6c2070616e69632069662074686572652061726520616e7920756e73746167656420646570656e64656e636965730a202020202020202020202020202020202f2f207468652070616e6963206d6573736167652077696c6c20696e636c7564652074686520756e73746167656420646570656e64656e636965730a2020202020202020202020202020202076617220756e737461676564446570656e64656e63696573537472696e67203d2022220a20202020202020202020202020202020766172206e756d556e737461676564446570656e64656e63696573203d20756e737461676564446570656e64656e636965732e6c656e6774680a20202020202020202020202020202020766172206a203d20300a202020202020202020202020202020207768696c65206a203c206e756d556e737461676564446570656e64656e63696573207b0a20202020202020202020202020202020202020206966206a203e2030207b0a202020202020202020202020202020202020202020202020756e737461676564446570656e64656e63696573537472696e67203d20756e737461676564446570656e64656e63696573537472696e672e636f6e63617428222c2022290a20202020202020202020202020202020202020207d0a2020202020202020202020202020202020202020756e737461676564446570656e64656e63696573537472696e67203d20756e737461676564446570656e64656e63696573537472696e672e636f6e63617428756e737461676564446570656e64656e636965735b6a5d2e746f537472696e672829290a0a20202020202020202020202020202020202020206a203d206a202b20310a202020202020202020202020202020207d0a0a202020202020202020202020202020202f2f20746865207472616e73616374696f6e732077696c6c206661696c20776974682061206d6573736167652074686174206c6f6f6b73206c696b6520746869733a20606572726f723a2070616e69633a20466f756e6420756e73746167656420646570656e64656e636965733a20412e326365616539353965643161376537612e4d6967726174696f6e436f6e747261637453746167696e672c20412e326365616539353965643161376537612e446570656e64656e63794175646974600a2020202020202020202020202020202070616e6963282254686973207472616e73616374696f6e206973207573696e6720646570656e64656e63696573206e6f742073746167656420666f72204372657363656e646f207570677261646520636f6d696e6720736f6f6e21204c6561726e206d6f72653a2068747470733a2f2f6269742e6c792f464c4f574352455343454e444f2e20446570656e64656e63696573206e6f74207374616765643a20222e636f6e63617428756e737461676564446570656e64656e63696573537472696e6729290a2020202020202020202020207d20656c7365207b0a20202020202020202020202020202020656d697420556e737461676564446570656e64656e6369657328646570656e64656e636965733a20756e737461676564446570656e64656e63696573290a2020202020202020202020207d0a20202020202020207d0a202020207d0a0a202020202f2f205468652041646d696e6973747261746f72207265736f7263652063616e206265207573656420746f20616464206f722072656d6f7665206164647265737365732066726f6d20746865206578636c756465644164647265737365732064696374696f6e6172790a202020202f2f0a2020202061636365737328616c6c29207265736f757263652041646d696e6973747261746f72207b0a20202020202020202f2f206164644578636c7564656441646472657373657320616464207468652061646472657373657320746f20746865206578636c756465644164647265737365732064696374696f6e6172790a202020202020202061636365737328616c6c292066756e206164644578636c75646564416464726573736573286164647265737365733a205b416464726573735d29207b0a202020202020202020202020666f72206164647265737320696e20616464726573736573207b0a20202020202020202020202020202020446570656e64656e637941756469742e6578636c756465644164647265737365735b616464726573735d203d20747275650a2020202020202020202020207d0a20202020202020207d0a0a20202020202020202f2f2072656d6f76654578636c756465644164647265737365732072656d6f766520746865206164647265737365732066726f6d20746865206578636c756465644164647265737365732064696374696f6e6172790a202020202020202061636365737328616c6c292066756e2072656d6f76654578636c75646564416464726573736573286164647265737365733a205b416464726573735d29207b0a202020202020202020202020666f72206164647265737320696e20616464726573736573207b0a20202020202020202020202020202020446570656e64656e637941756469742e6578636c756465644164647265737365732e72656d6f7665286b65793a2061646472657373290a2020202020202020202020207d0a20202020202020207d0a0a20202020202020202f2f2073657450616e69634f6e556e737461676564446570656e64656e63696573207365747320746865206070616e69634f6e556e73746167656460207661726961626c6520746f207468652076616c7565206f66206073686f756c6450616e6963600a202020202020202061636365737328616c6c292066756e2073657450616e69634f6e556e737461676564446570656e64656e636965732873686f756c6450616e69633a20426f6f6c29207b0a202020202020202020202020446570656e64656e637941756469742e70616e69634f6e556e737461676564203d2073686f756c6450616e69630a202020202020202020202020656d69742050616e69634f6e556e737461676564446570656e64656e636965734368616e6765642873686f756c6450616e69633a2073686f756c6450616e6963290a20202020202020207d0a0a20202020202020202f2f2074657374436865636b446570656e64656e63696573206973207573656420666f722074657374696e6720707572706f7365730a20202020202020202f2f2049742077696c6c2063616c6c207468652060636865636b446570656e64656e63696573602066756e6374696f6e2077697468207468652070726f766964656420646570656e64656e636965730a20202020202020202f2f2060636865636b446570656e64656e6369657360206973206f7468657277697365206e6f742063616c6c61626c652066726f6d20746865206f7574736964650a202020202020202061636365737328616c6c292066756e2074657374436865636b446570656e64656e63696573285f20646570656e64656e636965734164647265737365733a205b416464726573735d2c205f20646570656e64656e636965734e616d65733a205b537472696e675d2c205f20617574686f72697a6572733a205b416464726573735d29207b0a20202020202020202020202072657475726e20446570656e64656e637941756469742e636865636b446570656e64656e6369657328646570656e64656e636965734164647265737365732c20646570656e64656e636965734e616d65732c20617574686f72697a657273290a20202020202020207d0a202020207d0a0a2020202061636365737328616c6c292073747275637420446570656e64656e6379207b0a202020202020202061636365737328616c6c29206c657420616464726573733a20416464726573730a202020202020202061636365737328616c6c29206c6574206e616d653a20537472696e670a0a2020202020202020696e697428616464726573733a20416464726573732c206e616d653a20537472696e6729207b0a20202020202020202020202073656c662e61646472657373203d20616464726573730a20202020202020202020202073656c662e6e616d65203d206e616d650a20202020202020207d0a0a202020202020202061636365737328616c6c292066756e20746f537472696e6728293a20537472696e67207b0a2020202020202020202020207661722061646472657373537472696e67203d2073656c662e616464726573732e746f537472696e6728290a2020202020202020202020202f2f2072656d6f7665203078207072656669780a20202020202020202020202061646472657373537472696e67203d2061646472657373537472696e672e736c6963652866726f6d3a20322c207570546f3a2061646472657373537472696e672e6c656e677468290a20202020202020202020202072657475726e2022412e222e636f6e6361742861646472657373537472696e67292e636f6e63617428222e22292e636f6e6361742873656c662e6e616d65290a20202020202020207d0a202020207d0a0a202020202f2f205468652061646d696e207265736f7572636520697320736176656420746f207468652073746f7261676520736f2074686174207468652061646d696e2063616e206265206163636573736564206279207468652073657276696365206163636f756e740a202020202f2f2054686520606578636c75646564416464726573736573602077696c6c20626520746865206164647265737365732077697468207468652073797374656d20636f6e7472616374732e0a20202020696e6974286578636c756465644164647265737365733a205b416464726573735d29207b0a202020202020202073656c662e6578636c75646564416464726573736573203d207b7d0a202020202020202073656c662e70616e69634f6e556e737461676564203d2066616c73650a0a202020202020202073656c662e41646d696e6973747261746f7253746f7261676550617468203d202f73746f726167652f666c6f77446570656e64656e6379417564697441646d696e0a0a2020202020202020666f72206164647265737320696e206578636c75646564416464726573736573207b0a20202020202020202020202073656c662e6578636c756465644164647265737365735b616464726573735d203d20747275650a20202020202020207d0a0a20202020202020206c65742061646d696e203c2d206372656174652041646d696e6973747261746f7228290a202020202020202073656c662e6163636f756e742e73617665283c2d61646d696e2c20746f3a2073656c662e41646d696e6973747261746f7253746f7261676550617468290a202020207d0a7d0a"}, { "type": "Array", "value": [{ "type": "Address", "value": "0x8624b52f9ddcd04a"},{ "type": "Address", "value": "0xe467b9dd11fa00df"},{"type": "Address", "value": "0x8d0e87b65159ae63"},{ "type": "Address", "value": "0x62430cf28c26d095"},{"type": "Address", "value": "0xf919ee77447b7497"},{ "type": "Address", "value": "0x1654653399040a61"},{ "type": "Address", "value": "0xf233dcee88fe0abe"},{ "type": "Address", "value": "0x1d7e57aa55817448"},{ "type": "Address", "value": "0xb19436aae4d94622"},{ "type": "Address", "value": "0x220c1b4155f86f2f"}]}]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the list of excluded addresses for the DependencyAudit contract

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned here: #294

Loading