evm 101
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract Counter {
|
||||
uint256 private data = 1337;
|
||||
|
||||
function increment(uint256 val) public {
|
||||
// forge debug contracts/test/foundry/protocol-academy/8-evm/Counter.t.sol --sig 'increment(uint256)' 10
|
||||
data += val;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract Hash {
|
||||
bytes data = hex"42";
|
||||
|
||||
function sha3() public {
|
||||
// forge debug contracts/test/foundry/protocol-academy/8-evm/Hash.sol --sig 'sha3()'
|
||||
|
||||
// Follow the opcodes:
|
||||
// how does the data get loaded
|
||||
// which one is keccak256
|
||||
keccak256(data);
|
||||
}
|
||||
|
||||
function sha2() public {
|
||||
// forge debug contracts/test/foundry/protocol-academy/8-evm/Hash.sol --sig 'sha2()'
|
||||
|
||||
// Follow the opcodes:
|
||||
// why is sha256 so different from keccak256
|
||||
sha256(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2022 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract Memory {
|
||||
|
||||
function expand() public {
|
||||
// forge debug contracts/test/foundry/protocol-academy/8-evm/Memory.sol --sig 'expand()'
|
||||
|
||||
// Observe the free memory pointer increase
|
||||
// when more memory is allocated
|
||||
bytes1[3] memory data;
|
||||
}
|
||||
|
||||
function mstore() public {
|
||||
// forge debug contracts/test/foundry/protocol-academy/8-evm/Memory.sol --sig 'mstore()'
|
||||
|
||||
// Observe the free memory pointer increase
|
||||
// when more memory is allocated
|
||||
bytes1[3] memory data;
|
||||
// Observe each value being set in the memory
|
||||
// slots
|
||||
data[1] = 0x42;
|
||||
data[0] = 0x0a;
|
||||
data[2] = 0xff;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user