This repository was archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Implement simpler hash function #9
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
136819f
Added code from bridge repo
pixelcircuits ddb7e02
Updated CI tests
pixelcircuits cce7068
Fix migration issue
pixelcircuits 7fdba00
Ran formatter
pixelcircuits 6c4520a
CI updates
pixelcircuits 759b5a3
Disabled CI tests
pixelcircuits 4528278
Added build instructions to README
pixelcircuits f44fc30
Fixed tests
pixelcircuits 5edcc23
Migrated WIP predicate/script from bridge repo
pixelcircuits 299620b
Merge branch 'master' into 1-migrate-code-from-original-bridge-branch
pixelcircuits a5a318e
Ran formatter
pixelcircuits 8da0b7e
Ran rust formatter
pixelcircuits fa614b4
Added util to get script hash
pixelcircuits de305dd
Ran formatter
pixelcircuits cf0b99a
Merge remote-tracking branch 'origin/master' into 7-implement-simpler…
pixelcircuits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| library utils; | ||
|
|
||
| use std::{ | ||
| address::Address, | ||
| tx::{ | ||
| INPUT_COIN, | ||
| INPUT_CONTRACT, | ||
| INPUT_MESSAGE, | ||
| OUTPUT_CHANGE, | ||
| OUTPUT_CONTRACT, | ||
| OUTPUT_VARIABLE, | ||
| b256_from_pointer_offset, | ||
| tx_gas_limit, | ||
| tx_input_pointer, | ||
| tx_input_type, | ||
| tx_inputs_count, | ||
| tx_output_type, | ||
| tx_outputs_count, | ||
| tx_script_bytecode} | ||
| }; | ||
|
|
||
| use std::assert::assert; | ||
| use std::hash::sha256; | ||
| use std::contract_id::ContractId; | ||
|
|
||
| /// Get the ID of a contract input | ||
| pub fn contract_id_from_contract_input(index: u8) -> ContractId { | ||
| // Check that input at this index is a contract input | ||
| assert(tx_input_type(index) == INPUT_CONTRACT); | ||
| let ptr = tx_input_pointer(index); | ||
| let contract_id_bytes = b256_from_pointer_offset(ptr, 128); // Contract ID starts at 17th word: 16 * 8 = 128 | ||
|
|
||
| // TODO: Replace with actual contract id | ||
| ~ContractId::from(0xf5dbe963c235c1e54f8732f1ecdc955df2ad8db8c9ab58eea8e1338762bf8bc2) //~ContractId::from(contract_id_bytes) | ||
| } | ||
|
|
||
| /// Get the contract ID from a message input's data | ||
| pub fn contract_id_from_message_input(index: u8) -> ContractId { | ||
| // TODO: Replace with actual message check once input messages are enabled in the sdk | ||
| assert(tx_input_type(index) == INPUT_COIN); | ||
| ~ContractId::from(0xf5dbe963c235c1e54f8732f1ecdc955df2ad8db8c9ab58eea8e1338762bf8bc2)/* | ||
| // Check that input at this index is a message input | ||
| assert(tx_input_type(index) == INPUT_MESSAGE); | ||
|
|
||
| let ptr = tx_input_pointer(index); | ||
| let contract_id_bytes = b256_from_pointer_offset(ptr, 192); // Contract ID is at start of data, which is at 24th word: 24 * 8 = 192 | ||
| ~ContractId::from(contract_id_bytes) | ||
| */ | ||
| } | ||
|
|
||
| // From sway repo: tx.sw | ||
| use std::core::num::*; | ||
| const TX_SCRIPT_LENGTH_OFFSET = 10280; | ||
| const TX_SCRIPT_START_OFFSET = 10352; | ||
|
|
||
| /// Get the hash of the script bytecode | ||
| pub fn tx_script_bytecode_hash() -> b256 { | ||
| let mut result_buffer: b256 = ~b256::min(); | ||
|
|
||
| asm(hash: result_buffer, script_offset: TX_SCRIPT_START_OFFSET, length_offset: TX_SCRIPT_LENGTH_OFFSET, length) { | ||
| lw length length_offset i0; // Load the length value at the length_offset | ||
| s256 hash script_offset length; // Hash the an array of length "length" starting from "script_offset" into "hash" | ||
| hash: b256 // Return | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like the perfect usecase for configuration-time constants!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be deferred to a subsequent PR.