Skip to content

Commit

Permalink
Add atRoot parameter to Value.Transfer()
Browse files Browse the repository at this point in the history
This commit adds a new parameter atRoot to Transfer().  Atree storage
is validated only if both remove and atRoot parameters are true in
ArrayValue.Transfer(), DictionaryValue.Transfer(), and
CompositeValue.Transfer().

Currently in ArrayValue.Transfer(), DictionaryValue.Transfer(),
and CompositeValue.Transfer() if remove parameter is true:
- atree storage is validated
- container slab is removed

However, when transferring nested ArrayValue, DictionaryValue,
and CompositeValue with remove flag, atree storage validation can
fail because child slab is removed while parent container is not
reset completely yet.

This validation problem is similar to the previously fixed
atree storage validation problem during nested DeepRemove().
  • Loading branch information
fxamacker committed Nov 9, 2023
1 parent b98a84e commit 1ecf35c
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 6 deletions.
3 changes: 3 additions & 0 deletions runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,7 @@ func (interpreter *Interpreter) transferAndConvert(
false,
nil,
nil,
true,
)

result := interpreter.ConvertAndBox(
Expand Down Expand Up @@ -3924,6 +3925,7 @@ func (interpreter *Interpreter) authAccountSaveFunction(addressValue AddressValu
true,
nil,
nil,
true,
)

// Write new value
Expand Down Expand Up @@ -4048,6 +4050,7 @@ func (interpreter *Interpreter) authAccountReadFunction(addressValue AddressValu
false,
nil,
nil,
false,
)

// Remove the value from storage,
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/interpreter_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ func (interpreter *Interpreter) VisitAttachExpression(attachExpression *ast.Atta
false,
nil,
nil,
true,
).(*CompositeValue)

// we enforce this in the checker
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/interpreter_invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (interpreter *Interpreter) invokeFunctionValue(
false,
nil,
nil,
true,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/interpreter_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ func (interpreter *Interpreter) VisitForStatement(statement *ast.ForStatement) S
false,
nil,
nil,
true,
)

iterable, ok := transferredValue.(IterableValue)
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/simplecompositevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (v *SimpleCompositeValue) Transfer(
remove bool,
storable atree.Storable,
_ map[atree.ValueID]struct{},
_ bool,
) Value {
// TODO: actually not needed, value is not storable
if remove {
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ func TestNestedContainerMutationAfterMove(t *testing.T) {
false,
nil,
map[atree.ValueID]struct{}{},
true,
).(*CompositeValue)

containerValue1.Append(inter, EmptyLocationRange, childValue1)
Expand Down
Loading

0 comments on commit 1ecf35c

Please sign in to comment.