<pre>
  PIP: PIP-0042
  Title: Update OP_RECOVER to initial sense described on original WhitePaper and allow ASK FOR PASA feature
  Type: Protocol
  Impact: Hard-Fork
  Author: Albert Molina <bpascalblockchain@gmail.com>  
  Copyright: Albert Molina, 2021 (All Rights Reserved)
  Comments-URI: https://discord.gg/gamPX9E4RF (Discord channel #pip-42)
  Status: Proposed
  Created: 2021-09-23
</pre>

## Summary

Update current OP_RECOVER operation in order to have a similar sense as described on [Original PascalCoin WhitePaper published on July 2016][1] few weeks before Genesis Block. 

## Motivation

OP_RECOVER feature was defined on original PascalCoin Whitepaper published on July 2016 as a way to allow recover coins that has lost private key. 

**PascalCoin WhitePaper:** 
```
PascalCoin proposes an alternative to the basic operation of Bitcoin, through which change
several aspects for working on the new virtual currency:
...
  - PascalCoin provides a method set by protocol to retrieve coins that are not used
    instead (lost key). This method only applies if after a certain time the owner does not
    make any operation with the account private key.
...
(Page 2/8)
```

Basically was a way to mantain a constant and predectible inflation and available coin because burning coins are not possible. 

Current problem is that WhitePaper definition is ambiguous and **certain time** was not specified, initial source code proposal was to **set a time value = 4 years** (420480 blocks in PascalCoin) 

Another problem is that WhitePaper didn't specified who can retrieve coins that are not used, neither what to do with Pascal Accounts (aka **PASA**) not used. 

## Proposal

This PIP specifies a more accurated OP_RECOVER feature that will mantain initial sense and will allow a fair PASA and coins distribution. 

Update current OP_RECOVER to work as this: 

1. The way to know if an Account is not used will be counting how many blocks since last private key signed this Account as an Active mode as defined on [PIP-0037][2]. 

2. Accounts without coins (amount = 0) can be reused to community usage in a ASK FOR PASA (OP_RECOVER special case) after 4 years if Account has not been used as specified on 1. 

3. Coins stored in Accounts (where amount > 0) can be retrieved to MINER that generates a block as a fee in the OP_RECOVER operation after 10 years if Account has not been used as specified on 1. 

4. ASK FOR PASA will be an OP_RECOVER special case operation signed by an Authority Account, Authority Account will be the Account stored in the type value of Account number 1 ( Account(1).type == Authority Account ). 

5. Accounts 0 to 9 (inclusive) are exempt for OP_RECOVER operation. 


## Specification

The following changes are required to implement this in PascalCoin.

### New OP_RECOVER fields

A new field `sign` will be added to OP_RECOVER that will be used in Proposal number 2. Value MUST be empty in other cases. 

```
  TOpRecoverFoundsData = Record
    account: Cardinal;
    n_operation : Cardinal;
    fee: UInt64;
    new_publicKey: TAccountKey;
	// New field for PIP-0042
    sign: TECDSA_SIG;
  End;
```

### Update OP_RECOVER code

#### Changes on check

Check proposals 2 to 5: 

```
  let A = target PASA 
  let L4Years = 420480  ((24 hours * 60 minutes) DIV 5 minutes) * 365 days * 4 years)  
  let L10Years = 1051200  ((24 hours * 60 minutes) DIV 5 minutes) * 365 days * 10 years)  
  let LCurrentBlock = Current Blockchain new block number
  
  // Proposal 5 protection
  if (A.account<=9) then
     Error 'Accounts 0..9 are protected';
  
  // Proposal 2 protection
  if (A.updated_on_block_active_mode + L4Years >= LCurrentBlock) then
     Error 'Account is still active (less than 4 years without private key usage)';  
  
  // Proposal 3 protection
  if (A.updated_on_block_active_mode + L10Years >= LCurrentBlock) AND (A.Balance > 0) then
     Error 'Account has balance>0 and still active (less than 10 years without private key usage)';
	 
  let B = Account(1)
  let C = Account( B.type ) // Authority account
  let DATA = OP_RECOVER fields

  // Proposal 4 ASK FOR PASA signed by Authority account
  if ((DATA.new_publicKey) not null) AND (NOT IsValidSignature(DATA.sign, C.accountInfo.publicKey)) then
     Error 'Ask for Pasa feature must be signed by Authority account';
  
```

#### Changes on Execute

Execution is done only **after checks are passed** 

```
  // Assume same fields than check code
   
  // Ask for Pasa
  if ((DATA.new_publicKey) not null) then 
    set A.accountInfo.publicKey = DATA.new_publicKey
	
  set FEE = A.balance
  set A.balance = 0; // Sets Account balance to 0, balance will be a fee for the miner
  
  SaveAccount( A );
  
  // Only the miner will obtain coins as a Fee of the block, none other can retrieve coins
  IncrementNewBlockFee( FEE );

```

### Conclusion

Only miner can retrieve coins, this will help and add a miners and pools race 

Current holders will have a reasonable time period (10 years) to hold coins

Ask for Pasa feature will be available since activation thanks to 4 years rule

## Affected PIP's

This PIP deactivates PIP-0012 and PIP-0019 

## Backwards Compatibility

This change is not backwards compatible and requires a hard-fork activation. 

## Links

1. [Original PascalCoin WhitePaper published on July 2016. Accessed 2021-09.][1]
2. [PIP-0037][2]

[1]: https://github.com/PascalCoin/PascalCoin/blob/c22184dd7a407c6646ab651494822071726ed36e/PascalCoin%20White%20Paper%20-%20EN.pdf
[2]: https://github.com/PascalCoin/PascalCoin/blob/master/PIP/PIP-0037.md
