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

Added generic sha256 #1544

Merged
merged 31 commits into from May 18, 2022
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9ada878
Added generic sha256
May 13, 2022
fecf8a1
Update sway-lib-std/src/hash.sw
Braqzen May 13, 2022
ea4a8c0
Inlined comments and updated formatting
May 13, 2022
0b93a03
Cleaned up asm
May 14, 2022
1f0a3b6
Fixing import
May 14, 2022
cdb5214
Updating tests, WIP
May 14, 2022
cbad5ea
Pushing up tests that fail to compile
May 15, 2022
85b521d
Updating docs
May 15, 2022
37d9731
Formatting
May 15, 2022
348f856
Updating compiler intrinsics
May 15, 2022
116eba2
Saving before pulling master in
May 16, 2022
cc0443c
Merge branch 'master' into braqzen-1511
Braqzen May 16, 2022
8928646
Updated tests
May 16, 2022
c7ab048
Fixed formatting
May 16, 2022
9ae4572
Starting to add hash validation for testing
May 17, 2022
9b4519d
Updated integers
May 17, 2022
2225304
Added str hashing
May 17, 2022
a83ba57
Added concrete tuple validation
May 17, 2022
4adfcb1
Added concrete array validation
May 17, 2022
da0d75a
Added concrete enum validation
May 17, 2022
ffbe0fd
Added b256 validation
May 18, 2022
eef3c7c
Formatting & core::num update
May 18, 2022
6cd60a7
Testing struct, WIP
May 18, 2022
00122b8
Merge branch 'master' into braqzen-1511
Braqzen May 18, 2022
9ce7fcc
Merge branch 'braqzen-1511' of https://github.com/FuelLabs/sway into …
May 18, 2022
53cbc67
Hashing struct works
May 18, 2022
29355bb
Formatting
May 18, 2022
b9ebdb2
Updating examples for mdbook
May 18, 2022
d13e155
Updating to buggy formatting and removed comment
May 18, 2022
dfa306d
Updating import formatting
May 18, 2022
c2a9c1b
Update sway-lib-std/src/hash.sw
Braqzen May 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions sway-lib-std/src/hash.sw
Expand Up @@ -124,3 +124,31 @@ pub fn hash_pair(value_a: b256, value_b: b256, method: HashMethod) -> b256 {
}
}
}

// Registers are 64 bits (8 bytes) wide. Words are the same width as registers.
Braqzen marked this conversation as resolved.
Show resolved Hide resolved
nfurfaro marked this conversation as resolved.
Show resolved Hide resolved
pub fn sha256<T>(param: T) -> b256 {
let result_buffer: b256 = 0x0000000000000000000000000000000000000000000000000000000000000000;
Braqzen marked this conversation as resolved.
Show resolved Hide resolved
if !is_reference_type::<T>() {
asm(r1: param, r2, r3: 8, r4: result_buffer) {
// Move to register r2
move r2 sp;
Braqzen marked this conversation as resolved.
Show resolved Hide resolved
// Grow stack by 1 word
cfei i8;
// Save value in register r1 to memory at r2
sw r2 r1 i0;
// Hash
s256 r4 r2 r3;
// Return
r4: b256
}
} else {
let size = size_of::<T>();
asm(r1: result_buffer, r2: param, r3: size) {
// Hash
s256 r1 r2 r3;
// Return
r1: b256
}
}
}

Braqzen marked this conversation as resolved.
Show resolved Hide resolved