i have the following formula for generating public key
hash160 h = h0+h1+h2+h3+h4+h5+h6+h7+h8+h9
pubkey = g.base[h0]+g.offset[h1]+g.offset[h2]+g.offset[h3]+g.offset[h4]+g.offset[h5]+g.offset[h6]+g.offset[h7]+g.offset[h8]+g.offset[h9]
And the following code which generate the pub key from hash160
#define BASE_MAX 0xFFFF
static secp256k1_gej_t bases[BASE_MAX];
static secp256k1_scalar_t priv_bases[BASE_MAX];
#define OFFSET_MAX_COL 9
#define OFFSET_MAX_ROW BASE_MAX
#define BITS 16
#define NUM_PARTS(n) (((n) - 1) / 16 + 1)
static secp256k1_ge_t offsets[OFFSET_MAX_ROW][OFFSET_MAX_COL];
static secp256k1_scalar_t priv_offsets[OFFSET_MAX_ROW][OFFSET_MAX_COL];
union uint256_s
{
uint8_t i8[32];
uint16_t i16[16];
uint32_t i32[8];
uint64_t i64[4];
};
typedef union uint256_s uint256_t;
static void gen_pub_key(uint8_t *pub_key, size_t n, uint160_t x)
{
size_t idx = get_bits(n, x.i16, 0);
secp256k1_gej_t r = bases[idx];
for (size_t i = 1; i < NUM_PARTS(n); i++)
{
size_t col = i - 1;
size_t row = get_bits(n, x.i16, i);
secp256k1_gej_add_ge(&r, &r, &offsets[row][col]);
}
secp256k1_ge_t s;
secp256k1_ge_set_gej(&s, &r);
pub_key[0] = 0x02 | (secp256k1_fe_is_odd(&s.y) ? 0x01 : 0x00);
secp256k1_fe_get_b32(pub_key+1, &s.x);
}
But what if i had public key and i want the corresponding hash160 using the above formula and the code.
For clarity, g in the g.offset[i]
is the seck256k1's generator point.
i have no idea where to start but i know the original code collects random bytes and write them into memory then access them later to make 10*16 bit parts which will be used to generate public key and private key respectively.
so i want to do it in reverse like
pubkey => hash160
not to be confused by bitcoin's normal pubkey=> hash160=> address
.