diff --git a/prdoc/pr_8734.prdoc b/prdoc/pr_8734.prdoc new file mode 100644 index 0000000000000..82e3ebc5cf727 --- /dev/null +++ b/prdoc/pr_8734.prdoc @@ -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 diff --git a/substrate/frame/revive/src/exec.rs b/substrate/frame/revive/src/exec.rs index 7797b7b2e475b..ee9b77513faf7 100644 --- a/substrate/frame/revive/src/exec.rs +++ b/substrate/frame/revive/src/exec.rs @@ -1143,6 +1143,9 @@ where // account. >::inc_consumers(account_id)?; + // Contracts nonce starts at 1 + >::inc_account_nonce(account_id); + // Needs to be incremented before calling into the code so that it is visible // in case of recursion. >::inc_account_nonce(caller.account_id()?); diff --git a/substrate/frame/revive/src/exec/tests.rs b/substrate/frame/revive/src/exec/tests.rs index ef2b165fd337b..6023b5974b810 100644 --- a/substrate/frame/revive/src/exec/tests.rs +++ b/substrate/frame/revive/src/exec/tests.rs @@ -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 @@ -1753,8 +1753,8 @@ fn nonce() { <::AddressMapper as AddressMapper>::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 @@ -1762,8 +1762,8 @@ fn nonce() { .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() }); diff --git a/substrate/frame/revive/src/tests.rs b/substrate/frame/revive/src/tests.rs index b9251e1168b32..770ab77accdc4 100644 --- a/substrate/frame/revive/src/tests.rs +++ b/substrate/frame/revive/src/tests.rs @@ -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 = ::AddressMapper::to_account_id(&address); let usable_balance = ::Currency::usable_balance(&account_id); assert_eq!(usable_balance, value);