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

Fix U/I128 and U/I256 number representation for consistent sorting #78

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions Stellar-contract.x
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,36 @@ case SST_HOST_AUTH_ERROR:
SCHostAuthErrorCode authCode;
};

struct UInt128Parts {
uint64 hi;
uint64 lo;
};

// A signed int128 has a high sign bit and 127 value bits. We break it into a
// signed high int64 (that carries the sign bit and the high 63 value bits) and
// a low unsigned uint64 that carries the low 64 bits. This will sort in
// generated code in the same order the underlying int128 sorts.
struct Int128Parts {
// Both signed and unsigned 128-bit ints
// are transported in a pair of uint64s
// to reduce the risk of sign-extension.
int64 hi;
uint64 lo;
uint64 hi;
};

struct UInt256Parts {
uint64 hi_hi;
uint64 hi_lo;
uint64 lo_hi;
uint64 lo_lo;
};

// A signed int256 has a high sign bit and 255 value bits. We break it into a
// signed high int64 (that carries the sign bit and the high 63 value bits) and
// three low unsigned `uint64`s that carry the lower bits. This will sort in
// generated code in the same order the underlying int256 sorts.
struct Int256Parts {
int64 hi_hi;
uint64 hi_lo;
uint64 lo_hi;
uint64 lo_lo;
};

enum SCContractExecutableType
Expand Down Expand Up @@ -279,14 +303,14 @@ case SCV_DURATION:
Duration duration;

case SCV_U128:
Int128Parts u128;
UInt128Parts u128;
case SCV_I128:
Int128Parts i128;

case SCV_U256:
uint256 u256;
UInt256Parts u256;
case SCV_I256:
uint256 i256;
Int256Parts i256;

case SCV_BYTES:
SCBytes bytes;
Expand Down