Currently, the multisig descriptor constructions are limited to 16 keys only possibly because of template parsing reasons. Under p2sh context, such scripts would be invalid anyway because of 520-byte rule, but we can support up to 20 keys for CHECKMULTISIG in witness script context. 


typedef std::vector<uint32_t> KeyPath;
struct PubkeyProvider
{
protected:
    
    
    uint32_t m_expr_index;
public:
    explicit PubkeyProvider(uint32_t exp_index) : m_expr_index(exp_index) {}
    virtual ~PubkeyProvider() = default;
    /** Derive a public key.
     *  read_cache is the cache to read keys from (if not nullptr)
     *  write_cache is the cache to write keys to (if not nullptr)
     *  Caches are not exclusive but this is not tested. Currently we use them exclusively
     */
    virtual bool GetPubKey(int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr, DescriptorCache* write_cache = nullptr) = 0;
    
    virtual bool IsRange() const = 0;
    
    virtual size_t GetSize() const = 0;
    
    virtual std::string ToString() const = 0;
    
    virtual bool ToPrivateString(const SigningProvider& arg, std::string& out) const = 0;
    
    virtual bool ToNormalizedString(const SigningProvider& arg, std::string& out, bool priv) const = 0;
    
    virtual bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const = 0;
};
class OriginPubkeyProvider final : public PubkeyProvider