HyperByte


Found you lost and guided (you)

This is how flash loan arbitrages

At first, a non-developer intuitively thought of a complete contract transaction as a single fast ‘action’, but indeed a contract “transaction” actually wraps many “internal actions”, sometimes they’re hundreds. They’re all executed synchronously , one by one , in a single thread, before the transa...

Smart contract security (I)

Let’s review this piece of code and see what vulnerabilities might be hiding in there. // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IERC20 { function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address from, address to, u...

Color and Light - from the Masnavi (Rumi)

رەڭ ۋە نۇر قىزىل، يېشىل ۋە كۈلرەڭلەرنى يورۇقلۇقتا كۆرمىسەڭ كۆرەلمەيسەن ســەن رەڭلەرنــى كۆرگەنلىگىــڭ ئۈچــۈن، نــۇر ســەندىن رەڭگــە يوشــۇرۇنغان بولىدۇ قاراڭغــۇ چۈشســە رەڭلــەر يوشــۇرۇنىدۇ. دەل مانــا شــۇ چاغــدا، رەڭنــى كۆرسـەتكەننىڭ نـۇر ئىكەنلىكىنـى بىلىسـەن. نـۇر بولمىسـا رەڭنـى كۆ...

Uniswap-V3 after V2

Suppose the real-time price of the ETH/DAI trading pair is 1500 DAI/ETH. Initial state: The pool holds 4,500 DAI and 3 ETH, with a price of 1,500 DAI/ETH. After a price drop: ETH falls to 1,300 DAI/ETH, and arbitrageurs will buy ETH from the pool until the pool price also reaches 1,300. Final state:...

A use case for multi-sign wallet

Recently, I’ve developed an interesting business using multi-sign wallet. This project, requires tokens(ERC20) can be only minted by someone who approved by multiple administrators. I decided to implement those multi-approvals by administrators using multi-sign wallet. First of all, there must be ...

Impermanent Loss (IL)

Once we do LP, impermanent loss (LP) is pretty much guaranteed, it’s not a matter of if, but how much. There’s a vivid breakdown for much better understanding: Scenerio 1: Suppose we got a pool with initial liquidity of 100DAI and 1ETH now the LP's position value is 200DAI (100DAI+1ETH) ETH goes...

How the fee calculated in uniswap-v2?

Download uniswap whitepaper: https://app.uniswap.org/whitepaper.pdf it’s not very friendly to read, I learned so hard, then this is my summaries. Origin AMM formula: Assume the fee is 0.3% (in uniswapv-v2, this is a fixed fee), dx is the token you’re trying to exchange, the fee will be charged on t...

How AMM module works? [x*y=k]

All swapping pools between two currncies mostly base on the x·y=k equation. Usually, x: number of TokenA, y: number of TokenB. (Initial number of TokenA and TokenB are based on the exact price when the pool was created). Here are two scenarios for buy and sell, User sells ETH for getting USDC: (x+...

UUPS and transparent proxy

UUPS We chose UUPS over the transparent proxy because UUPS puts the upgrade logic in the implementation contract, which makes the proxy smaller and cheaper on gas. The tradeoff is that the implementation must inherit UUPSUpgradeable and implement _authorizeUpgrade. transparent proxy ...

Thought sparked by my friend Erpan

I was confusing about some things happened recently, driving around but nowhere to go. I texted Erpan , a good buddy of mine. He said he drunk , then I drove to where he is and picked him up. This night, this alcoholic guy’s words blew my mind: 我们还是要往前看,或许,还会如你所愿,或许,超乎你的预期。从一无所有到如今的如你希望,本身就是这道题的答案,...

MQ

I think MQ is a genuis solution of non-real-time data requests between systems, especially in distributed systems for e-commerce, finance, big data. Here I am going to document some of my thoughts on MQ. Most of typical financial process systems, the first level system which directly access by user...

A dramatic story of tech tinkering with DB performance

A business originally starts with a smaller code project, usually with monolithic architecture. Through the ongoing maintenance over a time, SQLs uprises little by little, eventually,the main direction of queries are likely to incline a certain pattern or trend. for much better understanding, let me...

Eid Mubarak 2025

这是一个倡导敬畏,巩固大爱,履行孝敬,主动担起社会责任,恩怨要相销的节日。 今天人们会重新开始规范自己的心灵和行为,我们相互分享最好食物,重新强调造物主的脚下没有谁贱谁贵,都去看望父母,也去看望那些离开我们的人。 我想,人不要麻木,千万不要做那种心灵僵化的人。不能像一颗CPU一样尽管跑人为的程序但从不感知自己的purpose,一定要知道1+1=2的背后为什么是正确无疑的0001+0001=0010。 我坚定不移的相信:真理,任何力量撼动不了的真理,还在那儿,从亚当夏娃到现在,即便无数次被人们偏离,无数次的被遵循。 愿土上的挚爱之人平安健康 愿土下的至亲之人安息永宁 祝我们节日快乐 ...

关于CPU缓存

cpu与内存简易关系 计算机组成原理中,也可以简单认为cpu和内存是直接通信的,程序在运行时,将内存条中的01010010…指令读到cpu寄存器里寄存以及由ALU来计算,返回的结果写到寄存器或者写回到内存条里,成千上万个运算实现了代码的运行逻辑。 不过,真正实际的嵌入式设备或电脑主板上的内存和cpu中间还隔着缓存和总线(缓存在cpu芯片内部)。以4核cpu为例,像这样: L1是一级缓存,L2是二级缓存,L3是三级缓存,再到内存条。离cpu越近的读写越快,L1,L2,L3的一次IO速度大约是1ns,3ns,15ns。内存条的IO速度是60ns至80ns,再加上大约20ns的总线传输速度,...

Code pattern design(一)

Business: As the diagram below shows, suppose we receive a requirement: listen to MySQL data changes via Canal, and sync those changes to other systems in real time — like Elasticsearch, MQ messages, or triggering business logic. What I’m trying to show is a solid, extensible base built with the rig...

到底数据量达到多少时要考虑分库分表?

经常有人会说500w或两千万就应该考虑分表,但是实际工作中做决策时需要负责任的,需明察其理。 其实, 如果了解B+树数据结构,我们自己就可以计算和预判数据量达到多少后数据库性能可能会下降,并且按业务现有的数据评估要不要分表。 首先复习一下B+树。一个主键索引的B+树数据结构大概长这样: 如所见,这些大框(不是有数字的小框)都我们称之为节点或“页”,每页大小在mysql默认为16kb(官方说这是mysql做了大量的实验和调优后得出来的合适值)。请看第一页,假设索引的类型用的是bingint类型,那么"50"这一格大小为8byte,"50"隔壁的格存储的是...

Redis在拔掉电线后数据可以完好无损,能做到

​ 去年得了一场大病,我现在不再那么执着于当架构师,多少年后我要做到什么title,挣多少钱,没有这样的想法,反而有了新的目标和计划, 不算太迷茫。 一直想记录一个关于redis相关的内容。 ​ 我很喜欢Redis的持久化机制,原因在于现在Redis发展到哪怕突然被人拔电线,重启后仍然能够快速恢复数据,掉电数据丢失率很低很低,目前持久化的机制还是很强的。 Redis的持久化有三种模式:RDB, AOF, RDB&AOF RDB模式 ​ RDB模式下,redis会每隔一段时间,将内存中的该时刻的数据快照存到硬盘里,会在一个xxx.rdb文件里,宕机重新启动后从xxx.rdb恢复,RDB...

有一点厉害的Usafe.class

第一次知道Unsafe概念是在使用ReentrntLock和CountDownLatch。这两个都实现了AQS,AQS能够做到线程安全同步,关键在于AQS中通过查询state变量的值来知道当前资源有没有被锁,改变state变量的值来表示当前资源被锁,改变state是要保证原子性的,原子性保障由Unsafe中的CompareAntSwap支持。 从ReentrantLock的非公平锁开始看: 123456789101112131415161718192021/** * Sync object for non-fair locks */static final class NonfairSync ...