native: ensure proper endianness is used for CryptoLib's field element multiplier

Field element multiplier must be provided in the LE form, confirmed by
cross-node invocation: https://github.com/nspcc-dev/neo-go/pull/3043#issuecomment-1733424840.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-10-04 17:56:40 +03:00
parent 8c46517522
commit b7e019e7ef

View file

@ -230,9 +230,8 @@ func scalarFromBytes(bytes []byte, neg bool) (*fr.Element, error) {
return nil, fmt.Errorf("invalid multiplier: 32-bytes scalar is expected, got %d", len(bytes))
}
// The input bytes are in the LE form, so we can't use fr.Element.SetBytesCanonical as far
// as it accepts BE.
// TODO: ensure that LE is really used in the C# node. More common way is to use BE form, and these
// lines of code are here only because that's the way how C# example works (https://github.com/neo-project/neo/issues/2647#issuecomment-1129849870).
// as it accepts BE. Confirmed by https://github.com/neo-project/neo/issues/2647#issuecomment-1129849870
// and by https://github.com/nspcc-dev/neo-go/pull/3043#issuecomment-1733424840.
v, err := fr.LittleEndian.Element((*[fr.Bytes]byte)(bytes))
if err != nil {
return nil, fmt.Errorf("invalid multiplier: failed to decode scalar: %w", err)