Skip to content
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
Prev Previous commit
Next Next commit
fix: correct bytecode getters/setters
Whenever we output the bytecode of an account, whether to
a file or in a response, we need to return the *original*
bytecode using `Bytecode::len`, otherwise the bytecode
will differ depending on whether the bytecode has been
checked, analyzed or not.
  • Loading branch information
onbjerg committed Aug 1, 2022
commit b2e8eb23428d69343493e55cac8d6ff99b392a86
15 changes: 7 additions & 8 deletions anvil/src/eth/backend/mem/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ impl Db for MemDb {
.clone()
.into_iter()
.map(|(k, v)| {
let code = v
.info
.code
.unwrap_or_else(|| self.inner.code_by_hash(v.info.code_hash))
.to_checked();
(
k,
SerializableAccountRecord {
nonce: v.info.nonce,
balance: v.info.balance,
code: v
.info
.code
.unwrap_or_else(|| self.inner.code_by_hash(v.info.code_hash))
.bytes()
.clone()
.into(),
code: code.bytes()[..code.len()].to_vec().into(),
storage: v.storage.into_iter().collect(),
},
)
Expand Down Expand Up @@ -207,7 +206,7 @@ mod tests {
test_addr,
SerializableAccountRecord {
balance: 100100.into(),
code: contract_code.bytes().clone().into(),
code: contract_code.bytes()[..contract_code.len()].to_vec().into(),
nonce: 100,
storage: new_storage,
},
Expand Down
6 changes: 3 additions & 3 deletions anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,11 @@ impl Backend {
trace!(target: "backend", "get code for {:?}", address);
let account = db.basic(address);
let code = if let Some(code) = account.code {
code.bytes().clone().into()
code
} else {
db.code_by_hash(account.code_hash).bytes().clone().into()
db.code_by_hash(account.code_hash)
};
Ok(code)
Ok(code.bytes()[..code.len()].to_vec().into())
})
}

Expand Down