Inter-Contract Call on Bitcoin

Background

Sighash Preimage Format
Outputs are shared in 2 inputs’ sighash preimages

Inter-Contract Call

To demonstrate how to call a contract from another, we consider the example of solving a quadratic equation: a * x² + b * x + c = 0.

Inter-contract Call
Callee contract
Caller contract

Advantages

Compared to the straightforward way of calling a function by including it directly into a contract itself, there are several salient advantages of calling it through another separate contract.

  • Efficiency. A stateful contract can have multiple internal functions. Each time it mutates state, not all of them have to be called. However, since they are all part of the contract, they all have to be included and thus bloat transaction size. By placing them into separate contracts, only ones needed for a given call are invoked from the main contract, leading to huge savings especially when there are many functions.
  • Extensibility. A common function can be wrapped into a library contract, which can be called from any other contract, without knowing its internal implementation details. It is decoupled from the calling contract².

Acknowledgements

This technique has been independently invented by Chen Cheng, Jie Jiang, and Lu Gu of Sensible Contract and Ying Chan of Cambridge Cryptographic.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
sCrypt

sCrypt

sCrypt (https://scrypt.io) is a company with a mission to provide integrated on-chain smart contracting solutions on Bitcoin SV