-
Notifications
You must be signed in to change notification settings - Fork 2.7k
avoid key collision on child trie and proof on child trie #2209
Changes from 1 commit
f6c4bb2
878a7ae
a464936
4de73d7
be0e340
7f3a282
4d208db
6d7f355
25bcb4c
9eaef35
37d9536
67c03a2
99dbb5a
3be1802
fec73d0
20d168d
d797bd0
27096aa
3560acc
c3fc432
3e417eb
5af490f
5a8dddd
8f04f00
8051179
8eac118
a65f9f2
d495ef5
197d77a
2ea3c89
99c45ea
3553ab2
47984fe
2bf2d7b
bc7165c
21c3acf
98b2fc3
432cb10
e266dfe
7f64652
999a26e
7bbd681
87f03b7
f18e002
0eaeca0
b57319d
1f848d2
403df51
305b60a
423cfb1
a0ffa31
6e3bed7
7411146
331be51
bc2935c
5a87b6a
f40400b
9bc1ab7
c073b21
d15ca49
0736b96
9e0485d
586b50e
65d7485
95a69b2
d089693
ec69ae0
76ea14d
b2050c8
5a0cbe1
6e84810
7f5694f
5006d73
b85508e
0c14777
10c4f58
453927b
349f9a5
fc034fb
45cfbd6
4f9717e
7cb2d84
c821a08
c3ba830
acf9641
0050457
c36b91b
9d3d9e2
3db4da8
4348d70
134a4bf
5325621
97118e8
0ed7f80
8a6986a
7652de9
94c629e
7675740
90fba8a
d8c58c6
661ba2e
833e9ff
71bda12
08b3062
89f3cd5
834f52a
0445228
75add99
e70edab
b8a0cd4
1514171
a7da811
b96c523
865672d
b6d7705
b45344c
517f95c
79a07de
a027fb0
b92655c
8a875f4
fcd8bdb
3241fc4
ecac03b
10369b9
15a2967
acc94e4
7d96338
ba7bdcb
aacea85
6789641
2b37160
b1183bd
bc5653c
5ecfd19
baf89c8
0f8bff9
5a8576b
045ee32
58e6e41
70555c5
130e5e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,7 +71,11 @@ impl<'e, E: Externalities<Blake2Hasher>> FunctionExecutor<'e, E> { | |||||||
| // (yet), so when wasm call a child function it got its runtime subtrie mem then call with | ||||||||
| // its storage_key and native will fetch through this function: need either to ref native subtrie | ||||||||
| // or pass by value the Subtrie. | ||||||||
| fn with_subtrie<R>(&mut self, prefixed_storage_key: &[u8], f: impl Fn(&mut Self, SubTrie) -> R) -> Option<R> { | ||||||||
| fn with_subtrie<R>( | ||||||||
| &mut self, | ||||||||
| prefixed_storage_key: &[u8], | ||||||||
| f: impl Fn(&mut Self,SubTrie) -> R | ||||||||
| ) -> Option<R> { | ||||||||
| // note that we use empty prefix which result in a subtrie that requires | ||||||||
| // key + prefix but the subtrie is quickly drop so it is not an issue). | ||||||||
|
||||||||
| self.ext.child_trie(&[], prefixed_storage_key).map(|s|f(self,s)) | ||||||||
|
|
@@ -119,7 +123,8 @@ trait ReadPrimitive<T: Sized> { | |||||||
| impl ReadPrimitive<u32> for MemoryInstance { | ||||||||
| fn read_primitive(&self, offset: u32) -> ::std::result::Result<u32, UserError> { | ||||||||
| use byteorder::{LittleEndian, ByteOrder}; | ||||||||
| Ok(LittleEndian::read_u32(&self.get(offset, 4).map_err(|_| UserError("Invalid attempt to read_primitive"))?)) | ||||||||
| Ok(LittleEndian::read_u32(&self.get(offset, 4) | ||||||||
| .map_err(|_| UserError("Invalid attempt to read_primitive"))?)) | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -153,8 +158,10 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, | |||||||
| Ok(()) | ||||||||
| }, | ||||||||
| ext_set_storage(key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32) => { | ||||||||
| let key = this.memory.get(key_data, key_len as usize).map_err(|_| UserError("Invalid attempt to determine key in ext_set_storage"))?; | ||||||||
| let value = this.memory.get(value_data, value_len as usize).map_err(|_| UserError("Invalid attempt to determine value in ext_set_storage"))?; | ||||||||
| let key = this.memory.get(key_data, key_len as usize) | ||||||||
| .map_err(|_| UserError("Invalid attempt to determine key in ext_set_storage"))?; | ||||||||
| let value = this.memory.get(value_data, value_len as usize) | ||||||||
| .map_err(|_| UserError("Invalid attempt to determine value in ext_set_storage"))?; | ||||||||
| if let Some(_preimage) = this.hash_lookup.get(&key) { | ||||||||
| debug_trace!(target: "wasm-trace", "*** Setting storage: %{} -> {} [k={}]", ::primitives::hexdisplay::ascii_format(&_preimage), HexDisplay::from(&value), HexDisplay::from(&key)); | ||||||||
| } else { | ||||||||
|
|
@@ -170,12 +177,12 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, | |||||||
| key_len: u32, | ||||||||
| value_data: *const u8, | ||||||||
| value_len: u32) => { | ||||||||
|
||||||||
| value_len: u32) => { | |
| value_len: u32 | |
| ) => { |
cheme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
In some places, storage_key_data was renamed to prefixed_storage_key_data and in some others it is renamed to keyspace_data. On the other hand, in some places it is left as storage_key_data.
Why is this difference there? Can we use one name?
cheme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
cheme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
cheme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
isn't the this.memory.get should be performed inside the yes branch ? Because root_data shouldn't be read in case len is 0 no ?
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.
definitely
cheme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
ditto perform memory.get inside true-branch ?
cheme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
I am having some problems with this proof. There is no comment on with_subtrie that explains when it can return Err.
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 is related to the comment above with_subtrie: with_subtrie should be call with an already resolved subtrie so the query should not fail. This is clearly an unnecessary expect, I will remove it.
Uh oh!
There was an error while loading. Please reload this page.