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
Consumer
contract to produce an unlinked .bin - Deploy library B
- Use
solc
to linkA
references in theConsumer
contract to the address of deployed libraryB
- Deploy the
Consumer
contract
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.