difftreelog
path: Fix parsing simple values.
in: master
6 files changed
Cargo.lockdiffbeforeafterboth216921692170[[package]]2170[[package]]2171name = "evm-coder"2171name = "evm-coder"2172version = "0.1.1"2172version = "0.1.2"2173dependencies = [2173dependencies = [2174 "ethereum",2174 "ethereum",2175 "evm-coder-procedural",2175 "evm-coder-procedural",2178 "hex-literal",2178 "hex-literal",2179 "impl-trait-for-tuples",2179 "impl-trait-for-tuples",2180 "primitive-types",2180 "primitive-types",2181 "sp-std",2181]2182]218221832183[[package]]2184[[package]]crates/evm-coder/CHANGELOG.mddiffbeforeafterboth223All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.445## [0.1.3] - 2022-08-2967### Fixed89 - Parsing simple values.105<!-- bureaucrate goes here -->11<!-- bureaucrate goes here -->6## [v0.1.2] 2022-08-1912## [v0.1.2] 2022-08-19713212722- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf828- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf8232924- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b30- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b31crates/evm-coder/Cargo.tomldiffbeforeafterboth1[package]1[package]2name = "evm-coder"2name = "evm-coder"3version = "0.1.1"3version = "0.1.2"4license = "GPLv3"4license = "GPLv3"5edition = "2021"5edition = "2021"6611primitive-types = { version = "0.11.1", default-features = false }11primitive-types = { version = "0.11.1", default-features = false }12# Evm doesn't have reexports for log and others12# Evm doesn't have reexports for log and others13ethereum = { version = "0.12.0", default-features = false }13ethereum = { version = "0.12.0", default-features = false }14sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }14# Error types for execution15# Error types for execution15evm-core = { default-features = false, git = "https://github.com/uniquenetwork/evm", branch = "unique-polkadot-v0.9.27" }16evm-core = { default-features = false , git = "https://github.com/uniquenetwork/evm", branch = "unique-polkadot-v0.9.27" }16# We have tuple-heavy code in solidity.rs17# We have tuple-heavy code in solidity.rscrates/evm-coder/src/abi.rsdiffbeforeafterboth28 types::{string, self},28 types::{string, self},29};29};30use crate::execution::Result;30use crate::execution::Result;31use crate::solidity::SolidityTypeName;313232const ABI_ALIGNMENT: usize = 32;33const ABI_ALIGNMENT: usize = 32;333477 return Err(Error::Error(ExitError::OutOfOffset));78 return Err(Error::Error(ExitError::OutOfOffset));78 }79 }79 let mut block = [0; S];80 let mut block = [0; S];80 // Verify padding is empty81 if !buf[pad_start..pad_size].iter().all(|&v| v == 0) {81 let is_pad_zeroed = !buf[pad_start..pad_size].iter().all(|&v| v == 0);82 if is_pad_zeroed {82 return Err(Error::Error(ExitError::InvalidRange));83 return Err(Error::Error(ExitError::InvalidRange));83 }84 }84 block.copy_from_slice(&buf[block_start..block_size]);85 block.copy_from_slice(&buf[block_start..block_size]);133134134 /// Read [`Vec<u8>`] at current position, then advance135 /// Read [`Vec<u8>`] at current position, then advance135 pub fn bytes(&mut self) -> Result<Vec<u8>> {136 pub fn bytes(&mut self) -> Result<Vec<u8>> {136 let mut subresult = self.subresult()?;137 let mut subresult = self.subresult(None)?;137 let length = subresult.uint32()? as usize;138 let length = subresult.uint32()? as usize;138 if subresult.buf.len() < subresult.offset + length {139 if subresult.buf.len() < subresult.offset + length {139 return Err(Error::Error(ExitError::OutOfOffset));140 return Err(Error::Error(ExitError::OutOfOffset));179 }180 }180181181 /// Slice recursive buffer, advance one word for buffer offset182 /// Slice recursive buffer, advance one word for buffer offset183 /// If `size` is [`None`] then [`Self::offset`] and [`Self::subresult_offset`] evals from [`Self::buf`].182 fn subresult(&mut self) -> Result<AbiReader<'i>> {184 fn subresult(&mut self, size: Option<usize>) -> Result<AbiReader<'i>> {185 let subresult_offset = self.subresult_offset;183 let offset = self.uint32()? as usize;186 let offset = if let Some(size) = size {187 self.offset += size;188 self.subresult_offset += size;189 0190 } else {191 self.uint32()? as usize192 };193184 if offset + self.subresult_offset > self.buf.len() {194 if offset + self.subresult_offset > self.buf.len() {185 return Err(Error::Error(ExitError::InvalidRange));195 return Err(Error::Error(ExitError::InvalidRange));186 }196 }197198 let new_offset = offset + subresult_offset;187 Ok(AbiReader {199 Ok(AbiReader {188 buf: self.buf,200 buf: self.buf,189 subresult_offset: offset + self.subresult_offset,201 subresult_offset: new_offset,190 offset: offset + self.subresult_offset,202 offset: new_offset,191 })203 })192 }204 }193205355 Self: AbiRead<R>,367 Self: AbiRead<R>,356{368{357 fn abi_read(&mut self) -> Result<Vec<R>> {369 fn abi_read(&mut self) -> Result<Vec<R>> {358 let mut sub = self.subresult()?;370 let mut sub = self.subresult(None)?;359 let size = sub.uint32()? as usize;371 let size = sub.uint32()? as usize;360 sub.subresult_offset = sub.offset;372 sub.subresult_offset = sub.offset;361 let mut out = Vec::with_capacity(size);373 let mut out = Vec::with_capacity(size);366 }378 }367}379}380381fn aligned_size(size: usize) -> usize {382 let need_align = (size % ABI_ALIGNMENT) != 0;383 let aligned_parts = size / ABI_ALIGNMENT;384 (aligned_parts * ABI_ALIGNMENT) + if need_align { ABI_ALIGNMENT } else { 0 }385}386387#[test]388fn test_aligned_size() {389 assert_eq!(aligned_size(20), ABI_ALIGNMENT);390 assert_eq!(aligned_size(32), ABI_ALIGNMENT);391 assert_eq!(aligned_size(52), 2 * ABI_ALIGNMENT);392 assert_eq!(aligned_size(64), 2 * ABI_ALIGNMENT);393}368394369macro_rules! impl_tuples {395macro_rules! impl_tuples {370 ($($ident:ident)+) => {396 ($($ident:ident)+) => {371 impl<$($ident),+> sealed::CanBePlacedInVec for ($($ident,)+) {}397 impl<$($ident),+> sealed::CanBePlacedInVec for ($($ident,)+) {}372 impl<$($ident),+> AbiRead<($($ident,)+)> for AbiReader<'_>398 impl<$($ident),+> AbiRead<($($ident,)+)> for AbiReader<'_>373 where399 where374 $(Self: AbiRead<$ident>),+400 $(401 Self: AbiRead<$ident>,402 )+403 ($($ident,)+): SolidityTypeName,375 {404 {376 fn abi_read(&mut self) -> Result<($($ident,)+)> {405 fn abi_read(&mut self) -> Result<($($ident,)+)> {406 let size = if <($($ident,)+)>::is_simple() { Some(0 $(+aligned_size(sp_std::mem::size_of::<$ident>()))+) } else { None };377 let mut subresult = self.subresult()?;407 let mut subresult = self.subresult(size)?;378 Ok((408 Ok((379 $(<Self as AbiRead<$ident>>::abi_read(&mut subresult)?,)+409 $(<Self as AbiRead<$ident>>::abi_read(&mut subresult)?,)+380 ))410 ))535 assert_eq!(encoded, alternative_encoded);565 assert_eq!(encoded, alternative_encoded);536566537 let mut decoder = AbiReader::new(&encoded);567 let mut decoder = AbiReader::new(&encoded);538 assert_eq!(decoder.bool().unwrap(), true);568 assert!(decoder.bool().unwrap());539 assert_eq!(decoder.string().unwrap(), "test");569 assert_eq!(decoder.string().unwrap(), "test");540 }570 }541571crates/evm-coder/src/solidity.rsdiffbeforeafterboth192 write!(writer, "{}", tc.collect_tuple::<Self>())192 write!(writer, "{}", tc.collect_tuple::<Self>())193 }193 }194 fn is_simple() -> bool {194 fn is_simple() -> bool {195 false195 true196 $(197 && <$ident>::is_simple()198 )*196 }199 }197 #[allow(unused_assignments)]200 #[allow(unused_assignments)]198 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {201 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {pallets/fungible/src/erc.rsdiffbeforeafterboth179 .weight_calls_budget(<StructureWeight<T>>::find_parent());179 .weight_calls_budget(<StructureWeight<T>>::find_parent());180 let amounts = amounts180 let amounts = amounts181 .into_iter()181 .into_iter()182 .map(|(to, amount)| Ok((T::CrossAccountId::from_eth(to), amount.try_into().map_err(|_| "amount overflow")?)))182 .map(|(to, amount)| {183 Ok((184 T::CrossAccountId::from_eth(to),185 amount.try_into().map_err(|_| "amount overflow")?,186 ))187 })183 .collect::<Result<_>>()?;188 .collect::<Result<_>>()?;184189185 <Pallet<T>>::create_multiple_items(&self, &caller, amounts, &budget)190 <Pallet<T>>::create_multiple_items(&self, &caller, amounts, &budget)