Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View_tag #8406

Closed
Edan3blov opened this issue Jun 27, 2022 · 7 comments
Closed

View_tag #8406

Edan3blov opened this issue Jun 27, 2022 · 7 comments

Comments

@Edan3blov
Copy link

Hi,

As i saw on IIRC and elsewhere there is a need for view_tag function to create manually tx even after HF.

Thank you.

@j-berman
Copy link
Collaborator

Your question is a little unclear. Are you a normal user of Monero, or a developer of software that manually creates Monero txs?

@Edan3blov
Copy link
Author

I'm developer that manually creates Monero txs.

Thank you.

@selsta
Copy link
Collaborator

selsta commented Jun 28, 2022

If you post more detailed information it will be easier to help you.

@j-berman
Copy link
Collaborator

Every output in every tx will need to have a view_tag after the HF. It must be calculated correctly, otherwise other wallets won't be able to recognize received outputs.

A view tag is the first byte of hash["view_tag" | derivation | output index]

  • The hash function is the same Keccak used across the code base (see cn_fast_hash)
  • derivation is the shared secret

Relevant code

You can see how to derive the view tag here:

void crypto_ops::derive_view_tag(const key_derivation &derivation, size_t output_index, view_tag &view_tag) {
#pragma pack(push, 1)
struct {
char salt[8]; // view tag domain-separator
key_derivation derivation;
char output_index[(sizeof(size_t) * 8 + 6) / 7];
} buf;
#pragma pack(pop)
char *end = buf.output_index;
memcpy(buf.salt, "view_tag", 8); // leave off null terminator
buf.derivation = derivation;
tools::write_varint(end, output_index);
assert(end <= buf.output_index + sizeof buf.output_index);
// view_tag_full = H[salt|derivation|output_index]
hash view_tag_full;
cn_fast_hash(&buf, end - reinterpret_cast<char *>(&buf), view_tag_full);
// only need a slice of view_tag_full to realize optimal perf/space efficiency
static_assert(sizeof(crypto::view_tag) <= sizeof(view_tag_full), "view tag should not be larger than hash result");
memcpy(&view_tag, &view_tag_full, sizeof(crypto::view_tag));
}

Here is where the default tx builder derives them:

if (use_view_tags)
{
derive_view_tag(derivation, output_index, view_tag);
}

Testing

View tags are live on testnet now. You can test by compiling master (commit 9750e1f) and running monerod on testnet. Construct transactions using your tx builder, and then make sure a recipient using monero-wallet-cli is able to see those transactions.

There are also test vectors for derive_view_tag here: https://github.com/monero-project/monero/blob/9750e1fa103539b3e533455500610aae76e253a5/tests/crypto/tests.txt

Original PR

#8061

@Edan3blov
Copy link
Author

Hello again,

The best solution is a wallet-cli command line like --create-view-tag-from-spend-key

@selsta
Copy link
Collaborator

selsta commented Jul 6, 2022

Again, if you don't explain in detail what you are trying to do we can't help you. And if there is some language barrier maybe you can try to give an example of what you are doing?

@selsta
Copy link
Collaborator

selsta commented Jul 19, 2022

Closing this as it's unclear what the issue creator is asking and there was no attempt at clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants