sway icon indicating copy to clipboard operation
sway copied to clipboard

Extend support for Input::Message type fields in std::inputs

Open nfurfaro opened this issue 3 years ago • 4 comments

Also adds tests for untested functions currently in the stdlib.

nfurfaro avatar Sep 02 '22 19:09 nfurfaro

Can we add support for getting the hash of the script bytecode? I've been using this in the current predicate for the bridge:

use std::constants::ZERO_B256;

const GTF_SCRIPT_SCRIPT_LENGTH = 0x005;
const GTF_SCRIPT_SCRIPT = 0x00B;

/// Get the hash of the script bytecode
pub fn tx_script_bytecode_hash() -> b256 {
    // Get the script memory details
    let mut result_buffer: b256 = ZERO_B256;
    let script_length = __gtf::<u64>(0, GTF_SCRIPT_SCRIPT_LENGTH);
    let script_ptr = __gtf::<u64>(0, GTF_SCRIPT_SCRIPT);
    
    // Run the hash opcode for the script in memory
    asm(hash: result_buffer, ptr: script_ptr, len: script_length) {
        s256 hash ptr len;
        hash: b256
    }
}

I feel like it belongs in tx.sw since it requires the constant values for certain GTF fields.

pixelcircuits avatar Sep 03 '22 15:09 pixelcircuits

Can we add support for getting the hash of the script bytecode?

@pixelcircuits I'm not opposed to this. Would you mind opening a separate issue to track it?

nfurfaro avatar Sep 04 '22 14:09 nfurfaro

Can we add support for getting the hash of the script bytecode?

@pixelcircuits I'm not opposed to this. Would you mind opening a separate issue to track it?

Sure! #2721

pixelcircuits avatar Sep 05 '22 01:09 pixelcircuits

This PR should wait until #2810 is finished since there is a lot of overlap

pixelcircuits avatar Sep 20 '22 02:09 pixelcircuits

This PR is looking good. I just wanted to point to the tests on my now defunct branch for testing things like predicate bytecode and data when you get to that.

pixelcircuits avatar Sep 28 '22 00:09 pixelcircuits

Can we go ahead and use this issue to make all GTF_ const definitions public (pub) so that they can be referenced for more lower level solutions like the current bridge message-contract-predicate?

pixelcircuits avatar Oct 04 '22 00:10 pixelcircuits

Can we go ahead and use this issue to make all GTF_ const definitions public (pub) so that they can be referenced for more lower level solutions like the current bridge message-contract-predicate?

I think so. So far I've only been exposing them as needed, but no reason to keep any of them private.

nfurfaro avatar Oct 04 '22 00:10 nfurfaro