Code Monkey home page Code Monkey logo

openzeppelin-contracts's Introduction

OpenZeppelin

NPM Package Coverage Status GitPOAPs Docs Forum

A library for secure smart contract development. Build on a solid foundation of community-vetted code.

🧙 Not sure how to get started? Check out Contracts Wizard — an interactive smart contract generator.

🏗️ Want to scale your decentralized application? Check out OpenZeppelin Defender — a mission-critical developer security platform to code, audit, deploy, monitor, and operate with confidence.

Important

OpenZeppelin Contracts uses semantic versioning to communicate backwards compatibility of its API and storage layout. For upgradeable contracts, the storage layout of different major versions should be assumed incompatible, for example, it is unsafe to upgrade from 4.9.3 to 5.0.0. Learn more at Backwards Compatibility.

Overview

Installation

Hardhat (npm)

$ npm install @openzeppelin/contracts

Foundry (git)

Warning

When installing via git, it is a common error to use the master branch. This is a development branch that should be avoided in favor of tagged releases. The release process involves security measures that the master branch does not guarantee.

Warning

Foundry installs the latest version initially, but subsequent forge update commands will use the master branch.

$ forge install OpenZeppelin/openzeppelin-contracts

Add @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ in remappings.txt.

Usage

Once installed, you can use the contracts in the library by importing them:

pragma solidity ^0.8.20;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MyCollectible is ERC721 {
    constructor() ERC721("MyCollectible", "MCO") {
    }
}

If you're new to smart contract development, head to Developing Smart Contracts to learn about creating a new project and compiling your contracts.

To keep your system secure, you should always use the installed code as-is, and neither copy-paste it from online sources nor modify it yourself. The library is designed so that only the contracts and functions you use are deployed, so you don't need to worry about it needlessly increasing gas costs.

Learn More

The guides in the documentation site will teach about different concepts, and how to use the related contracts that OpenZeppelin Contracts provides:

  • Access Control: decide who can perform each of the actions on your system.
  • Tokens: create tradeable assets or collectives, and distribute them via Crowdsales.
  • Utilities: generic useful tools including non-overflowing math, signature verification, and trustless paying systems.

The full API is also thoroughly documented, and serves as a great reference when developing your smart contract application. You can also ask for help or follow Contracts's development in the community forum.

Finally, you may want to take a look at the guides on our blog, which cover several common use cases and good practices. The following articles provide great background reading, though please note that some of the referenced tools have changed, as the tooling in the ecosystem continues to rapidly evolve.

Security

This project is maintained by OpenZeppelin with the goal of providing a secure and reliable library of smart contract components for the ecosystem. We address security through risk management in various areas such as engineering and open source best practices, scoping and API design, multi-layered review processes, and incident response preparedness.

The OpenZeppelin Contracts Security Center contains more details about the secure development process.

The security policy is detailed in SECURITY.md as well, and specifies how you can report security vulnerabilities, which versions will receive security patches, and how to stay informed about them. We run a bug bounty program on Immunefi to reward the responsible disclosure of vulnerabilities.

The engineering guidelines we follow to promote project quality can be found in GUIDELINES.md.

Past audits can be found in audits/.

Smart contracts are a nascent technology and carry a high level of technical risk and uncertainty. Although OpenZeppelin is well known for its security audits, using OpenZeppelin Contracts is not a substitute for a security audit.

OpenZeppelin Contracts is made available under the MIT License, which disclaims all warranties in relation to the project and which limits the liability of those that contribute and maintain the project, including OpenZeppelin. As set out further in the Terms, you acknowledge that you are solely responsible for any use of OpenZeppelin Contracts and you assume all risks associated with any such use.

Contribute

OpenZeppelin Contracts exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the contribution guide!

License

OpenZeppelin Contracts is released under the MIT License.

Legal

Your use of this Project is governed by the terms found at www.openzeppelin.com/tos (the "Terms").

openzeppelin-contracts's People

Contributors

abcoathup avatar adklempner avatar amxx avatar aniket-engg avatar augustol avatar azavalla avatar demibrener avatar dependabot-preview[bot] avatar dependabot[bot] avatar ernestognw avatar facuspagnuolo avatar frangio avatar fulldecent avatar githubpang avatar izqui avatar jakub-wojciechowski avatar julianmrodri avatar julissadantes avatar k06a avatar makoto avatar maraoz avatar martriay avatar nventuro avatar pcaversaccio avatar renansouza2 avatar renovate[bot] avatar rudygodoy avatar shrugs avatar spalladino avatar theethernaut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openzeppelin-contracts's Issues

Condition Oriented Programming?

Do you all have any thoughts on Condition Oriented Programming? I've seen a couple places where branching logic is in the methods, most often something like if (foo) throw;. Which still seems like it could be pulled out into modifiers. Does Zeppelin have any stance on this pattern?

It definitely requires more code, and could be more expensive. But on the positive side, there is cleaner separation of concerns, limited complexity, and I think the expressiveness that comes with naming modifiers is very valuable.

Better code reuse tools

Current Solidity code reuse is based on copy-pasting or downloading existing code from other repositories. Mature ecosystems have good code repository management systems such as NodeJS’ npm or Ruby’s gems.
An interesting variation in Ethereum is the possibility of reusing code already deployed to the blockchain. Let's build tools that allow to easily link your contracts to deployed libraries.

Superuser: Upgradeable security for Smart Contracts

Scenario: you create a small crowdsale for your widget and it becomes really popular very quickly. Now there is a million dollar price tag on the poorly secured private key you used to deploy your contract and you start sleeping badly at night. Nobody worth their salt would secure a million dollars in a hot wallet.

Luckily, you remember that your contract inherits from Superuser, so next morning you generate a key in cold storage and take note of its address. You then use your owner account to configureSuperuser(address) and your sleep improves again because any sensitive method is using the requireSuperuser modifier. This modifier ensures that msg.sender is the superuser or (in case no superuser is configured, the owner). BOOM! Upgradeable security and peace of mind.

I will have a working implementation later today. Feel free to leave any feedback.

UPDATE: As was pointed out in the Slack channel, this is not a good example, as you can just transfer the ownership of the contract. A better example is when you want to keep a hot key for performing managerial actions but have a cold storage key as superuser in case the hot key is compromised.

Vault contract

The idea is to create a contract for fund management that is separate from other contract/business logic. In this way, we can define clear interfaces for dealing with funds and reduce the attack surface on contracts managing funds.

Implement 2 line separation between top level declarations

The Solidity style guide recommends a 2 line separation between top level declarations, so we should format files like this:

pragma solidity ^0.4.4;


import "../MyImport.sol";


/*
 * MyContract
 * Here goes the contract description
 */
contract MyContract {
  ...
}

Timed/Periodic payments helpers

Contracts want to send periodic or timed payments. E.g: "send x ether to this address every week for 5 weeks". Or "Send x ether to this address in 10 days".

We should write a contract that does that securely

Better oracle interfaces

An important part of smart contract development is how to interact with off-blockchain data sources.

An interesting idea to explore is to do inversion of control, where oracles call contracts (to communicate outside truths) through a common interface method, and can implement their oracle logic as wanted: trusted expert, closed voting, open voting, API wrapper.
Instead of contracts requesting data from oracles, oracles inform contracts of data changes.

Add Versioning mechanism

Pulling zeppelin-solidity into a project does not support any visibility into which version of zeppelin-solidity is actually being used

Malicious adversary contracts for stress-testing

It might be helpful to provide a set of "adversarial" contracts that would help people write tests for common bugs and vulnerabilities. Some ideas:

  • A contract that pushes the call stack down to 1023 frames before calling some other function
  • A contract that responds in weird/nonstandard ways to being sent a transaction
  • A contract that uses reentrancy to try to break things?

Not sure how easy it would be to implement these flexibly and reusably. It might require first-class functions.

does not install on my windows 10

$ npm i zeppelin-solidity

[email protected] install C:\projects\truffle-dapps\coinmaker\node_modul es\zeppelin-solidity
scripts/install.sh

'scripts' is not recognized as an internal or external command,
operable program or batch file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\projects\truffle-dap ps\coinmaker\package.json'
npm WARN coinmaker No description
npm WARN coinmaker No repository field.
npm WARN coinmaker No README data
npm WARN coinmaker No license field.
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\Rocky\AppData\ Roaming\npm\node_modules\npm\bin\npm-cli.js" "i" "zeppelin-solidity"
npm ERR! node v6.7.0
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: scripts/install.sh
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'scripts/install.s h'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the zeppelin-solidity pac kage,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! scripts/install.sh
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs zeppelin-solidity
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls zeppelin-solidity
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\projects\truffle-dapps\coinmaker\npm-debug.log

Rocky@ASUS MINGW64 /c/projects/truffle-dapps/coinmaker
$ node --version
v6.7.0

Rocky@ASUS MINGW64 /c/projects/truffle-dapps/coinmaker
$ npm --version
3.10.8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.