Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating applications #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/.vuepress/config/sidebar-pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,36 @@ module.exports = [
"/exemplos/linguagem-v0.8.3/import.md",
"/exemplos/linguagem-v0.8.3/biblioteca.md",
"/exemplos/linguagem-v0.8.3/hashing-with-keccak256.md",
"/exemplos/linguagem-v0.8.3/verificando-assinatura.md"
"/exemplos/linguagem-v0.8.3/verificando-assinatura.md",
],
},
{
title: "Aplicações",
path: "/exemplos/aplicacoes/",
children: [
"/exemplos/aplicacoes/carteira-ether.md",
"/exemplos/aplicacoes/carteira-multi-assinaturas.md",
"/exemplos/aplicacoes/arvore-de-merkle.md",
"/exemplos/aplicacoes/mapping-iteravel",
"/exemplos/aplicacoes/erc20.md",
"/exemplos/aplicacoes/erc721.md",
"/exemplos/aplicacoes/erc1155.md",
"/exemplos/aplicacoes/transferencia-de-token-sem-gas.md",
"/exemplos/aplicacoes/contrato-de-bytecode-simples.md",
"/exemplos/aplicacoes/endereco-de-contrato-pre-computado-com-create2.md",
"/exemplos/aplicacoes/contrato-proxy-minimo.md",
"/exemplos/aplicacoes/proxy-atualizavel.md",
"/exemplos/aplicacoes/implante-qualquer-contrato.md",
"/exemplos/aplicacoes/gravar-em-qualquer-slot.md",
"/exemplos/aplicacoes/canal-de-pagamento-unidirecional.md",
"/exemplos/aplicacoes/canal-de-pagamento-bidirecional.md",
"/exemplos/aplicacoes/leilao-ingles.md",
"/exemplos/aplicacoes/leilao-holandes.md",
"/exemplos/aplicacoes/vaquinha.md",
"/exemplos/aplicacoes/multi-chamadas.md",
"/exemplos/aplicacoes/multi-delegatecall.md",
"/exemplos/aplicacoes/bloqueio-de-tempo.md",
"/exemplos/aplicacoes/exponenciacao-binaria-em-assembly.md",
],
},
{
Expand Down Expand Up @@ -153,7 +165,9 @@ module.exports = [
{
title: "Patterns and Standards",
path: "/evm-maquina-virtual-ethereum/patterns-and-standards",
children: ["/evm-maquina-virtual-ethereum/patterns-and-standards/erc20-and-eip-20.md"],
children: [
"/evm-maquina-virtual-ethereum/patterns-and-standards/erc20-and-eip-20.md",
],
},
],
},
Expand All @@ -171,4 +185,4 @@ module.exports = [
},
],
},
]
];
20 changes: 11 additions & 9 deletions src/exemplos/aplicacoes/arvore-de-merkle.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Árvore de Merkle

A árvore de Merkle te permite provar criptograficamente que um elemento está contido

num conjunto sem revelar o conjunto inteiro.
A árvore de Merkle permite você provar criptograficamente que um elemento está contido num conjunto sem revelar o conjunto inteiro.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
pragma solidity ^0.8.20;

contract MerkleProof {
function verify(
Expand Down Expand Up @@ -70,17 +68,21 @@ contract TestMerkleProof is MerkleProof {

/* verifica
3rd leaf
0x1bbd78ae6188015c4a6772eb1526292b5985fc3272ead4c65002240fb9ae5d13
0xdca3326ad7e8121bf9cf9c12333e6b2271abe823ec9edfe42f813b1e768fa57b

raiz
0x074b43252ffb4a469154df5fb7fe4ecce30953ba8b7095fe1e006185f017ad10
root
0xcc086fcc038189b4641db2cc4f1de3bb132aefbd65d510d817591550937818c7

index
2

prova
0x948f90037b4ea787c14540d9feb1034d4a5bc251b9b5f8e57d81e4b470027af8
0x63ac1b92046d474f84be3aa0ee04ffe5600862228c81803cce07ac40484aee43
0x8da9e1c820f9dbd1589fd6585872bc1063588625729e7ab0797cfc63a00bd950
0x995788ffc103b987ad50f5e5707fd094419eb12d9552cc423bd0cd86a3861433
*/
}
```

## Teste no Remix

- [MerkleProof.sol](https://remix.ethereum.org/#code=Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yMDsKCmNvbnRyYWN0IE1lcmtsZVByb29mIHsKICAgIGZ1bmN0aW9uIHZlcmlmeSgKICAgICAgICBieXRlczMyW10gbWVtb3J5IHByb29mLAogICAgICAgIGJ5dGVzMzIgcm9vdCwKICAgICAgICBieXRlczMyIGxlYWYsCiAgICAgICAgdWludCBpbmRleAogICAgKSBwdWJsaWMgcHVyZSByZXR1cm5zIChib29sKSB7CiAgICAgICAgYnl0ZXMzMiBoYXNoID0gbGVhZjsKCiAgICAgICAgZm9yICh1aW50IGkgPSAwOyBpIDwgcHJvb2YubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgYnl0ZXMzMiBwcm9vZkVsZW1lbnQgPSBwcm9vZltpXTsKCiAgICAgICAgICAgIGlmIChpbmRleCAlIDIgPT0gMCkgewogICAgICAgICAgICAgICAgaGFzaCA9IGtlY2NhazI1NihhYmkuZW5jb2RlUGFja2VkKGhhc2gsIHByb29mRWxlbWVudCkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgaGFzaCA9IGtlY2NhazI1NihhYmkuZW5jb2RlUGFja2VkKHByb29mRWxlbWVudCwgaGFzaCkpOwogICAgICAgICAgICB9CgogICAgICAgICAgICBpbmRleCA9IGluZGV4IC8gMjsKICAgICAgICB9CgogICAgICAgIHJldHVybiBoYXNoID09IHJvb3Q7CiAgICB9Cn0KCmNvbnRyYWN0IFRlc3RNZXJrbGVQcm9vZiBpcyBNZXJrbGVQcm9vZiB7CiAgICBieXRlczMyW10gcHVibGljIGhhc2hlczsKCiAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICBzdHJpbmdbNF0gbWVtb3J5IHRyYW5zYWN0aW9ucyA9IFsKICAgICAgICAgICAiYWxpY2UgLT4gYm9iIiwKICAgICAgICAgICAiYm9iIC0+IGRhdmUiLAogICAgICAgICAgICJjYXJvbCAtPiBhbGljZSIsCiAgICAgICAgICAgImRhdmUgLT4gYm9iIgogICAgICAgIF07CgogICAgICAgIGZvciAodWludCBpID0gMDsgaSA8IHRyYW5zYWN0aW9ucy5sZW5ndGg7IGkrKykgewogICAgICAgICAgICBoYXNoZXMucHVzaChrZWNjYWsyNTYoYWJpLmVuY29kZVBhY2tlZCh0cmFuc2FjdGlvbnNbaV0pKSk7CiAgICAgICAgfQoKICAgICAgICB1aW50IG4gPSB0cmFuc2FjdGlvbnMubGVuZ3RoOwogICAgICAgIHVpbnQgb2Zmc2V0ID0gMDsKCiAgICAgICAgd2hpbGUgKG4gPiAwKSB7CiAgICAgICAgICAgIGZvciAodWludCBpID0gMDsgaSA8IG4gLSAxOyBpICs9IDIpIHsKICAgICAgICAgICAgICAgIGhhc2hlcy5wdXNoKAogICAgICAgICAgICAgICAgICAgIGtlY2NhazI1NigKICAgICAgICAgICAgICAgICAgICAgICAgYWJpLmVuY29kZVBhY2tlZChoYXNoZXNbb2Zmc2V0ICsgaV0sIGhhc2hlc1tvZmZzZXQgKyBpICsgMV0pCiAgICAgICAgICAgICAgICAgICAgKQogICAgICAgICAgICAgICAgKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBvZmZzZXQgKz0gbjsKICAgICAgICAgICAgbiA9IG4gLyAyOwogICAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlvbiBnZXRSb290KCkgcHVibGljIHZpZXcgcmV0dXJucyAoYnl0ZXMzMikgewogICAgICAgIHJldHVybiBoYXNoZXNbaGFzaGVzLmxlbmd0aCAtIDFdOwogICAgfQoKICAgIC8qIHZlcmlmaWNhCiAgICAzcmQgbGVhZgogICAgMHhkY2EzMzI2YWQ3ZTgxMjFiZjljZjljMTIzMzNlNmIyMjcxYWJlODIzZWM5ZWRmZTQyZjgxM2IxZTc2OGZhNTdiCgogICAgcm9vdAogICAgMHhjYzA4NmZjYzAzODE4OWI0NjQxZGIyY2M0ZjFkZTNiYjEzMmFlZmJkNjVkNTEwZDgxNzU5MTU1MDkzNzgxOGM3CgogICAgaW5kZXgKICAgIDIKCiAgICBwcm92YQogICAgMHg4ZGE5ZTFjODIwZjlkYmQxNTg5ZmQ2NTg1ODcyYmMxMDYzNTg4NjI1NzI5ZTdhYjA3OTdjZmM2M2EwMGJkOTUwCiAgICAweDk5NTc4OGZmYzEwM2I5ODdhZDUwZjVlNTcwN2ZkMDk0NDE5ZWIxMmQ5NTUyY2M0MjNiZDBjZDg2YTM4NjE0MzMKICAgICovCn0=&version=soljson-v0.8.20+commit.a1b79de6.js)
158 changes: 158 additions & 0 deletions src/exemplos/aplicacoes/bloqueio-de-tempo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Bloqueio de tempo

`TimeLock` é um contrato que publica uma transação a ser executada no futuro. Após um período de espera mínimo, a transação pode ser executada.

`TimeLocks` são comumente usados ​​em DAOs.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract TimeLock {
error NotOwnerError();
error AlreadyQueuedError(bytes32 txId);
error TimestampNotInRangeError(uint blockTimestamp, uint timestamp);
error NotQueuedError(bytes32 txId);
error TimestampNotPassedError(uint blockTimestmap, uint timestamp);
error TimestampExpiredError(uint blockTimestamp, uint expiresAt);
error TxFailedError();

event Queue(
bytes32 indexed txId,
address indexed target,
uint value,
string func,
bytes data,
uint timestamp
);
event Execute(
bytes32 indexed txId,
address indexed target,
uint value,
string func,
bytes data,
uint timestamp
);
event Cancel(bytes32 indexed txId);

uint public constant MIN_DELAY = 10; // segundos
uint public constant MAX_DELAY = 1000; // segundos
uint public constant GRACE_PERIOD = 1000; // segundos

address public owner;
// tx id => queued
mapping(bytes32 => bool) public queued;

constructor() {
owner = msg.sender;
}

modifier onlyOwner() {
if (msg.sender != owner) {
revert NotOwnerError();
}
_;
}

receive() external payable {}

function getTxId(
address _target,
uint _value,
string calldata _func,
bytes calldata _data,
uint _timestamp
) public pure returns (bytes32) {
return keccak256(abi.encode(_target, _value, _func, _data, _timestamp));
}

/**
* @param _target Address of contract or account to call
* @param _value Amount of ETH to send
* @param _func Function signature, for example "foo(address,uint256)"
* @param _data ABI encoded data send.
* @param _timestamp Timestamp after which the transaction can be executed.
*/
function queue(
address _target,
uint _value,
string calldata _func,
bytes calldata _data,
uint _timestamp
) external onlyOwner returns (bytes32 txId) {
txId = getTxId(_target, _value, _func, _data, _timestamp);
if (queued[txId]) {
revert AlreadyQueuedError(txId);
}
// ---|------------|---------------|-------
// block block + min block + max
if (
_timestamp < block.timestamp + MIN_DELAY ||
_timestamp > block.timestamp + MAX_DELAY
) {
revert TimestampNotInRangeError(block.timestamp, _timestamp);
}

queued[txId] = true;

emit Queue(txId, _target, _value, _func, _data, _timestamp);
}

function execute(
address _target,
uint _value,
string calldata _func,
bytes calldata _data,
uint _timestamp
) external payable onlyOwner returns (bytes memory) {
bytes32 txId = getTxId(_target, _value, _func, _data, _timestamp);
if (!queued[txId]) {
revert NotQueuedError(txId);
}
// ----|-------------------|-------
// timestamp timestamp + período de carência
if (block.timestamp < _timestamp) {
revert TimestampNotPassedError(block.timestamp, _timestamp);
}
if (block.timestamp > _timestamp + GRACE_PERIOD) {
revert TimestampExpiredError(block.timestamp, _timestamp + GRACE_PERIOD);
}

queued[txId] = false;

// preparar dados
bytes memory data;
if (bytes(_func).length > 0) {
// data = func selector + _data
data = abi.encodePacked(bytes4(keccak256(bytes(_func))), _data);
} else {
// chamada de fallback com dados
data = _data;
}

// alvo de chamada
(bool ok, bytes memory res) = _target.call{value: _value}(data);
if (!ok) {
revert TxFailedError();
}

emit Execute(txId, _target, _value, _func, _data, _timestamp);

return res;
}

function cancel(bytes32 _txId) external onlyOwner {
if (!queued[_txId]) {
revert NotQueuedError(_txId);
}

queued[_txId] = false;

emit Cancel(_txId);
}
}
```

## Teste no Remix

- [TimeLock.sol](https://remix.ethereum.org/#code=Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbW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QpOwogICAgfQp9&version=soljson-v0.8.20+commit.a1b79de6.js)
Loading