git.delta.rocks / unique-network / refs/commits / 420882b802b8

difftreelog

path: Fix parsing simple values.

Trubnikov Sergey2022-08-17parent: #5562dab.patch.diff
in: master

6 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2169,7 +2169,7 @@
 
 [[package]]
 name = "evm-coder"
-version = "0.1.1"
+version = "0.1.2"
 dependencies = [
  "ethereum",
  "evm-coder-procedural",
@@ -2178,6 +2178,7 @@
  "hex-literal",
  "impl-trait-for-tuples",
  "primitive-types",
+ "sp-std",
 ]
 
 [[package]]
modifiedcrates/evm-coder/CHANGELOG.mddiffbeforeafterboth
--- a/crates/evm-coder/CHANGELOG.md
+++ b/crates/evm-coder/CHANGELOG.md
@@ -2,6 +2,12 @@
 
 All notable changes to this project will be documented in this file.
 
+## [0.1.3] - 2022-08-29
+
+### Fixed
+
+ - Parsing simple values.
+
 <!-- bureaucrate goes here -->
 ## [v0.1.2] 2022-08-19
 
@@ -21,4 +27,4 @@
 
 - build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf8
 
-- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
\ No newline at end of file
+- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
modifiedcrates/evm-coder/Cargo.tomldiffbeforeafterboth
--- a/crates/evm-coder/Cargo.toml
+++ b/crates/evm-coder/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "evm-coder"
-version = "0.1.1"
+version = "0.1.2"
 license = "GPLv3"
 edition = "2021"
 
@@ -11,8 +11,9 @@
 primitive-types = { version = "0.11.1", default-features = false }
 # Evm doesn't have reexports for log and others
 ethereum = { version = "0.12.0", default-features = false }
+sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
 # Error types for execution
-evm-core = { default-features = false, git = "https://github.com/uniquenetwork/evm", branch = "unique-polkadot-v0.9.27" }
+evm-core = { default-features = false , git = "https://github.com/uniquenetwork/evm", branch = "unique-polkadot-v0.9.27" }
 # We have tuple-heavy code in solidity.rs
 impl-trait-for-tuples = "0.2.2"
 
modifiedcrates/evm-coder/src/abi.rsdiffbeforeafterboth
28 types::{string, self},28 types::{string, self},
29};29};
30use crate::execution::Result;30use crate::execution::Result;
31use crate::solidity::SolidityTypeName;
3132
32const ABI_ALIGNMENT: usize = 32;33const ABI_ALIGNMENT: usize = 32;
3334
77 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 empty
81 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]);
133134
134 /// Read [`Vec<u8>`] at current position, then advance135 /// Read [`Vec<u8>`] at current position, then advance
135 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 }
180181
181 /// Slice recursive buffer, advance one word for buffer offset182 /// Slice recursive buffer, advance one word for buffer offset
183 /// 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 0
190 } else {
191 self.uint32()? as usize
192 };
193
184 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 }
197
198 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 }
193205
355 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}
380
381fn 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}
386
387#[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}
368394
369macro_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 where
374 $(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);
536566
537 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 }
541571
modifiedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -192,7 +192,10 @@
 				write!(writer, "{}", tc.collect_tuple::<Self>())
 			}
 			fn is_simple() -> bool {
-				false
+				true
+				$(
+					&& <$ident>::is_simple()
+				)*
 			}
 			#[allow(unused_assignments)]
 			fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -179,7 +179,12 @@
 			.weight_calls_budget(<StructureWeight<T>>::find_parent());
 		let amounts = amounts
 			.into_iter()
-			.map(|(to, amount)| Ok((T::CrossAccountId::from_eth(to), amount.try_into().map_err(|_| "amount overflow")?)))
+			.map(|(to, amount)| {
+				Ok((
+					T::CrossAccountId::from_eth(to),
+					amount.try_into().map_err(|_| "amount overflow")?,
+				))
+			})
 			.collect::<Result<_>>()?;
 
 		<Pallet<T>>::create_multiple_items(&self, &caller, amounts, &budget)