Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8
Problem
initializeonly required the proposedadminto sign. On a freshly created vault, a third party reachinginitializebefore the deployer could name itself as admin and sign its own call. It would then controlpause/unpausepermanently, since there is no way to replace an admin. The deploy scripts hid the window by initializing right after creation, but the contract itself did nothing to close it.Fix
initialize(deployer, salt, admin, asset, name, symbol, decimals)re-derives the contract's own address fromdeployerand the 32-byte creationsalt. If the result is not this contract, it returns the newVaultError::BadDeployer(17).deployermust authorize the call, and so mustadminwhen it is a different address. These checks run before metadata validation, andAlreadyInitstill prevents re-initialization.createVaultContractnow always passes an explicit salt (random unless one is given) and returns it.YieldVaultClient.initializeand the validation schema takedeployerand a hexsalt.BadDeployeris added to the error constants and messages.initialize. They also write the salt toscripts/.deploy_saltright after creation, so the vault can still be initialized if the run fails later.deploy-yield-vault.shacceptsDEPLOY_SALTfrom the environment to redeploy at a known address. It checks that the value is exactly 64 hex characters and stops with an error before building anything if it isn't; otherwise it generates a random salt as before.contracts/yield_vault/README.mdanddocs/deployment/testnet.mddescribe the new guarantee. The testnet doc replaces the old caveat, explains how to initialize later from the saved salt, and notes that a lost salt can be recovered from the vault's creation transaction.How it was verified
cargo test -p yield_vault: 17 tests pass. They include:front_runner_cannot_capture_admin_of_a_fresh_vault: an attacker that signs its own call is rejected withBadDeployer, then the deployer initializes, then the attacker getsAlreadyInit.G...account deployer can initialize.initializefails for a missing signature (no signature, deployer's missing, or separate admin's missing), the tests assert that the host rejected it withError(Auth, InvalidAction), not just that it errored. Atry_call can't show this, because the host narrows non-contract failures toError(Context, InvalidAction). So these cases invoke withouttry_and check the host error they fail with.cargo clippy -p yield_vault --all-targets -- -D warningsandcargo fmt --all -- --checkare clean.@yieldanchor/contract-clientsand@yieldanchor/validationtests pass.eslintreports no errors andprettier --checkpasses on the changed docs.DEPLOY_SALTcheck indeploy-yield-vault.shwas exercised locally with empty, short, 65-character, non-hex and upper-case hex values.