According to the documenation when using a library with internal functions, the function's bytecode gets inlined into the calling contract's function.
Can someone confirm if the following is therefore a correct observation?
library A {
function doSomething() constant returns (uint) { return 10; }
function doInternal() internal constant returns (uint) { return 99; }
}
library B {
function doSomething() constant returns (uint) { return 2000; }
function doInternal() internal constant returns (uint) { return 8888; }
}
contract Consumer {
function execute() {
uint x = A.doSomething();
uint y = A.doInternal();
}
}
- Compile the
Consumercontract to produce an unlinked .bin - Deploy library B
- Use
solcto linkAreferences in theConsumercontract to the address of deployed libraryB - Deploy the
Consumercontract
When invoking the execute() of the Consumer contract, the result would be
x == 2000
y == 99
This means that the doInternal() function will always yield 99 as a result, because it was inlined into the consumer contract and was not affected by the linking.
This means it's possible when using libraries and linking to end up with essentially calling functions across multiple libraries. A rather dangerous situation as it's a fact that is hidden from most users and not explicit in the documentation.