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

BytesType.bytes32PaddedLength() returns incorrect value for lengths greater than 32 and multiples of 32 #2080

Closed
junsung-cho opened this issue Jul 17, 2024 · 0 comments · Fixed by #2089
Labels
needs-review issue/PR needs review from maintainer

Comments

@junsung-cho
Copy link
Contributor

junsung-cho commented Jul 17, 2024

Issue_title

BytesType.bytes32PaddedLength() returns incorrect value for lengths greater than 32 and multiples of 32.

Issue_description

BytesType::bytes32PaddedLength‎

    @Override
    public int bytes32PaddedLength() {
        return value.length <= 32
                ? MAX_BYTE_LENGTH
                : (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
    }

In case of the value.length is 64, 96, 128, ...
It should return 64, 96, 128, ...
However, the results are 96, 128, 160, ...

Issue_context

The corrected code is as follows:

    @Override
    public int bytes32PaddedLength() {
        if (value.length < MAX_BYTE_LENGTH) {
            return MAX_BYTE_LENGTH;
        } else if (value.length % MAX_BYTE_LENGTH == 0) {
            return value.length;
        } else {
            return (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
        }
    }

If it looks fine, I will create a pull request.

@junsung-cho junsung-cho added the needs-review issue/PR needs review from maintainer label Jul 17, 2024
@gtebrean gtebrean mentioned this issue Aug 8, 2024
3 tasks
gtebrean added a commit that referenced this issue Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review issue/PR needs review from maintainer
Projects
None yet
1 participant