Skip to content

Commit 9cf448a

Browse files
committed
enforce evm.sender as the predeploys deployer
1 parent aed0139 commit 9cf448a

File tree

1 file changed

+28
-136
lines changed

1 file changed

+28
-136
lines changed

cli/src/cmd/forge/script.rs

Lines changed: 28 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,11 @@ impl Cmd for ScriptArgs {
104104
let nonce = foundry_utils::next_nonce(evm_opts.sender, fork_url, None)?;
105105

106106
let BuildOutput {
107-
target,
108-
mut contract,
109-
mut highlevel_known_contracts,
110-
mut predeploy_libraries,
111-
known_contracts: default_known_contracts,
107+
target, contract, highlevel_known_contracts, predeploy_libraries, ..
112108
} = self.build(&config, &evm_opts, nonce)?;
113109

114110
if !self.force_resume && !self.resume {
115-
let mut known_contracts = highlevel_known_contracts
111+
let known_contracts = highlevel_known_contracts
116112
.iter()
117113
.map(|(id, c)| {
118114
(
@@ -129,137 +125,33 @@ impl Cmd for ScriptArgs {
129125
})
130126
.collect::<BTreeMap<ArtifactId, (Abi, Vec<u8>)>>();
131127

132-
// execute once with default sender
133-
let mut result =
134-
self.execute(contract, &evm_opts, None, &predeploy_libraries, &config)?;
135-
136-
let mut new_sender = None;
137-
if let Some(ref txs) = result.transactions {
138-
// If we did any linking with assumed predeploys, we cant support multiple
139-
// deployers.
140-
//
141-
// If we didn't do any linking with predeploys, then none of the contracts will
142-
// change their code based on the sender, so we can skip relinking +
143-
// reexecuting.
144-
if !predeploy_libraries.is_empty() {
145-
for tx in txs.iter() {
146-
match tx {
147-
TypedTransaction::Legacy(tx) => {
148-
if tx.to.is_none() {
149-
let sender = tx.from.expect("no sender");
150-
if let Some(ns) = new_sender {
151-
if sender != ns {
152-
panic!("Currently, only 1 contract deployer is possible per public function. This limitation may be lifted in the future but for safety/simplicity this is currently disallowed. Split deployment into more functions & run separately.")
153-
}
154-
} else if sender != evm_opts.sender {
155-
new_sender = Some(sender);
156-
}
157-
}
158-
}
159-
_ => unreachable!(),
160-
}
161-
}
162-
}
163-
}
164-
165-
// reexecute with the correct deployer after relinking contracts
166-
if let Some(new_sender) = new_sender {
167-
// if we had a new sender that requires relinking, we need to
168-
// get the nonce mainnet for accurate addresses for predeploy libs
169-
let nonce = foundry_utils::next_nonce(new_sender, fork_url, None)?;
170-
171-
// relink with new sender
172-
let BuildOutput {
173-
target: _,
174-
contract: c2,
175-
highlevel_known_contracts: hkc,
176-
predeploy_libraries: pl,
177-
known_contracts: _default_known_contracts,
178-
} = self.link(default_known_contracts, new_sender, nonce)?;
179-
180-
contract = c2;
181-
highlevel_known_contracts = hkc;
182-
predeploy_libraries = pl;
183-
184-
known_contracts = highlevel_known_contracts
185-
.iter()
186-
.map(|(id, c)| {
187-
(
188-
id.clone(),
189-
(
190-
c.abi.clone(),
191-
c.deployed_bytecode
192-
.clone()
193-
.into_bytes()
194-
.expect("not bytecode")
195-
.to_vec(),
196-
),
197-
)
198-
})
199-
.collect::<BTreeMap<ArtifactId, (Abi, Vec<u8>)>>();
200-
201-
let lib_deploy = predeploy_libraries
202-
.iter()
203-
.enumerate()
204-
.map(|(i, bytes)| {
205-
TypedTransaction::Legacy(TransactionRequest {
206-
from: Some(new_sender),
207-
data: Some(bytes.clone()),
208-
nonce: Some(nonce + i),
209-
..Default::default()
210-
})
211-
})
212-
.collect();
213-
214-
result.transactions = Some(lib_deploy);
215-
216-
let result2 = self.execute(
217-
contract,
218-
&evm_opts,
219-
Some(new_sender),
220-
&predeploy_libraries,
221-
&config,
222-
)?;
128+
let mut result = self.execute(
129+
contract,
130+
&evm_opts,
131+
Some(evm_opts.sender),
132+
&predeploy_libraries,
133+
&config,
134+
)?;
223135

224-
result.success &= result2.success;
225-
226-
result.gas = result2.gas;
227-
result.logs = result2.logs;
228-
result.traces.extend(result2.traces);
229-
result.debug = result2.debug;
230-
result.labeled_addresses.extend(result2.labeled_addresses);
231-
match (&mut result.transactions, result2.transactions) {
232-
(Some(txs), Some(new_txs)) => {
233-
new_txs.iter().for_each(|tx| {
234-
txs.push_back(TypedTransaction::Legacy(into_legacy(tx.clone())));
235-
});
236-
}
237-
(None, Some(new_txs)) => {
238-
result.transactions = Some(new_txs);
239-
}
240-
_ => {}
241-
}
242-
} else {
243-
let mut lib_deploy: VecDeque<TypedTransaction> = predeploy_libraries
244-
.iter()
245-
.enumerate()
246-
.map(|(i, bytes)| {
247-
TypedTransaction::Legacy(TransactionRequest {
248-
from: Some(evm_opts.sender),
249-
data: Some(bytes.clone()),
250-
nonce: Some(nonce + i),
251-
..Default::default()
252-
})
136+
let mut lib_deploy: VecDeque<TypedTransaction> = predeploy_libraries
137+
.iter()
138+
.enumerate()
139+
.map(|(i, bytes)| {
140+
TypedTransaction::Legacy(TransactionRequest {
141+
from: Some(evm_opts.sender),
142+
data: Some(bytes.clone()),
143+
nonce: Some(nonce + i),
144+
..Default::default()
253145
})
254-
.collect();
255-
256-
// prepend predeploy libraries
257-
if let Some(txs) = &mut result.transactions {
258-
txs.iter().for_each(|tx| {
259-
lib_deploy.push_back(TypedTransaction::Legacy(into_legacy(tx.clone())));
260-
});
261-
*txs = lib_deploy;
262-
}
146+
})
147+
.collect();
148+
149+
// prepend predeploy libraries
150+
if let Some(txs) = &mut result.transactions {
151+
txs.iter().for_each(|tx| {
152+
lib_deploy.push_back(TypedTransaction::Legacy(into_legacy(tx.clone())));
153+
});
154+
*txs = lib_deploy;
263155
}
264156

265157
// Identify addresses in each trace
@@ -706,7 +598,7 @@ impl ScriptArgs {
706598
Ok((tx.clone(), signer))
707599
} else {
708600
Err(eyre::eyre!(format!(
709-
"No associated wallet for `from` address: {:?}. Unlocked wallets: {:?}",
601+
"No associated wallet for `from` address: {:?}. Unlocked wallets: {:?}. \nMake sure you have loaded all the private keys including of the `--sender`.",
710602
from,
711603
local_wallets
712604
.iter()

0 commit comments

Comments
 (0)