Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions chain-evm/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ pub fn transact_create<State: EvmState>(
value: U256,
init_code: ByteCode,
access_list: Vec<(Address, Vec<Key>)>,
) -> Result<ByteCode, Error> {
) -> Result<Vec<u8>, Error> {
let caller = vm.origin;
let gas_limit = vm.gas_limit;
execute_transaction(vm, |executor| {
executor.transact_create(
caller,
value,
init_code.to_vec(),
init_code.into(),
gas_limit,
access_list.clone(),
)
Expand All @@ -296,14 +296,14 @@ pub fn transact_create2<State: EvmState>(
init_code: ByteCode,
salt: H256,
access_list: Vec<(Address, Vec<Key>)>,
) -> Result<ByteCode, Error> {
) -> Result<Vec<u8>, Error> {
let caller = vm.origin;
let gas_limit = vm.gas_limit;
execute_transaction(vm, |executor| {
executor.transact_create2(
caller,
value,
init_code.to_vec(),
init_code.into(),
salt,
gas_limit,
access_list.clone(),
Expand All @@ -319,15 +319,15 @@ pub fn transact_call<State: EvmState>(
value: U256,
data: ByteCode,
access_list: Vec<(Address, Vec<Key>)>,
) -> Result<ByteCode, Error> {
) -> Result<Vec<u8>, Error> {
let caller = vm.origin;
let gas_limit = vm.gas_limit;
execute_transaction(vm, |executor| {
executor.transact_call(
caller,
address,
value,
data.to_vec(),
data.into(),
gas_limit,
access_list.clone(),
)
Expand Down Expand Up @@ -403,6 +403,7 @@ impl<'a, State: EvmState> Backend for VirtualMachine<'a, State> {
.map(|account| account.state.code)
.unwrap_or_default()
})
.into()
}
fn storage(&self, address: H160, index: H256) -> H256 {
self.substate
Expand Down Expand Up @@ -582,7 +583,7 @@ impl<'a, State: EvmState> StackState<'a> for VirtualMachine<'a, State> {
}

fn set_code(&mut self, address: H160, code: Vec<u8>) {
self.substate.account_mut(address, self.state).state.code = code;
self.substate.account_mut(address, self.state).state.code = code.into();
}

fn transfer(&mut self, transfer: Transfer) -> Result<(), ExitError> {
Expand Down
2 changes: 1 addition & 1 deletion chain-evm/src/state/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Balance {
}

/// Smart-contract bytecode, such as the one compiled from Solidity code, for example.
pub type ByteCode = Vec<u8>;
pub type ByteCode = Box<[u8]>;

/// A represantation of an EVM account.
#[derive(Clone, Default, PartialEq, Eq)]
Expand Down
4 changes: 2 additions & 2 deletions chain-evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl TryFrom<AccountState> for Account {
state: crate::state::AccountState {
nonce: val.nonce,
storage: val.storage.into_iter().collect(),
code: val.code,
code: val.code.into(),
},
})
}
Expand Down Expand Up @@ -133,7 +133,7 @@ impl evm_test_suite::TestEvmState for TestEvmLedger {
tx.gas_limit.as_u64(),
true,
);
transact_call(vm, tx.to, tx.value, tx.data, Vec::new())
transact_call(vm, tx.to, tx.value, tx.data.into(), Vec::new())
.map_err(|e| format!("can not run transaction, err: {}", e))?;

Ok(self)
Expand Down
6 changes: 3 additions & 3 deletions chain-impl-mockchain/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ mod test {
0 => Self::Create {
caller,
value,
init_code: Arbitrary::arbitrary(g),
init_code: Box::new([Arbitrary::arbitrary(g); 32]),
gas_limit,
access_list,
},
1 => Self::Create2 {
caller,
value,
init_code: Arbitrary::arbitrary(g),
init_code: Box::new([Arbitrary::arbitrary(g); 32]),
salt: [u8::arbitrary(g); H256::len_bytes()].into(),
gas_limit,
access_list,
Expand All @@ -330,7 +330,7 @@ mod test {
caller,
address: [u8::arbitrary(g); H160::len_bytes()].into(),
value,
data: Arbitrary::arbitrary(g),
data: Box::new([Arbitrary::arbitrary(g); 32]),
gas_limit,
access_list,
},
Expand Down
4 changes: 2 additions & 2 deletions chain-impl-mockchain/src/ledger/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn pack_evm_state<W: std::io::Write>(
codec: &mut Codec<W>,
) -> Result<(), WriteError> {
codec.put_be_u32(evm_state.code.len().try_into().unwrap())?;
codec.put_bytes(evm_state.code.as_slice())?;
codec.put_bytes(&evm_state.code)?;

let mut bytes = [0; 32];
evm_state.nonce.to_big_endian(&mut bytes);
Expand All @@ -204,7 +204,7 @@ fn unpack_evm_state<R: std::io::BufRead>(
use chain_evm::state::Value;

let code_size = codec.get_be_u32()? as usize;
let code = codec.get_bytes(code_size)?;
let code = codec.get_bytes(code_size)?.into();

let nonce_bytes = codec.get_bytes(32)?;
let nonce = chain_evm::ethereum_types::U256::from_big_endian(&nonce_bytes);
Expand Down