scilla icon indicating copy to clipboard operation
scilla copied to clipboard

Warn if contract address types require too many fields

Open anton-trunov opened this issue 3 years ago • 1 comments

Let's say we have a transition with a parameter contract_address whose type contains some unused fields, i.e. the transition body never reads from some fields:

transition Foo (
  contract_address: ByStr20 with contract 
    field field1: ByStr20, 
    field field2: Uint128, 
    field unused_field: Map Uint256 ByStr20
end)
  foo <-& contract_address.field1;
  bar <-& contract_address.field2;
  ... (* never tries to access unused_field *)
end

This can be a consequence of refactoring of a multi-contract project, where one field turned out to be non-essential. We should warn the programmer in such cases, because it unnecessarily restricts the transition signature.

anton-trunov avatar Jul 22 '22 09:07 anton-trunov

Related issue: sometimes contract authors add too many fields to contract addresses in their ADTs

For example, in a contract I've seen this:

type OrderParam =
| OrderParam of ByStr20 with contract 
field royalty_recipient: ByStr20, 
field royalty_fee_bps: Uint128, 
field spenders: Map Uint256 ByStr20, 
field token_owners: Map Uint256 ByStr20 
end Uint256 ByStr20 Uint128 Uint32 BNum

although the following would suffice:

type OrderParam =
| OrderParam of ByStr20 with contract 
field spenders: Map Uint256 ByStr20,
field token_owners: Map Uint256 ByStr20
end Uint256 ByStr20 Uint128 Uint32 BNum

Requiring extra fields in contract address can lead to interface mismatches in a multi-contract project.

anton-trunov avatar Aug 09 '22 13:08 anton-trunov