Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
Accept salt arg in ext_create.
  • Loading branch information
pepyakin committed Sep 10, 2018
commit a06dbead16e8d5c9f2687930170caea0840f5108
8 changes: 5 additions & 3 deletions substrate/runtime/contract/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,21 @@ fn code_create(constructor: &[u8]) -> String {
;; ext_create(
;; code_ptr: u32,
;; code_len: u32,
;; salt: u64,
;; gas: u64,
;; value_ptr: u32,
;; value_len: u32,
;; input_data_ptr: u32,
;; input_data_len: u32,
;; ) -> u32
(import "env" "ext_create" (func $ext_create (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
(import "env" "ext_create" (func $ext_create (param i32 i32 i64 i64 i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(drop
(call $ext_create
(i32.const 12) ;; Pointer to `code`
(i32.const {code_len}) ;; Length of `code`
(i64.const 0) ;; Salt used for determining account address.
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 4) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
Expand Down Expand Up @@ -363,12 +365,12 @@ fn contract_create() {
);

// 11 - value sent with the transaction
// 2 * 139 - gas spent by the deployer contract (139) multiplied by gas price (2)
// 2 * 140 - gas spent by the deployer contract (140) multiplied by gas price (2)
// 2 * 135 - base gas fee for call (top level)
// 2 * 175 - base gas fee for create (by contract)
// ((21 / 2) * 2) - price per account creation
let expected_gas_after_create =
100_000_000 - 11 - (2 * 139) - (2 * 135) - (2 * 175) - ((21 / 2) * 2);
100_000_000 - 11 - (2 * 140) - (2 * 135) - (2 * 175) - ((21 / 2) * 2);
assert_eq!(Balances::free_balance(&0), expected_gas_after_create);
assert_eq!(Balances::free_balance(&1), 8);
assert_eq!(Balances::free_balance(&derived_address), 3);
Expand Down
4 changes: 2 additions & 2 deletions substrate/runtime/contract/src/vm/env_def/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,11 @@ define_env!(init_env, <E: Ext>,
}
},

// ext_create(code_ptr: u32, code_len: u32, gas: u64, value_ptr: u32, value_len: u32, input_data_ptr: u32, input_data_len: u32) -> u32
// ext_create(code_ptr: u32, code_len: u32, salt: u64, gas: u64, value_ptr: u32, value_len: u32, input_data_ptr: u32, input_data_len: u32) -> u32
ext_create(
ctx, code_ptr: u32,
code_len: u32,
salt: u64,
gas: u64,
value_ptr: u32,
value_len: u32,
Expand All @@ -251,7 +252,6 @@ define_env!(init_env, <E: Ext>,
} else {
<<<E as Ext>::T as Trait>::Gas as As<u64>>::sa(gas)
};
let salt = 0;
let ext = &mut ctx.ext;
let create_outcome = ctx.gas_meter.with_nested(nested_gas_limit, |nested_meter| {
match nested_meter {
Expand Down
8 changes: 5 additions & 3 deletions substrate/runtime/contract/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,21 @@ mod tests {
;; ext_create(
;; code_ptr: u32,
;; code_len: u32,
;; salt: u64,
;; gas: u64,
;; value_ptr: u32,
;; value_len: u32,
;; input_data_ptr: u32,
;; input_data_len: u32,
;; ) -> u32
(import "env" "ext_create" (func $ext_create (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
(import "env" "ext_create" (func $ext_create (param i32 i32 i64 i64 i32 i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(drop
(call $ext_create
(i32.const 12) ;; Pointer to `code`
(i32.const 8) ;; Length of `code`
(i64.const 228) ;; Salt used for determining account address.
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 4) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
Expand Down Expand Up @@ -460,8 +462,8 @@ mod tests {
data: vec![
1, 2, 3, 4,
],
gas_left: 49990,
salt: 0,
gas_left: 49989,
salt: 228,
}]
);
}
Expand Down