Skip to content

Commit

Permalink
native: ensure proper endianness is used for CryptoLib's field elemen…
Browse files Browse the repository at this point in the history
…t multiplier

Field element multiplier must be provided in the LE form, confirmed by
cross-node invocation: #3043 (comment).

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Oct 4, 2023
1 parent 1b83de9 commit 1216744
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/core/native/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1216744

Please sign in to comment.