scilla
scilla copied to clipboard
Warn if contract address types require too many fields
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.
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.