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
7 changes: 7 additions & 0 deletions prdoc/pr_8734.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: '[pallet-revive] contract''s nonce starts at 1'
doc:
- audience: Runtime Dev
description: nonce starting value should be 1 see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md
crates:
- name: pallet-revive
bump: minor
3 changes: 3 additions & 0 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,9 @@ where
// account.
<System<T>>::inc_consumers(account_id)?;

// Contracts nonce starts at 1
<System<T>>::inc_account_nonce(account_id);

// Needs to be incremented before calling into the code so that it is visible
// in case of recursion.
<System<T>>::inc_account_nonce(caller.account_id()?);
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/revive/src/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ fn nonce() {
});
let succ_succ_code = MockLoader::insert(Constructor, move |ctx, _| {
let alice_nonce = System::account_nonce(&ALICE);
assert_eq!(System::account_nonce(ctx.ext.account_id()), 0);
assert_eq!(System::account_nonce(ctx.ext.account_id()), 1);
assert_eq!(ctx.ext.caller().account_id().unwrap(), &ALICE);
let addr = ctx
.ext
Expand All @@ -1753,17 +1753,17 @@ fn nonce() {
<<Test as Config>::AddressMapper as AddressMapper<Test>>::to_fallback_account_id(&addr);

assert_eq!(System::account_nonce(&ALICE), alice_nonce);
assert_eq!(System::account_nonce(ctx.ext.account_id()), 1);
assert_eq!(System::account_nonce(&account_id), 0);
assert_eq!(System::account_nonce(ctx.ext.account_id()), 2);
assert_eq!(System::account_nonce(&account_id), 1);

// a plain call should not influence the account counter
ctx.ext
.call(Weight::zero(), U256::zero(), &addr, U256::zero(), vec![], false, false)
.unwrap();

assert_eq!(System::account_nonce(ALICE), alice_nonce);
assert_eq!(System::account_nonce(ctx.ext.account_id()), 1);
assert_eq!(System::account_nonce(&account_id), 0);
assert_eq!(System::account_nonce(ctx.ext.account_id()), 2);
assert_eq!(System::account_nonce(&account_id), 1);

exec_success()
});
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3492,7 +3492,7 @@ fn create1_with_value_works() {
assert_ok!(builder::call(addr).value(value).data(code_hash.encode()).build());

// We should see the expected balance at the expected account
let address = crate::address::create1(&addr, 0);
let address = crate::address::create1(&addr, 1);
let account_id = <Test as Config>::AddressMapper::to_account_id(&address);
let usable_balance = <Test as Config>::Currency::usable_balance(&account_id);
assert_eq!(usable_balance, value);
Expand Down
Loading