Skip to content
Snippets Groups Projects
  1. Jan 15, 2025
  2. Dec 18, 2024
  3. Dec 05, 2024
    • Alexander Theißen's avatar
      pallet-revive: Adjust error handling of sub calls (#6741) · 0d3d4502
      Alexander Theißen authored
      
      We were trapping the host context in case a sub call was exhausting the
      storage deposit limit set for this sub call. This prevents the caller
      from handling this error. In this PR we added a new error code that is
      returned when either gas or storage deposit limit is exhausted by the
      sub call.
      
      We also remove the longer used `NotCallable` error. No longer used
      because this is no longer an error: It will just be a balance transfer.
      
      We also make `set_code_hash` infallible to be consistent with other host
      functions which just trap on any error condition.
      
      ---------
      
      Co-authored-by: default avatarGitHub Action <action@github.com>
  4. Dec 01, 2024
    • PG Herveou's avatar
      [pallet-revive] eth-prc fix geth diff (#6608) · d1fafa85
      PG Herveou authored
      
      * Add a bunch of differential tests to ensure that responses from
      eth-rpc matches the one from `geth`
      - These
      [tests](https://github.com/paritytech/polkadot-sdk/blob/pg/fix-geth-diff/substrate/frame/revive/rpc/examples/js/src/geth-diff.test.ts)
      are not run in CI for now but can be run locally with
      ```bash
      cd revive/rpc/examples/js
      bun test
      ```
      
      * EVM RPC server will not fail gas_estimation if no gas is specified, I
      updated pallet-revive to add an extra `skip_transfer` boolean check to
      replicate this behavior in our pallet
      
      * `eth_transact` and `bare_eth_transact` api have been updated to use
      `GenericTransaction` directly as this is what is used by
      `eth_estimateGas` and `eth_call`
      
      ## TODO
      
      - [ ]  Add tests the new `skip_transfer` flag
      
      ---------
      
      Co-authored-by: default avatarGitHub Action <action@github.com>
      Co-authored-by: default avatarAlexander Theißen <alex.theissen@me.com>
  5. Nov 19, 2024
  6. Nov 15, 2024
  7. Nov 04, 2024
    • Cyrill Leutwiler's avatar
      [pallet-revive] rework balance transfers (#6187) · d69a80e6
      Cyrill Leutwiler authored
      
      This PR removes the `transfer` syscall and changes balance transfers to
      make the existential deposit (ED) fully transparent for contracts.
      
      The `transfer` API is removed since there is no corresponding EVM opcode
      and transferring via a call introduces barely any overhead.
      
      We make the ED transparent to contracts by transferring the ED from the
      call origin to nonexistent accounts. Without this change, transfers to
      nonexistant accounts will transfer the supplied value minus the ED from
      the contracts viewpoint, and consequentially fail if the supplied value
      lies below the ED. Changing this behavior removes the need for contract
      code to handle this rather annoying corner case and aligns better with
      the EVM. The EVM charges a similar deposit from the gas meter, so
      transferring the ED from the call origin is practically the same as the
      call origin pays for gas.
      
      ---------
      
      Signed-off-by: default avatarxermicus <cyrill@parity.io>
      Signed-off-by: default avatarCyrill Leutwiler <bigcyrill@hotmail.com>
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarGitHub Action <action@github.com>
      Co-authored-by: default avatarPG Herveou <pgherveou@gmail.com>
    • PG Herveou's avatar
      [eth-rpc] Fixes (#6317) · 7f80f452
      PG Herveou authored
      
      Various fixes for the release of eth-rpc & ah-westend-runtime
      
      - Bump asset-hub westend spec version
      - Fix the status of the Receipt to properly report failed transactions
      - Fix value conversion between native and eth decimal representation
      
      ---------
      
      Co-authored-by: default avatarGitHub Action <action@github.com>
  8. Oct 31, 2024
  9. Oct 30, 2024
  10. Oct 29, 2024
  11. Oct 25, 2024
  12. Oct 22, 2024
    • PG Herveou's avatar
      [pallet-revive] Eth RPC integration (#5866) · 21930ed2
      PG Herveou authored
      
      This PR introduces the necessary changes to pallet-revive for
      integrating with our Ethereum JSON-RPC.
      The RPC proxy itself will be added in a follow up.
      
      ## Changes
      
      - A new pallet::call `Call::eth_transact`. This is used as a wrapper to
      accept unsigned Ethereum transaction, valid call will be routed to
      `Call::call` or `Call::instantiate_with_code`
      
      - A custom UncheckedExtrinsic struct, that wraps the generic one usually
      and add the ability to check eth_transact calls sent from an Ethereum
      JSON-RPC proxy.
      - Generated types and traits to support implementing a JSON-RPC Ethereum
      proxy.
      
      ## Flow Overview:
      - A user submits a transaction via MetaMask or another
      Ethereum-compatible wallet.
      - The proxy dry run the transaction and add metadata to the call (gas
      limit in Weight, storage deposit limit, and length of bytecode and
      constructor input for contract instantiation)
      - The raw transaction, along with the additional metadata, is submitted
      to the node as an unsigned extrinsic.
      - On the runtime, our custom UncheckedExtrinsic define a custom
      Checkable implementation that converts the unsigned extrinsics into
      checked one
       - It recovers the signer
      - validates the payload, and injects signed extensions, allowing the
      system to increment the nonce and charge the appropriate fees.
      - re-route the call to pallet-revive::Call::call or
      pallet-revive::Call::instantiateWithCode
      
      ## Dependencies
      
      - https://github.com/koute/polkavm/pull/188
      
      ## Follow up PRs
      - #5926  
      - #6147 (previously #5953)
      - #5502
      
      ---------
      
      Co-authored-by: default avatarAlexander Theißen <alex.theissen@me.com>
      Co-authored-by: default avatarCyrill Leutwiler <cyrill@parity.io>
  13. Oct 18, 2024
  14. Oct 16, 2024
  15. Oct 05, 2024
    • Cyrill Leutwiler's avatar
      [pallet-revive] immutable data storage (#5861) · a8ebe9af
      Cyrill Leutwiler authored
      
      This PR introduces the concept of immutable storage data, used for
      [Solidity immutable
      variables](https://docs.soliditylang.org/en/latest/contracts.html#immutable).
      
      This is a minimal implementation. Immutable data is attached to a
      contract; to keep `ContractInfo` fixed in size, we only store the length
      there, and store the immutable data in a dedicated storage map instead.
      Which comes at the cost of requiring an additional storage read (costly)
      for contracts using this feature.
      
      We discussed more optimal solutions not requiring any additional storage
      accesses internally, but they turned out to be non-trivial to implement.
      Another optimization benefiting multiple calls to the same contract in a
      single call stack would be to cache the immutable data in `Stack`.
      However, this potential creates a DOS vulnerability (the attack vector
      is to call into as many contracts in a single stack as possible, where
      they all have maximum immutable data to fill the cache as efficiently as
      possible). So this either has to be guaranteed to be a non-issue by
      limits, or, more likely, to have some logic to bound the cache.
      Eventually, we should think about introducing the concept of warm and
      cold storage reads (akin to EVM). Since immutable variables are commonly
      used in contracts, this change is blocking our initial launch and we
      should only optimize it properly in follow-ups.
      
      This PR also disables the `set_code_hash` API (which isn't usable for
      Solidity contracts without pre-compiles anyways). With immutable storage
      attached to contracts, we now want to run the constructor of the new
      code hash to collect the immutable data during `set_code_hash`. This
      will be implemented in a follow up PR.
      
      ---------
      
      Signed-off-by: default avatarCyrill Leutwiler <bigcyrill@hotmail.com>
      Signed-off-by: default avatarxermicus <cyrill@parity.io>
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarAlexander Theißen <alex.theissen@me.com>
      Co-authored-by: default avatarPG Herveou <pgherveou@gmail.com>
  16. Sep 25, 2024
    • Cyrill Leutwiler's avatar
      [pallet-revive] last call return data API (#5779) · c77095f5
      Cyrill Leutwiler authored
      
      This PR introduces 2 new syscalls: `return_data_size` and
      `return_data_copy`, resembling the semantics of the EVM `RETURNDATASIZE`
      and `RETURNDATACOPY` opcodes.
      
      The ownership of `ExecReturnValue` (the return data) has moved to the
      `Frame`. This allows implementing the new contract API functionality in
      ext with no additional copies. Returned data is passed via contract
      memory, memory is (will be) metered, hence the amount of returned data
      can not be statically known, so we should avoid storing copies of the
      returned data if we can. By moving the ownership of the exectuables
      return value into the `Frame` struct we achieve this.
      
      A zero-copy implementation of those APIs would be technically possible
      without that internal change by making the callsite in the runtime
      responsible for moving the returned data into the frame after any call.
      However, resetting the stored output needs to be handled in ext, since
      plain transfers will _not_ affect the stored return data (and we don't
      want to handle this special call case inside the `runtime` API). This
      has drawbacks:
      - It can not be tested easily in the mock.
      - It introduces an inconsistency where resetting the stored output is
      handled in ext, but the runtime API is responsible to store it back
      correctly after any calls made. Instead, with ownership of the data in
      `Frame`, both can be handled in a single place. Handling both in `fn
      run()` is more natural and leaves less room for runtime API bugs.
      
      The returned output is reset each time _before_ running any executable
      in a nested stack. This change should not incur any overhead to the
      overall memory usage as _only_ the returned data from the last executed
      frame will be kept around at any time.
      
      ---------
      
      Signed-off-by: default avatarCyrill Leutwiler <bigcyrill@hotmail.com>
      Signed-off-by: default avatarxermicus <cyrill@parity.io>
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarPG Herveou <pgherveou@gmail.com>
  17. Sep 13, 2024
  18. Sep 11, 2024
    • Alexander Theißen's avatar
      Send balance when contract doesn't exist (#5664) · ea5fb02e
      Alexander Theißen authored
      Fixes #5577 
      
      I decided to bubble up the error from where we actually try to load the
      contract info. This helps to make sure that we don't miss some entry
      point by accident. The draw back is that we have to live with some
      additional `.expect`.
      
      @pgherveou
      
       With this logic the proxy and its runtime part should be
      completely unaware whether something is a contract call or a balance
      transfer. They should just route everything into pallet_revive.
      
      ---------
      
      Co-authored-by: default avatarCyrill Leutwiler <cyrill@parity.io>
  19. Sep 09, 2024
  20. Sep 08, 2024
    • PG Herveou's avatar
      [pallet-revive] update generic runtime types (#5608) · 868a36bd
      PG Herveou authored
      
      fix #5574
      
      - Use U256 instead of BalanceOf<T> and MomentOf<T> in Ext trait
      - Enforce H256 for T::Hash
      
      The Ext trait still depends on the associated type `T: Config`, we can
      look into refactoring it even more later but even in the current state
      it should not influence how the data is encoded / decoded between the
      contract and the host
      ```
      fn caller(&self) -> Origin<Self::T>;
      -> only use to extract the address of the caller 
      
      fn account_id(&self) -> &AccountIdOf<Self::T>;
       -> only used to expose the address or access the account_id internally   
      
      fn gas_meter(&self) -> &GasMeter<Self::T>;
      fn gas_meter_mut(&mut self) -> &mut GasMeter<Self::T>;
       -> encoding does not depend on T
      
      fn call_runtime(&self, call: <Self::T as Config>::RuntimeCall) -> DispatchResultWithPostInfo;
      -> Substrate specific, just an opaque blob of bytes from the contract's perspective
      
      fn contract_info(&mut self) -> &mut ContractInfo<Self::T>;
      fn transient_storage(&mut self) -> &mut TransientStorage<Self::T>;
      -> gated by #[cfg(any(test, feature = "runtime-benchmarks"))]
      ```
      
      ---------
      
      Co-authored-by: default avatarAlexander Theißen <alex.theissen@me.com>
  21. Sep 03, 2024
  22. Sep 02, 2024
  23. Aug 23, 2024
    • Alexander Theißen's avatar
      Add initial version of `pallet_revive` (#5293) · 559fa1db
      Alexander Theißen authored
      This is a heavily modified and stripped down version of
      `pallet_contracts`. We decided to fork instead of extend the old pallet.
      Reasons for that are:
      
      - There is no benefit of supporting both on the same pallet as the
      intended payload for the new pallet (recompiled YUL) will be using a
      different ABI.
      - It is much easier since it allows us to remove all the code that was
      necessary to support Wasm and focus fully on running cross compiled YUL
      contracts.
      
      **The code is reviewable but can't be merged because it depends on an
      unreleased version of PolkaVM via git.**
      
      ## Current state
      
      All tests are passing and the code is not quick and dirty but written to
      last. The work is not finished, though. It is included in the
      `kitchensink-runtime` and a node can be built. However, we merge early
      in order to be able to start testing other components as early as
      possible.
      
      Outstanding changes are tracked here and will be merged separately:
      https://github.com/paritytech/polkadot-sdk/issues/5308
      
      ## Syscall Interface
      
      The syscall interface is best explored by generating the docs of this
      crate and looking at the `SyscallDoc` trait. Arguments are passed in
      registers a0-a5 in the order they are listed. If there are more than 6
      arguments (call, instantiate) a pointer to a packed struct of the
      arguments is expected as the only argument. I plan to create variants of
      those syscalls with less arguments specifically for YUL.
      
      Functions are just referenced by their name as ASCII within the PolkaVM
      container. Rather than by a syscall number as it was the case in the
      last implementation.
       
      
      ## Changes vs. `pallet_contracts`
      
      The changes are too numerous to list them all here. This is an
      incomplete list:
      
      - Use PolkaVM instead of wasmi to execute contracts
      - Made Runtime generic over a new `Memory` trait as we can't map memory
      directly on PolkaVM anymore
      - No static verification on code upload. Everything is a determinstic
      runtime failure
      - Removed all migrations and reset the pallet version
      - Removed the nonce storage item and instead use the deployers account
      nonce to generate a unique trie
      - We now bump the deployers account nonce on contract instantiation to
      they are bumped even within a batch transaction
      - Removed the instantiation nonce host function: We should add a new
      `instantiate` variant as a replacement for thos
      - ContractInfoOf of uses the indentity hasher now
      - Remove the determinism feature: User of that feature should switch to
      soft floats
      - The `unstable` attribute has been replaced by a `api_version`
      attribute to declare at which version an API became available
      	- leaving out that attribute makes the API effectively unstable
      - a new `api_version` field on the CodeInfo makes sure that old
      contracts can't access new APIs (necessary due to lack of static
      verification.
      - Added a `behaviour_version` field to CodeInfo that can used if we need
      to introduce breaking changes and keep the old behaviour for existing
      contracts
      - Unified storage vs. transient and fixed vs. variable sized keys all
      into one set of multiplexing host functions
      - Removed all contract observeable limits from the `Config` trait and
      instead hardcode them
      - Removed the Schedule
      - Removed all deprecated host functions
      - Simplify chain extension as preperation for making it a pre-compile
      
      ---------
      
      Co-authored-by: command-bot <>
  24. Jul 16, 2024
  25. Jul 15, 2024
    • Jun Jiang's avatar
      Remove most all usage of `sp-std` (#5010) · 7ecf3f75
      Jun Jiang authored
      
      This should remove nearly all usage of `sp-std` except:
      - bridge and bridge-hubs
      - a few of frames re-export `sp-std`, keep them for now
      - there is a usage of `sp_std::Writer`, I don't have an idea how to move
      it
      
      Please review proc-macro carefully. I'm not sure I'm doing it the right
      way.
      
      Note: need `/bot fmt`
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      Co-authored-by: command-bot <>
  26. Jun 04, 2024
  27. May 23, 2024
    • PG Herveou's avatar
      Contracts: Rework host fn benchmarks (#4233) · 493ba5e2
      PG Herveou authored
      
      fix https://github.com/paritytech/polkadot-sdk/issues/4163
      
      This PR does the following:
      Update to pallet-contracts-proc-macro: 
      - Parse #[cfg] so we can add a dummy noop host function for benchmark.
      - Generate BenchEnv::<host_fn> so we can call host functions directly in
      the benchmark.
      - Add the weight of the noop host function before calling the host
      function itself
      
      Update benchmarks:
      - Update all host function benchmark, a host function benchmark now
      simply call the host function, instead of invoking the function n times
      from within a contract.
      - Refactor RuntimeCosts & Schedule, for most host functions, we can now
      use the generated weight function directly instead of computing the diff
      with the cost! macro
      
      ```rust
      // Before
      #[benchmark(pov_mode = Measured)]
      fn seal_input(r: Linear<0, API_BENCHMARK_RUNS>) {
          let code = WasmModule::<T>::from(ModuleDefinition {
              memory: Some(ImportedMemory::max::<T>()),
              imported_functions: vec![ImportedFunction {
                  module: "seal0",
                  name: "seal_input",
                  params: vec![ValueType::I32, ValueType::I32],
                  return_type: None,
              }],
              data_segments: vec![DataSegment { offset: 0, value: 0u32.to_le_bytes().to_vec() }],
              call_body: Some(body::repeated(
                  r,
                  &[
                      Instruction::I32Const(4), // ptr where to store output
                      Instruction::I32Const(0), // ptr to length
                      Instruction::Call(0),
                  ],
              )),
              ..Default::default()
          });
      
          call_builder!(func, code);
      
          let res;
          #[block]
          {
              res = func.call();
          }
          assert_eq!(res.did_revert(), false);
      }
      ```
      
      ```rust
      // After
      fn seal_input(n: Linear<0, { code::max_pages::<T>() * 64 * 1024 - 4 }>) {
          let mut setup = CallSetup::<T>::default();
          let (mut ext, _) = setup.ext();
          let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![42u8; n as usize]);
          let mut memory = memory!(n.to_le_bytes(), vec![0u8; n as usize],);
          let result;
          #[block]
          {
              result = BenchEnv::seal0_input(&mut runtime, &mut memory, 4, 0)
          }
          assert_ok!(result);
          assert_eq!(&memory[4..], &vec![42u8; n as usize]);
      }
      ``` 
      
      [Weights
      compare](https://weights.tasty.limo/compare?unit=weight&ignore_errors=true&threshold=10&method=asymptotic&repo=polkadot-sdk&old=master&new=pg%2Frework-host-benchs&path_pattern=substrate%2Fframe%2Fcontracts%2Fsrc%2Fweights.rs%2Cpolkadot%2Fruntime%2F*%2Fsrc%2Fweights%2F**%2F*.rs%2Cpolkadot%2Fbridges%2Fmodules%2F*%2Fsrc%2Fweights.rs%2Ccumulus%2F**%2Fweights%2F*.rs%2Ccumulus%2F**%2Fweights%2Fxcm%2F*.rs%2Ccumulus%2F**%2Fsrc%2Fweights.rs)
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarAlexander Theißen <alex.theissen@me.com>
  28. May 17, 2024
  29. Apr 10, 2024
    • PG Herveou's avatar
      Contracts: Only exec parsed code in benchmarks (#3915) · 0d71753e
      PG Herveou authored
      [Weights
      compare](https://weights.tasty.limo/compare?unit=weight&ignore_errors=true&threshold=10&method=asymptotic&repo=polkadot-sdk&old=master&new=pg%2Fbench_tweaks&path_pattern=substrate%2Fframe%2F**%2Fsrc%2Fweights.rs%2Cpolkadot%2Fruntime%2F*%2Fsrc%2Fweights%2F**%2F*.rs%2Cpolkadot%2Fbridges%2Fmodules%2F*%2Fsrc%2Fweights.rs%2Ccumulus%2F**%2Fweights%2F*.rs%2Ccumulus%2F**%2Fweights%2Fxcm%2F*.rs%2Ccumulus%2F**%2Fsrc%2Fweights.rs)
      
      Note: Raw weights change does not mean much here, as this PR reduce the
      scope of what is benchmarked, they are therefore decreased by a good
      margin. One should instead print the Schedule using
      
      cargo test --features runtime-benchmarks bench_print_schedule --
      --nocapture
      or following the instructions from the
      [README](https://github.com/paritytech/polkadot-sdk/tree/pg/bench_tweaks/substrate/frame/contracts#schedule)
      for looking at the Schedule of a specific runtime
      
      ---------
      
      Co-authored-by: command-bot <>
  30. Mar 26, 2024
    • Dcompoze's avatar
      Fix spelling mistakes across the whole repository (#3808) · 002d9260
      Dcompoze authored
      **Update:** Pushed additional changes based on the review comments.
      
      **This pull request fixes various spelling mistakes in this
      repository.**
      
      Most of the changes are contained in the first **3** commits:
      
      - `Fix spelling mistakes in comments and docs`
      
      - `Fix spelling mistakes in test names`
      
      - `Fix spelling mistakes in error messages, panic messages, logs and
      tracing`
      
      Other source code spelling mistakes are separated into individual
      commits for easier reviewing:
      
      - `Fix the spelling of 'authority'`
      
      - `Fix the spelling of 'REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY'`
      
      - `Fix the spelling of 'prev_enqueud_messages'`
      
      - `Fix the spelling of 'endpoint'`
      
      - `Fix the spelling of 'children'`
      
      - `Fix the spelling of 'PenpalSiblingSovereignAccount'`
      
      - `Fix the spelling of 'PenpalSudoAccount'`
      
      - `Fix the spelling of 'insufficient'`
      
      - `Fix the spelling of 'PalletXcmExtrinsicsBenchmark'`
      
      - `Fix the spelling of 'subtracted'`
      
      - `Fix the spelling of 'CandidatePendingAvailability'`
      
      - `Fix the spelling of 'exclusive'`
      
      - `Fix the spelling of 'until'`
      
      - `Fix the spelling of 'discriminator'`
      
      - `Fix the spelling of 'nonexistent'`
      
      - `Fix the spelling of 'subsystem'`
      
      - `Fix the spelling of 'indices'`
      
      - `Fix the spelling of 'committed'`
      
      - `Fix the spelling of 'topology'`
      
      - `Fix the spelling of 'response'`
      
      - `Fix the spelling of 'beneficiary'`
      
      - `Fix the spelling of 'formatted'`
      
      - `Fix the spelling of 'UNKNOWN_PROOF_REQUEST'`
      
      - `Fix the spelling of 'succeeded'`
      
      - `Fix the spelling of 'reopened'`
      
      - `Fix the spelling of 'proposer'`
      
      - `Fix the spelling of 'InstantiationNonce'`
      
      - `Fix the spelling of 'depositor'`
      
      - `Fix the spelling of 'expiration'`
      
      - `Fix the spelling of 'phantom'`
      
      - `Fix the spelling of 'AggregatedKeyValue'`
      
      - `Fix the spelling of 'randomness'`
      
      - `Fix the spelling of 'defendant'`
      
      - `Fix the spelling of 'AquaticMammal'`
      
      - `Fix the spelling of 'transactions'`
      
      - `Fix the spelling of 'PassingTracingSubscriber'`
      
      - `Fix the spelling of 'TxSignaturePayload'`
      
      - `Fix the spelling of 'versioning'`
      
      - `Fix the spelling of 'descendant'`
      
      - `Fix the spelling of 'overridden'`
      
      - `Fix the spelling of 'network'`
      
      Let me know if this structure is adequate.
      
      **Note:** The usage of the words `Merkle`, `Merkelize`, `Merklization`,
      `Merkelization`, `Merkleization`, is somewhat inconsistent but I left it
      as it is.
      
      ~~**Note:** In some places the term `Receival` is used to refer to
      message reception, IMO `Reception` is the correct word here, but I left
      it as it is.~~
      
      ~~**Note:** In some places the term `Overlayed` is used instead of the
      more acceptable version `Overlaid` but I also left it as it is.~~
      
      ~~**Note:** In some places the term `Applyable` is used instead of the
      correct version `Applicable` but I also left it as it is.~~
      
      **Note:** Some usage of British vs American english e.g. `judgement` vs
      `judgment`, `initialise` vs `initialize`, `optimise` vs `optimize` etc.
      are both present in different places, but I suppose that's
      understandable given the number of contributors.
      
      ~~**Note:** There is a spelling mistake in `.github/CODEOWNERS` but it
      triggers errors in CI when I make changes to it, so I left it as it
      is.~~
  31. Mar 19, 2024
    • Davide Galassi's avatar
      Implement crypto byte array newtypes in term of a shared type (#3684) · 1e9fd237
      Davide Galassi authored
      Introduces `CryptoBytes` type defined as:
      
      ```rust
      pub struct CryptoBytes<const N: usize, Tag = ()>(pub [u8; N], PhantomData<fn() -> Tag>);
      ```
      
      The type implements a bunch of methods and traits which are typically
      expected from a byte array newtype
      (NOTE: some of the methods and trait implementations IMO are a bit
      redundant, but I decided to maintain them all to not change too much
      stuff in this PR)
      
      It also introduces two (generic) typical consumers of `CryptoBytes`:
      `PublicBytes` and `SignatureBytes`.
      
      ```rust
      pub struct PublicTag;
      pub PublicBytes<const N: usize, CryptoTag> = CryptoBytes<N, (PublicTag, CryptoTag)>;
      
      pub struct SignatureTag;
      pub SignatureBytes<const N: usize, CryptoTag> = CryptoBytes<N, (SignatureTag, CryptoTag)>;
      ```
      
      Both of them use a tag to differentiate the two types at a higher level.
      Downstream specializations will further specialize using a dedicated
      crypto tag. For example in ECDSA:
      
      
      ```rust
      pub struct EcdsaTag;
      
      pub type Public = PublicBytes<PUBLIC_KEY_SERIALIZED_SIZE, EcdsaTag>;
      pub type Signature = PublicBytes<PUBLIC_KEY_SERIALIZED_SIZE, EcdsaTag>;
      ```
      
      Overall we have a cleaner and most importantly **consistent** code for
      all the types involved
      
      All these details are opaque to the end user which can use `Public` and
      `Signature` for the cryptos as before
  32. Feb 20, 2024
    • PG Herveou's avatar
      Contracts: Stabilize APIs (#3384) · d250a6e4
      PG Herveou authored
      Remove `#[unstable]` on `call_v2`, `instantiate_v2`,
      `lock_delegate_dependency` and `unlock_delegate_dependency`.
      See ink! integrations: 
      - call_v2: https://github.com/paritytech/ink/pull/2077
      - instantiate_v2: <TODO>
      - lock/unlock dependency: https://github.com/paritytech/ink/pull/2076
  33. Feb 19, 2024
    • PG Herveou's avatar
      Contracts: xcm host fn fixes (#3086) · ca382f32
      PG Herveou authored
      ## Xcm changes:
      - Fix `pallet_xcm::execute`, move the logic into The `ExecuteController`
      so it can be shared with anything that implement that trait.
      - Make `ExecuteController::execute` retursn `DispatchErrorWithPostInfo`
      instead of `DispatchError`, so that we don't charge the full
      `max_weight` provided if the execution is incomplete (useful for
      force_batch or contracts calls)
      - Fix docstring for `pallet_xcm::execute`, to reflect the changes from
      #2405
      - Update the signature for `ExecuteController::execute`, we don't need
      to return the `Outcome` anymore since we only care about
      `Outcome::Complete`
      
      ## Contracts changes:
      
      - Update host fn `xcm_exexute`, we don't need to write the `Outcome` to
      the sandbox memory anymore. This was also not charged as well before so
      it if fixes this too.
      - One of the issue was that the dry_run of a contract that call
      `xcm_execute` would exhaust the `gas_limit`.
      
      This is because `XcmExecuteController::execute` takes a `max_weight`
      argument, and since we don't want the user to specify it manually we
      were passing everything left by pre-charghing
      `ctx.ext.gas_meter().gas_left()`
      
      - To fix it I added a `fn influence_lowest_limit` on the `Token` trait
      and make it return false for `RuntimeCost::XcmExecute`.
      - Got rid of the `RuntimeToken` indirection, we can just use
      `RuntimeCost` directly.
      
      ---------
      
      Co-authored-by: command-bot <>