openethereum / parity-ethereum

The fast, light, and robust client for Ethereum-like networks.
Other
6.82k stars 1.69k forks source link

Problem using Transaction Type permission contract - TX Hash used as sender #11765

Closed jacekv closed 4 years ago

jacekv commented 4 years ago

Hi everyone,

I setup a private PoA network using AuRa. All works fine. I am able to send transactions, create contracts, and interact with those. The next step is to setup the Transaction Type Permission contract, which looks as follows:

  pragma solidity ^0.4.18;

  contract Permissions {
      /// Allowed transaction types mask
      uint32 constant None = 0;
      uint32 constant All = 0xffffffff;
      uint32 constant Basic = 0x01;
      uint32 constant Call = 0x02;
      uint32 constant Create = 0x04;
      uint32 constant Private = 0x08;

     function allowedTxType(address sender) public returns (uint32) {
        return All;
    }
  }

I compile the smart contract using Remix and copied the bytecode in order to add it to my spec file (it's at 0x0000000000000000000000000000000000000009):

{
  "name": "test",
  "engine": {
    "authorityRound": {
      "params": {
        "stepDuration": "5",
        "emptyStepsTransition": "10",
        "maximumEmptySteps": "119",
        "validators": {
          "multi": {
            "0": {
              "list": [
                "0x0065916b857b61089d8162132f3f04eebf4a4cce"
              ]
            }
          }
        }
      }
    }
  },
  "params": {
    "transactionPermissionContract": "0x0000000000000000000000000000000000000009",
    "transactionPermissionContractTransition": "0x2",
    "maximumExtraDataSize": "0x20",
    "minGasLimit": "0x1388",
    "gasLimitBoundDivisor": "0x400",
    "networkID": "0x200",
    "eip140Transition": "0x0",
    "eip211Transition": "0x0",
    "eip214Transition": "0x0",
    "eip658Transition": "0x0",
    "wasmActivationTransition": "0x0",
    "eip145Transition": "0x0",
    "eip1014Transition": "0x0",
    "eip1052Transition": "0x0",
    "eip1283Transition": "0x0",
    "kip4Transition": "0x0",
    "kip6Transition": "0x0"
  },
  "genesis": {
    "seal": {
      "authorityRound": {
        "step": "0x0",
        "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
      }
    },
    "difficulty": "0x20000",
    "gasLimit": "0x2625A00"
  },
  "accounts": {
    "0x0000000000000000000000000000000000000001": {
      "balance": 1,
      "builtin": {
        "name": "ecrecover",
        "pricing": {
          "linear": {
            "base": 3000,
            "word": 0
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000002": {
      "balance": 1,
      "builtin": {
        "name": "sha256",
        "pricing": {
          "linear": {
            "base": 60,
            "word": 12
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000003": {
      "balance": 1,
      "builtin": {
        "name": "ripemd160",
        "pricing": {
          "linear": {
            "base": 600,
            "word": 120
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000004": {
      "balance": 1,
      "builtin": {
        "name": "identity",
        "pricing": {
          "linear": {
            "base": 15,
            "word": 3
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000005": {
      "builtin": {
        "activate_at": "0x0",
        "name": "modexp",
        "pricing": {
          "modexp": {
            "divisor": 20
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000006": {
      "builtin": {
        "activate_at": "0x0",
        "name": "alt_bn128_add",
        "pricing": {
          "linear": {
            "base": 500,
            "word": 0
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000007": {
      "builtin": {
        "activate_at": "0x0",
        "name": "alt_bn128_mul",
        "pricing": {
          "linear": {
            "base": 40000,
            "word": 0
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000008": {
      "builtin": {
        "activate_at": "0x0",
        "name": "alt_bn128_pairing",
        "pricing": {
          "alt_bn128_pairing": {
            "base": 100000,
            "pair": 80000
          }
        }
      }
    },
    "0x0000000000000000000000000000000000000009": {
      "balance":  "1",
      "constructor": "0x608060405234801561001057600080fd5b5060de8061001f6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063da26f8f6146044575b600080fd5b348015604f57600080fd5b506082600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505060a4565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b600063ffffffff90509190505600a165627a7a7230582063942f37af7f5da4898f05da69d54146c342101e55f4ca34982bc41d51026dfb0029"
    },
    "0x301569DC1CF54CAb8389E8B119407014d8e33C5a": {
      "balance": "2000000000000000000000"
    },
    "0xeC3b2668dB1ed047DFa4C8D06C68dc6ec86e0dB4": {
      "balance": "2000000000000000000000"
    }
  }
}

When I start my network and try to send a transaction through MetaMask using 0xeC3b2668dB1ed047DFa4C8D06C68dc6ec86e0dB4 I get the following message:

Skipping non-allowed transaction for sender 0x161fa0b92e9b0349d9da42a4ac0a5749f6e4d52e2e3761f49be6f1e2bf170078

I was wondering, why it says that 0x161 is the sender. As it turns out, it is the hash of the transaction:

2020-06-05 06:40:00 UTC http.worker10 TRACE own_tx  Importing transaction: 
PendingTransaction { transaction: SignedTransaction { 
  transaction: UnverifiedTransaction { 
    unsigned: Transaction { 
      nonce: 0, 
      gas_price: 20900000000, 
      gas: 21000, 
      action: Call(0xec3b2668db1ed047dfa4c8d06c68dc6ec86e0db4), 
      value: 1000000000000000000, data: [] 
    }, 
    v: 1060, 
    r: 91881198206846952532455968936880363128354229908606060642227702465332599729957, 
    s: 11563482316684662601992200427257820268902068021657820107865293331478783909291, 
   hash: 0x161fa0b92e9b0349d9da42a4ac0a5749f6e4d52e2e3761f49be6f1e2bf170078 
  }, 
  sender: 0xec3b2668db1ed047dfa4c8d06c68dc6ec86e0db4, 
  public: Some(0x7e9f704d15337f03c6b6fa552cec2c5bc218649882ffb3465ff21ffd906e38dcffc10d3aeb48c37791cc30f3cf1b1b65bd795019e166b1fe0e3ba4e279dcea1a) 
}, 
condition: None 
}

Am I doing something wrong or is there somewhere a bug?

Thanks :)

jacekv commented 4 years ago

Problem has been solved. It turns out that you have to change the All variable:

pragma solidity ^0.4.18;

  contract Permissions {
      /// Allowed transaction types mask
      uint32 constant None = 0;
      uint32 constant All = 0x0f; // before 0xffffffff
      uint32 constant Basic = 0x01;
      uint32 constant Call = 0x02;
      uint32 constant Create = 0x04;
      uint32 constant Private = 0x08;

     function allowedTxType(address sender) public returns (uint32) {
        return All;
    }
  }

I would recommend updating the docs regarding this :)