Created at 7am, May 8
eWhgbrMVSoftware Development
1
Solidity Development Doc v0.8.26
LmKbI--yUnN-ga67EqvYU1QcixK4rEw5pJGR04BdeEw
File Type
PDF
Entry Count
1113
Embed. Model
jina_embeddings_v2_base_en
Index Type
hnsw

This the the convenient book for solidity smart contract devlopment document v0.8.26

Array data is located starting at keccak256(p) and it is laid out in the same way as statically-sized array data would: One element after the other, potentially sharing storage slots if the elements are not longer than 16 bytes. Dynamic arrays of dynamic arrays apply this rule recursively. The location of element x[i][j], where the type of x is uint24[][], is computed as follows (again, assuming x itself is stored at slot p): The slot is keccak256(keccak256(p) + i) + floor(j / floor(256 / 24)) and the element can be obtained from the slot data v using (v >> ((j % floor(256 / 24)) * 24)) & type(uint24).max. The value corresponding to a mapping key k is located at keccak256(h(k) . p) where . is concatenation and h is a function that is applied to the key depending on its type: for value types, h pads the value to 32 bytes in the same way as when storing the value in memory. for strings and byte arrays, h(k) is just the unpadded data.
id: 5caa05fd0b2e2c9705481f0e064f5556 - page: 218
If the mapping value is a non-value type, the computed slot marks the start of the data. If the value is of struct type, for example, you have to add an offset corresponding to the struct member to reach the member. As an example, consider the following contract: // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.4.0 <0.9.0; contract C { struct S { uint16 a; uint16 b; uint256 c; } uint x; mapping(uint => mapping(uint => S)) data; } 214 Chapter 3. Contents
id: 22ffcc9bc649a6eb0be127b46ee2fb99 - page: 218
Solidity Documentation, Release 0.8.26 Let us compute the storage location of data.c. The position of the mapping itself is 1 (the variable x with 32 bytes precedes it). This means data is stored at keccak256(uint256(4) . uint256(1)). The type of data is again a mapping and the data for data starts at slot keccak256(uint256(9) . keccak256(uint256(4) . uint256(1))). The slot offset of the member c inside the struct S is 1 because a and b are packed in a single slot. This means the slot for data.c is keccak256(uint256(9) . keccak256(uint256(4) . uint256(1))) + 1. The type of the value is uint256, so it uses a single slot. bytes and string
id: 58be2895f86944bfefca1a9a4df6b1de - page: 219
In general, the encoding is similar to bytes1[], in the sense that there is a slot for the array itself and a data area that is computed using a keccak256 hash of that slots position. However, for short values (shorter than 32 bytes) the array elements are stored together with the length in the same slot. In particular: if the data is at most 31 bytes long, the elements are stored in the higher-order bytes (left aligned) and the lowest-order byte stores the value length * 2. For byte arrays that store data which is 32 or more bytes long, the main slot p stores length * 2 + 1 and the data is stored as usual in keccak256(p). This means that you can distinguish a short array from a long array by checking if the lowest bit is set: short (not set) and long (set).
id: bdb49f509bcdb7892a025bd2e1670922 - page: 219
How to Retrieve?
# Search

curl -X POST "https://search.dria.co/hnsw/search" \
-H "x-api-key: <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"rerank": true, "top_n": 10, "contract_id": "LmKbI--yUnN-ga67EqvYU1QcixK4rEw5pJGR04BdeEw", "query": "What is alexanDRIA library?"}'
        
# Query

curl -X POST "https://search.dria.co/hnsw/query" \
-H "x-api-key: <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"vector": [0.123, 0.5236], "top_n": 10, "contract_id": "LmKbI--yUnN-ga67EqvYU1QcixK4rEw5pJGR04BdeEw", "level": 2}'