Skip to content

Commit

Permalink
[move] Deny list object (MystenLabs#15427)
Browse files Browse the repository at this point in the history
## Description 

- Standalone deny list object used for coins currently, though can be
extended to other types
- 2 table solution for quick lookups in either direction
- Required some fun parsing in Move, which is really the most intensive
part of this PR

### TODO
- We need to decide on how we are creating this shared object 
 
## Test Plan 
- New tests


---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [X] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
tnowacki authored Jan 12, 2024
1 parent c859f41 commit 0310242
Show file tree
Hide file tree
Showing 65 changed files with 4,746 additions and 653 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Constants](#@Constants_0)
- [Function `get`](#0x1_type_name_get)
- [Function `get_with_original_ids`](#0x1_type_name_get_with_original_ids)
- [Function `is_primitive`](#0x1_type_name_is_primitive)
- [Function `borrow_string`](#0x1_type_name_borrow_string)
- [Function `get_address`](#0x1_type_name_get_address)
- [Function `get_module`](#0x1_type_name_get_module)
Expand Down Expand Up @@ -53,6 +54,15 @@
## Constants


<a name="0x1_type_name_ASCII_C"></a>



<pre><code><b>const</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_C">ASCII_C</a>: u8 = 99;
</code></pre>



<a name="0x1_type_name_ASCII_COLON"></a>


Expand All @@ -62,6 +72,60 @@



<a name="0x1_type_name_ASCII_E"></a>



<pre><code><b>const</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_E">ASCII_E</a>: u8 = 101;
</code></pre>



<a name="0x1_type_name_ASCII_O"></a>



<pre><code><b>const</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_O">ASCII_O</a>: u8 = 111;
</code></pre>



<a name="0x1_type_name_ASCII_R"></a>



<pre><code><b>const</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_R">ASCII_R</a>: u8 = 114;
</code></pre>



<a name="0x1_type_name_ASCII_T"></a>



<pre><code><b>const</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_T">ASCII_T</a>: u8 = 116;
</code></pre>



<a name="0x1_type_name_ASCII_V"></a>



<pre><code><b>const</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_V">ASCII_V</a>: u8 = 118;
</code></pre>



<a name="0x1_type_name_ENonModuleType"></a>



<pre><code><b>const</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ENonModuleType">ENonModuleType</a>: u64 = 0;
</code></pre>



<a name="0x1_type_name_get"></a>

## Function `get`
Expand Down Expand Up @@ -104,6 +168,46 @@



</details>

<a name="0x1_type_name_is_primitive"></a>

## Function `is_primitive`



<pre><code><b>public</b> <b>fun</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_is_primitive">is_primitive</a>(self: &<a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_TypeName">type_name::TypeName</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_is_primitive">is_primitive</a>(self: &<a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_TypeName">TypeName</a>): bool {
<b>let</b> bytes = <a href="../../dependencies/move-stdlib/ascii.md#0x1_ascii_as_bytes">ascii::as_bytes</a>(&self.name);
bytes == &b"bool" ||
bytes == &b"u8" ||
bytes == &b"u16" ||
bytes == &b"u32" ||
bytes == &b"u64" ||
bytes == &b"u128" ||
bytes == &b"u256" ||
bytes == &b"<b>address</b>" ||
(<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_length">vector::length</a>(bytes) &gt;= 6 &&
*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, 0) == <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_V">ASCII_V</a> &&
*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, 1) == <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_E">ASCII_E</a> &&
*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, 2) == <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_C">ASCII_C</a> &&
*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, 3) == <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_T">ASCII_T</a> &&
*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, 4) == <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_O">ASCII_O</a> &&
*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, 5) == <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ASCII_R">ASCII_R</a>)

}
</code></pre>



</details>

<a name="0x1_type_name_borrow_string"></a>
Expand Down Expand Up @@ -146,6 +250,8 @@


<pre><code><b>public</b> <b>fun</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_get_address">get_address</a>(self: &<a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_TypeName">TypeName</a>): String {
<b>assert</b>!(!<a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_is_primitive">is_primitive</a>(self), <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ENonModuleType">ENonModuleType</a>);

// Base16 (<a href="../../dependencies/move-stdlib/string.md#0x1_string">string</a>) representation of an <b>address</b> <b>has</b> 2 symbols per byte.
<b>let</b> len = <a href="../../dependencies/move-stdlib/address.md#0x1_address_length">address::length</a>() * 2;
<b>let</b> str_bytes = <a href="../../dependencies/move-stdlib/ascii.md#0x1_ascii_as_bytes">ascii::as_bytes</a>(&self.name);
Expand Down Expand Up @@ -185,6 +291,8 @@


<pre><code><b>public</b> <b>fun</b> <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_get_module">get_module</a>(self: &<a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_TypeName">TypeName</a>): String {
<b>assert</b>!(!<a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_is_primitive">is_primitive</a>(self), <a href="../../dependencies/move-stdlib/type_name.md#0x1_type_name_ENonModuleType">ENonModuleType</a>);

// Starts after <b>address</b> and a double colon: `&lt;addr <b>as</b> HEX&gt;::`
<b>let</b> i = <a href="../../dependencies/move-stdlib/address.md#0x1_address_length">address::length</a>() * 2 + 2;
<b>let</b> str_bytes = <a href="../../dependencies/move-stdlib/ascii.md#0x1_ascii_as_bytes">ascii::as_bytes</a>(&self.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- [Function `to_bytes`](#0x2_address_to_bytes)
- [Function `to_ascii_string`](#0x2_address_to_ascii_string)
- [Function `to_string`](#0x2_address_to_string)
- [Function `from_ascii_bytes`](#0x2_address_from_ascii_bytes)
- [Function `hex_char_value`](#0x2_address_hex_char_value)
- [Function `length`](#0x2_address_length)
- [Function `max`](#0x2_address_max)

Expand Down Expand Up @@ -192,6 +194,66 @@



</details>

<a name="0x2_address_from_ascii_bytes"></a>

## Function `from_ascii_bytes`



<pre><code><b>public</b> <b>fun</b> <a href="../../dependencies/sui-framework/address.md#0x2_address_from_ascii_bytes">from_ascii_bytes</a>(bytes: &<a href="../../dependencies/move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <b>address</b>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="../../dependencies/sui-framework/address.md#0x2_address_from_ascii_bytes">from_ascii_bytes</a>(bytes: &<a href="../../dependencies/move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <b>address</b> {
<b>assert</b>!(<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_length">vector::length</a>(bytes) == 64, <a href="../../dependencies/sui-framework/address.md#0x2_address_EAddressParseError">EAddressParseError</a>);
<b>let</b> hex_bytes = <a href="../../dependencies/move-stdlib/vector.md#0x1_vector">vector</a>[];
<b>let</b> i = 0;
<b>while</b> (i &lt; 64) {
<b>let</b> hi = <a href="../../dependencies/sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, i));
<b>let</b> lo = <a href="../../dependencies/sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(*<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, i + 1));
<a href="../../dependencies/move-stdlib/vector.md#0x1_vector_push_back">vector::push_back</a>(&<b>mut</b> hex_bytes, (hi &lt;&lt; 4) | lo);
i = i + 2;
};
<a href="../../dependencies/sui-framework/address.md#0x2_address_from_bytes">from_bytes</a>(hex_bytes)
}
</code></pre>



</details>

<a name="0x2_address_hex_char_value"></a>

## Function `hex_char_value`



<pre><code><b>fun</b> <a href="../../dependencies/sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(c: u8): u8
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="../../dependencies/sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(c: u8): u8 {
<b>if</b> (c &gt;= 48 && c &lt;= 57) c - 48 // 0-9
<b>else</b> <b>if</b> (c &gt;= 65 && c &lt;= 70) c - 55 // A-F
<b>else</b> <b>if</b> (c &gt;= 97 && c &lt;= 102) c - 87 // a-f
<b>else</b> <b>abort</b> <a href="../../dependencies/sui-framework/address.md#0x2_address_EAddressParseError">EAddressParseError</a>
}
</code></pre>



</details>

<a name="0x2_address_length"></a>
Expand Down
Loading

0 comments on commit 0310242

Please sign in to comment.