Skip to content

feat(soroban): implement get/set storage bytes subscript#1918

Open
aryanbaranwal001 wants to merge 8 commits into
hyperledger-solang:mainfrom
aryanbaranwal001:feat/soroban-bytes-subscript
Open

feat(soroban): implement get/set storage bytes subscript#1918
aryanbaranwal001 wants to merge 8 commits into
hyperledger-solang:mainfrom
aryanbaranwal001:feat/soroban-bytes-subscript

Conversation

@aryanbaranwal001

Copy link
Copy Markdown

Description

Adds support for reading or writing a particular byte of a bytes state variable on soroban by implementing previously stubbed functions of get_storage_bytes_subscript and set_storage_bytes_subscript with unimplemented! in soroban/target.rs.

The following contract now compiles to a valid WASM binary

// SPDX-License-Identifier: Apache-2.0
contract BytesSubscript {
    bytes public data;

    function set_data(bytes memory d) public {
        data = d;
    }

    function get_byte(uint32 i) public view returns (bytes1) {
        return data[i];
    }

    function set_byte(uint32 i, bytes1 v) public {
        data[i] = v;
    }
}

Key Changes

  • codegen/mod.rs: added BytesGet and BytesPut variants to HostFunctions & their "b.6" / "b.5" name mappings.

  • emit/soroban/mod.rs: added BytesGet and BytesPut arms to function_signature, and added BytesLen / BytesGet / BytesPut to the declare_externals host_functions list.

  • emit/soroban/target.rs: implemented get_storage_bytes_subscript and set_storage_bytes_subscript.

Tests

  • Added 8 tests in tests/soroban_testcases/bytes_subscript.rs covering read at every index, boundary writes, write isolation against unrelated bytes, sequential writes at the same index, and three out-of-the-bounds trap cases.

… and codec

Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
…alues

Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
…, bytes32

Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
…bytes_subscript

Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
@aryanbaranwal001

Copy link
Copy Markdown
Author

This PR is continuation of the work in #1908 and depends on it.

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.

1 participant