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

[6.0] Global.fromBigEndianBytes implementation #1013

Merged
merged 8 commits into from
Oct 1, 2024
Merged

[6.0] Global.fromBigEndianBytes implementation #1013

merged 8 commits into from
Oct 1, 2024

Conversation

kushti
Copy link
Member

@kushti kushti commented Jun 17, 2024

A new Global.fromBigEndianBytes[TNum] method is implemented in this PR, which can parse big-endian two's complement binary representation of TNum type.

example:

{
  val l = 1088800L
  val ba = l.toBytes
  Global.fromBigEndianBytes[Long](ba) == l
}

close #993

@kushti kushti self-assigned this Jun 17, 2024
@kushti kushti added this to the v6.0 milestone Jun 29, 2024
Base automatically changed from v6.0-methodcall to v6.0.0 August 6, 2024 07:14
Copy link
Member

@aslesarenko aslesarenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please see comments.

if (bytes.length > SBigInt.MaxSizeInBytes) {
throw SerializerException(s"BigInt value doesn't not fit into ${SBigInt.MaxSizeInBytes} bytes in fromBigEndianBytes")
}
CBigInt(new BigInteger(bytes.toArray)).asInstanceOf[T]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also satisfy the bit size for BigInt values, to catch the potential problem early.
See multiplication operation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done ,

        CBigInt(new BigInteger(bytes.toArray).to256BitValueExact).asInstanceOf[T]

now

@@ -516,7 +516,7 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C
(SGlobal.typeId, Seq(
MInfo(1, groupGeneratorMethod), MInfo(2, xorMethod)
) ++ (if (isV6Activated) {
Seq(MInfo(3, serializeMethod)) // methods added in v6.0
Seq(MInfo(3, serializeMethod), MInfo(5, fromBigEndianBytesMethod)) // methods added in v6.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth making a note about id = 4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kushti kushti merged commit 6fa801c into v6.0.0 Oct 1, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants