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

[Code Review]: Invalid judgement in decode_account #890

Closed
huye0728 opened this issue May 25, 2018 · 2 comments
Closed

[Code Review]: Invalid judgement in decode_account #890

huye0728 opened this issue May 25, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@huye0728
Copy link
Contributor

huye0728 commented May 25, 2018

bool rai::uint256_union::decode_account (std::string const & source_a)
{
    auto error (source_a.size () < 5);
    if (!error)
    {
        auto xrb_prefix (source_a[0] == 'x' && source_a[1] == 'r' && source_a[2] == 'b' && (source_a[3] == '_' || source_a[3] == '-'));
        auto nano_prefix (source_a[0] == 'n' && source_a[1] == 'a' && source_a[2] == 'n' && source_a[3] == 'o' && (source_a[4] == '_' || source_a[4] == '-'));
        error = (xrb_prefix && source_a.size () != 64) || (nano_prefix && source_a.size () != 65);
        if (!error)
        {
            if (xrb_prefix || nano_prefix)
            {
                auto i (source_a.begin () + (xrb_prefix ? 4 : 5));
                if (*i == '1' || *i == '3')
                {
                    rai::uint512_t number_l;
                    for (auto j (source_a.end ()); !error && i != j; ++i)
                    {
                        uint8_t character (*i);
                        error = character < 0x30 || character >= 0x80;
                        if (!error)
                        {
                            uint8_t byte (account_decode (character));
                            error = byte == '~'; // Invalid judgement, account_decode never return ~
                            if (!error)
                            {
                                number_l <<= 5;
                                number_l += byte;
                            }
                        }
                    }
                    if (!error)
                    {
                        *this = (number_l >> 40).convert_to<rai::uint256_t> ();
                        uint64_t check (number_l & static_cast<uint64_t> (0xffffffffff));
                        uint64_t validation (0);
                        blake2b_state hash;
                        blake2b_init (&hash, 5);
                        blake2b_update (&hash, bytes.data (), bytes.size ());
                        blake2b_final (&hash, reinterpret_cast<uint8_t *> (&validation), 5);
                        error = check != validation;
                    }
                }
                else
                {
                    error = true;
                }
            }
            else
            {
                error = true;
            }
        }
    }
    return error;
}
@rkeene rkeene self-assigned this Aug 23, 2018
@rkeene rkeene added the bug label Aug 23, 2018
@rkeene rkeene added this to the V16.0 milestone Aug 23, 2018
@rkeene
Copy link
Contributor

rkeene commented Aug 28, 2018

Can you provide more specific information ?

@rkeene rkeene modified the milestones: V16.0, V18.0 Aug 28, 2018
@rkeene
Copy link
Contributor

rkeene commented Aug 28, 2018

Nevermind, @PlasmaPower spotted the comment and helped me !

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

No branches or pull requests

2 participants