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

BLS consensus failure #2208

Closed
holiman opened this issue Aug 12, 2020 · 2 comments
Closed

BLS consensus failure #2208

holiman opened this issue Aug 12, 2020 · 2 comments

Comments

@holiman
Copy link
Contributor

holiman commented Aug 12, 2020

From EIP

G1 multiexponentiation call expects 160*k bytes as an input that is interpreted as byte concatenation of k slices each of them being a byte concatenation of encoding of G1 point (128 bytes) and encoding of a scalar value (32 bytes). Output is an encoding of multiexponentiation operation result - single G1 point (128 bytes).

So each input point is 160 bytes.

To avoid non-integer arithmetic call cost is calculated as k * multiplication_cost * discount / multiplier where multiplier = 1000, k is a number of (scalar, point) pairs for the call, multiplication_cost is a corresponding single multiplication call cost for G1/G2.

But: https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Shamatar/G1MultiExpPrecompile.cs#L45 ,

        public long DataGasCost(byte[] inputData, IReleaseSpec releaseSpec)
        {
            int k = inputData.Length / 192;
            return 12000L * k * Discount.For(k) / 1000;
        }

        private const int ItemSize = 160;
        
        public (byte[], bool) Run(byte[] inputData)
        {
            inputData ??= Array.Empty<byte>();
            if (inputData.Length % ItemSize > 0)

The itemSize is correctly set to 160, but alas not used for cost calculation.

Credits to goevmlab fuzzing and @MariusVanDerWijden 's bls-fuzzer

@holiman
Copy link
Contributor Author

holiman commented Aug 12, 2020

cc @shamatar

@shamatar
Copy link

Thank you for mentioning, @holiman :)

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

No branches or pull requests

3 participants