🌳 Branching Tree Technique (BTT)

Paul Berg

Spearbit seminar: Sep 28, 2023

Personal Background

  • 👨‍💻 Ethereum developer for 5+ years
  • 🐦 Exporting my brain on Twitter @PaulRBerg
  • ⏳ Co-founder and Builder at Sablier Labs
  • 📈 Sablier: >$1B in cumulative TVL since 2019
  • 🚀 Sablier V2: 100% built with Foundry and BTT

😇 How it starts

              
                function test_Foo() external {
                  uint256 x = 42;
                  assertEq(contract.foo(x), x, "value mismatch");
                }
              
            

😵‍💫 How it ends (monolith)

              
                function test_Foo_1() external {
                  // --- snip ---
                }

                function test_Foo_2() external {
                  // --- snip ---
                }

                function test_Foo_3(uint256 arg0) external {
                  // --- snip ---
                }

                function test_Foo_4(uint256 arg0, uint256 arg1) external {
                  // --- snip ---
                }
              
            

Specification Frameworks

Technique Barrier to entry Effectiveness
Braching Tree Technique Entry-level Moderately effective
Cucumber Gherkin Medium-level Moderately effective
Certora, K Framework, TLA+ Senior-level Highly effective

Example: whenBranch.tree

              
                WhenBranchTest
                ├── when x is false
                │   └── it should revert
                └── when x is true
                    └── it should return x
					    
            

Example: simpleWhen.t.sol

              
                contract SimpleWhenTest {
                    function test_RevertWhen_XIsFalse() external {
                        // it should revert
                    }

                    function test_WhenXIsTrue() external {
                        // it should return x
                    }
                }
					    
            

Example: simpleWhen.t.sol

              
                contract SimpleWhenTest {
                    function test_RevertWhen_XIsFalse() external {
                        vm.expectRevert("x must not be false");
                        foo.simpleWhen({ x: false });
                    }

                    function test_WhenXIsTrue() external {
                        bool result = foo.simpleWhen({ x: true });
                        assertTrue(result);
                    }
                }
					    
            

🤔 Given or When?

Scenario Answer
Is it a contract state that is prepared in advance? Given
Is it a mode of execution, e.g. call vs delegatecall? When
Is it a function parameter that the user is in control when calling the function? When

The End

Thanks for attending!
Sablier Lockup